Documentation

CslibFrontier.Crypto.Computational.LWE.Basic

Decision LWE #

The decision learning-with-errors experiments over a finite commutative ring R ([Reg09], [GSW13], Section 2): the real experiment LWE.realExperiment draws a uniform matrix A and gives the distinguisher A and A *ᵥ s + e for a secret s and an error vector e; the random experiment LWE.randomExperiment gives it a uniform pair. For a secret law and an error law, the real game LWE.realGame draws s and e and runs the real experiment, LWE.randomGame runs the random one, and LWE.advantage is the distance between them.

DecisionLWE n m w noise is the asymptotic assumption at modulus 2 ^ w κ, with n κ secret coordinates and m κ samples: every distinguisher that is uniform strict PPT on encodings (LWE.Distinguisher.IsPPT) has negligible advantage between the real game with a uniform secret and independent errors from noise κ and the random game. A distinguisher machine reads the unary security parameter and the row-major binary word of the matrix [b | A] (LWE.encInput_apply).

A distinguisher outputs a bit, so DecisionLWE is the same assumption as the indistinguishability of the encoded real and uniform matrices LWE.realEnsemble and LWE.uniformEnsemble against word-level distinguishers (decisionLWE_iff_encoded). Clients that reduce on encoded words use DecisionLWE.encoded.

DecisionLWE is a hypothesis against uniform classical strict polynomial-time programs. It makes no assertion of hardness for any particular parameter or error family. In particular, using a bounded noise distribution does not identify it with a discrete Gaussian or establish a worst-case lattice reduction.

Main definitions #

Main results #

References #

Encoded matrices #

def Cslib.Crypto.LWE.publicMatrix {n m : ℕ} {R : Type} [CommRing R] (B : Matrix (Fin m) (Fin n) R) (t : Fin n → R) (error : Fin m → R) :
Matrix (Fin m) (Fin (n + 1)) R

The deterministic LWE public matrix [B * t + error | B].

noncomputable def Cslib.Crypto.LWE.publicMatrixLaw {R : Type} [CommRing R] [Fintype R] [Nonempty R] (n m : ℕ) (noise : PMF R) :
PMF (Matrix (Fin m) (Fin (n + 1)) R)

Draw the public matrix [B * t + e | B]. The errors are independent of one another, of the uniform matrix, and of the uniform secret shared by all rows.

noncomputable def Cslib.Crypto.LWE.realEnsemble (n m w : ℕ → ℕ) (noise : (security : ℕ) → PMF (ZMod (2 ^ w security))) (security : ℕ) :

Binary decision-LWE samples, using w bits per residue and a uniform secret.

noncomputable def Cslib.Crypto.LWE.uniformEnsemble (n m w : ℕ → ℕ) (security : ℕ) :

Encode a uniform matrix with exactly the real experiment's dimensions and modulus.

theorem Cslib.Crypto.LWE.length_of_mem_support_realEnsemble {n m w : ℕ → ℕ} {noise : (security : ℕ) → PMF (ZMod (2 ^ w security))} {security : ℕ} {word : List Bool} (h : word ∈ (realEnsemble n m w noise security).support) :
word.length = m security * (n security + 1) * w security

The real public word contains exactly one fixed-width residue for each matrix entry.

theorem Cslib.Crypto.LWE.length_of_mem_support_uniformEnsemble {n m w : ℕ → ℕ} {security : ℕ} {word : List Bool} (h : word ∈ (uniformEnsemble n m w security).support) :
word.length = m security * (n security + 1) * w security

Uniform public words have the same complete serialized length as real public words.

Fixed-instance experiments #

noncomputable def Cslib.Crypto.LWE.realExperiment {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (s : Fin n → R) (e : Fin m → R) (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :

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

noncomputable def Cslib.Crypto.LWE.randomExperiment {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :

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

@[simp]
theorem Cslib.Crypto.LWE.eval_realExperiment {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (s : Fin n → R) (e : Fin m → R) (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :
ProbComp.eval (realExperiment s e distinguisher) = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) R)).bind fun (A : Matrix (Fin m) (Fin n) R) => (distinguisher A (A.mulVec s + e)).eval
@[simp]
theorem Cslib.Crypto.LWE.eval_randomExperiment {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :
ProbComp.eval (randomExperiment distinguisher) = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) R)).bind fun (A : Matrix (Fin m) (Fin n) R) => (Probability.PMF.uniformOfFintype (Fin m → R)).bind fun (b : Fin m → R) => (distinguisher A b).eval
noncomputable def Cslib.Crypto.LWE.realGame {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (secretLaw : PMF (Fin n → R)) (errorLaw : PMF (Fin m → R)) (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :

The real decision-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.LWE.randomGame {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :

The random decision-LWE game: run randomExperiment.

noncomputable def Cslib.Crypto.LWE.advantage {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (secretLaw : PMF (Fin n → R)) (errorLaw : PMF (Fin m → R)) (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :

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

theorem Cslib.Crypto.LWE.realGame_uniform_error_eq_randomGame {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (secretLaw : PMF (Fin n → R)) (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :
realGame secretLaw (Probability.PMF.uniformOfFintype (Fin m → R)) distinguisher = randomGame distinguisher

With uniform errors the real game is the random game, for every secret law: A *ᵥ s + e is uniform and independent of (A, s).

theorem Cslib.Crypto.LWE.advantage_uniform_error_eq_zero {R : Type} [CommRing R] [Fintype R] {n m : ℕ} (secretLaw : PMF (Fin n → R)) (distinguisher : Matrix (Fin m) (Fin n) R → (Fin m → R) → ProbComp Bool) :
advantage secretLaw (Probability.PMF.uniformOfFintype (Fin m → R)) distinguisher = 0

With uniform errors every distinguisher has advantage 0, for every secret law.

The matrix of a sample #

def Cslib.Crypto.LWE.augmentedMatrix {R : Type} {n m : ℕ} (A : Matrix (Fin m) (Fin n) R) (b : Fin m → R) :
Matrix (Fin m) (Fin (n + 1)) R

The matrix [b | A] of an LWE sample: row i is b i followed by row i of A.

def Cslib.Crypto.LWE.augmentedMatrixEquiv {R : Type} {n m : ℕ} :
Matrix (Fin m) (Fin n) R × (Fin m → R) ≃ Matrix (Fin m) (Fin (n + 1)) R

Splitting off the first column identifies pairs (A, b) with matrices [b | A].

@[simp]
theorem Cslib.Crypto.LWE.augmentedMatrixEquiv_apply {R : Type} {n m : ℕ} (p : Matrix (Fin m) (Fin n) R × (Fin m → R)) :
theorem Cslib.Crypto.LWE.augmentedMatrix_inj {R : Type} {n m : ℕ} {A A' : Matrix (Fin m) (Fin n) R} {b b' : Fin m → R} :
augmentedMatrix A b = augmentedMatrix A' b' ↔ A = A' ∧ b = b'

[b | A] determines A and b.

[b | A] for a uniform matrix A and an independent uniform vector b is uniform.

theorem Cslib.Crypto.LWE.publicMatrix_eq_augmentedMatrix {n m w : ℕ} (B : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) (t : Fin n → ZMod (2 ^ w)) (e : Fin m → ZMod (2 ^ w)) :

The public matrix [B * t + e | B] is the matrix of the sample (B, B *ᵥ t + e).

theorem Cslib.Crypto.LWE.binaryEntry_toBinary_augmentedMatrix_zero {n m w : ℕ} (A : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) (b : Fin m → ZMod (2 ^ w)) (i : Fin m) :
↑(Matrix.binaryEntry (n + 1) w (Matrix.toBinary (augmentedMatrix A b)) (↑i) 0) = b i

Column 0 of row i of the word of [b | A] is b i.

theorem Cslib.Crypto.LWE.binaryEntry_toBinary_augmentedMatrix_succ {n m w : ℕ} (A : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) (b : Fin m → ZMod (2 ^ w)) (i : Fin m) (j : Fin n) :
↑(Matrix.binaryEntry (n + 1) w (Matrix.toBinary (augmentedMatrix A b)) (↑i) (↑j + 1)) = A i j

Column j + 1 of row i of the word of [b | A] is A i j.

Distinguishers at modulus 2 ^ w #

structure Cslib.Crypto.LWE.Input (n m w : ℕ → ℕ) :

The input of a decision-LWE distinguisher with n κ secret coordinates, m κ samples and modulus 2 ^ w κ: the security parameter κ, a matrix A and a vector b, which is A *ᵥ s + e in the real experiment and uniform in the random one.

def Cslib.Crypto.LWE.Input.words {n m w : ℕ → ℕ} (x : Input n m w) :

The words a machine reads for a decision-LWE input: the security parameter and the binary word of the matrix [b | A].

A decision-LWE input is determined by its words.

The encoding of a decision-LWE input: the framed unary security parameter followed by the row-major binary word of [b | A] (encInput_apply). Its matrix part is the word realEnsemble and uniformEnsemble sample.

The security parameter of a decision-LWE input is computable in polynomial time from its encoding.

The word of the matrix [b | A] of a decision-LWE input is computable in polynomial time from its encoding.

@[reducible, inline]

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

A decision-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 binary word of [b | A].

theorem Cslib.Crypto.LWE.distinguishingGame_realEnsemble {n m w : ℕ → ℕ} (noise : (κ : ℕ) → PMF (ZMod (2 ^ w κ))) (W : Crypto.Distinguisher) (κ : ℕ) :
distinguishingGame (realEnsemble n m w noise κ) (W κ) = realGame (Probability.PMF.uniformOfFintype (Fin (n κ) → ZMod (2 ^ w κ))) (Probability.PMF.pi fun (x : Fin (m κ)) => noise κ) (Distinguisher.ofWords W κ)

A word-level distinguisher on the encoded real matrix runs the real game with a uniform secret and independent errors from noise κ.

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

def Cslib.Crypto.DecisionLWEWithErrors (n m w : ℕ → ℕ) (errors : (κ : ℕ) → PMF (Fin (m κ) → ZMod (2 ^ w κ))) :

The decision-LWE assumption with n κ secret coordinates, m κ samples, modulus 2 ^ w κ and a joint law errors κ on the whole error vector: every PPT distinguisher has negligible advantage between LWE.realGame, with a uniform secret and an error vector drawn from errors κ, and LWE.randomGame. The coordinates of the error vector need not be independent or identically distributed, which is the form needed when a noisy source supplies the errors, as in the LWE fuzzy extractor. DecisionLWE is the case of independent coordinates. This is a hypothesis against uniform classical strict PPT distinguishers, not a theorem of hardness or a claim about quantum adversaries; whether it holds depends on the error laws.

Status. This assumption is novel to this library. It has the form of dist-LWE_{n,m,q,χ} of [FMR20], Definition 4.5 (p. 13 of the ePrint revision of June 23, 2020), with χ := errors κ an arbitrary distribution on the whole error vector, but at modulus 2 ^ w κ, outside that definition's range of prime q = poly(n): the two ranges meet only at q = 2. Fuller, Meng and Reyzin use the source reading W as that error law (Section 4, p. 11): Lemma 4.7 (p. 14) assumes Definition 4.5 in dimension n - k for any χ, and Theorem 4.11 (p. 17) assumes it for the uniform source over 𝒵^m, where 𝒵 = [−2^{b−1}, 2^{b−1}].

Relation to standard assumptions. DecisionLWE is the case of independent coordinates (decisionLWE_iff_decisionLWEWithErrors). For other laws, neither this assumption nor FMR's prime-modulus form is proved or cited to imply the other, and hardness can differ between the two moduli for the same law. Take an error law supported on even residues. At each κ with w κ > 0 and m κ > n κ, reducing A and b modulo 2 and testing whether A s ≡ b (mod 2) has a solution separates the games: in the real game it always has one, and in the random game with probability at most 2 ^ (n κ - m κ) ≤ 1/2. At w κ = 0 the modulus is 1 and the two games coincide. The test needs n κ, m κ and w κ to locate the entries in its input, so it is PPT when n, m and w are computable in polynomial time in unary, and the assumption then fails if w κ > 0 and m κ > n κ for infinitely many κ. At an odd prime q, multiplying by 2⁻¹ turns errors 2 e' into e'.

Deviations from Definition 4.5.

  • The modulus 2 ^ w κ replaces the prime q = poly(n), which FMR need for decoding (footnote 2, p. 13), and w may make it superpolynomial. FMR's evidence for the assumption does not cover this modulus: Theorems 4.6 and 4.8 (pp. 13–14), which derive it for uniform-interval errors from LWE with Gaussian errors, and Theorem 5.2 (p. 18), which derives it for symbol-fixing sources from uniform errors, are all for prime q.
  • Distinguishers are uniform strict PPT programs and the advantage must be negligible, where Definition 4.5 is concrete: advantage at most ε against distinguishers of size s_sec.
  • The theorem that assumes it chooses the dimension. FuzzyExtractor.computationallySecure_lweFuzzyExtractor_of_decisionLWEWithErrors assumes it in dimension l = n - k, following Lemma 4.7, where Theorem 4.11 writes dist-LWE(n,m,q,𝒵^m) in dimension n; hardness in dimension n - k implies hardness in dimension n.
  • n, m and w are arbitrary functions of a separate security parameter κ, where Definition 4.5 takes n as the security parameter and m, q = poly(n). A distinguisher's clock is polynomial in the length of its encoded input (LWE.Distinguisher.IsPPT), which is framed unary κ followed by the m κ * (n κ + 1) * w κ bits of [b | A] (LWE.encInput). For arbitrary n, m and w that length need not be polynomial in κ. When they are computable in polynomial time in unary, as the theorem that assumes it requires, the length is at least κ and polynomial in κ, so the clock is polynomial in κ. A family whose dimension grows slowly in κ, such as n κ = ⌊log κ⌋, then asks for hardness against adversaries superpolynomial in the dimension, which is more than standard LWE asks.

Plausibility. It is the problem that FMR study, moved to the modulus of the library's DecisionLWE, its case of independent coordinates. At prime modulus, FMR derive it from LWE with Gaussian errors, directly for uniform-interval sources (Theorems 4.6 and 4.8) and through them for symbol-fixing sources (Theorem 5.2). No such derivation at modulus 2 ^ w κ is proved here or cited, and whether the assumption holds depends on the error law.

def Cslib.Crypto.DecisionLWE (n m w : ℕ → ℕ) (noise : (κ : ℕ) → PMF (ZMod (2 ^ w κ))) :

The decision-LWE assumption with n κ secret coordinates, m κ samples, modulus 2 ^ w κ and error law noise κ for each coordinate: every PPT distinguisher has negligible advantage between LWE.realGame, with a uniform secret and independent errors, and LWE.randomGame. It is DecisionLWEWithErrors for the product error law (decisionLWE_iff_decisionLWEWithErrors). This is a hypothesis against uniform classical strict PPT distinguishers, not a theorem of hardness or a claim about quantum adversaries.

Source. [Reg09] (the author's version of May 2, 2009), Section 2, p. 15, defines, for any integer p ≥ 2 and any distribution χ on ℤ_p, the distribution A_{s,χ} of pairs (a, ⟨a, s⟩ + e) with a uniform on ℤ_pⁿ and e ← χ, and the search problem LWE_{p,χ}. Section 4, Lemma 4.1, p. 30, concerns the decision variant: distinguishing A_{s,χ} from the uniform distribution for a non-negligible fraction of the secrets s. Here the secret is uniform and the advantage is averaged over it. This definition differs from the source as follows.

  • The modulus is 2 ^ w κ, a restriction of Regev's range of integers p ≥ 2 (Section 2, p. 15); at w κ = 0 it is 1, where the real and random games coincide. Regev's worst-case hardness for the decision variant covers none of these moduli: his decision-to-search reduction, Lemma 4.2, p. 31, needs a prime p ≤ poly(n), which leaves only 2, and his main theorem, Theorem 3.1, p. 18, needs αp > 2√n with α < 1, which fails at p = 2.
  • The distinguisher receives exactly m κ samples, as the rows of A and b, where Regev's algorithms draw samples from A_{s,χ} as they need them.
  • The noise law is arbitrary; Regev's hardness results are for Gaussian noise (Ψ_α, and its discretization Ψ̄_α for the decision variant).
  • Distinguishers are uniform classical strict PPT programs in the security parameter κ, where Regev's efficient algorithms run in time polynomial in n.
theorem Cslib.Crypto.decisionLWE_iff_decisionLWEWithErrors (n m w : ℕ → ℕ) (noise : (κ : ℕ) → PMF (ZMod (2 ^ w κ))) :
DecisionLWE n m w noise ↔ DecisionLWEWithErrors n m w fun (κ : ℕ) => Probability.PMF.pi fun (x : Fin (m κ)) => noise κ

DecisionLWE is DecisionLWEWithErrors for the error vector with independent coordinates drawn from noise κ.

theorem Cslib.Crypto.decisionLWE_iff_encoded (n m w : ℕ → ℕ) (noise : (κ : ℕ) → PMF (ZMod (2 ^ w κ))) :

DecisionLWE is the word-level decision-LWE assumption. Quantifying over distinguishers that read the encoded matrix [b | A] 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.DecisionLWE.encoded {n m w : ℕ → ℕ} {noise : (κ : ℕ) → PMF (ZMod (2 ^ w κ))} (h : DecisionLWE n m w noise) :

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