Skip to content

Commit 99f79eb

Browse files
authored
perf(primitives): use keccak_asm::Keccak256::digest (#1067)
1 parent aeca3ba commit 99f79eb

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ paste = "1.0"
7171

7272
# crypto
7373
k256 = { version = "0.13", default-features = false }
74-
keccak-asm = { version = "0.1.0", default-features = false }
74+
keccak-asm = { version = "0.1.5", default-features = false }
7575
tiny-keccak = { version = "2.0", default-features = false }
7676
sha3 = { version = "0.10.8", default-features = false, features = ["asm"] }
7777

crates/primitives/src/utils/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub fn keccak256_uncached<T: AsRef<[u8]>>(bytes: T) -> B256 {
176176
keccak256_impl(bytes.as_ref())
177177
}
178178

179+
#[allow(unused)]
179180
fn keccak256_impl(bytes: &[u8]) -> B256 {
180181
let mut output = MaybeUninit::<B256>::uninit();
181182

@@ -203,6 +204,8 @@ fn keccak256_impl(bytes: &[u8]) -> B256 {
203204

204205
// SAFETY: The output is 32-bytes, and the input comes from a slice.
205206
unsafe { native_keccak256(bytes.as_ptr(), bytes.len(), output.as_mut_ptr().cast::<u8>()) };
207+
} else if #[cfg(all(feature = "asm-keccak", not(miri)))] {
208+
return B256::new(keccak_asm::Keccak256::digest(bytes).into());
206209
} else {
207210
let mut hasher = Keccak256::new();
208211
hasher.update(bytes);

0 commit comments

Comments
 (0)