airbender_crypto/sha3/
naive.rs1use sha3::Digest;
2pub use sha3::Keccak256;
3
4impl crate::MiniDigest for Keccak256 {
5 type HashOutput = [u8; 32];
6
7 #[inline(always)]
8 fn new() -> Self {
9 <Keccak256 as Digest>::new()
10 }
11
12 #[inline(never)]
14 fn digest(input: impl AsRef<[u8]>) -> Self::HashOutput {
15 let mut hasher = <Keccak256 as Digest>::new();
16 <Keccak256 as Digest>::update(&mut hasher, input);
17 let digest = <Keccak256 as Digest>::finalize(hasher);
18 let mut result = [0u8; 32];
19 #[allow(deprecated)] result.copy_from_slice(digest.as_ref());
21 result
22 }
23
24 #[inline(always)]
25 fn update(&mut self, input: impl AsRef<[u8]>) {
26 <Keccak256 as Digest>::update(self, input);
27 }
28
29 #[inline(always)]
30 fn finalize(self) -> Self::HashOutput {
31 <Keccak256 as Digest>::finalize(self).into()
32 }
33
34 #[inline(always)]
35 fn finalize_reset(&mut self) -> Self::HashOutput {
36 <Keccak256 as Digest>::finalize_reset(self).into()
37 }
38}