Documentation

CslibFrontier.Crypto.Computational.LWE.Trapdoor.Basic

Micciancio–Peikert gadget-based lattice trapdoors (GenTrap, syndrome lifting, LWE inversion) #

This module formalizes the gadget-based trapdoor construction of Micciancio and Peikert, Section 5 over ZMod (2 ^ w), building on the primitive gadget matrix G = gadgetMatrix w and short kernel matrix S = gadgetBasis w from CslibFrontier.Crypto.Computational.LWE.Trapdoor.Gadget:

  1. Tagged parity-check matrices and H-tag trapdoors (Definition 5.2, Algorithm 1): Given Abar : Matrix ι μ (ZMod (2 ^ w)), a short integer matrix R : Matrix μ (ι × Fin w) ℤ, and a tag H : Matrix ι ι (ZMod (2 ^ w)), taggedMatrix w Abar R H = [Abar | H * G - Abar * R] (Matrix.fromCols) and trapdoorTransform R = [R; I] (Matrix.fromRows) satisfy the unrestricted tag equation A * [R; I] = H * G (taggedMatrix_mul_trapdoorTransform). When H is invertible (IsUnit H), R is an H-tag G-trapdoor for A in the sense of Definition 5.2 (IsHTagTrapdoor, isHTagTrapdoor_taggedMatrix, isHTagTrapdoor_untaggedMatrix).
  2. Syndrome lifting (f_A⁻¹) and lifted kernel vectors in Λ^⊥(A) (Section 5.1): Applying [R; I] lifts any gadget preimage z of H⁻¹ u to a short preimage x = [R z; z] satisfying A x = u (taggedMatrix_mulVec_invertSyndrome), so any matrix admitting an H-tag G-trapdoor is primitive (IsHTagTrapdoor.surjective, taggedMatrix_surjective; the remark after Definition 5.2). The w columns of [R; I] * S = [R S; S] lie in Λ^⊥(A) (taggedMatrix_mul_extendedGadgetBasis, extendedGadgetBasis_col_inKernelLattice), with entrywise bounds (natAbs_extendedGadgetBasis_inl_le, natAbs_extendedGadgetBasis_inr_le). These are the right-hand w columns of the basis S_A of Lemma 5.3; the left-hand block (built from a solution W of G W = -H⁻¹ A [I | 0]ᵀ), the claim that S_A generates Λ^⊥(A), and the Gram–Schmidt bound of Lemma 5.3 are not formalized.
  3. Deterministic trapdoor LWE inversion (g_A⁻¹, Section 5.3, Algorithm 2 / Theorem 5.4): Given bᵀ = sᵀ A + eᵀ mod 2 ^ w, right-multiplying by [R; I] yields bᵀ [R; I] = (sᵀ H) G + (e_1ᵀ R + e_2ᵀ) (trapdoorLWE_vecMul_trapdoorTransform). Applying invertGadget w followed by H⁻¹ recovers s whenever every coordinate of the projected error e_1ᵀ R + e_2ᵀ satisfies 4 * |projectedError R e p| < 2 ^ w (invertLWESecret_trapdoorLWE), and centered lifting (ZMod.valMinAbs) recovers the full pair (s, e) when in addition every original error coordinate satisfies 2 * |e k| < 2 ^ w (invertLWE_trapdoorLWE), both of which follow from the combined entrywise norm bound 4 * (1 + |μ| * B_R) * B_e < 2 ^ w (invertLWE_trapdoorLWE_of_norm_bound). This is the deterministic part of Theorem 5.4 with the oracle O instantiated by invertGadget and with coordinatewise (infinity-norm) hypotheses in place of the paper's Euclidean bound ‖e‖ < q / (2 ‖B‖ s); the second claim of Theorem 5.4 (success with overwhelming probability for Gaussian errors) is not formalized.
  4. Probabilistic trapdoor generation GenTrap and an idealized hybrid (Section 5.2, Algorithm 1): genTrap samples Abar uniformly via LWE.sampleMatrix and R with centered-binomial entries in [-η, η] (sampleTrapdoorMatrix; the paper allows any distribution D), returning (taggedMatrix w Abar R H, R) (mem_support_genTrap). In the idealized hybrid genTrapIdeal, where Abar * R is replaced by an independent uniform block, the public matrix is exactly uniform for every tag H (eval_genTrapIdeal_eq_uniform, eval_genTrapIdeal_eq_of_tags).

Not formalized here: the step from genTrap to genTrapIdeal, that is, the statistical instantiation (regularity of [Abar | Abar R]) and the computational instantiation (decision-LWE) of Section 5.2, so neither the statistical closeness of A to uniform claimed in Theorem 5.1 nor its pseudorandomness is proved; the trapdoor quality s_1(R); discrete-Gaussian preimage sampling (SampleD, Section 5.4); and trapdoor delegation (Section 5.5).

Main definitions #

Main results #

References #

Tagged parity-check matrices and H-tag trapdoors (Definition 5.2, Algorithm 1) #

def Cslib.Crypto.LWE.Trapdoor.taggedRightBlock {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) :
Matrix ι (ι × Fin w) (ZMod (2 ^ w))

The right block A_1 = H * G - Abar * R of a Micciancio–Peikert tagged parity-check matrix ([MP12], Section 5.2, Algorithm 1, step 2).

def Cslib.Crypto.LWE.Trapdoor.taggedMatrix {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) :
Matrix ι (μ ⊕ ι × Fin w) (ZMod (2 ^ w))

The Micciancio–Peikert tagged parity-check matrix A = [Abar | H * G - Abar * R] ([MP12], Section 5.2, Algorithm 1, step 2).

def Cslib.Crypto.LWE.Trapdoor.untaggedMatrix {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) :
Matrix ι (μ ⊕ ι × Fin w) (ZMod (2 ^ w))

The untagged parity-check matrix A = [Abar | G - Abar * R] corresponding to H = I, the default tag of [MP12], Algorithm 1.

def Cslib.Crypto.LWE.Trapdoor.trapdoorTransform {ι : Type u_1} {μ : Type u_2} {w : ℕ} [DecidableEq ι] (R : Matrix μ (ι × Fin w) ℤ) :
Matrix (μ ⊕ ι × Fin w) (ι × Fin w) ℤ

The integer trapdoor transformation matrix [R; I] mapping gadget coordinates ι × Fin w into full column coordinates μ ⊕ (ι × Fin w) ([MP12], Definition 5.2).

def Cslib.Crypto.LWE.Trapdoor.IsHTagTrapdoor {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (A : Matrix ι (μ ⊕ ι × Fin w) (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) :

R is a G-trapdoor for A with tag H ([MP12], Definition 5.2): A * [R; I] = H * G modulo 2 ^ w and the tag H is invertible (IsUnit H).

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.taggedMatrix_mul_trapdoorTransform {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) :

Unrestricted tag equation: [Abar | H * G - Abar * R] * [R; I] = H * G modulo 2 ^ w for any Abar, R, and H ([MP12], Section 5.2, Algorithm 1).

theorem Cslib.Crypto.LWE.Trapdoor.isHTagTrapdoor_taggedMatrix {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) {H : Matrix ι ι (ZMod (2 ^ w))} (hH : IsUnit H) :
IsHTagTrapdoor w (taggedMatrix w Abar R H) R H

When H is invertible (IsUnit H), R is an H-tag G-trapdoor for taggedMatrix w Abar R H ([MP12], Definition 5.2).

theorem Cslib.Crypto.LWE.Trapdoor.isHTagTrapdoor_untaggedMatrix {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) :

R is an I-tag G-trapdoor for untaggedMatrix w Abar R ([MP12], Definition 5.2 and Algorithm 1).

theorem Cslib.Crypto.LWE.Trapdoor.taggedRightBlock_sub_tag {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H H' : Matrix ι ι (ZMod (2 ^ w))) :
taggedRightBlock w Abar R H - (H - H') * gadgetMatrix w = taggedRightBlock w Abar R H'

Tag-shift identity: subtracting (H - H') * G from the right block of an H-tagged matrix yields the H'-tagged matrix for the same (Abar, R).

theorem Cslib.Crypto.LWE.Trapdoor.taggedMatrix_zero_mul_trapdoorTransform {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) :

When the tag vanishes (H = 0, which is not an invertible tag), the trapdoor transformation maps into the kernel of A: taggedMatrix w Abar R 0 * [R; I] = 0.

Syndrome lifting (f_A⁻¹) and lifted kernel vectors in Λ^⊥(A) (Section 5.1) #

theorem Cslib.Crypto.LWE.Trapdoor.inKernelLattice_of_isSolution {κ : Type u_3} {q : ℕ} {ρ : Type u_4} [Fintype κ] {A : Matrix ρ κ (ZMod q)} {β : ℕ} {z : κ → ℤ} (hz : SIS.IsSolution A β z) :

Every short integer solution in the sense of Cslib.Crypto.SIS.IsSolution lies in the q-ary kernel lattice Λ^⊥(A).

def Cslib.Crypto.LWE.Trapdoor.liftPreimage {ι : Type u_1} {μ : Type u_2} {w : ℕ} [Fintype ι] (R : Matrix μ (ι × Fin w) ℤ) (z : ι × Fin w → ℤ) :
μ ⊕ ι × Fin w → ℤ

Lift an integer vector z : ι × Fin w → ℤ in gadget space to x = [R z; z] in full column space μ ⊕ (ι × Fin w).

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.liftPreimage_inl {ι : Type u_1} {μ : Type u_2} {w : ℕ} [Fintype ι] (R : Matrix μ (ι × Fin w) ℤ) (z : ι × Fin w → ℤ) (j : μ) :
@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.liftPreimage_inr {ι : Type u_1} {μ : Type u_2} {w : ℕ} [Fintype ι] (R : Matrix μ (ι × Fin w) ℤ) (z : ι × Fin w → ℤ) (p : ι × Fin w) :
liftPreimage R z (Sum.inr p) = z p
theorem Cslib.Crypto.LWE.Trapdoor.liftPreimage_eq_mulVec {ι : Type u_1} {μ : Type u_2} {w : ℕ} [Fintype ι] [DecidableEq ι] (R : Matrix μ (ι × Fin w) ℤ) (z : ι × Fin w → ℤ) :
@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.taggedMatrix_mulVec_liftPreimage {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) (z : ι × Fin w → ℤ) :

Action of taggedMatrix w Abar R H on a lifted vector [R z; z]: A *ᵥ [R z; z] = H *ᵥ (G *ᵥ z) modulo 2 ^ w.

theorem Cslib.Crypto.LWE.Trapdoor.liftPreimage_inKernelLattice {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) {z : ι × Fin w → ℤ} (hz : InKernelLattice (gadgetMatrix w) z) :

Lifting any kernel vector z ∈ Λ^⊥(G) yields a kernel vector [R z; z] ∈ Λ^⊥(A).

def Cslib.Crypto.LWE.Trapdoor.extendedGadgetBasis {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] (R : Matrix μ (ι × Fin w) ℤ) :
Matrix (μ ⊕ ι × Fin w) (ι × Fin w) ℤ

The w lifted kernel vectors [R; I] * S = [R S; S] obtained from the gadget basis S = gadgetBasis w. These are the right-hand w columns of the basis S_A of [MP12], Lemma 5.3; they alone do not span Λ^⊥(A), and the left-hand block of S_A is not formalized.

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.taggedMatrix_mul_extendedGadgetBasis {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) :

Every column of extendedGadgetBasis w R lies in Λ^⊥(A): taggedMatrix w Abar R H * ([R; I] * S) ≡ 0 (mod 2 ^ w).

theorem Cslib.Crypto.LWE.Trapdoor.extendedGadgetBasis_col_inKernelLattice {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) (q : ι × Fin w) :
InKernelLattice (taggedMatrix w Abar R H) fun (k : μ ⊕ ι × Fin w) => extendedGadgetBasis w R k q
theorem Cslib.Crypto.LWE.Trapdoor.natAbs_extendedGadgetBasis_inl_le {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] (R : Matrix μ (ι × Fin w) ℤ) (j : μ) (q : ι × Fin w) (B : ℕ) (hR : ∀ (p : ι × Fin w), (R j p).natAbs ≤ B) :

Top-block entry bound for extendedGadgetBasis w R: if every entry of row j of R has magnitude at most B, then |(R * S) j q| ≤ 2 * (|ι| * w) * B.

theorem Cslib.Crypto.LWE.Trapdoor.natAbs_extendedGadgetBasis_inr_le {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] (R : Matrix μ (ι × Fin w) ℤ) (p q : ι × Fin w) :

Bottom-block entry bound for extendedGadgetBasis w R: every entry has magnitude at most 2.

def Cslib.Crypto.LWE.Trapdoor.invertSyndrome {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] (Hinv : Matrix ι ι (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (u : ι → ZMod (2 ^ w)) :
μ ⊕ ι × Fin w → ℤ

Deterministic syndrome inversion f_A⁻¹ using the trapdoor R and inverse tag Hinv: given u : ι → ZMod (2 ^ w), decompose Hinv *ᵥ u into {0, 1} digits via gadgetDecomp w and lift via [R; I]. This is a deterministic analogue of the preimage sampler of [MP12], Section 5.4: it returns a short preimage, not a Gaussian sample.

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.taggedMatrix_mulVec_invertSyndrome {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) {H Hinv : Matrix ι ι (ZMod (2 ^ w))} (hH : H * Hinv = 1) (u : ι → ZMod (2 ^ w)) :
(taggedMatrix w Abar R H).mulVec (Int.cast ∘ invertSyndrome w Hinv R u) = u

Correctness of deterministic syndrome inversion: if H * Hinv = 1, then A *ᵥ invertSyndrome w Hinv R u = u modulo 2 ^ w.

theorem Cslib.Crypto.LWE.Trapdoor.IsHTagTrapdoor.surjective {ι : Type u_1} {μ : Type u_2} {w : ℕ} [Fintype ι] [DecidableEq ι] [Fintype μ] {A : Matrix ι (μ ⊕ ι × Fin w) (ZMod (2 ^ w))} {R : Matrix μ (ι × Fin w) ℤ} {H : Matrix ι ι (ZMod (2 ^ w))} (htrap : IsHTagTrapdoor w A R H) :
Function.Surjective fun (x : μ ⊕ ι × Fin w → ℤ) => A.mulVec (Int.cast ∘ x)

Any parity-check matrix A admitting an H-tag G-trapdoor R is primitive: its integer column combinations span (ZMod (2 ^ w)) ^ ι (the remark after [MP12], Definition 5.2).

theorem Cslib.Crypto.LWE.Trapdoor.taggedMatrix_surjective {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) {H Hinv : Matrix ι ι (ZMod (2 ^ w))} (hH : H * Hinv = 1) :
Function.Surjective fun (x : μ ⊕ ι × Fin w → ℤ) => (taggedMatrix w Abar R H).mulVec (Int.cast ∘ x)

Any tagged matrix with an invertible tag H (H * Hinv = 1) is primitive: its integer column combinations span (ZMod (2 ^ w)) ^ ι (the remark after [MP12], Definition 5.2).

theorem Cslib.Crypto.LWE.Trapdoor.natAbs_invertSyndrome_inl_le {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] (Hinv : Matrix ι ι (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (u : ι → ZMod (2 ^ w)) (j : μ) (B : ℕ) (hR : ∀ (p : ι × Fin w), (R j p).natAbs ≤ B) :
(invertSyndrome w Hinv R u (Sum.inl j)).natAbs ≤ Fintype.card (ι × Fin w) * B

Top-block infinity-norm bound for invertSyndrome: if every entry in row j of R has magnitude at most B, then |invertSyndrome w Hinv R u (Sum.inl j)| ≤ (|ι| * w) * B.

theorem Cslib.Crypto.LWE.Trapdoor.natAbs_invertSyndrome_inr_le {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] (Hinv : Matrix ι ι (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (u : ι → ZMod (2 ^ w)) (p : ι × Fin w) :
(invertSyndrome w Hinv R u (Sum.inr p)).natAbs ≤ 1

Bottom-block infinity-norm bound for invertSyndrome: every bottom coordinate lies in {0, 1}, hence has magnitude at most 1.

Deterministic trapdoor LWE inversion (Section 5.3, Algorithm 2, Theorem 5.4) #

def Cslib.Crypto.LWE.Trapdoor.trapdoorLWE {ι : Type u_1} {κ : Type u_3} (w : ℕ) [Fintype ι] (A : Matrix ι κ (ZMod (2 ^ w))) (s : ι → ZMod (2 ^ w)) (e : κ → ℤ) :
κ → ZMod (2 ^ w)

The LWE evaluation g_A(s, e) = sᵀ A + eᵀ mod 2 ^ w associated with a parity-check matrix A ([MP12], Section 5.3; LWE itself is recalled in Section 2.2).

def Cslib.Crypto.LWE.Trapdoor.projectedError {ι : Type u_1} {μ : Type u_2} {w : ℕ} [Fintype μ] (R : Matrix μ (ι × Fin w) ℤ) (e : μ ⊕ ι × Fin w → ℤ) :
ι × Fin w → ℤ

The projected error eᵀ [R; I] = e_1ᵀ R + e_2ᵀ in gadget space ι × Fin w ([MP12], Section 5.3, Algorithm 2 and the proof of Theorem 5.4).

theorem Cslib.Crypto.LWE.Trapdoor.projectedError_eq_vecMul {ι : Type u_1} {μ : Type u_2} {w : ℕ} [Fintype ι] [DecidableEq ι] [Fintype μ] (R : Matrix μ (ι × Fin w) ℤ) (e : μ ⊕ ι × Fin w → ℤ) :
@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.trapdoorLWE_vecMul_trapdoorTransform {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H : Matrix ι ι (ZMod (2 ^ w))) (s : ι → ZMod (2 ^ w)) (e : μ ⊕ ι × Fin w → ℤ) :

Fundamental reduction of g_A to g_G via [R; I]: right-multiplying bᵀ = sᵀ A + eᵀ mod 2 ^ w by [R; I] produces g_G(Hᵀ s, eᵀ [R; I]) ([MP12], Section 5.3, Algorithm 2, step 1).

theorem Cslib.Crypto.LWE.Trapdoor.natAbs_projectedError_le {ι : Type u_1} {μ : Type u_2} {w : ℕ} [Fintype μ] (R : Matrix μ (ι × Fin w) ℤ) (e : μ ⊕ ι × Fin w → ℤ) (p : ι × Fin w) (B_R B_e : ℕ) (hR : ∀ (j : μ), (R j p).natAbs ≤ B_R) (he : ∀ (k : μ ⊕ ι × Fin w), (e k).natAbs ≤ B_e) :
(projectedError R e p).natAbs ≤ (1 + Fintype.card μ * B_R) * B_e

Infinity-norm bound on the projected error eᵀ [R; I]: if |R j p| ≤ B_R for all j and |e k| ≤ B_e for all k, then |projectedError R e p| ≤ (1 + |μ| * B_R) * B_e. This is an infinity-norm substitute for the Cauchy–Schwarz step in the proof of [MP12], Theorem 5.4.

def Cslib.Crypto.LWE.Trapdoor.invertLWESecret {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Hinv : Matrix ι ι (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (b : μ ⊕ ι × Fin w → ZMod (2 ^ w)) :
ι → ZMod (2 ^ w)

Recover the LWE secret s from bᵀ = sᵀ A + eᵀ mod 2 ^ w using the trapdoor R and inverse tag Hinv ([MP12], Section 5.3, Algorithm 2, steps 1–3, with the oracle O instantiated by invertGadget w): compute bhat = b ᵥ* [R; I], invert g_G, and multiply by Hinv.

def Cslib.Crypto.LWE.Trapdoor.invertLWE {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) (H Hinv : Matrix ι ι (ZMod (2 ^ w))) (b : μ ⊕ ι × Fin w → ZMod (2 ^ w)) :
(ι → ZMod (2 ^ w)) × (μ ⊕ ι × Fin w → ℤ)

Full LWE inversion algorithm Invert(R, A, b) ([MP12], Algorithm 2): recover s = invertLWESecret w Hinv R b and lift b - s ᵥ* A to its unique short integer representative via ZMod.valMinAbs.

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.invertLWESecret_trapdoorLWE {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) {H Hinv : Matrix ι ι (ZMod (2 ^ w))} (hH : H * Hinv = 1) (s : ι → ZMod (2 ^ w)) (e : μ ⊕ ι × Fin w → ℤ) (he : ∀ (p : ι × Fin w), 4 * (projectedError R e p).natAbs < 2 ^ w) :
invertLWESecret w Hinv R (trapdoorLWE w (taggedMatrix w Abar R H) s e) = s

Secret recovery for Algorithm 2 (deterministic part of [MP12], Theorem 5.4): if H * Hinv = 1 and 4 * |projectedError R e p| < 2 ^ w for all p : ι × Fin w, then invertLWESecret recovers s from trapdoorLWE w (taggedMatrix w Abar R H) s e. The hypothesis is the coordinatewise condition R̄ e ∈ P_{1/2}(q · B⁻ᵗ) from the proof of Theorem 5.4 with B = 2 I (slightly strict at the endpoint -q / 4), not the paper's Euclidean bound on e.

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.invertLWE_trapdoorLWE {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) {H Hinv : Matrix ι ι (ZMod (2 ^ w))} (hH : H * Hinv = 1) (s : ι → ZMod (2 ^ w)) (e : μ ⊕ ι × Fin w → ℤ) (hproj : ∀ (p : ι × Fin w), 4 * (projectedError R e p).natAbs < 2 ^ w) (he : ∀ (k : μ ⊕ ι × Fin w), 2 * (e k).natAbs < 2 ^ w) :
invertLWE w Abar R H Hinv (trapdoorLWE w (taggedMatrix w Abar R H) s e) = (s, e)

Full LWE inversion correctness (Invert, [MP12], Algorithm 2, deterministic part of Theorem 5.4): under H * Hinv = 1, 4 * |projectedError R e p| < 2 ^ w, and 2 * |e k| < 2 ^ w, invertLWE recovers the exact pair (s, e).

theorem Cslib.Crypto.LWE.Trapdoor.invertLWE_trapdoorLWE_of_norm_bound {ι : Type u_1} {μ : Type u_2} (w : ℕ) [Fintype ι] [DecidableEq ι] [Fintype μ] (Abar : Matrix ι μ (ZMod (2 ^ w))) (R : Matrix μ (ι × Fin w) ℤ) {H Hinv : Matrix ι ι (ZMod (2 ^ w))} (hH : H * Hinv = 1) (s : ι → ZMod (2 ^ w)) (e : μ ⊕ ι × Fin w → ℤ) {B_R B_e : ℕ} (hR : ∀ (j : μ) (p : ι × Fin w), (R j p).natAbs ≤ B_R) (he : ∀ (k : μ ⊕ ι × Fin w), (e k).natAbs ≤ B_e) (hbound : 4 * (1 + Fintype.card μ * B_R) * B_e < 2 ^ w) :
invertLWE w Abar R H Hinv (trapdoorLWE w (taggedMatrix w Abar R H) s e) = (s, e)

Infinity-norm analogue of the first claim of [MP12], Theorem 5.4: if |R j p| ≤ B_R, |e k| ≤ B_e, and 4 * (1 + |μ| * B_R) * B_e < 2 ^ w, then invertLWE recovers (s, e) from g_A(s, e). The paper's version bounds ‖e‖ in terms of s_1(R); the probabilistic claim for Gaussian errors is not formalized.

Probabilistic GenTrap algorithm and idealized hybrid (Section 5.2, Algorithm 1) #

noncomputable def Cslib.Crypto.LWE.Trapdoor.sampleTrapdoorRow (n w η : ℕ) :
ProbComp (Fin n × Fin w → ℤ)

Sample a row of a short integer trapdoor matrix R with independent centered-binomial entries in [-η, η] (one admissible choice of the distribution D in [MP12], Algorithm 1; the paper's instantiations use subgaussian or discrete Gaussian D).

noncomputable def Cslib.Crypto.LWE.Trapdoor.sampleTrapdoorMatrix (mbar n w η : ℕ) :
ProbComp (Matrix (Fin mbar) (Fin n × Fin w) ℤ)

Sample a short integer trapdoor matrix R : Matrix (Fin mbar) (Fin n × Fin w) ℤ with independent centered-binomial entries in [-η, η].

theorem Cslib.Crypto.LWE.Trapdoor.mem_support_sampleTrapdoorRow_iff (n w η : ℕ) (row : Fin n × Fin w → ℤ) :
row ∈ (sampleTrapdoorRow n w η).eval.support ↔ ∀ (p : Fin n × Fin w), (row p).natAbs ≤ η
theorem Cslib.Crypto.LWE.Trapdoor.mem_support_sampleTrapdoorMatrix_iff (mbar n w η : ℕ) (R : Matrix (Fin mbar) (Fin n × Fin w) ℤ) :
R ∈ (sampleTrapdoorMatrix mbar n w η).eval.support ↔ ∀ (j : Fin mbar) (p : Fin n × Fin w), (R j p).natAbs ≤ η

Support characterization of sampleTrapdoorMatrix: a matrix R is in the support iff every entry has magnitude at most η.

noncomputable def Cslib.Crypto.LWE.Trapdoor.genTrap (n mbar w η : ℕ) (H : Matrix (Fin n) (Fin n) (ZMod (2 ^ w))) :
ProbComp (Matrix (Fin n) (Fin mbar ⊕ Fin n × Fin w) (ZMod (2 ^ w)) × Matrix (Fin mbar) (Fin n × Fin w) ℤ)

Probabilistic trapdoor key generation GenTrap_D(Abar, H) with uniform Abar ([MP12], Section 5.2, Algorithm 1): sample a uniform matrix Abar ← sampleMatrix n mbar w and a short trapdoor matrix R ← sampleTrapdoorMatrix mbar n w η, and output (taggedMatrix w Abar R H, R).

theorem Cslib.Crypto.LWE.Trapdoor.mem_support_genTrap (n mbar w η : ℕ) {H : Matrix (Fin n) (Fin n) (ZMod (2 ^ w))} (hH : IsUnit H) {out : Matrix (Fin n) (Fin mbar ⊕ Fin n × Fin w) (ZMod (2 ^ w)) × Matrix (Fin mbar) (Fin n × Fin w) ℤ} (hout : out ∈ (genTrap n mbar w η H).eval.support) :
IsHTagTrapdoor w out.1 out.2 H ∧ (∀ (j : Fin mbar) (p : Fin n × Fin w), (out.2 j p).natAbs ≤ η) ∧ ∃ (Abar : Matrix (Fin n) (Fin mbar) (ZMod (2 ^ w))), out.1 = taggedMatrix w Abar out.2 H

For any invertible tag H (IsUnit H), every pair (A, R) in the support of genTrap n mbar w η H satisfies IsHTagTrapdoor w A R H, the entrywise bound |R j p| ≤ η, and A = taggedMatrix w Abar R H for some Abar ([MP12], Algorithm 1, "whose correctness is immediate").

noncomputable def Cslib.Crypto.LWE.Trapdoor.sampleGadgetRow (n w : ℕ) :
ProbComp (Fin n × Fin w → ZMod (2 ^ w))

Sample a uniform gadget-sized row Fin n × Fin w → ZMod (2 ^ w).

noncomputable def Cslib.Crypto.LWE.Trapdoor.sampleGadgetBlock (n w : ℕ) :
ProbComp (Matrix (Fin n) (Fin n × Fin w) (ZMod (2 ^ w)))

Sample a uniform gadget-sized matrix Matrix (Fin n) (Fin n × Fin w) (ZMod (2 ^ w)).

noncomputable def Cslib.Crypto.LWE.Trapdoor.genTrapIdeal (n mbar w : ℕ) (H : Matrix (Fin n) (Fin n) (ZMod (2 ^ w))) :
ProbComp (Matrix (Fin n) (Fin mbar ⊕ Fin n × Fin w) (ZMod (2 ^ w)))

Idealized hybrid of GenTrap: replacing Abar * R by an independent uniform matrix U yields [Abar | H * G - U]. [MP12], Section 5.2, argues that A is close to uniform "as long as the distribution of [Abar | -Abar R] is"; both the statistical and the computational instantiation justify exactly this replacement. Neither justification is formalized here, so no statement relates genTrap to genTrapIdeal.

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.eval_genTrapIdeal_eq_uniform (n mbar w : ℕ) (H : Matrix (Fin n) (Fin n) (ZMod (2 ^ w))) :

In the ideal LWE hybrid of GenTrap, the public matrix [Abar | H * G - U] is identically uniform over Matrix (Fin n) (Fin mbar ⊕ (Fin n × Fin w)) (ZMod (2 ^ w)) for every tag H. In particular, its distribution is independent of H.

theorem Cslib.Crypto.LWE.Trapdoor.eval_genTrapIdeal_eq_of_tags (n mbar w : ℕ) (H H' : Matrix (Fin n) (Fin n) (ZMod (2 ^ w))) :
(genTrapIdeal n mbar w H).eval = (genTrapIdeal n mbar w H').eval

Tag-independence of genTrapIdeal: any two tags H and H' induce the exact same public matrix distribution.