pub trait Hasher<const N: usize, T> {
// Required method
fn hash(&self, value: &T) -> Digest<N>;
}
Expand description
A hash function outputting a fixed-length digest of N
bytes.
The hash function must produce strong digests with a low probability of collision. Use of a cryptographic hash function is not required, but may be preferred for security/compliance reasons.
Use of a faster hash function results in faster tree operations. Use of
64bit hash values (N <= 8
) and smaller is not recommended due to the
higher probability of collisions.
§Determinism & Portability
Implementations are required to be deterministic across all peers which
compare tree values. Notably the standard library Hash
derive does not
produce portable hashes across differing platforms, endian-ness or Rust
compiler versions.
§Default Implementation
The default Hasher
implementation (SipHasher
) outputs 128-bit/16
byte digests which are strong, but not of cryptographic quality.
SipHasher
uses the standard library Hash
trait, which may produce
non-portable hashes as described above (and in the Hash
documentation).
Users may choose to initialise the SipHasher
with seed keys if untrusted
key/value user input is used in a tree in order to prevent chosen-hash
collision attacks.
The provided SipHasher
implementation is not portable across platforms /
Rust versions due to limitations of the Hash
trait.