Documentation

CslibFrontier.Crypto.Computational.MLDSA.Signing

Bounded ML-DSA signing #

FIPS 204 Algorithm 7 signs by rejection sampling. After the response and low-bits checks on line 23, line 28 performs a second rejection check: ‖c t₀‖∞ < γ₂, and the hint has at most ω set coefficients. This module adds that complete two-stage acceptance predicate to the existing semantic ML-DSA surface and gives executable bounded-loop semantics.

The source-shaped loop takes an explicit mask schedule. Attempt i uses the counter κ + i ℓ, matching Algorithm 7 line 31. Exhausting the supplied attempt limit returns none. This pure result represents the standard's single error result, but does not model destruction of intermediate state or side-channel behavior. The byte signer in MLDSA.FIPS204Signing supplies the concrete seeded mask and challenge and uses the same response calculation.

Appendix C, Table 3 of the published FIPS 204 gives 814 as the minimum permitted bounded signing limit under its stated hash/XOF distribution assumptions. This module does not derive the standard's failure estimate from the semantic mask model.

Main definitions #

Main results #

References #

def Cslib.Crypto.MLDSA.hintWeight (P : Params) (h : Fin P.k → Fin P.n → Bool) :

Number of set coefficients in an ML-DSA hint vector. This is the quantity compared with ω on line 28 of FIPS 204 Algorithm 7.

def Cslib.Crypto.MLDSA.LowProductShort (P : Params) (ct₀ : Fin P.k → Fin P.n → ZMod P.q) :

The line-28 norm check ‖c t₀‖∞ < γ₂, stated for the already-computed product.

Instances For
    @[instance_reducible]
    def Cslib.Crypto.MLDSA.tabulateRingVector {rows n q : ℕ} (f : Fin rows → Fin n → ZMod q) :
    Vector (Vector (ZMod q) n) rows

    Store the coefficients of a polynomial vector once, for repeated access during signing.

    def Cslib.Crypto.MLDSA.ringVectorCoeffs {rows n q : ℕ} (values : Vector (Vector (ZMod q) n) rows) :
    Fin rows → Fin n → ZMod q

    Read the coefficient polynomials of a stored vector.

    Reading the materialized vector returns the original coefficients.

    def Cslib.Crypto.MLDSA.compressedResponse (P : Params) (ω : ℕ) (s₁ : Fin P.ℓ → Fin P.n → ZMod P.q) (s₂ t₀ : Fin P.k → Fin P.n → ZMod P.q) (y : Fin P.ℓ → Fin P.n → ZMod P.q) (w : Fin P.k → Fin P.n → ZMod P.q) (c : Fin P.n → ZMod P.q) :

    Algorithm 7 lines 18--30. Given the signer's low public-key term and sampled challenge, return the response and hint precisely when both rejection stages pass.

    def Cslib.Crypto.MLDSA.compressedSignAttempt (P : Params) (d ω : ℕ) (H : Hash P) (sk : SecretKey P) (msg : List Bool) (y : Fin P.ℓ → Fin P.n → ZMod P.q) :

    One semantic execution of FIPS 204 Algorithm 7 lines 11--30.

    The hash and mask are still the abstract values used by Basic.lean; seed expansion, the message representative, byte encodings and malformed-input behavior are not modeled here. Unlike signAttempt, this compressed attempt constructs the FIPS hint and includes both line-28 checks.

    theorem Cslib.Crypto.MLDSA.signAttempt_eq_some_of_compressedSignAttempt_eq_some (P : Params) (d ω : ℕ) (H : Hash P) (sk : SecretKey P) (msg : List Bool) (y : Fin P.ℓ → Fin P.n → ZMod P.q) {σ : CompressedSignature P} (hout : compressedSignAttempt P d ω H sk msg y = some σ) :
    signAttempt P H sk msg y = some { z := σ.z, c := σ.c }

    Every compressed attempt output is also the corresponding output of the uncompressed signAttempt; the compressed attempt only adds the second-stage checks and the hint.

    theorem Cslib.Crypto.MLDSA.recovered_of_compressedResponse (P : Params) (hP : P.Valid) (hγq : 4 * P.γ₂ < P.q) {d ω : ℕ} {sk : SecretKey P} {y : Fin P.ℓ → Fin P.n → ZMod P.q} {c : Fin P.n → ZMod P.q} (hc : InBall P.τ c) (hs₂ : ∀ (i : Fin P.k) (j : Fin P.n), |(sk.s₂ i j).valMinAbs| ≤ ↑P.η) {σ : CompressedSignature P} (hout : compressedResponse P ω sk.s₁ sk.s₂ (publicKeyLowPart P d sk.publicKey) y (moduleSISMap sk.A y) c = some σ) :
    ResponseShort P σ.z ∧ hintWeight P σ.h ≤ ω ∧ σ.c = c ∧ (fun (i : Fin P.k) => useHintVec P.q P.γ₂ (σ.h i) (compressedVerifierCommitment P d sk.publicKey σ.z σ.c i)) = highBitsVec P (moduleSISMap sk.A y)

    Every accepted Algorithm 7 response has the prescribed response and hint bounds and reconstructs the exact high-bit commitment used by the signer.

    theorem Cslib.Crypto.MLDSA.compressedVerify_compressedSignAttempt (P : Params) (hP : P.Valid) (hγq : 4 * P.γ₂ < P.q) {d ω : ℕ} {H : Hash P} (hH : ∀ (x : (Fin P.k → Fin P.n → ℤ) × List Bool), InBall P.τ (H x)) {sk : SecretKey P} (hs₂ : ∀ (i : Fin P.k) (j : Fin P.n), |(sk.s₂ i j).valMinAbs| ≤ ↑P.η) {msg : List Bool} {y : Fin P.ℓ → Fin P.n → ZMod P.q} {σ : CompressedSignature P} (hout : compressedSignAttempt P d ω H sk msg y = some σ) :

    Correctness of one compressed attempt. Under the secret-key and hash-to-ball bounds, every signature returned by compressedSignAttempt passes compressedVerify under the matching public key. The proof uses the derived compressed/uncompressed commitment bridge and the MakeHint/UseHint recovery theorem.

    Counter supplied to the i-th scheduled attempt. Algorithm 7 starts at κ and advances it by ℓ after every rejection.

    def Cslib.Crypto.MLDSA.compressedSignAttempts (P : Params) (d ω : ℕ) (H : Hash P) (sk : SecretKey P) (msg : List Bool) (maskAt : ℕ → Fin P.ℓ → Fin P.n → ZMod P.q) (κ K : ℕ) :

    The K scheduled Algorithm 7 attempts starting from counter κ, with line 31's counter progression built into each mask lookup.

    def Cslib.Crypto.MLDSA.compressedSignBoundedFrom (P : Params) (d ω : ℕ) (H : Hash P) (sk : SecretKey P) (msg : List Bool) (maskAt : ℕ → Fin P.ℓ → Fin P.n → ZMod P.q) (κ K : ℕ) :

    Bounded Algorithm 7 signing from counter κ: return the first accepted signature among K scheduled attempts, or none if every attempt rejects. This is the pure semantics of the finite-maximum option in Section 6.2, footnote 10, and of Algorithm 7 lines 10--32.

    def Cslib.Crypto.MLDSA.compressedSignBounded (P : Params) (d ω : ℕ) (H : Hash P) (sk : SecretKey P) (msg : List Bool) (maskAt : ℕ → Fin P.ℓ → Fin P.n → ZMod P.q) (K : ℕ) :

    Bounded Algorithm 7 signing with the initial counter κ = 0 from Algorithm 7 line 8.

    theorem Cslib.Crypto.MLDSA.compressedVerify_compressedSignBoundedFrom (P : Params) (hP : P.Valid) (hγq : 4 * P.γ₂ < P.q) {d ω : ℕ} {H : Hash P} (hH : ∀ (x : (Fin P.k → Fin P.n → ℤ) × List Bool), InBall P.τ (H x)) {sk : SecretKey P} (hs₂ : ∀ (i : Fin P.k) (j : Fin P.n), |(sk.s₂ i j).valMinAbs| ≤ ↑P.η) {msg : List Bool} {maskAt : ℕ → Fin P.ℓ → Fin P.n → ZMod P.q} {κ K : ℕ} {σ : CompressedSignature P} (hout : compressedSignBoundedFrom P d ω H sk msg maskAt κ K = some σ) :

    Every signature returned by bounded signing from an arbitrary starting counter passes compressed verification under the matching public key.

    theorem Cslib.Crypto.MLDSA.compressedVerify_compressedSignBounded (P : Params) (hP : P.Valid) (hγq : 4 * P.γ₂ < P.q) {d ω : ℕ} {H : Hash P} (hH : ∀ (x : (Fin P.k → Fin P.n → ℤ) × List Bool), InBall P.τ (H x)) {sk : SecretKey P} (hs₂ : ∀ (i : Fin P.k) (j : Fin P.n), |(sk.s₂ i j).valMinAbs| ≤ ↑P.η) {msg : List Bool} {maskAt : ℕ → Fin P.ℓ → Fin P.n → ZMod P.q} {K : ℕ} {σ : CompressedSignature P} (hout : compressedSignBounded P d ω H sk msg maskAt K = some σ) :

    Every signature returned by bounded signing from Algorithm 7's initial counter passes compressed verification under the matching public key.