pub trait MerkleHasher {
const OUT_LEN: usize;
// Required method
fn hash_pair(
&self,
pair: &[[u8; <Self as MerkleHasher>::OUT_LEN]; 2],
) -> [u8; <Self as MerkleHasher>::OUT_LEN];
// Provided methods
fn hash_pairs<const NUM_PAIRS: usize>(
&self,
pairs: &[[[u8; <Self as MerkleHasher>::OUT_LEN]; 2]; NUM_PAIRS],
) -> [[u8; <Self as MerkleHasher>::OUT_LEN]; NUM_PAIRS] { ... }
fn hash_single_leaf(
&self,
leaf: &[u8; <Self as MerkleHasher>::OUT_LEN],
) -> [u8; <Self as MerkleHasher>::OUT_LEN] { ... }
}Expand description
Hash function for inner nodes of Merkle Trees.
Hashing of many pairs at once is a part of the API, such that hash functions like BLAKE3 can use SIMD to hash multiple pairs in parallel.
Required Associated Constants§
Required Methods§
Sourcefn hash_pair(
&self,
pair: &[[u8; <Self as MerkleHasher>::OUT_LEN]; 2],
) -> [u8; <Self as MerkleHasher>::OUT_LEN]
fn hash_pair( &self, pair: &[[u8; <Self as MerkleHasher>::OUT_LEN]; 2], ) -> [u8; <Self as MerkleHasher>::OUT_LEN]
Hash a pair of nodes together
Provided Methods§
Sourcefn hash_pairs<const NUM_PAIRS: usize>(
&self,
pairs: &[[[u8; <Self as MerkleHasher>::OUT_LEN]; 2]; NUM_PAIRS],
) -> [[u8; <Self as MerkleHasher>::OUT_LEN]; NUM_PAIRS]
fn hash_pairs<const NUM_PAIRS: usize>( &self, pairs: &[[[u8; <Self as MerkleHasher>::OUT_LEN]; 2]; NUM_PAIRS], ) -> [[u8; <Self as MerkleHasher>::OUT_LEN]; NUM_PAIRS]
Similar to Self::hash_pair(), but hashes multiple pairs at once.
The default implementation hashes pairs one by one, hash functions that can do better
should override it. An override must return the same as Self::hash_pair() for each pair,
because trees mix both.
Sourcefn hash_single_leaf(
&self,
leaf: &[u8; <Self as MerkleHasher>::OUT_LEN],
) -> [u8; <Self as MerkleHasher>::OUT_LEN]
fn hash_single_leaf( &self, leaf: &[u8; <Self as MerkleHasher>::OUT_LEN], ) -> [u8; <Self as MerkleHasher>::OUT_LEN]
Root of an UnbalancedMerkleTree or MerkleMountainRange with a single leaf.
The default implementation returns the leaf unchanged, which keeps a tree of trees the same as a single larger tree. Hashers that depend on the tree size should hash the leaf instead, otherwise the size isn’t committed to when the tree has a single leaf and no inner nodes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".