Unverified Commit d0e29735 authored by Hero Bird's avatar Hero Bird Committed by GitHub

[core] update crypto hasher dependencies 0.8 -> 0.9 (#445)

parent 13eb43e2
Pipeline #96402 passed with stages
in 14 minutes and 12 seconds
......@@ -30,9 +30,9 @@ generic-array = "0.14.1"
paste = "0.1"
# Hashes for the off-chain environment.
sha2 = { version = "0.8", optional = true }
sha3 = { version = "0.8", optional = true }
blake2 = { version = "0.8", optional = true }
sha2 = { version = "0.9", optional = true }
sha3 = { version = "0.9", optional = true }
blake2 = { version = "0.9", optional = true }
# Only used in the off-chain environment.
#
......
......@@ -16,13 +16,13 @@
/// Helper routine implementing variable size BLAKE2b hash computation.
fn blake2b_var(size: usize, input: &[u8], output: &mut [u8]) {
use blake2::digest::VariableOutput as _;
use std::io::Write as _;
use ::blake2::digest::{
Update as _,
VariableOutput as _,
};
let mut blake2 = blake2::VarBlake2b::new_keyed(&[], size);
blake2
.write_all(input)
.expect("failed to compute BLAKE2b hash of input");
output.copy_from_slice(blake2.vec_result().as_slice());
blake2.update(input);
blake2.finalize_variable(|result| output.copy_from_slice(result));
}
/// Conduct the BLAKE2 256-bit hash and place the result into `output`.
......@@ -37,16 +37,28 @@ pub fn blake2b_128(input: &[u8], output: &mut [u8; 16]) {
/// Conduct the KECCAK 256-bit hash and place the result into `output`.
pub fn keccak_256(input: &[u8], output: &mut [u8; 32]) {
use ::sha2::Digest as _;
use ::sha3::{
digest::{
generic_array::GenericArray,
FixedOutput as _,
},
Digest as _,
};
let mut hasher = ::sha3::Keccak256::new();
hasher.input(input);
output.copy_from_slice(hasher.result().as_slice());
hasher.update(input);
hasher.finalize_into(<&mut GenericArray<u8, _>>::from(&mut output[..]));
}
/// Conduct the SHA2 256-bit hash and place the result into `output`.
pub fn sha2_256(input: &[u8], output: &mut [u8; 32]) {
use ::sha2::Digest as _;
use ::sha2::{
digest::{
generic_array::GenericArray,
FixedOutput as _,
},
Digest as _,
};
let mut hasher = ::sha2::Sha256::new();
hasher.input(input);
output.copy_from_slice(hasher.result().as_slice());
hasher.update(input);
hasher.finalize_into(<&mut GenericArray<u8, _>>::from(&mut output[..]));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment