Skip to main content

CryptographicHasher

Trait CryptographicHasher 

Source
pub trait CryptographicHasher<Item: Clone, Out>: Clone {
    const LANES: usize = 1;
    const PREFER_CONTIGUOUS_INPUT: bool = false;

    // Required method
    fn hash_iter<I>(&self, input: I) -> Out
       where I: IntoIterator<Item = Item>;

    // Provided methods
    fn hash_iter_slices<'a, I>(&self, input: I) -> Out
       where I: IntoIterator<Item = &'a [Item]>,
             Item: 'a { ... }
    fn hash_slice(&self, input: &[Item]) -> Out { ... }
    fn hash_item(&self, input: Item) -> Out { ... }
    fn hash_many(&self, input: &[Item], out: &mut [Out]) { ... }
}
Expand description

A generic trait for cryptographic hashers that consume an arbitrary sequence of input items and produce a fixed-size output.

This trait abstracts over hash functions in a flexible way, supporting both field elements, scalars, or any other data type that implements Clone.

Provided Associated Constants§

Source

const LANES: usize = 1

Number of equal-length messages this implementation hashes most efficiently in one call.

One means every message is hashed on its own, which is the behaviour of a plain scalar sponge. A vectorized implementation reports how many independent states its permutation advances at once.

Callers read this only to decide whether grouping messages is worth the bookkeeping.

Source

const PREFER_CONTIGUOUS_INPUT: bool = false

Whether materializing a compound input iterator can improve hashing throughput.

Callers concatenating disjoint inputs may use this hint to reuse a contiguous staging buffer and pass its simple iterator to Self::hash_iter. It is not a request to copy inputs that already have an efficient iterator, nor does it affect the digest: the input sequence and message boundaries must stay identical.

Required Methods§

Source

fn hash_iter<I>(&self, input: I) -> Out
where I: IntoIterator<Item = Item>,

Hash an iterator of input items.

§Arguments
  • input: An iterator over items to be hashed.
§Returns

A fixed-size digest of type Out.

Provided Methods§

Source

fn hash_iter_slices<'a, I>(&self, input: I) -> Out
where I: IntoIterator<Item = &'a [Item]>, Item: 'a,

Hash an iterator of slices, by flattening it into a single stream of items.

§Arguments
  • input: An iterator over slices of items to hash.
§Returns

A fixed-size digest of type Out.

Source

fn hash_slice(&self, input: &[Item]) -> Out

Hash a single slice of items.

§Arguments
  • input: A slice of items to hash.
§Returns

A fixed-size digest of type Out.

Source

fn hash_item(&self, input: Item) -> Out

Hash a single item.

§Arguments
  • input: A single item to hash.
§Returns

A fixed-size digest of type Out.

Source

fn hash_many(&self, input: &[Item], out: &mut [Out])

Hash a batch of equal-length messages, one digest per message.

All messages sit back to back in a single slice. The common message length is the input length divided by the digest count:

    input: [ msg_0 | msg_1 | ... | msg_{m-1} ]   m * len items
    out:   [ dig_0 | dig_1 | ... | dig_{m-1} ]   m digests

The default hashes the messages one at a time. An override exists purely to exploit vector hardware and must return the very same digests.

§Panics

Panics if the batch is ragged: the input length must be a whole multiple of the digest count.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<F, Inner, const N: usize, const M: usize> CryptographicHasher<[F; M], [[u8; M]; N]> for SerializingHasher<Inner>
where F: Field, Inner: CryptographicHasher<[u8; M], [[u8; M]; N]>,

Source§

impl<F, Inner, const N: usize, const M: usize> CryptographicHasher<[F; M], [[u32; M]; N]> for SerializingHasher<Inner>
where F: Field, Inner: CryptographicHasher<[u32; M], [[u32; M]; N]>,

Source§

impl<F, Inner, const N: usize, const M: usize> CryptographicHasher<[F; M], [[u64; M]; N]> for SerializingHasher<Inner>
where F: Field, Inner: CryptographicHasher<[u64; M], [[u64; M]; N]>,

Source§

impl<F, Inner, const N: usize> CryptographicHasher<F, [u8; N]> for SerializingHasher<Inner>
where F: Field, Inner: CryptographicHasher<u8, [u8; N]>,

Source§

impl<F, Inner, const N: usize> CryptographicHasher<F, [u32; N]> for SerializingHasher<Inner>
where F: Field, Inner: CryptographicHasher<u32, [u32; N]>,

Source§

impl<F, Inner, const N: usize> CryptographicHasher<F, [u64; N]> for SerializingHasher<Inner>
where F: Field, Inner: CryptographicHasher<u64, [u64; N]>,

Source§

impl<F, PF, P, const WIDTH: usize, const RATE: usize, const OUT: usize> CryptographicHasher<F, [PF; OUT]> for MultiField32Pad10Sponge<F, PF, P, WIDTH, RATE, OUT>

Source§

impl<F, PF, P, const WIDTH: usize, const RATE: usize, const OUT: usize> CryptographicHasher<F, [PF; OUT]> for MultiField32PaddingFreeSponge<F, PF, P, WIDTH, RATE, OUT>

Source§

impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> CryptographicHasher<T, [T; OUT]> for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>

Source§

impl<T, P, const WIDTH: usize, const RATE: usize, const OUT: usize> CryptographicHasher<T, [T; OUT]> for PaddingFreeSponge<P, WIDTH, RATE, OUT>