reth_trie_common/key.rs
1use alloy_primitives::{keccak256, B256};
2
3/// Trait for hashing keys in state.
4pub trait KeyHasher: Default + Clone + Send + Sync + 'static {
5 /// Hashes the given bytes into a 256-bit hash.
6 fn hash_key<T: AsRef<[u8]>>(bytes: T) -> B256;
7}
8
9/// A key hasher that uses the Keccak-256 hash function.
10#[derive(Clone, Debug, Default)]
11pub struct KeccakKeyHasher;
12
13impl KeyHasher for KeccakKeyHasher {
14 fn hash_key<T: AsRef<[u8]>>(bytes: T) -> B256 {
15 keccak256(bytes)
16 }
17}