Documentation

CslibFrontier.Crypto.Computational.MLDSA.RandomXofMask

Algorithm 34 masks in the shared random-XOF signing game #

FIPS 204, Algorithms 7 and 34, read one SHAKE256 stream per 64-byte masking seed and two-byte nonce. BitUnpack sends its initial bytes bijectively to the signed coefficient box. The table is indexed by the literal 528-bit input and sampled before any key generation or quantum interaction. Its other uses, including Algorithm 33 at a coincident address and longer adversarial queries, see the same bytes. When those expansion bytes are private, the full capped signing loop has the same signature-or-failure law as drawing a fresh mask from signingMaskLaw on every attempt. Both executions hash each commitment with the ambient XOF and stop on sparse-challenge exhaustion.

@[reducible, inline]

One signed integer from Algorithm 34's half-open interval (-γ₁, γ₁].

Instances For
    @[reducible, inline]

    At a 528-bit masking seed and nonce address, store all 256 signed coefficients.

    The raw SHAKE256 word for one Algorithm 34 polynomial, including the two-byte nonce. Algorithm 33 accesses precisely the same stream if supplied the same word.

    noncomputable def Cslib.Crypto.MLDSA.FIPS204.Xofs.sampleWithMasks (base : Xofs) {s : Level} {a b : ℕ} (ha : 528 ≤ a) (hb : maskPolyBytes s ≤ b) (masks : MaskTable s) :

    Sample the finite raw XOF pair with its Algorithm 34 prefixes set to the packed signed polynomials in masks. Every other sampled byte, including each longer stream suffix, is independent and uniform. The background supplies bytes beyond the finite table.

    Installing independent uniform signed mask coefficients before key generation preserves the distribution of the entire finite pair of raw SHAKE oracles. Any subsequent signing and coherent quantum access, including repeated or overlapping reads, uses that same pair.

    theorem Cslib.Crypto.MLDSA.FIPS204.Xofs.read_mask_of_mem_sampleWithMasks {base H : Xofs} {s : Level} {a b : ℕ} {ha : 528 ≤ a} {hb : maskPolyBytes s ≤ b} {masks : MaskTable s} (h : H ∈ (base.sampleWithMasks ha hb masks).support) (seed : FixedBytes 64) (nonce : ℕ) :
    H.h256.readBytes (nonceInput seed.toList nonce) (maskPolyBytes s) = packSigned (s.params.γ₁.log2 + 1) s.params.γ₁ fun (x : Fin 1) (j : Fin 256) => ↑↑(masks (maskAddress seed nonce) j)

    The raw SHAKE256 read at the seed and nonce returns the FIPS packing of the supplied coefficients. This is also the stream available to Algorithm 33 and coherent prefix queries.

    theorem Cslib.Crypto.MLDSA.FIPS204.Xofs.expandMask_of_mem_sampleWithMasks {base H : Xofs} {s : Level} {a b : ℕ} {ha : 528 ≤ a} {hb : maskPolyBytes s ≤ b} {masks : MaskTable s} (h : H ∈ (base.sampleWithMasks ha hb masks).support) (seed : FixedBytes 64) (κ : ℕ) (i : Fin s.params.ℓ) (j : Fin 256) :
    ((H.expandMask s seed.toList κ).get i).get j = ↑↑(masks (maskAddress seed (κ + ↑i)) j)

    At every oracle in the sampled pair, the actual Algorithm 34 decoder returns the specified signed coefficients at the actual raw input. This is simultaneous over all masking seeds and counters, including seeds chosen from that same oracle and all 814 signing attempts.

    All 814 scheduled Algorithm 34 masks have the joint IID law used by the signing simulator.

    Reading the 814 scheduled mask polynomials from a uniform two-byte-indexed XOF row table produces i.i.d. uniform masks in the signing mask distribution.

    theorem Cslib.Crypto.MLDSA.FIPS204.Xofs.privateMaskRetries_eq_iid (H : Xofs) (s : Level) (sk : PrivateKey s) (A : PublicMatrix s) (μ : List Bool) :
    have finish := fun (y : Fin s.params.ℓ → Poly) => have w := moduleSISMap A y; have d := H.commitmentDigest s (highBitsVec s.params w) μ; finishSigningAttempt s sk y w d (H.sampleInBall s d); PMF.map (fun (row : FixedBytes 2 → FixedBytes (maskPolyBytes s)) => H.signingRetries s sk A μ (maskFromRow s row)) (Probability.PMF.uniformOfFintype (FixedBytes 2 → FixedBytes (maskPolyBytes s))) = PMF.map Option.join (List.findSomeM? (fun (x : ℕ) => PMF.map (fun (y : Fin s.params.ℓ → Poly) => (finish y).elim (some none) (Option.map some)) (signingMaskLaw s.params ⋯)) (List.range 814))

    Drawing independent full-width bytes per nonce and drawing a fresh mask from the signing simulator's coefficient box give the same native 814-attempt signing result. The ambient commitment and challenge XOF is fixed throughout. Sparse expansion failure stops signing, whereas a rejected response advances to the next mask.

    The quantum signing trial with the independent uniform lattice matrix and a pre-sampled table of signed masking coefficients has the joint law of the matrix-prefix hybrid averaged over the finite random XOFs. The equality retains both raw oracles, the public key, final forgery, whole signing log and setup failures, so it applies in particular to the fresh-digest event.

    The original finite random-XOF strong-forgery game equals the execution with independent uniform matrix and signed-mask table. The sampled widths cover the literal mask addresses and the full 894-byte matrix prefixes, in addition to the shorter Algorithm 34 reads.

    theorem Cslib.Crypto.MLDSA.FIPS204.QuantumSigningForger.expandMask_of_mem_programmedTrial (C : QuantumSigningForger) {s : Level} {a b : ℕ} {base H : Xofs} {ha : 528 ≤ a} {hb : maskPolyBytes s ≤ b} {masks : MaskTable s} (hH : H ∈ (base.sampleWithMasks ha hb masks).support) {A : PublicMatrix s} {u : SignedMatrixTrial s} (hu : some u ∈ (C.programmedTrial s H A).support) (seed : FixedBytes 64) (κ : ℕ) (i : Fin s.params.ℓ) (j : Fin 256) :
    ((u.xofs.expandMask s seed.toList κ).get i).get j = ↑↑(masks (maskAddress seed (κ + ↑i)) j)

    The SHAKE128 matrix installation leaves the entire SHAKE256 stream from the supplied mask table intact. Thus even a seed selected after earlier coherent queries or signing replies reads the very same coefficients at every counter of a surviving trial.