Documentation

CslibFrontier.Crypto.Computational.MLDSA.RandomXof

Finite random XOFs shared by the ML-DSA algorithms and quantum queries #

A coherent address encodes the SHAKE variant, a delimiter and the input bits. A random table supplies independent bytes on the encoded words and a fixed background supplies the remaining inputs and suffixes. The byte-table factorization is used for both the SHAKE128 public matrix and the SHAKE256 signing masks.

def Cslib.Crypto.MLDSA.FIPS204.Xofs.queryAddress (a : ℕ) (strength : Bool) (x : List Bool) :
x.length ≤ a → BitString (a + 2)

Encode a raw word of at most a bits in the coherent address register. The first bit selects SHAKE256 when set and SHAKE128 otherwise. Leading zero padding and a one-bit delimiter preserve the input length, including empty inputs and inputs starting with zero.

Decode a measured SHAKE256 address. A missing address, SHAKE128 tag or missing delimiter has no SHAKE256 input.

def Cslib.Crypto.MLDSA.FIPS204.Xofs.queryTable (H : Xofs) (a bytes : ℕ) (address : BitString (a + 2)) :
BitString (8 * bytes)

The XOR oracle's output bits in FIPS 202 least-significant-bit-first order. An address without a delimiter has the all-zero response.

theorem Cslib.Crypto.MLDSA.FIPS204.Xofs.shake256QueryInput_of_queryTable_ne {a b : ℕ} {H G : Xofs} (h128 : H.h128 = G.h128) {addr : Option (BitString (a + 2))} (hit : Option.any (fun (v : BitString (a + 2)) => decide (H.queryTable a b v ≠ G.queryTable a b v)) addr = true) :
∃ (raw : List Bool), shake256QueryInput addr = some raw ∧ H.h256.read raw b ≠ G.h256.read raw b

When the SHAKE128 streams agree, unequal coherent responses identify a successfully decoded SHAKE256 address whose two raw byte reads differ.

theorem Cslib.Crypto.MLDSA.FIPS204.Xofs.queryTable_queryAddress (H : Xofs) (a bytes : ℕ) (strength : Bool) (x : List Bool) (hx : x.length ≤ a) :
List.ofFn (H.queryTable a bytes (queryAddress a strength x hx)) = Keccak.bytesToBitsLE ((if strength = true then H.h256 else H.h128).read x bytes)

A coherent query at each encodable raw word reads the very stream used by FIPS, at the full device response length. Shorter reads use its prefix.

noncomputable def Cslib.Crypto.MLDSA.FIPS204.Xofs.uniformPrefixes (background : Xofs) (a bytes : ℕ) :

Sample one finite prefix table for both raw XOFs before the execution. Each raw input of at most a bits receives bytes independent uniform bytes for each SHAKE variant. The background supplies longer inputs and bytes beyond these prefixes.

Replace the prefix bytes at every n-bit SHAKE256 input with the supplied byte list, retaining longer suffixes, other input lengths and SHAKE128.

Replace the first k bytes at every n-bit SHAKE256 input using little-endian register words, retaining the other bytes and SHAKE128.

Installing k-byte rows directly as lists agrees with installing their little-endian bit-string encodings.

Read the first k SHAKE256 bytes on every n-bit input as little-endian bit strings.

Reading all k-byte prefixes at n-bit inputs from the current streams and reinstalling them preserves every raw query, including SHAKE256 output beyond the prefix.

theorem Cslib.Crypto.MLDSA.FIPS204.Xofs.uniformPrefixes_prefixRegister (base : Xofs) (n k : ℕ) {a b : ℕ} (ha : n ≤ a) (hb : k ≤ b) :
((base.uniformPrefixes a b).bind fun (H : Xofs) => PMF.map (fun (D : BitString n → BitString (8 * k)) => (D, H.withPrefixRegister n k D)) (Probability.PMF.uniformOfFintype (BitString n → BitString (8 * k)))) = PMF.map (fun (H : Xofs) => (H.readPrefixRegister n k, H)) (base.uniformPrefixes a b)

Independently replacing the first k SHAKE256 bytes at every n-bit input preserves the joint law of the replacement register and both full raw XOFs. The finite prefix limits must cover these inputs and outputs.

Decode the raw input wires for a fixed-length SHAKE256 prefix lookup. A malformed address selects zero, and the native raw response ignores the selected word there.

theorem Cslib.Crypto.MLDSA.FIPS204.Xofs.queryTable_withPrefixLists (H : Xofs) (n a b : ℕ) (R : BitString n → List Byte) :
(H.withPrefixLists n R).queryTable a b = fun (x : BitString (a + 2)) => (H.withPrefixLists n fun (x_1 : BitString n) => R (prefixLookup n x)).queryTable a b x

A native raw query to an installed byte-list prefix table reads at most one entry. The equality also covers SHAKE128, malformed words and requests extending beyond the installed prefix.

theorem Cslib.Crypto.MLDSA.FIPS204.Xofs.queryTable_withPrefixRegister (H : Xofs) (n k a b : ℕ) (D : BitString n → BitString (8 * k)) :
(H.withPrefixRegister n k D).queryTable a b = fun (x : BitString (a + 2)) => (H.withPrefixRegister n k fun (x_1 : BitString n) => D (prefixLookup n x)).queryTable a b x

A native raw query to the installed table reads at most one register value. The equality also covers SHAKE128, malformed words and requests extending beyond the installed prefix.