pub struct Pad10Sponge<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> { /* private fields */ }Expand description
An overwrite-mode sponge with 10-padding.
Absorbs input into the rate, permutes after each full block, and
squeezes OUT elements. Two-case padding ensures collision
resistance for inputs of variable length.
§Padding Rule
Case 1 – partial block (input ends at position i < RATE):
Sentinel at position i, zeros after, then permute.
[a] RATE=2: [a, S, 0, ... | cap...] -> P
[a, 0] RATE=2: [a, 0, S, ... | cap...] -> P
^
different position => no collisionCase 2 – full block (input length is a multiple of RATE):
Add sentinel to first capacity element, then permute.
[a, b] RATE=2: [a, b | cap_0 + S, cap_1, ...] -> PSentinel lands in rate (case 1) vs capacity (case 2), so no length-k input can collide with any length != k.
§Role of the Derangement
The padding function is a derangement d: a permutation with no fixed points (d(x) != x for all x). This guarantees:
- Rate-domain: d(0) != 0, so the sentinel is always non-zero.
- Capacity-domain: d(state[RATE]) != state[RATE], so the capacity always changes.
Partial: state[i] = d(0) -- sentinel
Full: state[RATE] = d(state[RATE]) -- domain separator§Construction
The padding function is a derangement (permutation with no fixed
points). The standard choice is Increment which computes d(x) = x + 1:
Pad10Sponge::new(permutation, Increment(BabyBear::ONE)) // field
Pad10Sponge::new(permutation, Increment(1u64)) // integerThe derangement must have no fixed points (d(x) != x for all x).
§Parameters
WIDTH– total state size (rate + capacity).RATE– positions overwritten per block.OUT– elements squeezed from the final state.
§Security
Indifferentiable from a random oracle up to |F|^{c/2} queries (c = WIDTH - RATE).
Implies collision resistance, preimage resistance, etc. [BDPA08] + [LBM25, Section 3.1].
Implementations§
Trait Implementations§
Source§impl<T, P: Clone, D: Clone, const WIDTH: usize, const RATE: usize, const OUT: usize> Clone for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
impl<T, P: Clone, D: Clone, const WIDTH: usize, const RATE: usize, const OUT: usize> Clone for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
impl<T, P: Copy, D: Copy, const WIDTH: usize, const RATE: usize, const OUT: usize> Copy for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
Source§impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> CryptographicHasher<T, [T; OUT]> for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> CryptographicHasher<T, [T; OUT]> for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
Source§fn hash_iter<I>(&self, input: I) -> [T; OUT]where
I: IntoIterator<Item = T>,
fn hash_iter<I>(&self, input: I) -> [T; OUT]where
I: IntoIterator<Item = T>,
Source§fn hash_iter_slices<'a, I>(&self, input: I) -> Outwhere
I: IntoIterator<Item = &'a [Item]>,
Item: 'a,
fn hash_iter_slices<'a, I>(&self, input: I) -> Outwhere
I: IntoIterator<Item = &'a [Item]>,
Item: 'a,
Source§fn hash_slice(&self, input: &[Item]) -> Out
fn hash_slice(&self, input: &[Item]) -> Out
Auto Trait Implementations§
impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> Freeze for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> RefUnwindSafe for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> Send for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> Sync for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> Unpin for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> UnsafeUnpin for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>where
P: UnsafeUnpin,
D: UnsafeUnpin,
impl<T, P, D, const WIDTH: usize, const RATE: usize, const OUT: usize> UnwindSafe for Pad10Sponge<T, P, D, WIDTH, RATE, OUT>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more