Skip to content
This repository has been archived by the owner on Dec 15, 2023. It is now read-only.

Commit

Permalink
Add hash blake2b512
Browse files Browse the repository at this point in the history
  • Loading branch information
kvinwang committed Dec 8, 2023
1 parent a032eae commit 1da255e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/hash-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ bench("sha256", iterations);
bench("keccak256", iterations);
bench("blake2b128", iterations);
bench("blake2b256", iterations);
bench("blake2b512", iterations);
3 changes: 2 additions & 1 deletion src/host_functions/hash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::Result;
use anyhow::bail;
use blake2::{
digest::typenum::{U16, U32},
digest::typenum::{U16, U32, U64},
Blake2b, Digest,
};
use js::AsBytes;
Expand All @@ -24,6 +24,7 @@ fn hash(algorithm: js::JsString, message: AsBytes<Vec<u8>>) -> Result<AsBytes<Ve
"keccak256" => do_hash::<sha3::Keccak256>(message.0),
"blake2b128" => do_hash::<Blake2b<U16>>(message.0),
"blake2b256" => do_hash::<Blake2b<U32>>(message.0),
"blake2b512" => do_hash::<Blake2b<U64>>(message.0),
_ => bail!("Unsupported hash algorithm: {}", algorithm.as_str()),
};
Ok(hash.into())
Expand Down

0 comments on commit 1da255e

Please sign in to comment.