Update sha2@0.9.1 (#938)

* Update sha2@0.9.1

Fixes #915

* Update zebra-chain/src/sprout/keys.rs

Co-authored-by: Jane Lusby <jlusby42@gmail.com>

* Update zebra-chain/src/sprout/note/nullifiers.rs

Co-authored-by: Jane Lusby <jlusby42@gmail.com>
This commit is contained in:
Ramana Venkata 2020-08-22 04:56:14 +05:30 committed by GitHub
parent dda0d2dd41
commit e90137e79b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 21 deletions

2
Cargo.lock generated
View File

@ -3061,7 +3061,7 @@ dependencies = [
"secp256k1",
"serde",
"serde-big-array",
"sha2 0.8.2",
"sha2 0.9.1",
"spandoc",
"thiserror",
"tracing",

View File

@ -25,7 +25,7 @@ ripemd160 = "0.8.0"
secp256k1 = { version = "0.17.2", features = ["serde"] }
serde = { version = "1", features = ["serde_derive", "rc"] }
serde-big-array = "0.3.0"
sha2 = { version = "0.8.2", features=["compress"] }
sha2 = { version = "0.9.1", features=["compress"] }
thiserror = "1"
x25519-dalek = { version = "1", features = ["serde"] }

View File

@ -13,7 +13,7 @@ pub struct Writer {
impl Writer {
/// Consume the Writer and produce the hash result.
pub fn finish(self) -> [u8; 32] {
let result1 = self.hash.result();
let result1 = self.hash.finalize();
let result2 = Sha256::digest(&result1);
let mut buffer = [0u8; 32];
buffer[0..32].copy_from_slice(&result2[0..32]);
@ -23,7 +23,7 @@ impl Writer {
impl Write for Writer {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.hash.input(buf);
self.hash.update(buf);
Ok(buf.len())
}

View File

@ -37,12 +37,12 @@ impl From<Note> for NoteCommitment {
fn from(note: Note) -> NoteCommitment {
let leading_byte: u8 = 0xB0;
let mut hasher = Sha256::default();
hasher.input([leading_byte]);
hasher.input(note.paying_key);
hasher.input(note.value.to_bytes());
hasher.input(note.rho);
hasher.input(note.rcm);
NoteCommitment(hasher.result().into())
hasher.update([leading_byte]);
hasher.update(note.paying_key);
hasher.update(note.value.to_bytes());
hasher.update(note.rho);
hasher.update(note.rcm);
NoteCommitment(hasher.finalize().into())
}
}

View File

@ -11,6 +11,7 @@ use std::{fmt, io};
use byteorder::{ByteOrder, LittleEndian};
use rand_core::{CryptoRng, RngCore};
use sha2::digest::generic_array::{typenum::U64, GenericArray};
#[cfg(test)]
use proptest::{array, prelude::*};
@ -37,17 +38,17 @@ mod sk_magics {
/// https://zips.z.cash/protocol/protocol.pdf#sproutkeycomponents
fn prf_addr(x: [u8; 32], t: u8) -> [u8; 32] {
let mut state = [0u32; 8];
let mut block = [0u8; 64];
let mut block = GenericArray::<u8, U64>::default();
block[0..32].copy_from_slice(&x[..]);
block.as_mut_slice()[0..32].copy_from_slice(&x[..]);
// The first four bits i.e. the most signicant four bits of the
// first byte are used to separate distinct uses
// of SHA256Compress, ensuring that the functions are independent.
block[0] |= 0b1100_0000;
block.as_mut_slice()[0] |= 0b1100_0000;
block[32] = t;
block.as_mut_slice()[32] = t;
sha2::compress256(&mut state, &block);
sha2::compress256(&mut state, &[block]);
let mut derived_bytes = [0u8; 32];
LittleEndian::write_u32_into(&state, &mut derived_bytes);

View File

@ -2,6 +2,7 @@
use byteorder::{ByteOrder, LittleEndian};
use serde::{Deserialize, Serialize};
use sha2::digest::generic_array::{typenum::U64, GenericArray};
use super::super::keys::SpendingKey;
@ -13,17 +14,17 @@ use super::super::keys::SpendingKey;
/// https://zips.z.cash/protocol/protocol.pdf#commitmentsandnullifiers
fn prf_nf(a_sk: [u8; 32], rho: [u8; 32]) -> [u8; 32] {
let mut state = [0u32; 8];
let mut block = [0u8; 64];
let mut block = GenericArray::<u8, U64>::default();
block[0..32].copy_from_slice(&a_sk[..]);
block.as_mut_slice()[0..32].copy_from_slice(&a_sk[..]);
// The first four bits i.e. the most signicant four bits of the
// first byte are used to separate distinct uses
// of SHA256Compress, ensuring that the functions are independent.
block[0] |= 0b1110_0000;
block.as_mut_slice()[0] |= 0b1100_0000;
block[32..].copy_from_slice(&rho[..]);
block.as_mut_slice()[32..].copy_from_slice(&rho[..]);
sha2::compress256(&mut state, &block);
sha2::compress256(&mut state, &[block]);
let mut derived_bytes = [0u8; 32];
LittleEndian::write_u32_into(&state, &mut derived_bytes);

View File

@ -4,7 +4,7 @@ use std::{fmt, io};
use ripemd160::{Digest, Ripemd160};
use secp256k1::PublicKey;
use sha2::Sha256;
use sha2::{Digest as sha2Digest, Sha256};
#[cfg(test)]
use proptest::{arbitrary::Arbitrary, collection::vec, prelude::*};