Skip to main content

KeccakState

Struct KeccakState 

Source
pub struct KeccakState { /* private fields */ }
Expand description

Keccak sponge state for SHA-3 and SHAKE constructions.

Implements the sponge construction over Keccak-f[1600] with configurable rate and domain-separation suffix. Supports the absorb-then-squeeze paradigm; once squeezing has begun, further absorption is not permitted.

Implementations§

Source§

impl KeccakState

Source

pub fn new(rate: usize, suffix: u8) -> Self

Create a new Keccak sponge state.

  • rate — the sponge rate in bytes (e.g., 168 for SHAKE128, 136 for SHA3-256/SHAKE256, 72 for SHA3-512).
  • suffix — the domain-separation/padding byte (0x06 for SHA-3, 0x1f for SHAKE).
Source

pub fn absorb(&mut self, data: &[u8])

Absorb input bytes into the sponge.

May be called multiple times before squeezing to incrementally feed data. XORs input into the rate portion of the state and applies the Keccak-f permutation whenever a full rate block is filled.

§Panics

Debug-panics if called after squeezing has begun.

Source

pub fn squeeze(&mut self, out: &mut [u8])

Squeeze output bytes from the sponge.

On the first call, finalizes absorption by applying padding and running Keccak-f. Subsequent calls continue squeezing, applying Keccak-f each time the rate buffer is exhausted. May be called multiple times to produce arbitrary-length output (XOF mode).

Auto Trait Implementations§

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> 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, 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.