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§
Sourcetype Parameters
type Parameters
Parameters used by the sponge.
Required Methods§
Sourcefn new(params: &Self::Parameters) -> Self
fn new(params: &Self::Parameters) -> Self
Initialize a new instance of the sponge.
Sourcefn squeeze_bytes(&mut self, num_bytes: usize) -> Vec<u8> ⓘ
fn squeeze_bytes(&mut self, num_bytes: usize) -> Vec<u8> ⓘ
Squeeze num_bytes bytes from the sponge.
Sourcefn squeeze_bits(&mut self, num_bits: usize) -> Vec<bool>
fn squeeze_bits(&mut self, num_bits: usize) -> Vec<bool>
Squeeze num_bits bits from the sponge.
Provided Methods§
Sourcefn squeeze_field_elements_with_sizes<F: PrimeField>(
&mut self,
sizes: &[FieldElementSize],
) -> Vec<F>
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}]
Sourcefn squeeze_field_elements<F: PrimeField>(
&mut self,
num_elements: usize,
) -> Vec<F>
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.
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.