Documentation

CslibFrontier.Crypto.Computational.MLDSA.SigningROM

Adaptive programming at ML-DSA signing commitments #

The signer runs the bounded retry loop of [NIST24a], Algorithm 7, with independent ideal masks. Signing and direct digest queries use a shared classical lazy random oracle on algebraic high bits and message representatives. The fresh-overwrite hybrid programs every attempted commitment, including those whose signatures are rejected. The digest returned on success is retained alongside its polynomial expansion in the algebraic signature.

For a fixed matrix, the distance between these executions is bounded by the largest commitment atom times the number of pairs of queries that could collide. The bound covers arbitrary interleavings and early termination of the signing loop. Erasing the writes of rejected trials costs at most the number of trial/direct-query pairs times the same largest atom. Replacing the remaining accepted responses with the full-public-key simulator preserves their joint law. For a partial digest expander the simulator also records the terminal failed attempt, with a fresh commitment drawn from the public matrix. This preserves expansion errors exactly.

The transcript of the partial simulator identifies the newest writer at the verifier’s actual digest read. Either a direct oracle call supplied the digest or the signing history contains an accepted response on the same representative. In the latter case a fresh signature gives the ordinary Module-SIS witness of [BDK+21], §6.2.2, equation (8).

@[reducible, inline]

The algebraic input to the commitment hash: high bits of the mask commitment and a message representative, in the order used by MLDSA.Hash.

@[reducible, inline]

The shared signing and digest-query interface. Successful signing replies retain the digest and the compressed algebraic signature, and a bounded signing loop may return none.

@[reducible, inline]

The primitive trial interface. none asks for another trial. A terminal value of type Reply may itself report a fatal error from a partial digest expansion.

def Cslib.Crypto.MLDSA.expandSigningRetries (P : Params) {Digest Reply α : Type} (K : ℕ) (program : OracleComp (SigningTrialSpec P Digest Reply) α) :
OracleComp (SigningTrialSpec P Digest Reply) α

Expand each signing request into up to K attempts on its message, stopping at the first terminal trial. Direct digest requests pass through unchanged.

noncomputable def Cslib.Crypto.MLDSA.commitmentGuessProbability (P : Params) (hγ : 0 < P.γ₁) (A : Matrix (Fin P.k) (Fin P.ℓ) (Fin P.n → ZMod P.q)) :

The largest atom of HighBits(A y) when y is one ideal signing mask.

noncomputable def Cslib.Crypto.MLDSA.runBoundedSigningROM (P : Params) {Digest α : Type} (overwrite : Bool) (d ω K : ℕ) (hγ : 0 < P.γ₁) (dist : PMF Digest) (expand : Digest → Fin P.n → ZMod P.q) (sk : SecretKey P) (program : OracleComp (SigningROMSpec P Digest) α) :
PMF (α × List (SigningHashPoint P × Digest))

Run an adaptive program from an empty digest table. Under overwrite = false the signer reads the ordinary lazy hash at every trial commitment. Under overwrite = true it samples a fresh digest and writes it there, including on rejected attempts. The entire final digest table is retained.

theorem Cslib.Crypto.MLDSA.closeTo_runBoundedSigningROM_overwrite (P : Params) {Digest α : Type} (d ω K : ℕ) (hγ : 0 < P.γ₁) (dist : PMF Digest) (expand : Digest → Fin P.n → ZMod P.q) (sk : SecretKey P) {program : OracleComp (SigningROMSpec P Digest) α} {S H : ℕ} (hS : OracleComp.IsCostBounded Protocols.ROMSignature.signingCost program S) (hH : OracleComp.IsCostBounded Protocols.ROMSignature.hashCost program H) :
Probability.CloseTo (runBoundedSigningROM P false d ω K hγ dist expand sk program) (runBoundedSigningROM P true d ω K hγ dist expand sk program) (↑(S * K * H + (S * K).choose 2) * commitmentGuessProbability P hγ sk.A)

For S adaptive signing queries and H direct hash queries, at most T = S K trial commitments are programmed. The honest and fresh-overwrite executions, including the final table, are within (T H + choose(T,2)) times the largest commitment atom for the actual matrix.

noncomputable def Cslib.Crypto.MLDSA.runAcceptedSigningROM (P : Params) {Digest α : Type} (K : ℕ) (dist : PMF Digest) (attempt : Digest → PMF (Option (AttemptTranscript P))) (program : OracleComp (SigningROMSpec P Digest) α) :
PMF (α × List (SigningHashPoint P × Digest))

Run a signer that samples a digest and an optional transcript independently of the cache at each attempt. Only accepted commitments are written. Direct hash queries use the same table, and the bounded retry loop ends at the first success.

theorem Cslib.Crypto.MLDSA.runAcceptedSigningROM_eq_simulate (P : Params) {Digest α : Type} (hP : P.Valid) (hq : 2 * P.γ₁ < P.q) (hβ : P.β < P.γ₁) (d ω K : ℕ) (dist : PMF Digest) (expand : Digest → Fin P.n → ZMod P.q) (sk : SecretKey P) (hs₁ : ∀ (i : Fin P.ℓ) (j : Fin P.n), |(sk.s₁ i j).valMinAbs| ≤ ↑P.η) (hs₂ : ∀ (i : Fin P.k) (j : Fin P.n), |(sk.s₂ i j).valMinAbs| ≤ ↑P.η) (hc : ∀ (c : Digest), InBall P.τ (expand c)) (program : OracleComp (SigningROMSpec P Digest) α) :
runAcceptedSigningROM P K dist (fun (c : Digest) => freshSigningAttempt P d ω ⋯ sk (expand c)) program = runAcceptedSigningROM P K dist (fun (c : Digest) => simulateFreshSigningAttempt P d ω hβ sk.publicKey (expand c)) program

For every adaptive signing and hash program, the accepted-write hybrid using the real masked response has exactly the law of the simulator using only the full public key. The equality includes all retry outcomes and the final table of accepted commitments and hash queries.

theorem Cslib.Crypto.MLDSA.closeTo_runBoundedSigningROM_simulate (P : Params) {Digest α : Type} (hP : P.Valid) (hq : 2 * P.γ₁ < P.q) (hβ : P.β < P.γ₁) (d ω K : ℕ) (dist : PMF Digest) (expand : Digest → Fin P.n → ZMod P.q) (sk : SecretKey P) (hs₁ : ∀ (i : Fin P.ℓ) (j : Fin P.n), |(sk.s₁ i j).valMinAbs| ≤ ↑P.η) (hs₂ : ∀ (i : Fin P.k) (j : Fin P.n), |(sk.s₂ i j).valMinAbs| ≤ ↑P.η) (hc : ∀ (c : Digest), InBall P.τ (expand c)) {program : OracleComp (SigningROMSpec P Digest) α} {S H : ℕ} (hS : OracleComp.IsCostBounded Protocols.ROMSignature.signingCost program S) (hH : OracleComp.IsCostBounded Protocols.ROMSignature.hashCost program H) :
Probability.CloseTo (PMF.map Prod.fst (runBoundedSigningROM P false d ω K ⋯ dist expand sk program)) (PMF.map Prod.fst (runAcceptedSigningROM P K dist (fun (c : Digest) => simulateFreshSigningAttempt P d ω hβ sk.publicKey (expand c)) program)) (↑(2 * (S * K) * H + (S * K).choose 2) * commitmentGuessProbability P ⋯ sk.A)

Adaptive classical-ROM simulation of bounded ML-DSA signing with ideal masks, for a fixed key and a digest law whose expansion is sparse. The simulator uses the full public key. For T = S K internal attempts and H direct queries, prior hash collisions cost (T H + choose(T,2)) δ and later reads of erased rejected commitments cost T H δ, where δ is the largest commitment atom for the actual matrix. The adversary sees only its output.

def Cslib.Crypto.MLDSA.partialSigningProgram (P : Params) {Digest α : Type} (program : OracleComp (SigningROMSpec P Digest) α) :

Route a signing request to the bounded trial loop. A terminal trial carries either a signature or an expansion error. After the loop the caller gets the signature, or one error value for either expansion failure or exhaustion of the trial budget.

noncomputable def Cslib.Crypto.MLDSA.runPartialSigningROM (P : Params) {Digest α : Type} (d ω K : ℕ) (hγ : 0 < P.γ₁) (dist : PMF Digest) (expand : Digest → Option (Fin P.n → ZMod P.q)) (sk : SecretKey P) (program : OracleComp (SigningROMSpec P Digest) α) :
PMF (α × List (SigningHashPoint P × Digest))

Honest signing in the classical digest ROM with a partial challenge expander. An expansion error stops this signing request, even when further retries remain. A norm or hint rejection advances to the next fresh ideal mask.

noncomputable def Cslib.Crypto.MLDSA.simulatePartialTrial (P : Params) {Digest : Type} (d ω : ℕ) (hβ : P.β < P.γ₁) (expand : Digest → Option (Fin P.n → ZMod P.q)) (pk : PublicKey P) (raw : Digest) :
PMF (Option ((Fin P.k → Fin P.n → ℤ) × Option (Digest × CompressedSignature P)))

One attempt of the partial-expansion signing simulator. An outer none requests another mask. A terminal outcome records the programmed commitment and either the error or the digest and signature returned to the adversary.

theorem Cslib.Crypto.MLDSA.isSolution_of_forgery_at_simulated_digest (P : Params) {Digest : Type} (hP : P.Valid) (hq : 2 * P.γ₁ < P.q) (hγq : 4 * P.γ₂ < P.q) (d ω : ℕ) (hβ : P.β < P.γ₁) (pk : PublicKey P) (expand : Digest → Option (Fin P.n → ZMod P.q)) (raw : Digest) {w : Fin P.k → Fin P.n → ℤ} {sent : Option (Digest × CompressedSignature P)} (ht : some (w, sent) ∈ (simulatePartialTrial P d ω hβ expand pk raw).support) {σ : CompressedSignature P} (hfresh : sent ≠ some (raw, σ)) (hexpand : expand raw = some σ.c) (hz : ResponseShort P σ.z) (hw : σ.recover d pk = w) :
∃ (other : CompressedSignature P), sent = some (raw, other) ∧ ModuleSIS.IsSolution (ModuleSIS.hermiteMatrix pk.A) (max (2 * (P.γ₁ - P.β)) (4 * P.γ₂ + 2)) (responseDifference d pk σ other)

A fresh verifying response at a commitment written by the partial signing simulator yields Dilithium's ordinary MSIS witness (v3.1, §6.2.2, equation (8)). Successful expansion of the programmed raw digest rules out a terminal signing error. The simulator's own response supplies the second short witness, including for arbitrary uniform public vectors.

noncomputable def Cslib.Crypto.MLDSA.simulatePartialSigningROM (P : Params) {Digest α : Type} (d ω K : ℕ) (hβ : P.β < P.γ₁) (dist : PMF Digest) (expand : Digest → Option (Fin P.n → ZMod P.q)) (pk : PublicKey P) (program : OracleComp (SigningROMSpec P Digest) α) :
PMF (α × List (SigningHashPoint P × Digest))

Simulate bounded signing against the public matrix and full public vector with the same partial digest expander. On an expansion error, independently sample a mask, program the terminal trial's commitment, and return the public error. Successful expansions use the fresh-transcript simulator.

theorem Cslib.Crypto.MLDSA.closeTo_partialSigningROM (P : Params) {Digest α : Type} (hP : P.Valid) (hq : 2 * P.γ₁ < P.q) (hβ : P.β < P.γ₁) (d ω K : ℕ) (dist : PMF Digest) (expand : Digest → Option (Fin P.n → ZMod P.q)) (sk : SecretKey P) (hs₁ : ∀ (i : Fin P.ℓ) (j : Fin P.n), |(sk.s₁ i j).valMinAbs| ≤ ↑P.η) (hs₂ : ∀ (i : Fin P.k) (j : Fin P.n), |(sk.s₂ i j).valMinAbs| ≤ ↑P.η) (hc : ∀ (c : Digest) (poly : Fin P.n → ZMod P.q), expand c = some poly → InBall P.τ poly) {program : OracleComp (SigningROMSpec P Digest) α} {S H : ℕ} (hS : OracleComp.IsCostBounded Protocols.ROMSignature.signingCost program S) (hH : OracleComp.IsCostBounded Protocols.ROMSignature.hashCost program H) :
Probability.CloseTo (PMF.map Prod.fst (runPartialSigningROM P d ω K ⋯ dist expand sk program)) (PMF.map Prod.fst (simulatePartialSigningROM P d ω K hβ dist expand sk.publicKey program)) (↑(2 * (S * K) * H + (S * K).choose 2) * commitmentGuessProbability P ⋯ sk.A)

The adaptive signing-oracle simulation bound for partial challenge expansion. Expansions may fail with arbitrary probability. Both experiments propagate that stopping event exactly in the fresh-digest hybrid, including the attempted commitment written to the hash table. Only queries colliding with earlier or erased commitments contribute to the error bound.

inductive Cslib.Crypto.MLDSA.SigningWrite (Digest Reply : Type) :

A digest cache write records the direct hash reply or the terminal answer of a signing request. A signing error is a terminal write, while an erased rejection makes no entry.

  • ambient {Digest Reply : Type} (raw : Digest) : SigningWrite Digest Reply

    First direct query at an unassigned point.

  • signing {Digest Reply : Type} (raw : Digest) (reply : Reply) : SigningWrite Digest Reply

    Terminal signing trial, including a possible expansion error in reply.

def Cslib.Crypto.MLDSA.SigningWrite.digest {Digest Reply : Type} :
SigningWrite Digest Reply → Digest

The raw digest that a later lookup observes.

noncomputable def Cslib.Crypto.MLDSA.simulatePartialSigningTranscript (P : Params) {Digest α : Type} (d ω K : ℕ) (hβ : P.β < P.γ₁) (dist : PMF Digest) (expand : Digest → Option (Fin P.n → ZMod P.q)) (pk : PublicKey P) (program : OracleComp (SigningROMSpec P Digest) α) :

Execute the partial signing simulator, recording the last writer at each cache entry and the actual outward query/reply transcript. Both lists are newest first. Retry attempts are internal to a signing query and do not appear in the outward transcript.

theorem Cslib.Crypto.MLDSA.simulatePartialSigningTranscript_forget (P : Params) {Digest α : Type} (d ω K : ℕ) (hβ : P.β < P.γ₁) (dist : PMF Digest) (expand : Digest → Option (Fin P.n → ZMod P.q)) (pk : PublicKey P) (program : OracleComp (SigningROMSpec P Digest) α) :
PMF.map (fun (x : α × List (SigningHashPoint P × SigningWrite Digest (Option (Digest × CompressedSignature P))) × OracleComp.Transcript (SigningROMSpec P Digest)) => match x with | (a, cache, snd) => (a, List.map (fun (x : SigningHashPoint P × SigningWrite Digest (Option (Digest × CompressedSignature P))) => match x with | (key, entry) => (key, entry.digest)) cache)) (simulatePartialSigningTranscript P d ω K hβ dist expand pk program) = simulatePartialSigningROM P d ω K hβ dist expand pk program

Forgetting write annotations and the outward transcript recovers the original joint law of the adversary's output and the complete simulated digest cache.

A candidate forgery in the compressed signing ROM: a message representative, a transmitted commitment digest, and a decoded compressed signature.

  • message : List Bool

    The message representative bits.

  • digest : Digest

    The commitment digest carried by the candidate signature.

  • signature : CompressedSignature P

    The response, hint vector, and sparse challenge.

theorem Cslib.Crypto.MLDSA.ForgeryCandidate.ext {P : Params} {Digest : Type} {x y : ForgeryCandidate P Digest} (message : x.message = y.message) (digest : x.digest = y.digest) (signature : x.signature = y.signature) :
x = y
def Cslib.Crypto.MLDSA.queryForgeryDigest (P : Params) {Digest : Type} (d : ℕ) (pk : PublicKey P) (forger : OracleComp (SigningROMSpec P Digest) (ForgeryCandidate P Digest)) :
OracleComp (SigningROMSpec P Digest) (ForgeryCandidate P Digest × Digest)

Append the verifier's commitment-digest query to the forger, using its output message representative and the high bits recovered from its output response. Return the candidate and the oracle answer so that verification compares the transmitted digest with the actual read.

theorem Cslib.Crypto.MLDSA.ambient_or_isSolution_of_fresh_lookup (P : Params) {Digest : Type} (hP : P.Valid) (hq : 2 * P.γ₁ < P.q) (hγq : 4 * P.γ₂ < P.q) (d ω K : ℕ) (hβ : P.β < P.γ₁) (dist : PMF Digest) (expand : Digest → Option (Fin P.n → ZMod P.q)) (pk : PublicKey P) (forger : OracleComp (SigningROMSpec P Digest) (ForgeryCandidate P Digest)) {forged : ForgeryCandidate P Digest} {cache : List (SigningHashPoint P × SigningWrite Digest (Option (Digest × CompressedSignature P)))} {log : OracleComp.Transcript (SigningROMSpec P Digest)} (hrun : ((forged, forged.digest), cache, log) ∈ (simulatePartialSigningTranscript P d ω K hβ dist expand pk (queryForgeryDigest P d pk forger)).support) (hfresh : ⟨Sum.inl forged.message, some (forged.digest, forged.signature)⟩ ∉ log) (hexpand : expand forged.digest = some forged.signature.c) (hz : ResponseShort P forged.signature.z) :
List.lookup (forged.signature.recover d pk, forged.message) cache = some (SigningWrite.ambient forged.digest) ∧ ⟨Sum.inr (forged.signature.recover d pk, forged.message), forged.digest⟩ ∈ log ∨ ∃ (other : CompressedSignature P), List.lookup (forged.signature.recover d pk, forged.message) cache = some (SigningWrite.signing forged.digest (some (forged.digest, other))) ∧ ⟨Sum.inl forged.message, some (forged.digest, other)⟩ ∈ log ∧ ModuleSIS.IsSolution (ModuleSIS.hermiteMatrix pk.A) (max (2 * (P.γ₁ - P.β)) (4 * P.γ₂ + 2)) (responseDifference d pk forged.signature other)

At a fresh verifying lookup in the adaptive simulator, the newest entry is either a direct oracle answer or a signing reply on this same message representative. In the latter case the reply is in the outward transcript and subtracting it from the forgery gives an ordinary MSIS solution. Overwritten entries, signing errors and exhausted retries require no freshness assumptions. A first read by the verifier is covered by the direct-oracle case.