Skip to main content

MultiDigest

Trait MultiDigest 

Source
pub trait MultiDigest<const N: usize>: Clone {
    type Digest: Digest;

    // Required methods
    fn new() -> Self;
    fn update(&mut self, data: [&[u8]; N]);
    fn finalize_into(self, out: &mut [MaybeUninit<Output<Self::Digest>>; N]);
    fn finalize_into_reset(
        &mut self,
        out: &mut [MaybeUninit<Output<Self::Digest>>; N],
    );
    fn reset(&mut self);
    fn digest(
        data: [&[u8]; N],
        out: &mut [MaybeUninit<Output<Self::Digest>>; N],
    );

    // Provided methods
    fn new_with_prefix(data: impl AsRef<[u8]>) -> Self { ... }
    fn chain_update(self, data: [&[u8]; N]) -> Self { ... }
}
Expand description

An object that efficiently computes N instances of a cryptographic hash function in parallel.

This trait is useful when there is a more efficient way of calculating multiple digests at once, e.g. using SIMD instructions. It is supposed that this trait is implemented directly for some digest and some fixed N and passed as an implementation of the ParallelDigest trait which hides the N value.

Required Associated Types§

Source

type Digest: Digest

The corresponding non-parallelized hash function.

Required Methods§

Source

fn new() -> Self

Create new hasher instance with empty state.

Source

fn update(&mut self, data: [&[u8]; N])

Process data, updating the internal state. The number of rows in data must be equal to parallel_instances().

Source

fn finalize_into(self, out: &mut [MaybeUninit<Output<Self::Digest>>; N])

Write result into provided array and consume the hasher instance.

Source

fn finalize_into_reset( &mut self, out: &mut [MaybeUninit<Output<Self::Digest>>; N], )

Write result into provided array and reset the hasher instance.

Source

fn reset(&mut self)

Reset hasher instance to its initial state.

Source

fn digest(data: [&[u8]; N], out: &mut [MaybeUninit<Output<Self::Digest>>; N])

Compute hash of data. All slices in the data must have the same length.

§Panics

Panics if data contains slices of different lengths.

Provided Methods§

Source

fn new_with_prefix(data: impl AsRef<[u8]>) -> Self

Create new hasher instance which has processed the provided data.

Source

fn chain_update(self, data: [&[u8]; N]) -> Self

Process input data in a chained manner.

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§