Sponge

Struct Sponge 

Source
pub struct Sponge<S, T, const W: usize>
where S: Safe<T, W>, T: Default + Copy + Zeroize,
{ /* 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>
where S: Safe<T, W>, T: Default + Copy + Zeroize,

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<S, T, const W: usize> Clone for Sponge<S, T, W>
where S: Safe<T, W> + Clone, T: Default + Copy + Zeroize + Clone,

Source§

fn clone(&self) -> Sponge<S, T, W>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S, T, const W: usize> Debug for Sponge<S, T, W>
where S: Safe<T, W> + Debug, T: Default + Copy + Zeroize + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, T, const W: usize> Drop for Sponge<S, T, W>
where S: Safe<T, W>, T: Default + Copy + Zeroize,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<S, T, const W: usize> PartialEq for Sponge<S, T, W>
where S: Safe<T, W> + PartialEq, T: Default + Copy + Zeroize + PartialEq,

Source§

fn eq(&self, other: &Sponge<S, T, W>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<S, T, const W: usize> Zeroize for Sponge<S, T, W>
where S: Safe<T, W>, T: Default + Copy + Zeroize,

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<S, T, const W: usize> StructuralPartialEq for Sponge<S, T, W>
where S: Safe<T, W>, T: Default + Copy + Zeroize,

Auto Trait Implementations§

§

impl<S, T, const W: usize> Freeze for Sponge<S, T, W>
where S: Freeze, T: Freeze,

§

impl<S, T, const W: usize> RefUnwindSafe for Sponge<S, T, W>

§

impl<S, T, const W: usize> Send for Sponge<S, T, W>
where S: Send, T: Send,

§

impl<S, T, const W: usize> Sync for Sponge<S, T, W>
where S: Sync, T: Sync,

§

impl<S, T, const W: usize> Unpin for Sponge<S, T, W>
where S: Unpin, T: Unpin,

§

impl<S, T, const W: usize> UnwindSafe for Sponge<S, T, W>
where S: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.