Documentation

CslibFrontier.Crypto.Computational.LWE.Trapdoor.Gadget

Micciancio–Peikert primitive gadget matrices, short bases, and gadget inversion #

This module formalizes the power-of-two primitive gadget construction of Micciancio and Peikert, Section 4, Theorem 4.1 and Proposition 4.2 at modulus q = 2 ^ w, reusing the binary decomposition and recomposition operations from Cslib.Crypto.Homomorphic.GSW (GSW.bitDecomp, GSW.bitCompose, GSW.powersOfTwo) and the half-modulus bit decoder LWE.decode from Cslib.Crypto.LWE:

  1. Primitive gadget vector and matrix (gadgetVector, gadgetMatrix): The geometric vector g = (1, 2, …, 2 ^ (w - 1)) ∈ (ZMod (2 ^ w)) ^ w (Equation 4.1) and its block-diagonal tensor expansion G = I_ι ⊗ gᵀ : Matrix ι (ι × Fin w) (ZMod (2 ^ w)). Multiplication by G on the right is GSW.bitCompose (gadgetMatrix_mulVec), and multiplication on the left is GSW.powersOfTwo (vecMul_gadgetMatrix).
  2. Deterministic syndrome decomposition (scalarDecomp, gadgetDecomp, gadgetDecompMatrix): Lifting GSW.bitDecomp to {0, 1}-valued integer vectors gives a right inverse to f_G(x) = G x mod 2 ^ w (gadgetMatrix_mulVec_gadgetDecomp, gadgetMatrix_mul_gadgetDecompMatrix), establishing that G is primitive (gadgetMatrix_surjective).
  3. Kernel lattice Λ^⊥(gᵀ) and Λ^⊥(G) and the explicit short matrix S_w (scalarBasis, gadgetBasis): For q = 2 ^ w, the lower-bidiagonal integer matrix S_w ∈ ℤ^{w × w} with 2 on the diagonal and -1 on the subdiagonal (Section 4.1, Proposition 4.2) has columns in Λ^⊥(gᵀ) (gadgetVector_vecMul_scalarBasis), determinant 2 ^ w (det_scalarBasis), entry magnitudes at most 2 (natAbs_scalarBasis_le_two), and squared Euclidean column norm at most 5 (sum_sq_scalarBasis_col_le_five). Its block-diagonal sum S = I_ι ⊗ S_w (gadgetBasis) satisfies G S ≡ 0 (mod 2 ^ w) (gadgetMatrix_mul_gadgetBasis) with the same column norm bounds. The paper deduces that S_w is a basis of Λ^⊥(gᵀ) from these two facts and the index |ℤ^w / Λ^⊥(gᵀ)| = q; that lattice-index argument, and the Gram–Schmidt identity S̃_w = 2 I, are not formalized, so the generating-set property is not proved here.
  4. Deterministic g_G-inversion (invertScalar, invertGadget): The iterative nearest-plane algorithm of Section 4.1 recovers s from g_G(s, e) = sᵀ G + eᵀ mod 2 ^ w whenever every integer error coordinate satisfies 4 * (e p).natAbs < 2 ^ w (invertScalar_correct, invertGadget_gadgetLWE). The paper allows every e_i ∈ [-q/4, q/4); the hypothesis here excludes only the endpoint -q/4.

General (non-power-of-two) moduli from Section 4.2 and randomized discrete-Gaussian preimage sampling over cosets of Λ^⊥(G) are not formalized here.

Main definitions #

Main results #

References #

Primitive gadget vector and matrix #

The geometric gadget vector g = (1, 2, 4, …, 2 ^ (w - 1)) over ZMod (2 ^ w) ([MP12], Equation 4.1).

def Cslib.Crypto.LWE.Trapdoor.gadgetMatrix {ι : Type u_1} (w : ℕ) [DecidableEq ι] :
Matrix ι (ι × Fin w) (ZMod (2 ^ w))

The primitive gadget matrix G = I_ι ⊗ gᵀ over ZMod (2 ^ w) ([MP12], Section 4): row i has gadgetVector w in block i and zeros elsewhere.

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.gadgetMatrix_apply {ι : Type u_1} (w : ℕ) [DecidableEq ι] (i : ι) (p : ι × Fin w) :
gadgetMatrix w i p = if i = p.1 then 2 ^ ↑p.2 else 0
theorem Cslib.Crypto.LWE.Trapdoor.gadgetMatrix_apply_same {ι : Type u_1} (w : ℕ) [DecidableEq ι] (i : ι) (j : Fin w) :
gadgetMatrix w i (i, j) = 2 ^ ↑j
theorem Cslib.Crypto.LWE.Trapdoor.gadgetMatrix_apply_ne {ι : Type u_1} (w : ℕ) [DecidableEq ι] {i i' : ι} (h : i ≠ i') (j : Fin w) :
gadgetMatrix w i (i', j) = 0

Right-multiplying gadgetMatrix w by a vector is GSW.bitCompose w.

Left-multiplying gadgetMatrix w by a row vector s is GSW.powersOfTwo w s.

Multiplying a matrix on the right by (gadgetMatrix w)ᵀ recomposes its rows via GSW.recomposeMatrix w.

Deterministic gadget decomposition (G⁻¹ for f_G) #

Binary decomposition of a single residue u ∈ ZMod (2 ^ w) into {0, 1} integer digits, least significant bit first ([MP12], Section 4).

def Cslib.Crypto.LWE.Trapdoor.gadgetDecomp {ι : Type u_1} (w : ℕ) (u : ι → ZMod (2 ^ w)) :
ι × Fin w → ℤ

Binary decomposition of a syndrome vector u : ι → ZMod (2 ^ w) into {0, 1} integer digits, reusing GSW.bitDecomp ([MP12], Section 4).

def Cslib.Crypto.LWE.Trapdoor.gadgetDecompMatrix {ι : Type u_1} {κ : Type u_3} (w : ℕ) (U : Matrix ι κ (ZMod (2 ^ w))) :
Matrix (ι × Fin w) κ ℤ

Binary decomposition of a matrix U : Matrix ι κ (ZMod (2 ^ w)) column-by-column into a {0, 1} integer matrix W satisfying G * W ≡ U (mod 2 ^ w).

theorem Cslib.Crypto.LWE.Trapdoor.gadgetDecomp_eq_scalarDecomp {ι : Type u_1} (w : ℕ) (u : ι → ZMod (2 ^ w)) (p : ι × Fin w) :
gadgetDecomp w u p = scalarDecomp w (u p.1) p.2
theorem Cslib.Crypto.LWE.Trapdoor.gadgetDecomp_nonneg {ι : Type u_1} (w : ℕ) (u : ι → ZMod (2 ^ w)) (p : ι × Fin w) :
theorem Cslib.Crypto.LWE.Trapdoor.gadgetDecomp_le_one {ι : Type u_1} (w : ℕ) (u : ι → ZMod (2 ^ w)) (p : ι × Fin w) :
theorem Cslib.Crypto.LWE.Trapdoor.natAbs_gadgetDecomp_le_one {ι : Type u_1} (w : ℕ) (u : ι → ZMod (2 ^ w)) (p : ι × Fin w) :
theorem Cslib.Crypto.LWE.Trapdoor.natAbs_gadgetDecompMatrix_le_one {ι : Type u_1} {κ : Type u_3} (w : ℕ) (U : Matrix ι κ (ZMod (2 ^ w))) (p : ι × Fin w) (k : κ) :
@[simp]

gadgetDecomp w is a deterministic right inverse of f_G(x) = G x mod 2 ^ w: G *ᵥ gadgetDecomp w u = u ([MP12], Section 4).

@[simp]

scalarDecomp w is a deterministic right inverse of x ↦ ⟨g, x⟩ mod 2 ^ w.

@[simp]

Matrix form of gadget right-inversion: G * gadgetDecompMatrix w U = U modulo 2 ^ w.

The gadget matrix G is primitive ([MP12], Section 4): its integer column combinations span (ZMod (2 ^ w)) ^ ι.

Kernel lattice Λ^⊥(gᵀ), Λ^⊥(G) and the explicit short basis S_w #

Membership in the scalar gadget kernel lattice Λ^⊥(gᵀ) = { z ∈ ℤ ^ w : ⟨g, z⟩ ≡ 0 (mod 2 ^ w) } ([MP12], Section 4).

The matrix S_w ∈ ℤ ^ {w × w} that [MP12], Section 4.1 and Proposition 4.2, shows is a short basis of Λ^⊥(gᵀ) for q = 2 ^ w: 2 on the diagonal, -1 on the first subdiagonal, and 0 elsewhere. This module proves kernel membership and the determinant and norm bounds, not the basis property.

@[simp]

det(S_w) = 2 ^ w ([MP12], Section 4.1).

Every entry of S_w has magnitude at most 2.

Every column of S_w belongs to Λ^⊥(gᵀ) ([MP12], Section 4.1).

@[simp]

Matrix form of gᵀ S_w ≡ 0 (mod 2 ^ w) ([MP12], Section 4.1).

Every column of S_w has squared Euclidean length at most 5 (‖S_w‖ ≤ √5, [MP12], Proposition 4.2).

def Cslib.Crypto.LWE.Trapdoor.gadgetBasis {ι : Type u_1} (w : ℕ) [DecidableEq ι] :
Matrix (ι × Fin w) (ι × Fin w) ℤ

The block-diagonal matrix S = I_ι ⊗ S_w, the short basis of Λ^⊥(G) for q = 2 ^ w in [MP12], Section 4 and Theorem 4.1 (only kernel membership and norm bounds are proved here).

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.gadgetBasis_apply {ι : Type u_1} (w : ℕ) [DecidableEq ι] (p q : ι × Fin w) :
gadgetBasis w p q = if p.1 = q.1 then scalarBasis w p.2 q.2 else 0

Every entry of S = I_ι ⊗ S_w has magnitude at most 2.

@[simp]

G * S ≡ 0 (mod 2 ^ w) ([MP12], Section 4, Theorem 4.1).

Every column of gadgetBasis w belongs to Λ^⊥(G).

theorem Cslib.Crypto.LWE.Trapdoor.sum_sq_gadgetBasis_col_le_five {ι : Type u_1} [Fintype ι] [DecidableEq ι] (w : ℕ) (q : ι × Fin w) :
∑ p : ι × Fin w, gadgetBasis w p q ^ 2 ≤ 5

Every column of S = I_ι ⊗ S_w has squared Euclidean length at most 5 (‖S‖ ≤ √5, [MP12], Theorem 4.1 and Proposition 4.2).

Deterministic g_G-inversion (Theorem 4.1, Section 4.1) #

def Cslib.Crypto.LWE.Trapdoor.gadgetLWE {ι : Type u_1} [Fintype ι] [DecidableEq ι] (w : ℕ) (s : ι → ZMod (2 ^ w)) (e : ι × Fin w → ℤ) :
ι × Fin w → ZMod (2 ^ w)

The gadget LWE evaluation g_G(s, e) = sᵀ G + eᵀ mod 2 ^ w ([MP12], Theorem 4.1).

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.gadgetLWE_apply {ι : Type u_1} [Fintype ι] [DecidableEq ι] (w : ℕ) (s : ι → ZMod (2 ^ w)) (e : ι × Fin w → ℤ) (p : ι × Fin w) :
gadgetLWE w s e p = 2 ^ ↑p.2 * s p.1 + ↑(e p)
def Cslib.Crypto.LWE.Trapdoor.invertScalarAux (w : ℕ) (b : Fin w → ZMod (2 ^ w)) :
ℕ → ℕ

Iterative recovery of the low l binary digits of s from b = s · gᵀ + eᵀ mod 2 ^ w ([MP12], Section 4.1). At step l < w, coordinate w - 1 - l determines bit l via LWE.decode w.

def Cslib.Crypto.LWE.Trapdoor.invertScalar (w : ℕ) (b : Fin w → ZMod (2 ^ w)) :
ZMod (2 ^ w)

Recover s ∈ ZMod (2 ^ w) from b = s · gᵀ + eᵀ mod 2 ^ w ([MP12], Section 4.1).

def Cslib.Crypto.LWE.Trapdoor.invertGadget {ι : Type u_1} (w : ℕ) (b : ι × Fin w → ZMod (2 ^ w)) :
ι → ZMod (2 ^ w)

Recover the secret vector s : ι → ZMod (2 ^ w) from b = sᵀ G + eᵀ mod 2 ^ w by applying invertScalar w independently to each w-coordinate block ([MP12], Section 4).

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.invertScalar_correct (w : ℕ) (s : ZMod (2 ^ w)) (e : Fin w → ℤ) (he : ∀ (j : Fin w), 4 * (e j).natAbs < 2 ^ w) :
(invertScalar w fun (j : Fin w) => 2 ^ ↑j * s + ↑(e j)) = s

Iterative scalar gadget inversion recovers s whenever 4 * (e j).natAbs < 2 ^ w for every coordinate j ([MP12], Section 4.1, "Inversion"; the paper's condition e_j ∈ [-q/4, q/4) also admits e_j = -q/4).

@[simp]
theorem Cslib.Crypto.LWE.Trapdoor.invertGadget_gadgetLWE {ι : Type u_1} [Fintype ι] [DecidableEq ι] (w : ℕ) (s : ι → ZMod (2 ^ w)) (e : ι × Fin w → ℤ) (he : ∀ (p : ι × Fin w), 4 * (e p).natAbs < 2 ^ w) :

Blockwise gadget inversion recovers s from g_G(s, e) = sᵀ G + eᵀ mod 2 ^ w whenever 4 * (e p).natAbs < 2 ^ w for every coordinate p : ι × Fin w ([MP12], Theorem 4.1 and Section 4.1).