pub struct Sponge<S, T, const W: usize>{ /* private fields */ }Expand description
Struct that implements the Sponge API over field elements.
The capacity is fixed to one field element and the rate are W - 1 field
elements.
Implementations§
Source§impl<S, T, const W: usize> Sponge<S, T, W>
impl<S, T, const W: usize> Sponge<S, T, W>
Sourcepub fn start(
safe: S,
iopattern: impl Into<Vec<Call>>,
domain_sep: u64,
) -> Result<Self, Error>
pub fn start( safe: S, iopattern: impl Into<Vec<Call>>, domain_sep: u64, ) -> Result<Self, Error>
This initializes the sponge, setting the first element of the state to
the Safe::tag() and the other elements to the default value of
T. It’s done once in the lifetime of a sponge.
§Parameters
safe: The sponge safe implementation.iopattern: The IO-pattern for the sponge.domain_sep: The domain separator to be used.
§Returns
A result containing the initialized Sponge on success, or an Error if
the IO-pattern is invalid.
Sourcepub fn finish(self) -> Result<Vec<T>, Error>
pub fn finish(self) -> Result<Vec<T>, Error>
This marks the end of the sponge life, preventing any further operation. In particular, the state is erased from memory.
§Returns
A result containing the output vector on success, or an Error if the
IO-pattern wasn’t followed.
Sourcepub fn absorb(
&mut self,
len: usize,
input: impl AsRef<[T]>,
) -> Result<(), Error>
pub fn absorb( &mut self, len: usize, input: impl AsRef<[T]>, ) -> Result<(), Error>
This absorbs len field elements from the input into the state with
interleaving calls to the permutation function. It also checks if the
call matches the IO-pattern.
§Parameters
len: The number of field elements to absorb.input: The input slice of field elements.
§Returns
A result indicating success if the operation completes, or an Error
if the IO-pattern wasn’t followed.
Sourcepub fn squeeze(&mut self, len: usize) -> Result<(), Error>
pub fn squeeze(&mut self, len: usize) -> Result<(), Error>
This extracts len field elements from the state with interleaving
calls to the permutation function. It also checks if the call matches
the IO-pattern.
§Parameters
len: The number of field elements to squeeze.
§Returns
A result indicating success if the operation completes, or an Error
if the IO-pattern wasn’t followed.