light_hasher/
keccak.rs

1use crate::{
2    errors::HasherError,
3    zero_bytes::{keccak::ZERO_BYTES, ZeroBytes},
4    zero_indexed_leaf::keccak::ZERO_INDEXED_LEAF,
5    Hash, Hasher,
6};
7
8#[derive(Clone, Copy)] // To allow using with zero copy Solana accounts.
9pub struct Keccak;
10
11impl Hasher for Keccak {
12    const ID: u8 = 2;
13
14    fn hash(val: &[u8]) -> Result<Hash, HasherError> {
15        Self::hashv(&[val])
16    }
17
18    fn hashv(vals: &[&[u8]]) -> Result<Hash, HasherError> {
19        Ok(solana_nostd_keccak::hashv(vals))
20    }
21
22    fn zero_bytes() -> ZeroBytes {
23        ZERO_BYTES
24    }
25
26    fn zero_indexed_leaf() -> [u8; 32] {
27        ZERO_INDEXED_LEAF
28    }
29}