Replace SHA3 with BLAKE2b everywhere

This commit is contained in:
Ignotus Peverell
2017-07-20 13:52:07 +00:00
parent 9703cba92a
commit 01b66de437
7 changed files with 23 additions and 30 deletions
+8 -7
View File
@@ -19,9 +19,10 @@
use std::cmp::min;
use std::{fmt, ops};
use tiny_keccak::Keccak;
use std::convert::AsRef;
use blake2::blake2b::Blake2b;
use ser::{self, Reader, Readable, Writer, Writeable, Error, AsFixedBytes};
/// A hash consisting of all zeroes, used as a sentinel. No known preimage.
@@ -129,28 +130,28 @@ impl Writeable for Hash {
/// Serializer that outputs a hash of the serialized object
pub struct HashWriter {
state: Keccak,
state: Blake2b,
}
impl HashWriter {
/// Consume the `HashWriter`, outputting its current hash into a 32-byte
/// array
pub fn finalize(self, output: &mut [u8]) {
self.state.finalize(output);
output.copy_from_slice(self.state.finalize().as_bytes());
}
/// Consume the `HashWriter`, outputting a `Hash` corresponding to its
/// current state
pub fn into_hash(self) -> Hash {
let mut new_hash = ZERO_HASH;
self.state.finalize(&mut new_hash.0[..]);
new_hash
let mut res = [0; 32];
(&mut res).copy_from_slice(self.state.finalize().as_bytes());
Hash(res)
}
}
impl Default for HashWriter {
fn default() -> HashWriter {
HashWriter { state: Keccak::new_sha3_256() }
HashWriter { state: Blake2b::new(32) }
}
}
+1 -1
View File
@@ -23,6 +23,7 @@
#[macro_use]
extern crate bitflags;
extern crate blake2_rfc as blake2;
extern crate byteorder;
extern crate crypto;
extern crate num_bigint as bigint;
@@ -32,7 +33,6 @@ extern crate serde;
#[macro_use]
extern crate serde_derive;
extern crate time;
extern crate tiny_keccak;
#[macro_use]
pub mod macros;