Documentation

CslibFrontier.Crypto.Computational.MLDSA.RejNTTProgramming

Programming the byte stream of RejNTTPoly #

For the bounded matrix sampler in FIPS 204, Algorithms 14 and 30, interchange the first accepted coefficients with an external polynomial. The transformation retains the ignored high bits, rejected triples and remaining bytes of the XOF prefix. Applying it twice recovers the entire original input, including when the sampler exhausts its prefix. This gives an exact coupling on the joint space of raw bytes and NTT coefficients.

Interchange the first 256 accepted coefficients of a finite SHAKE128 byte prefix with a polynomial in NTT order. On exhaustion the exchange stops at the last accepted coefficient.

Two forward exchanges restore the complete byte row and supplied polynomial, also when too few coefficients were accepted.

theorem Cslib.Crypto.MLDSA.FIPS204.exchangeRejNTT_of_some {n : ℕ} {bytes : FixedBytes n} {u : Poly} (h : rejNTTPoly (List.ofFn bytes) = some u) (v : Poly) :
have z := (exchangeRejNTT n) (bytes, v); rejNTTPoly (List.ofFn z.1) = some v ∧ z.2 = u

When Algorithm 30 succeeds, the programmed bytes decode to the supplied polynomial and the exchange returns the original polynomial.

The bounded sampler exhausts exactly the same prefixes after programming.

theorem Cslib.Crypto.MLDSA.FIPS204.uniform_exchangeRejNTT (n : ℕ) :
PMF.map (fun (x : FixedBytes n × Poly) => match x with | (bytes, v) => (((exchangeRejNTT n) (bytes, v)).1, Option.map (fun (x : Poly) => v) (rejNTTPoly (List.ofFn bytes)))) (Probability.PMF.uniformOfFintype (FixedBytes n × Poly)) = PMF.map (fun (bytes : Fin n → Byte) => (bytes, rejNTTPoly (List.ofFn bytes))) (Probability.PMF.uniformOfFintype (FixedBytes n))

Joint law of the entire raw SHAKE128 prefix and the bounded Algorithm 30 answer. Drawing uniform bytes and an independent uniform polynomial, exchanging them and reporting the external polynomial on success gives the very same law as reading the polynomial from the bytes. The equality includes the finite-prefix failure event.