Documentation

CslibFrontier.Crypto.Computational.LWE.Module

Decision Module-LWE #

The decision Module-LWE experiments over the negacyclic ring R_q = ℤ_q[X] / (X^n + 1) ([LPR10], [DKL+18]), with polynomials stored as coefficient vectors Fin n → ZMod q. The real experiment ModuleLWE.realExperiment draws a uniform module matrix A and gives the distinguisher A and the sample A · s + e (ModuleLWE.sample) for a secret s and an error vector e; the random experiment ModuleLWE.randomExperiment gives it a uniform pair. For a secret law and an error law, the real game ModuleLWE.realGame draws s and e and runs the real experiment, ModuleLWE.randomGame runs the random one, and ModuleLWE.advantage is the distance between them. These are the games of the ML-KEM and ML-DSA reductions, whose secrets are short rather than uniform. Module-LWE is LWE over the ring Negacyclic (ZMod q) n (ModuleLWE.advantage_eq_lweAdvantage).

DecisionModuleLWEWith m d n q secret error is the asymptotic assumption with an m κ × d κ module matrix over ℤ_{q κ}[X] / (X^{n κ} + 1), a secret law secret κ and an error law error κ: every distinguisher that is uniform strict PPT on encodings (ModuleLWE.Distinguisher.IsPPT) has negligible advantage between the real game for these laws and the random game. A distinguisher machine reads the unary security parameter and the encoded sample (ModuleLWE.encInput_apply). With short secret and error laws, this is the assumption of the CRYSTALS-Kyber and CRYSTALS-Dilithium submissions ([ABD+21], §4.3; [BDK+21], §6.1). DecisionModuleLWE m d n q noise is the case of a uniform secret and independent polynomial errors from noise κ (decisionModuleLWE_iff_decisionModuleLWEWith).

A distinguisher outputs a bit, so DecisionModuleLWEWith is the same assumption as the indistinguishability of the encoded samples ModuleLWE.realEnsemble and ModuleLWE.uniformEnsemble against word-level distinguishers (decisionModuleLWEWith_iff_encoded). Clients that reduce on encoded words use DecisionModuleLWEWith.encoded.

DecisionModuleLWEWith is a hypothesis against uniform classical strict polynomial-time programs. It makes no assertion of hardness for any particular parameter family or laws, and no relation to DecisionLWE at modulus 2 ^ w is proved. It is meaningful only for a family whose parameters grow with the security parameter; at one fixed parameter set it fails unless the real sample is exactly uniform (see DecisionModuleLWEWith).

Main definitions #

Main results #

Implementation notes #

ModuleLWE.encInput encodes the layout ModuleLWE.Input.words (the security parameter and the encoded sample), so a typed distinguisher is a word-level distinguisher run on its input's words (IsPPTOn.exists_bool_factor). The converse direction of decisionModuleLWEWith_iff_encoded therefore replaces the typed distinguisher by that word-level one outright, with no congruence argument for the games.

References #

Samples #

def Cslib.Crypto.ModuleLWE.sample {m d n q : ℕ} (A : Matrix (Fin m) (Fin d) (Fin n → ZMod q)) (s : Fin d → Fin n → ZMod q) (e : Fin m → Fin n → ZMod q) :
Fin m → Fin n → ZMod q

Deterministic Module-LWE noisy linear map A · s + e over ℤ_q[X] / (X^n + 1).

theorem Cslib.Crypto.ModuleLWE.flattenPolyVec_sample {m d n q : ℕ} (A : Matrix (Fin m) (Fin d) (Fin n → ZMod q)) (s : Fin d → Fin n → ZMod q) (e : Fin m → Fin n → ZMod q) :

Structured-to-unstructured Module-LWE identity: flattening ModuleLWE.sample A s e gives the standard LWE vector expandModuleMatrix A *ᵥ flattenPolyVec s + flattenPolyVec e.

theorem Cslib.Crypto.ModuleLWE.ofCoeffs_comp_sample {m d n q : ℕ} (A : Matrix (Fin m) (Fin d) (Fin n → ZMod q)) (s : Fin d → Fin n → ZMod q) (e : Fin m → Fin n → ZMod q) :

A Module-LWE sample is the LWE sample A *ᵥ s + e over Negacyclic (ZMod q) n.

def Cslib.Crypto.ModuleLWE.encodeSample {m d n q : ℕ} (pair : Matrix (Fin m) (Fin d) (Fin n → ZMod q) × (Fin m → Fin n → ZMod q)) :

Encode a Module-LWE public pair (A, b) as a framed pair of the encoded module matrix A and the framed list of natural residue coefficients of b.

Module-LWE pairs of fixed shape are determined by their encodings when q ≠ 0.

Fixed-instance experiments #

noncomputable def Cslib.Crypto.ModuleLWE.realExperiment {m d n q : ℕ} [NeZero q] (s : Fin d → Fin n → ZMod q) (e : Fin m → Fin n → ZMod q) (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :

The real decision Module-LWE experiment for the secret s and error e: draw a uniform module matrix A and run the distinguisher on A and A · s + e.

noncomputable def Cslib.Crypto.ModuleLWE.randomExperiment {m d n q : ℕ} [NeZero q] (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :

The random decision Module-LWE experiment: run the distinguisher on a uniform module matrix A and an independent uniform vector b.

@[simp]
theorem Cslib.Crypto.ModuleLWE.eval_realExperiment {m d n q : ℕ} [NeZero q] (s : Fin d → Fin n → ZMod q) (e : Fin m → Fin n → ZMod q) (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :
ProbComp.eval (realExperiment s e distinguisher) = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin d) (Fin n → ZMod q))).bind fun (A : Matrix (Fin m) (Fin d) (Fin n → ZMod q)) => (distinguisher A (sample A s e)).eval
@[simp]
theorem Cslib.Crypto.ModuleLWE.eval_randomExperiment {m d n q : ℕ} [NeZero q] (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :
ProbComp.eval (randomExperiment distinguisher) = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin d) (Fin n → ZMod q))).bind fun (A : Matrix (Fin m) (Fin d) (Fin n → ZMod q)) => (Probability.PMF.uniformOfFintype (Fin m → Fin n → ZMod q)).bind fun (b : Fin m → Fin n → ZMod q) => (distinguisher A b).eval
noncomputable def Cslib.Crypto.ModuleLWE.realGame {m d n q : ℕ} [NeZero q] (secretLaw : PMF (Fin d → Fin n → ZMod q)) (errorLaw : PMF (Fin m → Fin n → ZMod q)) (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :

The real decision Module-LWE game for a secret law and an error law: draw s ← secretLaw and e ← errorLaw, then run realExperiment s e.

noncomputable def Cslib.Crypto.ModuleLWE.randomGame {m d n q : ℕ} [NeZero q] (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :

The random decision Module-LWE game: run randomExperiment.

noncomputable def Cslib.Crypto.ModuleLWE.advantage {m d n q : ℕ} [NeZero q] (secretLaw : PMF (Fin d → Fin n → ZMod q)) (errorLaw : PMF (Fin m → Fin n → ZMod q)) (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :

The decision Module-LWE advantage of a distinguisher for a secret law and an error law.

theorem Cslib.Crypto.ModuleLWE.realGame_eq_uniform_bind {m d n q : ℕ} [NeZero q] (secretLaw : PMF (Fin d → Fin n → ZMod q)) (errorLaw : PMF (Fin m → Fin n → ZMod q)) (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :
realGame secretLaw errorLaw distinguisher = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin d) (Fin n → ZMod q))).bind fun (A : Matrix (Fin m) (Fin d) (Fin n → ZMod q)) => secretLaw.bind fun (s : Fin d → Fin n → ZMod q) => errorLaw.bind fun (e : Fin m → Fin n → ZMod q) => (distinguisher A (sample A s e)).eval

The real game with the matrix drawn first, as key generation draws it.

theorem Cslib.Crypto.ModuleLWE.randomGame_eq {m d n q : ℕ} [NeZero q] (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :
randomGame distinguisher = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin d) (Fin n → ZMod q) × (Fin m → Fin n → ZMod q))).bind fun (p : Matrix (Fin m) (Fin d) (Fin n → ZMod q) × (Fin m → Fin n → ZMod q)) => (distinguisher p.1 p.2).eval

The random game draws one uniform pair.

Module-LWE is LWE over the negacyclic ring #

theorem Cslib.Crypto.ModuleLWE.advantage_eq_lweAdvantage {m d n q : ℕ} [NeZero q] (secretLaw : PMF (Fin d → Fin n → ZMod q)) (errorLaw : PMF (Fin m → Fin n → ZMod q)) (distinguisher : Matrix (Fin m) (Fin d) (Fin n → ZMod q) → (Fin m → Fin n → ZMod q) → ProbComp Bool) :
advantage secretLaw errorLaw distinguisher = LWE.advantage (PMF.map (fun (x : Fin d → Fin n → ZMod q) => Negacyclic.ofCoeffs ∘ x) secretLaw) (PMF.map (fun (x : Fin m → Fin n → ZMod q) => Negacyclic.ofCoeffs ∘ x) errorLaw) fun (A : Matrix (Fin m) (Fin d) (Negacyclic (ZMod q) n)) (b : Fin m → Negacyclic (ZMod q) n) => distinguisher (A.map Negacyclic.coeffs) (Negacyclic.coeffs ∘ b)

Module-LWE is LWE over Negacyclic (ZMod q) n. The Module-LWE advantage for a secret law and an error law is the LWE advantage over the ring for their coefficientwise images, against the distinguisher that reads coefficients.

Encoded samples #

noncomputable def Cslib.Crypto.ModuleLWE.sampleLaw {m d n q : ℕ} [NeZero q] (secretLaw : PMF (Fin d → Fin n → ZMod q)) (errorLaw : PMF (Fin m → Fin n → ZMod q)) :
PMF (Matrix (Fin m) (Fin d) (Fin n → ZMod q) × (Fin m → Fin n → ZMod q))

Draw a Module-LWE sample (A, A · s + e) with secret s ← secretLaw, uniform A and error vector e ← errorLaw.

noncomputable def Cslib.Crypto.ModuleLWE.realEnsemble (m d n q : ℕ → ℕ) [∀ (κ : ℕ), NeZero (q κ)] (secret : (κ : ℕ) → PMF (Fin (d κ) → Fin (n κ) → ZMod (q κ))) (error : (κ : ℕ) → PMF (Fin (m κ) → Fin (n κ) → ZMod (q κ))) (κ : ℕ) :

Encoded real Module-LWE ensemble at each security parameter, for the secret law secret κ and the error law error κ.

noncomputable def Cslib.Crypto.ModuleLWE.uniformEnsemble (m d n q : ℕ → ℕ) [∀ (security : ℕ), NeZero (q security)] (security : ℕ) :

Encoded uniform comparison ensemble (A, u) with independent uniform A and u.

Distinguishers #

structure Cslib.Crypto.ModuleLWE.Input (m d n q : ℕ → ℕ) :

The input of a decision Module-LWE distinguisher with an m κ × d κ module matrix over ℤ_{q κ}[X] / (X^{n κ} + 1): the security parameter κ, a module matrix A and a vector b, which is A · s + e in the real experiment and uniform in the random one.

def Cslib.Crypto.ModuleLWE.Input.words {m d n q : ℕ → ℕ} (x : Input m d n q) :

The words a machine reads for a decision Module-LWE input: the security parameter and the encoded pair (A, b).

A decision Module-LWE input is determined by its words.

def Cslib.Crypto.ModuleLWE.encInput (m d n q : ℕ → ℕ) [∀ (κ : ℕ), NeZero (q κ)] :
Input m d n q ↪ List Bool

The encoding of a decision Module-LWE input: the framed unary security parameter followed by the encoded pair (A, b) (encInput_apply). Its sample part is the word realEnsemble and uniformEnsemble sample.

The decision Module-LWE input layout.

@[reducible, inline]

A decision Module-LWE distinguisher: given the security parameter κ, a module matrix A and a vector b of the shape, degree and modulus at κ, it outputs a bit. Distinguisher.IsPPT states its efficiency on encodings.

def Cslib.Crypto.ModuleLWE.Distinguisher.IsPPT {m d n q : ℕ → ℕ} [∀ (κ : ℕ), NeZero (q κ)] (D : Distinguisher m d n q) :

A decision Module-LWE distinguisher is PPT when one uniform strict PPT machine reads encInput and writes the distinguisher's output bit.

Word-level distinguishers #

The typed distinguisher that runs a word-level distinguisher on the encoded pair (A, b).

theorem Cslib.Crypto.ModuleLWE.distinguishingGame_realEnsemble {m d n q : ℕ → ℕ} [∀ (κ : ℕ), NeZero (q κ)] (secret : (κ : ℕ) → PMF (Fin (d κ) → Fin (n κ) → ZMod (q κ))) (error : (κ : ℕ) → PMF (Fin (m κ) → Fin (n κ) → ZMod (q κ))) (W : Crypto.Distinguisher) (κ : ℕ) :
distinguishingGame (realEnsemble m d n q secret error κ) (W κ) = realGame (secret κ) (error κ) (Distinguisher.ofWords W κ)

A word-level distinguisher on the encoded real sample runs the real game for the same laws.

A word-level distinguisher on the encoded uniform sample runs the random game.

def Cslib.Crypto.DecisionModuleLWEWith (m d n q : ℕ → ℕ) [∀ (κ : ℕ), NeZero (q κ)] (secret : (κ : ℕ) → PMF (Fin (d κ) → Fin (n κ) → ZMod (q κ))) (error : (κ : ℕ) → PMF (Fin (m κ) → Fin (n κ) → ZMod (q κ))) :

The decision Module-LWE assumption with an m κ × d κ module matrix over ℤ_{q κ}[X] / (X^{n κ} + 1), secret law secret κ and error law error κ: every PPT distinguisher has negligible advantage between ModuleLWE.realGame (secret κ) (error κ) and ModuleLWE.randomGame.

With short laws this is the assumption of the CRYSTALS submissions, in asymptotic form. Kyber v3.02 ([ABD+21], §4.3, p. 19) defines Adv^mlwe_{m,k,η} with (s, e) ← β_η^k × β_η^m for the centered binomial law β_η, and its Module-LWER problem without compression (§4.4 and footnote 3, pp. 21–22) draws s ← β_{η₁}^k and e ← β_{η₂}^m. Dilithium v3.1 ([BDK+21], §6.1, p. 23) defines MLWE_{m,k,D} with s₁ ← D^k and s₂ ← D^m, and §6.2, eq. (6), p. 24 takes D uniform on S_η. The sources define concrete advantages and take them to be small at their parameter sets; here every uniform classical strict PPT distinguisher has negligible advantage over the family. This is a hypothesis, not a theorem of hardness for any laws, and makes no claim about quantum adversaries; with uniform errors it holds trivially.

The assumption is meaningful only for a family whose parameters grow with κ. When m, d, n, q and the laws do not depend on κ, as at any FIPS 203 or FIPS 204 parameter set, the real and random games are two fixed distributions. Unless the real sample is exactly uniform, a polynomial-time distinguisher that looks the sample up in a fixed finite table has constant advantage, so the assumption fails.

def Cslib.Crypto.DecisionModuleLWE (m d n q : ℕ → ℕ) [∀ (κ : ℕ), NeZero (q κ)] (noise : (κ : ℕ) → PMF (Fin (n κ) → ZMod (q κ))) :

The decision Module-LWE assumption with an m κ × d κ module matrix over ℤ_{q κ}[X] / (X^{n κ} + 1) and error law noise κ for each polynomial: every PPT distinguisher has negligible advantage between ModuleLWE.realGame, with a uniform secret and independent errors, and ModuleLWE.randomGame. It is DecisionModuleLWEWith for these laws (decisionModuleLWE_iff_decisionModuleLWEWith). This is a hypothesis against uniform classical strict PPT distinguishers, not a theorem of hardness or a claim about quantum adversaries.

Source. [DKL+18], Section 4.1, p. 249, defines the advantage against the decisional MLWE_{m,k,D} problem over R_q = ℤ_q[X]/(X^n + 1) (Section 2.1, p. 242) for a distribution D on R_q: the gap between (A, t) with A ← R_q^{m×k} and t ← R_q^m, and (A, A s₁ + s₂) with s₁ ← D^k and s₂ ← D^m. Here k = d κ and the errors are drawn from D = noise κ. This definition differs from the source as follows.

  • The secret is uniform on R_q^k, not drawn from D^k. This form follows from MLWE_{m,k,D}: a distinguisher for it, run on (A, t + A u) for an independent uniform u, has the same advantage there. ML-KEM and ML-DSA need the short secrets that DecisionModuleLWEWith admits.
  • The degree n κ and modulus q κ are arbitrary, where Ducas et al. fix n = 256 and the prime q = 8380417.
  • Every uniform classical strict PPT distinguisher has negligible advantage over the family, where the source defines a concrete advantage at one parameter set.
theorem Cslib.Crypto.decisionModuleLWE_iff_decisionModuleLWEWith (m d n q : ℕ → ℕ) [∀ (κ : ℕ), NeZero (q κ)] (noise : (κ : ℕ) → PMF (Fin (n κ) → ZMod (q κ))) :
DecisionModuleLWE m d n q noise ↔ DecisionModuleLWEWith m d n q (fun (κ : ℕ) => Probability.PMF.uniformOfFintype (Fin (d κ) → Fin (n κ) → ZMod (q κ))) fun (κ : ℕ) => Probability.PMF.pi fun (x : Fin (m κ)) => noise κ

DecisionModuleLWE is DecisionModuleLWEWith for a uniform secret and independent polynomial errors drawn from noise κ.

theorem Cslib.Crypto.decisionModuleLWEWith_iff_encoded (m d n q : ℕ → ℕ) [∀ (κ : ℕ), NeZero (q κ)] (secret : (κ : ℕ) → PMF (Fin (d κ) → Fin (n κ) → ZMod (q κ))) (error : (κ : ℕ) → PMF (Fin (m κ) → Fin (n κ) → ZMod (q κ))) :

DecisionModuleLWEWith is the word-level decision Module-LWE assumption. Quantifying over distinguishers that read the encoded sample as a word gives the same assumption as quantifying over typed distinguishers. A typed distinguisher's machine reads exactly that word; conversely, a word distinguisher is typed by encoding its input, and a typed one is a word distinguisher run on that word (IsPPTOn.exists_bool_factor), since its output is a single bit.

theorem Cslib.Crypto.DecisionModuleLWEWith.encoded {m d n q : ℕ → ℕ} [∀ (κ : ℕ), NeZero (q κ)] {secret : (κ : ℕ) → PMF (Fin (d κ) → Fin (n κ) → ZMod (q κ))} {error : (κ : ℕ) → PMF (Fin (m κ) → Fin (n κ) → ZMod (q κ))} (h : DecisionModuleLWEWith m d n q secret error) :

Under DecisionModuleLWEWith, the encoded real and uniform samples are computationally indistinguishable to word-level distinguishers.