Documentation

CslibFrontier.Crypto.Computational.MLDSA.Decompose

ML-DSA high-order and low-order rounding #

ML-DSA (CRYSTALS-Dilithium, [DKL+18], standardized as [NIST24a]) uses two coefficient decompositions. Power2Round compresses the public key by writing r = r₁ 2^d + r₀ with a centered low part. Decompose rounds commitments with the range α = 2 γ₂, using a special wrap-around rule needed by the hint mechanism.

power2Round is Algorithm 35 of [NIST24a], p. 40. It takes the canonical representative r⁺ ∈ [0, q) and its centered remainder r₀ = r⁺ mod± 2^d, and returns ((r⁺ - r₀) / 2^d, r₀). The coefficientwise power2RoundVec is the operation used on the uncompressed public-key vector t; reconstruction and the bound |t₀| ≤ 2^(d-1) are the facts used in the self-target MSIS calculation of [BDK+21], Section 6.2.1, Eq. (10).

For Decompose, the centered remainder is r₀ = r⁺ mod± α ∈ (-γ₂, γ₂]. The algorithm returns (r₁, r₀) = ((r⁺ - r₀) / α, r₀), except in the one wrap-around case r⁺ - r₀ = q - 1, where it returns (0, r₀ - 1). HighBits and LowBits are the two components.

This module defines the decomposition on ZMod q and proves the facts that the scheme and its security reduction use:

Main definitions #

Main results #

References #

Public-key power-of-two rounding #

The Power2Round algorithm of [NIST24a], Algorithm 35, p. 40. From the canonical representative r⁺ = r.val and the centered remainder r₀ = r⁺ mod± 2^d, return ((r⁺ - r₀) / 2^d, r₀).

def Cslib.Crypto.MLDSA.power2RoundVec {k n : ℕ} (q d : ℕ) (t : Fin k → Fin n → ZMod q) :
(Fin k → Fin n → ℤ) × (Fin k → Fin n → ℤ)

Power2Round applied coefficientwise to a vector of ring polynomials.

theorem Cslib.Crypto.MLDSA.power2Round_high_mul_add_low {q d : ℕ} (r : ZMod q) :
(power2Round q d r).1 * ↑(2 ^ d) + (power2Round q d r).2 = ↑r.val

The integer outputs of power-of-two rounding reconstruct the canonical representative.

theorem Cslib.Crypto.MLDSA.intCast_power2Round_high_mul_add_low {q d : ℕ} [NeZero q] (r : ZMod q) :
↑((power2Round q d r).1 * ↑(2 ^ d) + (power2Round q d r).2) = r

Power2Round reconstruction. The two outputs reconstruct the input modulo q.

theorem Cslib.Crypto.MLDSA.power2Round_low_mem_Ioc {q d : ℕ} (hd : 0 < d) (r : ZMod q) :
(power2Round q d r).2 ∈ Set.Ioc (-2 ^ (d - 1)) (2 ^ (d - 1))

For d > 0, the low output of Power2Round lies in (-2^(d-1), 2^(d-1)].

theorem Cslib.Crypto.MLDSA.abs_power2Round_low_le {q d : ℕ} (hd : 0 < d) (r : ZMod q) :
|(power2Round q d r).2| ≤ ↑(2 ^ (d - 1))

The low output of Power2Round has magnitude at most 2^(d-1).

theorem Cslib.Crypto.MLDSA.power2RoundVec_reconstruct {q d : ℕ} [NeZero q] {k n : ℕ} (t : Fin k → Fin n → ZMod q) :
(fun (i : Fin k) (j : Fin n) => ↑((power2RoundVec q d t).1 i j * ↑(2 ^ d) + (power2RoundVec q d t).2 i j)) = t

Coefficientwise Power2Round reconstructs the public-key vector.

theorem Cslib.Crypto.MLDSA.abs_power2RoundVec_low_le {q d : ℕ} (hd : 0 < d) {k n : ℕ} (t : Fin k → Fin n → ZMod q) (i : Fin k) (j : Fin n) :
|(power2RoundVec q d t).2 i j| ≤ ↑(2 ^ (d - 1))

Every low coefficient of a coefficientwise Power2Round is at most 2^(d-1) in magnitude.

Commitment rounding #

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

The Decompose algorithm of [NIST24a] with rounding range 2 γ₂: from the canonical representative r⁺ = r.val ∈ [0, q) and the centered remainder r₀ = r⁺ mod± 2 γ₂, return ((r⁺ - r₀) / (2 γ₂), r₀), or (0, r₀ - 1) in the wrap-around case r⁺ - r₀ = q - 1.

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

HighBits of [NIST24a]: the first component of decompose.

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

LowBits of [NIST24a]: the second component of decompose.

theorem Cslib.Crypto.MLDSA.abs_lowBits_le {q γ₂ : ℕ} (hγ : 0 < γ₂) (r : ZMod q) :
|lowBits q γ₂ r| ≤ ↑γ₂

The low bits are short: |LowBits r| ≤ γ₂.

theorem Cslib.Crypto.MLDSA.intCast_highBits_mul_add_lowBits {q γ₂ : ℕ} [NeZero q] (r : ZMod q) :
↑(highBits q γ₂ r * ↑(2 * γ₂) + lowBits q γ₂ r) = r

Reconstruction. r = HighBits r · 2 γ₂ + LowBits r in ℤ_q.

theorem Cslib.Crypto.MLDSA.natCast_eq_bucketCount_mul_add_one {q γ₂ : ℕ} (hdvd : 2 * γ₂ ∣ q - 1) [NeZero q] :
↑q = ↑((q - 1) / (2 * γ₂)) * ↑(2 * γ₂) + 1

In a valid ML-DSA modulus (2 * γ₂ ∣ q - 1 and q ≠ 0), q decomposes in ℤ as ((q - 1) / (2 * γ₂)) * (2 * γ₂) + 1.

theorem Cslib.Crypto.MLDSA.highBits_nonneg {q γ₂ : ℕ} (hγ : 0 < γ₂) (r : ZMod q) :
0 ≤ highBits q γ₂ r

The high bits are nonnegative.

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

When 2 γ₂ ∣ q - 1, the high bits lie below (q - 1) / (2 γ₂), the number of high-order buckets.

theorem Cslib.Crypto.MLDSA.decompose_intCast_mul_add {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) [NeZero q] {a b : ℤ} (ha₀ : 0 ≤ a) (ha : a < ↑((q - 1) / (2 * γ₂))) (hb₁ : -↑γ₂ < b) (hb₂ : b ≤ ↑γ₂) :
decompose q γ₂ ↑(a * ↑(2 * γ₂) + b) = (a, b)

Uniqueness of the decomposition. If r = a · 2 γ₂ + b in ℤ_q with 0 ≤ a < (q - 1) / (2 γ₂) and -γ₂ < b ≤ γ₂, then decompose r = (a, b).

theorem Cslib.Crypto.MLDSA.highBits_intCast_mul_add {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) [NeZero q] {a b : ℤ} (ha₀ : 0 ≤ a) (ha : a < ↑((q - 1) / (2 * γ₂))) (hb₁ : -↑γ₂ < b) (hb₂ : b ≤ ↑γ₂) :
highBits q γ₂ ↑(a * ↑(2 * γ₂) + b) = a

Uniqueness, high-bits component.

theorem Cslib.Crypto.MLDSA.lowBits_intCast_mul_add {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) [NeZero q] {a b : ℤ} (ha₀ : 0 ≤ a) (ha : a < ↑((q - 1) / (2 * γ₂))) (hb₁ : -↑γ₂ < b) (hb₂ : b ≤ ↑γ₂) :
lowBits q γ₂ ↑(a * ↑(2 * γ₂) + b) = b

Uniqueness, low-bits component.

theorem Cslib.Crypto.MLDSA.highBits_intCast_mul {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) [NeZero q] {a : ℤ} (ha₀ : 0 ≤ a) (ha : a < ↑((q - 1) / (2 * γ₂))) :
highBits q γ₂ ↑(a * ↑(2 * γ₂)) = a

A multiple a · 2 γ₂ of the rounding range with 0 ≤ a < (q - 1) / (2 γ₂) has high bits a.

theorem Cslib.Crypto.MLDSA.decompose_add_of_abs_lowBits_lt {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 1 < q) {β : ℕ} {r s : ZMod q} (hs : |s.valMinAbs| ≤ ↑β) (hr : |lowBits q γ₂ r| < ↑γ₂ - ↑β) :
decompose q γ₂ (r + s) = (highBits q γ₂ r, lowBits q γ₂ r + s.valMinAbs)

Adding a short perturbation to a value with small low bits: the decomposition of r + s is (HighBits r, LowBits r + s), where s is read through its centered representative.

theorem Cslib.Crypto.MLDSA.highBits_add_of_abs_lowBits_lt {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 1 < q) {β : ℕ} {r s : ZMod q} (hs : |s.valMinAbs| ≤ ↑β) (hr : |lowBits q γ₂ r| < ↑γ₂ - ↑β) :
highBits q γ₂ (r + s) = highBits q γ₂ r

High bits are stable under short perturbations. If |s| ≤ β and |LowBits r| < γ₂ - β, then HighBits (r + s) = HighBits r.

theorem Cslib.Crypto.MLDSA.lowBits_add_of_abs_lowBits_lt {q γ₂ : ℕ} (hγ : 0 < γ₂) (hdvd : 2 * γ₂ ∣ q - 1) (hq : 1 < q) {β : ℕ} {r s : ZMod q} (hs : |s.valMinAbs| ≤ ↑β) (hr : |lowBits q γ₂ r| < ↑γ₂ - ↑β) :
lowBits q γ₂ (r + s) = lowBits q γ₂ r + s.valMinAbs

Under the hypotheses of highBits_add_of_abs_lowBits_lt, the low bits shift by s.