Documentation

CslibFrontier.Crypto.Computational.LWE.DualRegev

Dual-Regev public-key encryption and preimage-sampleable trapdoors #

The dual of Regev's scheme [GentryPeikertVaikuntanathan2008, Section 7.1] in the presentation of [Peikert2016, Section 5.2.2], at modulus q = 2 ^ w. We store the public matrix in the orientation of LWE.publicMatrix: A has m rows of n residues (it is the transpose of the papers' n × m matrix). The secret key is a short integer vector e, and the public key is (A, u) with syndrome u = eᵀ A. With a secret s, integer errors x and x₀, a bit μ is encrypted as (A s + x, ⟨u, s⟩ + x₀ + μ * 2 ^ (w - 1)), and decryption rounds c₀ - ⟨e, b⟩ = μ * 2 ^ (w - 1) + x₀ - ⟨e, x⟩.

GPVTrapdoor is the interface of a preimage-sampleable trapdoor function [GentryPeikertVaikuntanathan2008, Section 5]: trapdoor generation together with a preimage sampler that returns a short preimage e of any syndrome u. Only the support condition used for correctness is part of GPVTrapdoor.SamplesShortPreimages; the distributional requirements of a preimage-sampleable function (near-uniform public matrices and the discrete-Gaussian law of preimages) are not formalized here. Dual-Regev keys extracted with such a sampler, as in the identity-based encryption scheme of [GentryPeikertVaikuntanathan2008, Section 7.2], decrypt with zero error under the stated noise margin.

The key generator keyGen draws a uniform binary secret. Its public key is statistically close to a uniform pair by the leftover hash lemma for e ↦ eᵀ A. Native serialized codecs, PPT certificates, and the IND-CPA security reduction to decision LWE with m + 1 samples are in LWE.DualRegev.Security.

Main definitions #

Main results #

References #

A public key (A, u): m rows of n residues and a syndrome in n residues.

  • matrix : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))

    Public matrix A with m rows of n residues modulo 2 ^ w.

  • syndrome : Fin n → ZMod (2 ^ w)

    Syndrome u = eᵀ A in n residues modulo 2 ^ w.

Instances For
    theorem Cslib.Crypto.DualRegev.PublicKey.ext {n m w : ℕ} {x y : PublicKey n m w} (matrix : x.matrix = y.matrix) (syndrome : x.syndrome = y.syndrome) :
    x = y
    @[instance_reducible]
    @[instance_reducible]
    @[instance_reducible]

    A ciphertext (b, c₀): m vector residues and one message-carrying scalar residue.

    • vector : Fin m → ZMod (2 ^ w)

      Ciphertext vector b = A s + x in m residues modulo 2 ^ w.

    • scalar : ZMod (2 ^ w)

      Message-carrying scalar c₀ = ⟨u, s⟩ + x₀ + μ * 2 ^ (w - 1) modulo 2 ^ w.

    Instances For
      theorem Cslib.Crypto.DualRegev.Ciphertext.ext {m w : ℕ} {x y : Ciphertext m w} (vector : x.vector = y.vector) (scalar : x.scalar = y.scalar) :
      x = y
      @[instance_reducible]
      def Cslib.Crypto.DualRegev.castVector {m : ℕ} (w : ℕ) (v : Fin m → ℤ) :
      Fin m → ZMod (2 ^ w)

      Integer vectors reduced modulo 2 ^ w.

      def Cslib.Crypto.DualRegev.publicKeyOf {n m w : ℕ} (A : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) (e : Fin m → ℤ) :
      PublicKey n m w

      The public key (A, eᵀ A) of a secret e.

      def Cslib.Crypto.DualRegev.encryptWithCoins {n m w : ℕ} (pk : PublicKey n m w) (μ : Bool) (s : Fin n → ZMod (2 ^ w)) (x : Fin m → ℤ) (x₀ : ℤ) :

      Encrypt μ with secret s and integer errors x, x₀ as (A s + x, ⟨u, s⟩ + x₀ + μ * 2 ^ (w - 1)).

      def Cslib.Crypto.DualRegev.decrypt {m w : ℕ} (e : Fin m → ℤ) (c : Ciphertext m w) :

      Decrypt by rounding c₀ - ⟨e, b⟩.

      def Cslib.Crypto.DualRegev.noise {m : ℕ} (e x : Fin m → ℤ) (x₀ : ℤ) :

      The integer decryption noise x₀ - ⟨e, x⟩.

      theorem Cslib.Crypto.DualRegev.encryptWithCoins_residual {n m w : ℕ} (A : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) (e : Fin m → ℤ) (μ : Bool) (s : Fin n → ZMod (2 ^ w)) (x : Fin m → ℤ) (x₀ : ℤ) :
      (encryptWithCoins (publicKeyOf A e) μ s x x₀).scalar - castVector w e ⬝ᵥ (encryptWithCoins (publicKeyOf A e) μ s x x₀).vector = ↑(↑μ.toNat * 2 ^ (w - 1) + noise e x x₀)

      The decryption residual: c₀ - ⟨e, b⟩ = μ * 2 ^ (w - 1) + x₀ - ⟨e, x⟩ modulo 2 ^ w.

      theorem Cslib.Crypto.DualRegev.natAbs_noise_le {m β η : ℕ} (e x : Fin m → ℤ) (x₀ : ℤ) (he : ∀ (i : Fin m), (e i).natAbs ≤ β) (hx : ∀ (i : Fin m), (x i).natAbs ≤ η) (hx₀ : x₀.natAbs ≤ η) :
      (noise e x x₀).natAbs ≤ m * (β * η) + η

      Bounded secrets and errors give decryption noise of magnitude at most m * (β * η) + η.

      theorem Cslib.Crypto.DualRegev.decrypt_encryptWithCoins {n m w β η : ℕ} (A : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) (e : Fin m → ℤ) (μ : Bool) (s : Fin n → ZMod (2 ^ w)) (x : Fin m → ℤ) (x₀ : ℤ) (hw : 0 < w) (he : ∀ (i : Fin m), (e i).natAbs ≤ β) (hx : ∀ (i : Fin m), (x i).natAbs ≤ η) (hx₀ : x₀.natAbs ≤ η) (hmargin : 4 * (m * (β * η) + η) < 2 ^ w) :
      decrypt e (encryptWithCoins (publicKeyOf A e) μ s x x₀) = μ

      Zero decryption error under the strict margin 4 * (m * (β * η) + η) < 2 ^ w.

      noncomputable def Cslib.Crypto.DualRegev.keyGen (n m w : ℕ) :
      ProbComp (PublicKey n m w × (Fin m → ℤ))

      Sample a uniform matrix and a uniform binary secret, and output (A, eᵀ A) and e.

      noncomputable def Cslib.Crypto.DualRegev.encrypt {n m w : ℕ} (η : ℕ) (pk : PublicKey n m w) (μ : Bool) :

      Encrypt with a uniform secret and independent centered-binomial errors of parameter η.

      theorem Cslib.Crypto.DualRegev.mem_support_keyGen {n m w : ℕ} {pk : PublicKey n m w} {e : Fin m → ℤ} (hkeys : (pk, e) ∈ (keyGen n m w).eval.support) :
      pk = publicKeyOf pk.matrix e ∧ ∀ (i : Fin m), (e i).natAbs ≤ 1

      Generated keys have the form (A, eᵀ A) with a binary secret.

      theorem Cslib.Crypto.DualRegev.mem_support_encrypt {n m w η : ℕ} {pk : PublicKey n m w} {μ : Bool} {c : Ciphertext m w} (hc : c ∈ (encrypt η pk μ).eval.support) :
      ∃ (s : Fin n → ZMod (2 ^ w)) (x : Fin m → ℤ) (x₀ : ℤ), (∀ (i : Fin m), (x i).natAbs ≤ η) ∧ x₀.natAbs ≤ η ∧ c = encryptWithCoins pk μ s x x₀

      Supported ciphertexts are encryptions with errors bounded by η.

      theorem Cslib.Crypto.DualRegev.keyGen_encrypt_correct {n m w η : ℕ} (hw : 0 < w) (hmargin : 4 * (m * η + η) < 2 ^ w) {keys : PublicKey n m w × (Fin m → ℤ)} (hkeys : keys ∈ (keyGen n m w).eval.support) (μ : Bool) {c : Ciphertext m w} (hc : c ∈ (encrypt η keys.1 μ).eval.support) :
      decrypt keys.2 c = μ

      Every generated key and supported ciphertext decrypt correctly when 4 * (m * η + η) < 2 ^ w.

      The public key of a uniform binary secret is statistically close to uniform.

      Preimage-sampleable trapdoors #

      structure Cslib.Crypto.DualRegev.GPVTrapdoor (n m w : ℕ) (Trapdoor : Type) :

      The algorithm interface of a preimage-sampleable trapdoor function [GentryPeikertVaikuntanathan2008, Section 5]: trapGen outputs a public matrix with a trapdoor, and samplePre uses the trapdoor to sample an integer preimage e of a syndrome u, meaning eᵀ A = u. No one-wayness or distributional requirement is imposed.

      • trapGen : ProbComp (Matrix (Fin m) (Fin n) (ZMod (2 ^ w)) × Trapdoor)

        Generate a public matrix together with its trapdoor.

      • samplePre : Trapdoor → (Fin n → ZMod (2 ^ w)) → ProbComp (Fin m → ℤ)

        Sample a preimage of a syndrome using the trapdoor.

      def Cslib.Crypto.DualRegev.GPVTrapdoor.SamplesShortPreimages {n m w : ℕ} {Trapdoor : Type} (T : GPVTrapdoor n m w Trapdoor) (bound : ℕ) :

      On every generated matrix and every syndrome, each sampled preimage e satisfies eᵀ A = u and has entries of magnitude at most bound.

      noncomputable def Cslib.Crypto.DualRegev.GPVTrapdoor.extract {n m w : ℕ} {Trapdoor : Type} (T : GPVTrapdoor n m w Trapdoor) (keys : Matrix (Fin m) (Fin n) (ZMod (2 ^ w)) × Trapdoor) (u : Fin n → ZMod (2 ^ w)) :
      ProbComp (Fin m → ℤ)

      Extract the dual-Regev secret key for syndrome u: the key-extraction step of the identity-based scheme, where u is the hash of an identity.

      theorem Cslib.Crypto.DualRegev.GPVTrapdoor.decrypt_encryptWithCoins_extract {n m w : ℕ} {Trapdoor : Type} {bound η : ℕ} (T : GPVTrapdoor n m w Trapdoor) (hT : T.SamplesShortPreimages bound) {keys : Matrix (Fin m) (Fin n) (ZMod (2 ^ w)) × Trapdoor} (hkeys : keys ∈ T.trapGen.eval.support) (u : Fin n → ZMod (2 ^ w)) {e : Fin m → ℤ} (he : e ∈ (T.extract keys u).eval.support) (μ : Bool) (s : Fin n → ZMod (2 ^ w)) (x : Fin m → ℤ) (x₀ : ℤ) (hw : 0 < w) (hx : ∀ (i : Fin m), (x i).natAbs ≤ η) (hx₀ : x₀.natAbs ≤ η) (hmargin : 4 * (m * (bound * η) + η) < 2 ^ w) :
      decrypt e (encryptWithCoins { matrix := keys.1, syndrome := u } μ s x x₀) = μ

      Extracted keys decrypt every dual-Regev encryption under (A, u) with zero error when 4 * (m * (bound * η) + η) < 2 ^ w.