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
impl KeccakState
Sourcepub fn new(rate: usize, suffix: u8) -> Self
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).
Sourcepub fn absorb(&mut self, data: &[u8])
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.
Sourcepub fn squeeze(&mut self, out: &mut [u8])
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).