Documentation

CslibFrontier.Crypto.Primitives.Hash.Keccak.SHAKE128

SHAKE128 #

This module supplies byte-aligned SHAKE128 on the checked Keccak-p[1600, 24] permutation from Cslib.Crypto.Keccak. FIPS 202 Section 6.2 gives SHAKE128 a 1344-bit rate and 256-bit capacity. Bytes use the same least-significant-bit-first convention as shake256; the only sponge-level difference is the rate/capacity split.

This is an executable specification with a uniform multitape-Turing-machine polynomial-time certificate. It is not a constant-time implementation, a concrete retained-machine cost bound, a security certificate, or a claim of FIPS validation.

Main definitions #

Main results #

References #

The SHAKE128 layout: 21 rate lanes and four capacity lanes.

@[reducible, inline]

The 1344-bit rate and 256-bit capacity views used by SHAKE128.

Convert the SHAKE128 rate/capacity split into the FIPS 202 lane array.

theorem Cslib.Crypto.Keccak.get_ofShake128SpongeState_rate (state : Shake128SpongeState) (lane : Fin 25) (h : ↑lane < 21) :
Vector.get (ofShake128SpongeState state) lane = laneOfBits fun (z : Fin 64) => state.1 ⟨64 * ↑lane + ↑z, ⋯⟩

A SHAKE128 rate lane reads the corresponding 64 rate coordinates.

theorem Cslib.Crypto.Keccak.get_ofShake128SpongeState_capacity (state : Shake128SpongeState) (lane : Fin 25) (h : ¬↑lane < 21) :
Vector.get (ofShake128SpongeState state) lane = laneOfBits fun (z : Fin 64) => state.2 ⟨64 * (↑lane - 21) + ↑z, ⋯⟩

A SHAKE128 capacity lane reads the corresponding 64 capacity coordinates.

Convert the FIPS 202 lane array into SHAKE128's rate and capacity split.

Converting a SHAKE128 rate/capacity split to lanes and back preserves every state bit.

Converting a lane state to the SHAKE128 split and back preserves every lane.

FIPS 202 KECCAK-p[1600, 24] on SHAKE128's rate/capacity split.

Read the 1344-bit SHAKE128 rate as 168 consecutive little-endian bytes.

@[simp]

One SHAKE128 rate block contains exactly 168 output bytes.

def Cslib.Crypto.Keccak.shake128SqueezeBytes (blocks : List (BitString 1344)) (count : ℕ) :
List (Fin 256)

Absorb padded SHAKE128 blocks and expose count squeezed rate states as bytes.

@[simp]
theorem Cslib.Crypto.Keccak.length_shake128SqueezeBytes (blocks : List (BitString 1344)) (count : ℕ) :
(shake128SqueezeBytes blocks count).length = 168 * count

count SHAKE128 squeezing blocks contain exactly 168 * count bytes.

theorem Cslib.Crypto.Keccak.take_shake128SqueezeBytes (blocks : List (BitString 1344)) {m n : ℕ} (h : m ≤ n) :

Requesting more SHAKE128 squeezing blocks preserves every byte of the earlier blocks.

def Cslib.Crypto.Keccak.shake128 (input : List (Fin 256)) (outputBytes : ℕ) :
List (Fin 256)

Byte-aligned SHAKE128 from FIPS 202 Section 6.2.

The second argument is measured in output bytes. It changes only how much of the XOF stream is returned, not the preceding bytes.

@[simp]
theorem Cslib.Crypto.Keccak.length_shake128 (input : List (Fin 256)) (outputBytes : ℕ) :
(shake128 input outputBytes).length = outputBytes

SHAKE128 returns exactly the requested number of bytes.

theorem Cslib.Crypto.Keccak.take_shake128 (input : List (Fin 256)) {m n : ℕ} (h : m ≤ n) :
List.take m (shake128 input n) = shake128 input m

SHAKE128 is prefix-consistent: requesting more output never changes preceding bytes.

SHAKE128 is uniformly polynomial-time when the requested number of output bytes is unary.