CryptographicSponge

Trait CryptographicSponge 

Source
pub trait CryptographicSponge: Clone {
    type Parameters;

    // Required methods
    fn new(params: &Self::Parameters) -> Self;
    fn absorb(&mut self, input: &impl Absorb);
    fn squeeze_bytes(&mut self, num_bytes: usize) -> Vec<u8> ;
    fn squeeze_bits(&mut self, num_bits: usize) -> Vec<bool>;

    // Provided methods
    fn squeeze_field_elements_with_sizes<F: PrimeField>(
        &mut self,
        sizes: &[FieldElementSize],
    ) -> Vec<F> { ... }
    fn squeeze_field_elements<F: PrimeField>(
        &mut self,
        num_elements: usize,
    ) -> Vec<F> { ... }
    fn fork(&self, domain: &[u8]) -> Self { ... }
}
Expand description

The interface for a cryptographic sponge. A sponge can absorb or take in inputs and later squeeze or output bytes or field elements. The outputs are dependent on previous absorb and squeeze calls.

Required Associated Types§

Source

type Parameters

Parameters used by the sponge.

Required Methods§

Source

fn new(params: &Self::Parameters) -> Self

Initialize a new instance of the sponge.

Source

fn absorb(&mut self, input: &impl Absorb)

Absorb an input into the sponge.

Source

fn squeeze_bytes(&mut self, num_bytes: usize) -> Vec<u8>

Squeeze num_bytes bytes from the sponge.

Source

fn squeeze_bits(&mut self, num_bits: usize) -> Vec<bool>

Squeeze num_bits bits from the sponge.

Provided Methods§

Source

fn squeeze_field_elements_with_sizes<F: PrimeField>( &mut self, sizes: &[FieldElementSize], ) -> Vec<F>

Squeeze sizes.len() field elements from the sponge, where the i-th element of the output has size sizes[i].

If the implementation is field-based, to squeeze native field elements, call self.squeeze_native_field_elements instead.

TODO: Support general Field.

Note that when FieldElementSize is FULL, the output is not strictly uniform. Output space is uniform in [0, 2^{F::MODULUS_BITS - 1}]

Source

fn squeeze_field_elements<F: PrimeField>( &mut self, num_elements: usize, ) -> Vec<F>

Squeeze num_elements nonnative field elements from the sponge.

Because of rust limitation, for field-based implementation, using this method to squeeze native field elements will have runtime casting cost. For better efficiency, use squeeze_native_field_elements.

Source

fn fork(&self, domain: &[u8]) -> Self

Creates a new sponge with applied domain separation.

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§