Keccak-p[1600, 24], SHA3-512 and byte-aligned SHAKE #
This module implements the concrete permutation and byte-aligned extendable-output function from
NIST FIPS 202. The state is a 5 × 5 array of 64-bit lanes. Lane bit z is the
standard's A[x, y, z], and a flat state bit at position 64 * (5 * y + x) + z maps to that
coordinate (Sections 3.1.2--3.1.3). The five round steps follow Algorithms 1--7 and Tables 1--2
in Sections 3.2--3.3; keccakP1600Rounds24 is Algorithm 8's underlying function as specified in
Section 4.
byteSponge implements Algorithms 8--9 for byte-aligned messages at any lane-aligned
Keccak-p[1600] rate/capacity split and explicit domain-separation suffix. Bytes are expanded least
significant bit first, matching NIST's official example state dumps; the suffix and pad10*1 are
appended; rate blocks are processed by the existing Cslib.Crypto.Sponge.hashBlocks; and output
bytes are assembled in the same convention. sha3512 uses the 576-bit rate, suffix 01, and a
64-byte output. shake256 uses the 1088-bit rate and suffix 1111; SHAKE128 specializes the same
machinery in CslibFrontier.Crypto.Primitives.Hash.Keccak.SHAKE128.
This is a checked executable specification, not a constant-time or efficient implementation, a cryptographic security proof, or a claim of validation under FIPS 202. It maps to the published August 2015 standard and does not claim agreement with a future revision or with FN-DSA / FIPS 206.
Main definitions #
Cslib.Crypto.Keccak.State: a5 × 5array of 64-bit lanes.Cslib.Crypto.Keccak.SpongeLayout,SpongeView: a lane-aligned rate/capacity split.Cslib.Crypto.Keccak.theta,rho,pi,chi,iota: the five FIPS 202 round steps.Cslib.Crypto.Keccak.keccakP1600Rounds24: the 24-round state transformation.Cslib.Crypto.Keccak.keccakP1600Rounds24View: the transformation on a selected sponge split.Cslib.Crypto.Keccak.byteBitsLE,bytesToBitsLE,bitsToByteLE: the explicit FIPS 202 least-significant-bit-first byte boundary.Cslib.Crypto.Keccak.rateBytesFor,squeezeBytesFor,byteSponge: shared byte-aligned sponge machinery parameterized by the layout and domain-separation suffix.Cslib.Crypto.Keccak.sha3512: byte-aligned SHA3-512.Cslib.Crypto.Keccak.shake256: byte-aligned SHAKE256 with an output length in bytes.
Main results #
Cslib.Crypto.Keccak.bitsToByteLE_byteBitsLE,byteBitsLE_bitsToByteLE: the byte boundary round trips.Cslib.Crypto.Keccak.toSpongeView_ofSpongeView,ofSpongeView_toSpongeView: the selected state views are inverse.Cslib.Crypto.Keccak.length_byteSponge,take_byteSponge: the shared sponge has the requested length and preserves prefixes for a fixed suffix.Cslib.Crypto.Keccak.length_sha3512: SHA3-512 returns exactly 64 bytes.Cslib.Crypto.Keccak.length_shake256,take_shake256: SHAKE256 returns exactly the requested byte count, and longer requests preserve the preceding XOF bytes.
References #
- National Institute of Standards and Technology, SHA-3 Standard: Permutation-Based Hash and Extendable-Output Functions, FIPS PUB 202, August 2015, Sections 3.1.2--3.3, Algorithms 1--9, Tables 1--2 and Section 6.2.
- NIST, official SHAKE256 examples for the 0-bit and 1600-bit messages.
A 64-bit lane in the Keccak-p[1600] state. Bit-vector position zero is coordinate z = 0.
The 25 lanes of a Keccak-p[1600] state in FIPS 202's flat order 5 * y + x.
The vector representation makes each round materialize all lanes once. This avoids the exponential recomputation that would result from composing 24 rounds as nested state functions.
A lane-aligned rate/capacity split of the 25-lane Keccak-p[1600] state.
The rate and capacity bit-string views selected by a lane-aligned sponge layout.
The SHA3-512 layout: nine rate lanes and sixteen capacity lanes.
The SHAKE256 layout: 17 rate lanes and eight capacity lanes.
The sponge rate and capacity views used by SHAKE256.
Reduce a natural-number state coordinate modulo five.
The flat FIPS 202 lane index corresponding to state coordinates (x, y).
Read the Keccak state lane A[x, y].
The rotation offset for lane (x, y), from FIPS 202 Table 2, reduced modulo 64.
The 24 round constants for Keccak-f[1600], in round order.
FIPS 202 Algorithm 1, the column-parity step θ.
FIPS 202 Algorithm 3, the lane-permutation step π.
FIPS 202 Algorithm 6, the round-constant step ι.
One FIPS 202 round: ι ∘ χ ∘ π ∘ ρ ∘ θ.
FIPS 202 KECCAK-p[1600, 24], equivalently KECCAK-f[1600], on lane arrays.
Pack 64 least-significant-bit-first coordinates into a lane.
Reading an in-range coordinate of laneOfBits returns the corresponding input bit.
Shared lane-aligned sponge adapter #
Convert a lane-aligned rate/capacity split into the FIPS 202 lane array.
A rate lane reads the corresponding 64 rate coordinates.
A capacity lane reads the corresponding 64 capacity coordinates.
Convert the FIPS 202 lane array into a selected rate/capacity split.
Converting a selected sponge view to lanes and back preserves every state bit.
Converting a lane state to a selected sponge view and back preserves every lane.
Keccak-p[1600, 24] on a lane-aligned sponge view.
Shared byte-aligned sponge machinery #
Expand a byte into FIPS 202 bit-string order, least significant bit first.
Each serialized FIPS 202 byte contributes exactly eight bits.
Pack the first eight least-significant-bit-first coordinates into a byte.
Expanding one byte least-significant bit first and reading it back recovers the byte.
Reading an eight-bit word as a byte and expanding it recovers the word.
Packing an aligned bit string eight bits at a time and expanding recovers the string.
Little-endian expansion preserves all the information in a byte string.
The FIPS 202 little-endian bijection between a fixed byte string and its bit register.
The register has precisely the bits that the underlying SHAKE byte stream returns.
The first n bytes expand to the first 8 * n bits, including truncated inputs.
Read the rate selected by layout as consecutive little-endian bytes.
A lane-aligned rate exposes eight bytes per lane.
Absorb padded blocks and expose count squeezed rate states as bytes.
count squeezing blocks contain 8 * rateLanes * count bytes.
Requesting more squeezing blocks preserves every byte of the earlier blocks.
Absorb an arbitrary bit string with a distinguished suffix and FIPS 202 padding, then squeeze the requested number of little-endian bytes.
Byte-aligned Keccak sponge with the rate and capacity selected by layout and the supplied
domain-separation suffix, whose bits are listed in FIPS 202 bit-string order.
The output length is measured in bytes. The input bytes and output bytes are little-endian at the
bit boundary, and FIPS 202's pad10*1 follows the suffix.
An arbitrary bit-string input produces exactly the requested number of output bytes.
A byte-aligned sponge returns exactly the requested byte count.
For a fixed suffix, byte-aligned sponge output is prefix-consistent across requested lengths.
Byte-aligned SHAKE with the rate and capacity selected by layout.
The output length is measured in bytes. Every specialization uses the SHAKE suffix 1111 and
FIPS 202's pad10*1; layout changes only the rate/capacity split.
A byte-aligned XOF returns exactly the requested byte count.
SHA3-512 specialization #
Byte-aligned SHA3-512 from FIPS 202 Section 6.1.
The input bytes use the explicit little-endian bit convention of bytesToBitsLE. The suffix is
the SHA-3 domain separator 01 in FIPS bit-string order, and the digest is 64 bytes.
SHAKE256 specialization #
Convert the SHAKE256 rate/capacity split into the FIPS 202 lane array.
A SHAKE256 rate lane reads the corresponding 64 rate coordinates.
A SHAKE256 capacity lane reads the corresponding 64 capacity coordinates.
Convert the FIPS 202 lane array into SHAKE256's 1088-bit rate and 512-bit capacity split.
Converting a SHAKE256 sponge split to lanes and back preserves every state bit.
Converting a lane state to the SHAKE256 split and back preserves every lane.
FIPS 202 KECCAK-p[1600, 24] on SHAKE256's rate/capacity split.
Read the 1088-bit SHAKE256 rate as 136 consecutive little-endian bytes.
count SHAKE256 squeezing blocks contain exactly 136 * count bytes.
Requesting more SHAKE256 squeezing blocks preserves every byte of the earlier blocks.