switch to blake2_simd

This commit is contained in:
NikVolf 2019-09-24 10:34:27 +02:00
parent 79cba2e500
commit 4cbc0451c1
2 changed files with 9 additions and 5 deletions

View File

@ -12,4 +12,4 @@ quickcheck = "0.8"
derive_more = "0.15"
bigint = "4"
byteorder = "1"
blake2 = { package = "blake2-rfc", git = "https://github.com/gtank/blake2-rfc.git", rev = "7a5b5fc99ae483a0043db7547fb79a6fa44b88a9" }
blake2 = { package = "blake2b_simd", version = "0.5" }

View File

@ -1,6 +1,6 @@
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt, ByteOrder};
use bigint::U256;
use blake2::blake2b::Blake2b;
use blake2::Params as Blake2Params;
pub const MAX_NODE_DATA_SIZE: usize = 32 + 4 + 4 + 4 + 4 + 32 + 32 + 32 + 9 + 9 + 9; // 171
@ -23,10 +23,14 @@ pub struct NodeData {
}
fn blake2b_personal(personalization: &[u8], input: &[u8]) -> [u8; 32] {
let mut hasher = Blake2b::with_params(32, &[], &[], personalization);
hasher.update(input);
let hash_result = Blake2Params::new()
.hash_length(32)
.personal(personalization)
.to_state()
.update(input)
.finalize();
let mut result = [0u8; 32];
result.copy_from_slice(hasher.finalize().as_bytes());
result.copy_from_slice(hash_result.as_bytes());
result
}