Documentation

CslibFrontier.Crypto.Computational.MLDSA.Hint

ML-DSA hint generation and use #

ML-DSA compresses a commitment to its high-order bits. The signer supplies one hint bit per coefficient saying whether a short correction changes those bits, and the verifier uses that bit to move by one high-order bucket in the direction determined by the low bits. These are Algorithms 39 (MakeHint) and 40 (UseHint) of [NIST24a].

Main definitions #

Main results #

The printed output bound of Algorithm 40 is non-strict, but NIST's potential-updates spreadsheet (identified 2026-02-27) records the strict range 0 ≤ r₁ < (q - 1) / (2 γ₂) used by w1Encode. The range theorem below states this corrected bound.

References #

def Cslib.Crypto.MLDSA.makeHint (q γ₂ : ℕ) (z r : ZMod q) :

MakeHint from Algorithm 39 of [NIST24a]. The bit is set exactly when adding z changes the high bits of r.

def Cslib.Crypto.MLDSA.useHint (q γ₂ : ℕ) (h : Bool) (r : ZMod q) :

UseHint from Algorithm 40 of [NIST24a]. A set hint moves the high part one bucket up when the low part is positive and one bucket down otherwise, modulo the number of buckets.

def Cslib.Crypto.MLDSA.hintResidual (q γ₂ : ℕ) (h : Bool) (r : ZMod q) :

The residual u = 2 γ₂ · UseHint(h, r, 2 γ₂) - r in ℤ_q. Lemma 1(2) of the Dilithium v3.1 specification bounds its centered representative by 2 γ₂ + 1.

theorem Cslib.Crypto.MLDSA.useHint_mul_eq_add_hintResidual (q γ₂ : ℕ) (h : Bool) (r : ZMod q) :
↑(useHint q γ₂ h r * ↑(2 * γ₂)) = r + hintResidual q γ₂ h r

The hinted high part is the original coefficient plus its residual. This is the scalar identity used in Equation (9) of Section 6.2.1 of the Dilithium v3.1 specification.

@[simp]
theorem Cslib.Crypto.MLDSA.makeHint_eq_true_iff {q γ₂ : ℕ} {z r : ZMod q} :
makeHint q γ₂ z r = true ↔ highBits q γ₂ r ≠ highBits q γ₂ (r + z)

MakeHint is set exactly when the correction changes the high bits.

@[simp]
theorem Cslib.Crypto.MLDSA.makeHint_eq_false_iff {q γ₂ : ℕ} {z r : ZMod q} :
makeHint q γ₂ z r = false ↔ highBits q γ₂ r = highBits q γ₂ (r + z)

MakeHint is clear exactly when the correction leaves the high bits unchanged.

@[simp]
theorem Cslib.Crypto.MLDSA.useHint_false (q γ₂ : ℕ) (r : ZMod q) :
useHint q γ₂ false r = highBits q γ₂ r

A clear hint returns the existing high bits.

theorem Cslib.Crypto.MLDSA.useHint_nonneg {q γ₂ : ℕ} (hγ : 0 < γ₂) (hq : 4 * γ₂ < q) (h : Bool) (r : ZMod q) :
0 ≤ useHint q γ₂ h r

UseHint always returns a nonnegative bucket index under the source parameter hypotheses.

theorem Cslib.Crypto.MLDSA.useHint_lt {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 4 * γ₂ < q) (h : Bool) (r : ZMod q) :
useHint q γ₂ h r < ↑((q - 1) / (2 * γ₂))

UseHint returns an index below the number (q - 1) / (2 γ₂) of high-order buckets.

theorem Cslib.Crypto.MLDSA.useHint_true_ne_highBits {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 4 * γ₂ < q) (r : ZMod q) :
useHint q γ₂ true r ≠ highBits q γ₂ r

A set hint never produces the unadjusted high bits. This is the scalar separation underlying Lemma 1(3) of the Dilithium v3.1 specification.

theorem Cslib.Crypto.MLDSA.useHint_injective {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 4 * γ₂ < q) (r : ZMod q) :
Function.Injective fun (h : Bool) => useHint q γ₂ h r

Hint injectivity. For a fixed coefficient, equal UseHint outputs imply equal hint bits. This is the scalar form of Lemma 1(3) in the Dilithium v3.1 specification.

theorem Cslib.Crypto.MLDSA.abs_hintResidual_valMinAbs_le {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 4 * γ₂ < q) (h : Bool) (r : ZMod q) :
|(hintResidual q γ₂ h r).valMinAbs| ≤ 2 * ↑γ₂ + 1

Arbitrary-hint residual bound. For every hint bit and coefficient, the centered residual between r and 2 γ₂ · UseHint(h, r, 2 γ₂) has magnitude at most 2 γ₂ + 1. This is the scalar norm statement in Lemma 1(2) of the Dilithium v3.1 specification. The vector lemma additionally states that only set-hint positions can exceed γ₂; that sparsity refinement is separate.

theorem Cslib.Crypto.MLDSA.useHint_makeHint {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 4 * γ₂ < q) {z r : ZMod q} (hz : |z.valMinAbs| ≤ ↑γ₂) :
useHint q γ₂ (makeHint q γ₂ z r) r = highBits q γ₂ (r + z)

Hint recovery. If |z| ≤ γ₂, using the hint made from z and r recovers the high bits of r + z. This is the scalar form of Lemma 1(1) in the Dilithium v3.1 specification, with its α specialized to 2 γ₂.

def Cslib.Crypto.MLDSA.makeHintVec {ι : Type u_1} (q γ₂ : ℕ) (z r : ι → ZMod q) :
ι → Bool

Apply MakeHint coefficientwise.

def Cslib.Crypto.MLDSA.useHintVec {ι : Type u_1} (q γ₂ : ℕ) (h : ι → Bool) (r : ι → ZMod q) :
ι → ℤ

Apply UseHint coefficientwise.

theorem Cslib.Crypto.MLDSA.useHintVec_makeHintVec {q γ₂ : ℕ} {ι : Type u_1} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 4 * γ₂ < q) {z r : ι → ZMod q} (hz : ∀ (i : ι), |(z i).valMinAbs| ≤ ↑γ₂) :
useHintVec q γ₂ (makeHintVec q γ₂ z r) r = fun (i : ι) => highBits q γ₂ (r i + z i)

Coefficientwise hint recovery.