Documentation

CslibFrontier.Crypto.Computational.MLDSA.Basic

ML-DSA: parameters, signing with aborts, verification and correctness #

This module states the CRYSTALS-Dilithium signature scheme ([DKL+18]), standardized as ML-DSA in [NIST24a], over R_q = ℤ_q[X] / (X^n + 1) (coefficient vectors Fin n → ZMod q with Cslib.negacyclicMul), and proves its correctness.

The model is the uncompressed-public-key scheme: the public key is (A, t) with t = A s₁ + s₂, a signature is (z, c), and verification recomputes w₁' = HighBits(A z - c t) and checks c = H(w₁', M). This fixed hash-to-ball function compares challenge polynomials. FIPS 204 Algorithm 8 checks equality of the full commitment digests, uses a rounded public vector and hint, and hashes the message representative and encoded commitment. Its byte-level verifier is in CslibFrontier.Crypto.Computational.MLDSA.FIPS204. Each signing attempt in this algebraic model draws its masking vector y from an arbitrary ProbComp sampler.

Main definitions #

Main results #

References #

Parameters #

ML-DSA parameters: ring degree n, modulus q, module ranks k × ℓ, secret bound η, masking range γ₁, low-order rounding range γ₂ (the rounding range of HighBits is 2 γ₂), challenge weight τ and rejection margin β (τ η in [NIST24a]).

  • n : ℕ

    Ring degree.

  • q : ℕ

    Modulus.

  • k : ℕ

    Number of rows of the public matrix.

  • ℓ : ℕ

    Number of columns of the public matrix.

  • η : ℕ

    Infinity-norm bound of the secret vectors.

  • γ₁ : ℕ

    Masking range.

  • γ₂ : ℕ

    Low-order rounding range.

  • τ : ℕ

    Number of nonzero challenge coefficients.

  • β : ℕ

    Rejection margin.

The side conditions used by correctness: q > 1, γ₂ > 0, the rounding range 2 γ₂ divides q - 1, the margin covers challenge-times-secret products (τ η ≤ β), and these products have centered representatives (2 β < q). These conditions do not require β < γ₁ or β < γ₂; without them every signing attempt aborts and correctness holds vacuously. The standard parameter sets satisfy both.

Challenges #

def Cslib.Crypto.MLDSA.InBall {n q : ℕ} (τ : ℕ) (c : Fin n → ZMod q) :

The challenge set B_τ: coefficients whose centered representatives lie in {-1, 0, 1}, exactly τ of them nonzero.

Instances For
    @[instance_reducible]
    instance Cslib.Crypto.MLDSA.instDecidableInBall {n q : ℕ} (τ : ℕ) (c : Fin n → ZMod q) :
    theorem Cslib.Crypto.MLDSA.sum_abs_valMinAbs_le {n q τ : ℕ} {c : Fin n → ZMod q} (hc : InBall τ c) :
    ∑ j : Fin n, |(c j).valMinAbs| ≤ ↑τ

    The centered ℓ₁ norm of a challenge in B_τ is at most τ.

    theorem Cslib.Crypto.MLDSA.abs_valMinAbs_negacyclicMul_le {n q : ℕ} [NeZero q] {τ η : ℕ} {c s : Fin n → ZMod q} (hc : InBall τ c) (hs : ∀ (j : Fin n), |(s j).valMinAbs| ≤ ↑η) (i : Fin n) :
    |(negacyclicMul c s i).valMinAbs| ≤ ↑τ * ↑η

    Challenge times short is short. If c ∈ B_τ and ‖s‖_∞ ≤ η, then ‖c s‖_∞ ≤ τ η in R_q. Centered reduction modulo q cannot increase the norm, so a no-wrap hypothesis is unnecessary.

    Keys, signing and verification #

    An ML-DSA public key (A, t) with A ∈ R_q^{k × ℓ} and t ∈ R_q^k.

    An ML-DSA secret key: the public matrix and the short secrets s₁ ∈ R_q^ℓ, s₂ ∈ R_q^k.

    The public key of a secret key: (A, A s₁ + s₂).

    An ML-DSA signature (z, c): a response z ∈ R_q^ℓ and a challenge c ∈ R_q.

    theorem Cslib.Crypto.MLDSA.Signature.ext {P : Params} {x y : Signature P} (z : x.z = y.z) (c : x.c = y.c) :
    x = y
    theorem Cslib.Crypto.MLDSA.Signature.ext_iff {P : Params} {x y : Signature P} :
    x = y ↔ x.z = y.z ∧ x.c = y.c
    @[instance_reducible]

    Signatures are compared field by field; unlike a derived instance, this one reduces under decide.

    @[reducible, inline]

    The commitment hash (w₁, M) ↦ c, standing for SampleInBall ∘ H of [NIST24a]: it maps a high-bits vector w₁ ∈ ℤ^{k × n} and a message to a challenge polynomial.

    def Cslib.Crypto.MLDSA.highBitsVec (P : Params) (w : Fin P.k → Fin P.n → ZMod P.q) :
    Fin P.k → Fin P.n → ℤ

    Coefficientwise HighBits of a vector in R_q^k.

    def Cslib.Crypto.MLDSA.ResponseShort (P : Params) (z : Fin P.ℓ → Fin P.n → ZMod P.q) :

    The ℓ∞ acceptance bound on responses: ‖z‖_∞ < γ₁ - β.

    Instances For
      @[instance_reducible]
      def Cslib.Crypto.MLDSA.LowBitsShort (P : Params) (r : Fin P.k → Fin P.n → ZMod P.q) :

      The low-bits acceptance bound: ‖LowBits(r)‖_∞ < γ₂ - β.

      Instances For
        @[instance_reducible]
        def Cslib.Crypto.MLDSA.verifierCommitment (P : Params) (pk : PublicKey P) (z : Fin P.ℓ → Fin P.n → ZMod P.q) (c : Fin P.n → ZMod P.q) :
        Fin P.k → Fin P.n → ZMod P.q

        The verifier's commitment A z - c t.

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

        One signing attempt with mask y: w = A y, c = H(HighBits(w), M), z = y + c s₁; output (z, c) when ‖z‖_∞ < γ₁ - β and ‖LowBits(w - c s₂)‖_∞ < γ₂ - β, and abort otherwise.

        def Cslib.Crypto.MLDSA.sign (P : Params) (H : Hash P) (sk : SecretKey P) (mask : ProbComp (Fin P.ℓ → Fin P.n → ZMod P.q)) (msg : List Bool) :

        Signing by rejection sampling: draw a mask from mask and run signAttempt, retrying after an abort, at most K times in total; none means that all K attempts aborted.

        def Cslib.Crypto.MLDSA.verify (P : Params) (H : Hash P) (pk : PublicKey P) (msg : List Bool) (σ : Signature P) :

        Verification: accept (z, c) on M iff ‖z‖_∞ < γ₁ - β, c ∈ B_τ, and c = H(HighBits(A z - c t), M).

        Correctness #

        theorem Cslib.Crypto.MLDSA.verifierCommitment_publicKey {P : Params} (sk : SecretKey P) (y : Fin P.ℓ → Fin P.n → ZMod P.q) (c : Fin P.n → ZMod P.q) :
        verifierCommitment P sk.publicKey (y + fun (j : Fin P.ℓ) => negacyclicMul c (sk.s₁ j)) c = moduleSISMap sk.A y - fun (i : Fin P.k) => negacyclicMul c (sk.s₂ i)

        The verifier's commitment for an honest response: A (y + c s₁) - c (A s₁ + s₂) = A y - c s₂.

        theorem Cslib.Crypto.MLDSA.highBitsVec_sub_challenge {P : Params} (hP : P.Valid) {c : Fin P.n → ZMod P.q} {w s : Fin P.k → Fin P.n → ZMod P.q} (hc : InBall P.τ c) (hs : ∀ (i : Fin P.k) (j : Fin P.n), |(s i j).valMinAbs| ≤ ↑P.η) (hlow : LowBitsShort P (w - fun (i : Fin P.k) => negacyclicMul c (s i))) :
        highBitsVec P (w - fun (i : Fin P.k) => negacyclicMul c (s i)) = highBitsVec P w

        Once the low-bits rejection test succeeds, subtracting the challenge times a short secret preserves the high bits of the original commitment.

        theorem Cslib.Crypto.MLDSA.verify_signAttempt {P : Params} (hP : P.Valid) {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} {σ : Signature P} (h : signAttempt P H sk msg y = some σ) :
        verify P H sk.publicKey msg σ = true

        Correctness of one attempt. If ‖s₂‖_∞ ≤ η and the hash takes values in B_τ, every signature output by signAttempt verifies under the matching public key.

        theorem Cslib.Crypto.MLDSA.verify_sign {P : Params} (hP : P.Valid) {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.η) (mask : ProbComp (Fin P.ℓ → Fin P.n → ZMod P.q)) (msg : List Bool) (K : ℕ) {σ : Signature P} (h : some σ ∈ (sign P H sk mask msg K).eval.support) :
        verify P H sk.publicKey msg σ = true

        Correctness of signing. Under the hypotheses of verify_signAttempt, every signature that sign can output verifies, whatever the mask sampler and the retry bound.