Documentation

CslibFrontier.Crypto.Computational.LWE.SearchToDecision

Finite probability bound toward search-to-decision for prime-modulus LWE #

Using Regev's coordinate transformation, a decision distinguisher D yields a finite-budget secret-recovery procedure over prime ZMod q. To test whether a guess g equals coordinate j of the secret s, it takes a fresh m-row sample [b | A], re-randomizes the secret to s + s' with a uniform s' (b ↦ b + A *ᵥ s'), and adds r to column j of A and (g + s' j) • r to b for a uniform r. When g = s j the result is a fresh LWE sample; otherwise its first column is uniform and independent of the rest, so the result is a uniform matrix. Each trial therefore accepts with D's acceptance probability on real samples or on uniform matrices, independently of all other trials.

The procedure runs N such trials for every coordinate j and guess g, each on its own block of m samples, and N trials of D on uniform matrices. For each j it outputs a guess whose acceptance count is farthest from the uniform count. Hoeffding's inequality and a union bound over the n * q + 1 estimators bound its failure probability.

This theorem and reduceSearchToDecision are finite steps toward Regev's polynomial-time search-to-decision reduction (#3673): the procedure samples exact uniform elements of ZMod q (which a fair-coin machine cannot sample exactly for odd primes q) and selects maximizing guesses via noncomputable guessSecret, so no IsPPTOn certificate or asymptotic SearchLWE → DecisionLWE implication is proved here.

Main definitions #

Main results #

References #

Shifting one coordinate #

def Cslib.Crypto.PrimeLWE.shiftCoordinate {n m q : ℕ} (P : Matrix (Fin m) (Fin (n + 1)) (ZMod q)) (j : Fin n) (g : ZMod q) (r : Fin m → ZMod q) :
Matrix (Fin m) (Fin (n + 1)) (ZMod q)

Shift the j-th coordinate of the public matrix by adding a vector r to the j-th column of A, and adding g * r to the 0-th column b.

theorem Cslib.Crypto.PrimeLWE.shiftCoordinate_publicMatrix {n m q : ℕ} [Fact (Nat.Prime q)] (A : Matrix (Fin m) (Fin n) (ZMod q)) (s : Fin n → ZMod q) (e : Fin m → ZMod q) (j : Fin n) (g : ZMod q) (r : Fin m → ZMod q) :
shiftCoordinate (LWE.publicMatrix A s e) j g r = LWE.publicMatrix (fun (i : Fin m) (c : Fin n) => if c = j then A i c + r i else A i c) s fun (i : Fin m) => e i + (g - s j) * r i

Shifting an LWE sample adds r to column j of A and (g - s j) * r to the error.

def Cslib.Crypto.PrimeLWE.shiftMatrixEquiv {n m q : ℕ} (j : Fin n) (r : Fin m → ZMod q) :
Matrix (Fin m) (Fin n) (ZMod q) ≃ Matrix (Fin m) (Fin n) (ZMod q)

For a fixed r, adding r to the j-th column is a bijection on matrices.

def Cslib.Crypto.PrimeLWE.shiftErrorEquiv {m q : ℕ} [Fact (Nat.Prime q)] (e : Fin m → ZMod q) (c : ZMod q) (hc : c ≠ 0) :
(Fin m → ZMod q) ≃ (Fin m → ZMod q)

For c ≠ 0, r ↦ e + c • r is a bijection on vectors over the field ZMod q.

noncomputable def Cslib.Crypto.PrimeLWE.lweSelfReduceDistinguisher {n m q : ℕ} [Fact (Nat.Prime q)] (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (P : Matrix (Fin m) (Fin (n + 1)) (ZMod q)) (j : Fin n) (g : ZMod q) :

The self-reduction for decision LWE: shift coordinate j by the guess g with a uniform vector, then run the distinguisher.

theorem Cslib.Crypto.PrimeLWE.uniform_bind_lweSelfReduceDistinguisher {n m q : ℕ} [Fact (Nat.Prime q)] (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (s : Fin n → ZMod q) (e : Fin m → ZMod q) (j : Fin n) (g : ZMod q) :
((Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) (ZMod q))).bind fun (A : Matrix (Fin m) (Fin n) (ZMod q)) => (lweSelfReduceDistinguisher distinguisher (LWE.publicMatrix A s e) j g).eval) = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) (ZMod q))).bind fun (A : Matrix (Fin m) (Fin n) (ZMod q)) => (Probability.PMF.uniformOfFintype (Fin m → ZMod q)).bind fun (r : Fin m → ZMod q) => (distinguisher (LWE.publicMatrix A s fun (i : Fin m) => e i + (g - s j) * r i)).eval

Over a uniform A, the self-reduction runs the distinguisher on an LWE sample with error e + (g - s j) • r for a uniform r.

theorem Cslib.Crypto.PrimeLWE.lweSelfReduce_real {n m q : ℕ} [Fact (Nat.Prime q)] (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (s : Fin n → ZMod q) (e : Fin m → ZMod q) (j : Fin n) (g : ZMod q) (hg : g = s j) :
((Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) (ZMod q))).bind fun (A : Matrix (Fin m) (Fin n) (ZMod q)) => (lweSelfReduceDistinguisher distinguisher (LWE.publicMatrix A s e) j g).eval) = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) (ZMod q))).bind fun (A : Matrix (Fin m) (Fin n) (ZMod q)) => (distinguisher (LWE.publicMatrix A s e)).eval

A correct guess leaves the law of an LWE sample with a uniform A unchanged.

theorem Cslib.Crypto.PrimeLWE.lweSelfReduce_ideal {n m q : ℕ} [Fact (Nat.Prime q)] (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (s : Fin n → ZMod q) (e : Fin m → ZMod q) (j : Fin n) (g : ZMod q) (hg : g ≠ s j) :
((Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) (ZMod q))).bind fun (A : Matrix (Fin m) (Fin n) (ZMod q)) => (lweSelfReduceDistinguisher distinguisher (LWE.publicMatrix A s e) j g).eval) = (Probability.PMF.uniformOfFintype (Matrix (Fin m) (Fin n) (ZMod q))).bind fun (A : Matrix (Fin m) (Fin n) (ZMod q)) => (Probability.PMF.uniformOfFintype (Fin m → ZMod q)).bind fun (v : Fin m → ZMod q) => (distinguisher (LWE.publicMatrix A s v)).eval

A wrong guess replaces the error of an LWE sample with a uniform A by a uniform vector.

Secret re-randomization and single trials #

def Cslib.Crypto.PrimeLWE.rerandomizeSecret {n m q : ℕ} (P : Matrix (Fin m) (Fin (n + 1)) (ZMod q)) (s' : Fin n → ZMod q) :
Matrix (Fin m) (Fin (n + 1)) (ZMod q)

Move the secret of a sample [b | A] from s to s + s' by adding A *ᵥ s' to b.

theorem Cslib.Crypto.PrimeLWE.rerandomizeSecret_publicMatrix {n m q : ℕ} [Fact (Nat.Prime q)] (A : Matrix (Fin m) (Fin n) (ZMod q)) (s s' : Fin n → ZMod q) (e : Fin m → ZMod q) :

Re-randomizing an LWE sample by s' adds s' to its secret.

noncomputable def Cslib.Crypto.PrimeLWE.coordinateTrial {n m q : ℕ} [Fact (Nat.Prime q)] (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (j : Fin n) (g : ZMod q) (P : Matrix (Fin m) (Fin (n + 1)) (ZMod q)) :

One trial for coordinate j and guess g on a fresh sample: re-randomize the secret by a uniform s', then run the self-reduction with the guess g + s' j.

noncomputable def Cslib.Crypto.PrimeLWE.estimatorTrial {n m q : ℕ} [Fact (Nat.Prime q)] (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) :
Option (Fin n × ZMod q) → Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool

The trial of an estimator on a sample. The estimator none runs the distinguisher on a fresh uniform matrix and ignores the sample; some (j, g) tests the guess g for coordinate j.

noncomputable def Cslib.Crypto.PrimeLWE.realLaw {n m q : ℕ} [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) :

The distinguisher's output law on real LWE samples.

noncomputable def Cslib.Crypto.PrimeLWE.uniformLaw {n m q : ℕ} [Fact (Nat.Prime q)] (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) :

The distinguisher's output law on uniform matrices.

noncomputable def Cslib.Crypto.PrimeLWE.sampleLaw (n m q : ℕ) [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (s : Fin n → ZMod q) :
PMF (Matrix (Fin m) (Fin (n + 1)) (ZMod q))

The law of an LWE sample with the fixed secret s.

noncomputable def Cslib.Crypto.PrimeLWE.estimatorLaw {n m q : ℕ} [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (s : Fin n → ZMod q) :
Option (Fin n × ZMod q) → PMF Bool

The output law of an estimator's trial on a fresh sample with secret s.

theorem Cslib.Crypto.PrimeLWE.sampleLaw_bind_coordinateTrial {n m q : ℕ} [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (s : Fin n → ZMod q) (j : Fin n) (g : ZMod q) :
((sampleLaw n m q noise s).bind fun (P : Matrix (Fin m) (Fin (n + 1)) (ZMod q)) => (coordinateTrial distinguisher j g P).eval) = if g = s j then realLaw noise distinguisher else uniformLaw distinguisher

On a fresh sample with secret s, a trial of guess g for coordinate j behaves like the distinguisher on real samples when g = s j and like the distinguisher on uniform matrices otherwise.

theorem Cslib.Crypto.PrimeLWE.sampleLaw_bind_estimatorTrial {n m q : ℕ} [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (s : Fin n → ZMod q) (o : Option (Fin n × ZMod q)) :
((sampleLaw n m q noise s).bind fun (P : Matrix (Fin m) (Fin (n + 1)) (ZMod q)) => (estimatorTrial distinguisher o P).eval) = estimatorLaw noise distinguisher s o

On a fresh sample with secret s, each estimator's trial has law estimatorLaw.

Independent blocks #

noncomputable def Cslib.Crypto.PrimeLWE.rowLaw (n q : ℕ) [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (s : Fin n → ZMod q) :
PMF (Fin (n + 1) → ZMod q)

The law of one row [a ⬝ᵥ s + x | a] of an LWE sample with secret s.

theorem Cslib.Crypto.PrimeLWE.sampleLaw_eq_pi (n m q : ℕ) [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (s : Fin n → ZMod q) :
sampleLaw n m q noise s = Probability.PMF.pi fun (x : Fin m) => rowLaw n q noise s

The rows of an LWE sample with a fixed secret are independent.

Number of samples used by reduceSearchToDecision: N blocks of m samples for each of the n * q + 1 estimators.

noncomputable def Cslib.Crypto.PrimeLWE.blockRow (n q N m : ℕ) [Fact (Nat.Prime q)] :
(Option (Fin n × ZMod q) × Fin N) × Fin m ≃ Fin (searchSamples n q N m)

Row i of block t of estimator o among the searchSamples n q N m samples.

noncomputable def Cslib.Crypto.PrimeLWE.sampleBlock {n q N m : ℕ} [Fact (Nat.Prime q)] (P : Matrix (Fin (searchSamples n q N m)) (Fin (n + 1)) (ZMod q)) (o : Option (Fin n × ZMod q)) (t : Fin N) :
Matrix (Fin m) (Fin (n + 1)) (ZMod q)

Block t of estimator o of a sample with searchSamples n q N m rows.

theorem Cslib.Crypto.PrimeLWE.sampleLaw_map_sampleBlock {n q N m : ℕ} [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (s : Fin n → ZMod q) :
PMF.map sampleBlock (sampleLaw n (searchSamples n q N m) q noise s) = Probability.PMF.pi fun (x : Option (Fin n × ZMod q)) => Probability.PMF.pi fun (x : Fin N) => sampleLaw n m q noise s

With secret s, the blocks of a searchSamples n q N m-row sample are independent m-row samples.

noncomputable def Cslib.Crypto.PrimeLWE.runTrials {n m q N : ℕ} [Fact (Nat.Prime q)] (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (P : Matrix (Fin (searchSamples n q N m)) (Fin (n + 1)) (ZMod q)) :
ProbComp (Option (Fin n × ZMod q) → Fin N → Bool)

Run every estimator's trials, each on its own block.

theorem Cslib.Crypto.PrimeLWE.sampleLaw_bind_runTrials {n m q N : ℕ} [Fact (Nat.Prime q)] (noise : PMF (ZMod q)) (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (s : Fin n → ZMod q) :
((sampleLaw n (searchSamples n q N m) q noise s).bind fun (P : Matrix (Fin (searchSamples n q N m)) (Fin (n + 1)) (ZMod q)) => (runTrials distinguisher P).eval) = Probability.PMF.pi fun (o : Option (Fin n × ZMod q)) => Probability.PMF.pi fun (x : Fin N) => estimatorLaw noise distinguisher s o

On a sample with secret s, all trials are independent with their estimators' laws.

Choosing the secret from the counts #

The number of accepting trials.

noncomputable def Cslib.Crypto.PrimeLWE.guessSecret {n q N : ℕ} [Fact (Nat.Prime q)] (X : Option (Fin n × ZMod q) → Fin N → Bool) (j : Fin n) :

For coordinate j, a guess g whose acceptance count is farthest from the count of the uniform estimator none.

theorem Cslib.Crypto.PrimeLWE.abs_sub_le_guessSecret {n q N : ℕ} [Fact (Nat.Prime q)] (X : Option (Fin n × ZMod q) → Fin N → Bool) (j : Fin n) (g : ZMod q) :
|↑(trueCount (X (some (j, g)))) - ↑(trueCount (X none))| ≤ |↑(trueCount (X (some (j, guessSecret X j)))) - ↑(trueCount (X none))|

guessSecret maximizes the distance from the uniform estimator's count.

theorem Cslib.Crypto.PrimeLWE.guessSecret_eq_of_close {n q N : ℕ} [Fact (Nat.Prime q)] (X : Option (Fin n × ZMod q) → Fin N → Bool) (s : Fin n → ZMod q) {pR pU : ℝ} (hnone : |↑(trueCount (X none)) - ↑N * pU| < ↑N * |pR - pU| / 4) (hsome : ∀ (j : Fin n) (g : ZMod q), |↑(trueCount (X (some (j, g)))) - ↑N * if g = s j then pR else pU| < ↑N * |pR - pU| / 4) :

If every count is within N * |pR - pU| / 4 of its mean, where correct guesses have mean N * pR and the uniform estimator and wrong guesses have mean N * pU, then guessSecret returns the secret.

theorem Cslib.Crypto.PrimeLWE.pi_estimatorLaw_guessSecret_ne_le {n m q : ℕ} [Fact (Nat.Prime q)] (N : ℕ) (noise : PMF (ZMod q)) (distinguisher : Matrix (Fin m) (Fin (n + 1)) (ZMod q) → ProbComp Bool) (s : Fin n → ZMod q) :
((Probability.PMF.pi fun (o : Option (Fin n × ZMod q)) => Probability.PMF.pi fun (x : Fin N) => estimatorLaw noise distinguisher s o).toOuterMeasure {X : Option (Fin n × ZMod q) → Fin N → Bool | guessSecret X ≠ s}).toReal ≤ (↑n * ↑q + 1) * (2 * Real.exp (-(↑N * |((realLaw noise distinguisher) true).toReal - ((uniformLaw distinguisher) true).toReal| ^ 2) / 8))

When the trials are drawn from their estimators' laws, guessSecret misses the secret with probability at most (n * q + 1) * 2 * exp (-N * |pR - pU| ^ 2 / 8).

Finite-budget search procedure #

noncomputable def Cslib.Crypto.PrimeLWE.reduceSearchToDecision {n m q : ℕ} [Fact (Nat.Prime q)] (N : ℕ) (adversary : List Bool → ProbComp Bool) (word : List Bool) :

Finite-budget search procedure on searchSamples n q N m samples (a finite step toward Regev's search-to-decision reduction): decode the sample, run N trials of every estimator on its own m-row blocks, each with the decision adversary on encoded matrices, and output a maximizing guessed secret.

theorem Cslib.Crypto.PrimeLWE.searchToDecision {n m q : ℕ} [Fact (Nat.Prime q)] {noise : PMF (ZMod q)} (adversary : List Bool → ProbComp Bool) (N : ℕ) :
1 - (↑n * ↑q + 1) * (2 * Real.exp (-(↑N * ↑((distinguishingGame (realEnsemble (fun (x : ℕ) => n) (fun (x : ℕ) => m) (fun (x : ℕ) => q) (fun (x : ℕ) => noise) 0) adversary).advantage (distinguishingGame (uniformEnsemble (fun (x : ℕ) => n) (fun (x : ℕ) => m) (fun (x : ℕ) => q) 0) adversary)) ^ 2) / 8)) ≤ ↑(searchGame n (searchSamples n q N m) q noise (reduceSearchToDecision N adversary)).succProbability

Finite probability step toward search-to-decision for prime-modulus LWE. From a decision-LWE adversary with advantage ε on m samples, reduceSearchToDecision recovers the uniform secret in searchGame from (n * q + 1) * N * m samples with probability at least 1 - (n * q + 1) * 2 * exp (-N * ε ^ 2 / 8).