af_price_updates/keccak.rs
1//! Keccak-256, the hash that Aftermath and Pyth Lazer signatures are made over and Stork asset
2//! IDs are encoded with.
3
4/// Keccak-256 of `bytes`, as used by Ethereum, Sui's `ecdsa_k1` and Stork asset IDs.
5pub fn keccak256(bytes: &[u8]) -> [u8; 32] {
6 use tiny_keccak::{Hasher, Keccak};
7 let mut hasher = Keccak::v256();
8 hasher.update(bytes);
9 let mut digest = [0; 32];
10 hasher.finalize(&mut digest);
11 digest
12}
13
14#[cfg(test)]
15mod tests {
16 use super::*;
17
18 #[test]
19 fn keccak256_of_empty_input() {
20 // Keccak-256, not the SHA3-256 standardized later.
21 assert_eq!(
22 const_hex::encode(keccak256(b"")),
23 "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
24 );
25 }
26}