commonware_cryptography

Trait Hasher

Source
pub trait Hasher:
    Clone
    + Send
    + 'static {
    // Required methods
    fn new() -> Self;
    fn update(&mut self, message: &[u8]);
    fn finalize(&mut self) -> Digest;
    fn reset(&mut self);
    fn validate(digest: &Digest) -> bool;
    fn len() -> usize;
    fn random<R: Rng + CryptoRng>(rng: &mut R) -> 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).

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 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) -> 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.

Source

fn validate(digest: &Digest) -> bool

Validate the digest.

Source

fn len() -> usize

Size of the digest in bytes.

Source

fn random<R: Rng + CryptoRng>(rng: &mut R) -> Digest

Generate a random digest.

§Warning

This function is typically used for testing and is not recommended for production use.

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§