pub trait Hasher:
Default
+ Send
+ Sync
+ 'static {
type Digest: Digest;
// Required methods
fn hash(parts: &[&[u8]]) -> Self::Digest;
fn hash_pair(
left: &[&[u8]],
right: &[&[u8]],
) -> (Self::Digest, Self::Digest);
fn update(&mut self, bytes: &[u8]) -> &mut Self;
fn finalize(self) -> (Self, Self::Digest);
}Expand description
Interface that commonware crates rely on for hashing.
Hash functions in commonware primitives are not typically hardcoded to a specific algorithm (e.g. SHA-256) because different hash functions may work better with different cryptographic schemes, may be more efficient to use in STARK/SNARK proofs, or provide different levels of security (with some performance/size penalty).
Hashers are cheap to construct: callers that need a fresh hasher should
create one with Default rather than duplicating an existing instance.
Required Associated Types§
Required Methods§
Sourcefn hash(parts: &[&[u8]]) -> Self::Digest
fn hash(parts: &[&[u8]]) -> Self::Digest
Hash the concatenation of parts in a single shot.
This is the preferred entrypoint for hashing data that is fully available up-front. Implementations are free to specialize this for small, fixed-shape inputs (e.g. hashing a pair of digests) to avoid the overhead of the streaming machinery.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".