universal_hash

Trait UniversalHash

Source
pub trait UniversalHash: BlockSizeUser + Sized {
    // Required methods
    fn update_with_backend(
        &mut self,
        f: impl UhfClosure<BlockSize = Self::BlockSize>,
    );
    fn finalize(self) -> Block<Self>;

    // Provided methods
    fn update(&mut self, blocks: &[Block<Self>]) { ... }
    fn update_padded(&mut self, data: &[u8]) { ... }
    fn finalize_reset(&mut self) -> Block<Self>
       where Self: Clone + Reset { ... }
    fn verify(self, expected: &Block<Self>) -> Result<(), Error> { ... }
}
Expand description

The UniversalHash trait defines a generic interface for universal hash functions.

Required Methods§

Source

fn update_with_backend( &mut self, f: impl UhfClosure<BlockSize = Self::BlockSize>, )

Update hash function state using the provided rank-2 closure.

Source

fn finalize(self) -> Block<Self>

Retrieve result and consume hasher instance.

Provided Methods§

Source

fn update(&mut self, blocks: &[Block<Self>])

Update hash function state with the provided block.

Source

fn update_padded(&mut self, data: &[u8])

Input data into the universal hash function. If the length of the data is not a multiple of the block size, the remaining data is padded with zeroes up to the BlockSize.

This approach is frequently used by AEAD modes which use Message Authentication Codes (MACs) based on universal hashing.

Source

fn finalize_reset(&mut self) -> Block<Self>
where Self: Clone + Reset,

Obtain the [Output] of a UniversalHash computation and reset it back to its initial state.

Source

fn verify(self, expected: &Block<Self>) -> Result<(), Error>

Verify the UniversalHash of the processed input matches a given expected value.

This is useful when constructing Message Authentication Codes (MACs) from universal hash functions.

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§