Trait Hasher

Source
pub trait Hasher:
    Clone
    + Send
    + Sync
    + 'static {
    type Digest: Digest;

    // Required methods
    fn new() -> Self;
    fn update(&mut self, message: &[u8]);
    fn finalize(&mut self) -> Self::Digest;
    fn reset(&mut self);
}
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).

This trait is required to implement the Clone trait because it is often part of a struct that is cloned. In practice, implementations do not actually clone the hasher state but users should not rely on this behavior and call reset after cloning.

Required Associated Types§

Source

type Digest: Digest

Digest generated by the hasher.

Required Methods§

Source

fn new() -> Self

Create a new hasher.

Source

fn update(&mut self, message: &[u8])

Append message to previously recorded data.

Source

fn finalize(&mut self) -> Self::Digest

Hash all recorded data and reset the hasher to the initial state.

Source

fn reset(&mut self)

Reset the hasher without generating a hash.

This function does not need to be called after finalize.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§