Documentation

CslibFrontier.Crypto.Computational.LWE.Regev

Regev public-key encryption #

Regev's bit encryption scheme [Regev2009, Section 5] in the presentation of [Peikert2016, Section 5.2.1], at modulus q = 2 ^ w. The public key is the decision-LWE matrix A = [B * t + e | B] of LWE.publicMatrixInt, generated by the LWE key generator LWE.keyGen; the secret key is t. A bit μ is encrypted with a uniform binary coin vector x ∈ {0, 1}^m as the row vector xᵀ A + (μ * 2 ^ (w - 1), 0, …, 0), and decrypted by rounding its inner product with (1, -t), which equals μ * 2 ^ (w - 1) + ⟨x, e⟩.

The security statements are concrete and make no efficiency assumption on the adversary. Under a uniform public matrix, the binary subset sums xᵀ A of independent coin vectors are jointly close to uniform by the leftover hash lemma for x ↦ xᵀ A (BitString.SubsetSum.dist_bind_mul_le). This bounds the advantage of every adaptive left-or-right adversary making Q encryption queries by Q * sqrt(2 ^ ((n + 1) * w) / 2 ^ m). Replacing the generated public key by a uniform matrix costs the advantage of two explicit decision-LWE distinguishers, one for each challenge bit. Native runtime certificates and the asymptotic single-challenge and adaptive Q-query left-or-right theorems are in LWE.Regev.Security.

Main definitions #

Main results #

References #

@[reducible, inline]

A ciphertext is one row vector of n + 1 residues modulo 2 ^ w.

@[reducible, inline]

A public key is an m × (n + 1) matrix modulo 2 ^ w, of the shape [B * t + e | B].

def Cslib.Crypto.Regev.coinVector {m : ℕ} (w : ℕ) (x : Fin m → Bool) :
Fin m → ZMod (2 ^ w)

Binary coins viewed as residues.

def Cslib.Crypto.Regev.encryptWithCoins {n m w : ℕ} (A : PublicKey n m w) (μ : Bool) (x : Fin m → Bool) :

Encrypt μ with binary coins x as xᵀ A + (LWE.encodeBit w μ, 0, …, 0).

def Cslib.Crypto.Regev.decrypt {n w : ℕ} (t : Fin n → ZMod (2 ^ w)) (c : Ciphertext n w) :

Decrypt by rounding the inner product with the secret vector (1, -t).

def Cslib.Crypto.Regev.noise {m : ℕ} (x : Fin m → Bool) (error : Fin m → ℤ) :

The integer decryption noise ⟨x, e⟩ selected by the coins.

noncomputable def Cslib.Crypto.Regev.encrypt {n m w : ℕ} (A : PublicKey n m w) (μ : Bool) :

Encrypt with independent uniform binary coins.

@[simp]

Encryption draws its coin vector uniformly.

theorem Cslib.Crypto.Regev.encryptWithCoins_dotProduct_secretVector {n m w : ℕ} (B : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) (t : Fin n → ZMod (2 ^ w)) (error : Fin m → ℤ) (μ : Bool) (x : Fin m → Bool) :
encryptWithCoins (LWE.publicMatrixInt B t error) μ x ⬝ᵥ LWE.secretVector t = ↑(↑μ.toNat * 2 ^ (w - 1) + noise x error)

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

theorem Cslib.Crypto.Regev.natAbs_noise_le {m bound : ℕ} (x : Fin m → Bool) (error : Fin m → ℤ) (herror : ∀ (i : Fin m), (error i).natAbs ≤ bound) :
(noise x error).natAbs ≤ m * bound

Errors bounded by bound give decryption noise of magnitude at most m * bound.

theorem Cslib.Crypto.Regev.decrypt_encryptWithCoins {n m w bound : ℕ} (B : Matrix (Fin m) (Fin n) (ZMod (2 ^ w))) (t : Fin n → ZMod (2 ^ w)) (error : Fin m → ℤ) (μ : Bool) (x : Fin m → Bool) (hw : 0 < w) (herror : ∀ (i : Fin m), (error i).natAbs ≤ bound) (hmargin : 4 * (m * bound) < 2 ^ w) :

Zero decryption error: every coin vector decrypts correctly when 4 * (m * bound) < 2 ^ w.

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

Every key generated with centered-binomial errors of parameter η and every supported ciphertext decrypt correctly under the strict margin 4 * (m * η) < 2 ^ w.

Adaptive left-or-right security #

structure Cslib.Crypto.Regev.LoRAdversary (n m w : ℕ) (State : Type) :

An adaptive left-or-right adversary. It receives the public matrix, repeatedly chooses a pair of bits and absorbs the ciphertext of the selected one, and finally guesses. Absorption is deterministic without loss of generality: the state may record the full transcript, and later stages are randomized.

  • start : PublicKey n m w → PMF State

    Receive the public matrix.

  • query : State → PMF (MessagePair Bool × State)

    Choose the next pair of challenge bits.

  • receive : State → Ciphertext n w → State

    Absorb the answer to the last query.

  • guess : State → PMF Bool

    Output the final guess.

noncomputable def Cslib.Crypto.Regev.lorRun {n m w : ℕ} {State : Type} (enc : Bool → PMF (Ciphertext n w)) (adversary : LoRAdversary n m w State) (bit : Bool) :
ℕ → State → PMF State

Answer q adaptive queries, encrypting the message of each pair selected by bit (msg₀ for false, msg₁ for true) with the oracle enc.

noncomputable def Cslib.Crypto.Regev.lorGame {n m w : ℕ} {State : Type} (keys : PMF (PublicKey n m w)) (Q : ℕ) (adversary : LoRAdversary n m w State) (bit : Bool) :

The adaptive Q-query left-or-right experiment with public keys drawn from keys; every query is answered by a fresh encryption under the drawn key.

noncomputable def Cslib.Crypto.Regev.idealLorGame {n m w : ℕ} {State : Type} (Q : ℕ) (adversary : LoRAdversary n m w State) :

The ideal experiment under a uniform public matrix: every answer is an independent uniform vector, independent of the challenge bit.

theorem Cslib.Crypto.Regev.dist_lorGame_uniform_ideal_le {n m w : ℕ} {State : Type} (Q : ℕ) (adversary : LoRAdversary n m w State) (bit : Bool) :
dist (lorGame (Probability.PMF.uniformOfFintype (PublicKey n m w)) Q adversary bit) (idealLorGame Q adversary) ≤ ↑Q * √(2 ^ ((n + 1) * w) / 2 ^ m) / 2

Under a uniform public matrix, each side of the adaptive Q-query experiment is within Q * sqrt(2 ^ ((n + 1) * w) / 2 ^ m) / 2 of the ideal experiment. No efficiency or finiteness assumption is imposed on the adversary.

theorem Cslib.Crypto.Regev.lorGame_uniform_advantage_le {n m w : ℕ} {State : Type} (Q : ℕ) (adversary : LoRAdversary n m w State) :
↑(Game.advantage (lorGame (Probability.PMF.uniformOfFintype (PublicKey n m w)) Q adversary false) (lorGame (Probability.PMF.uniformOfFintype (PublicKey n m w)) Q adversary true)) ≤ ↑Q * √(2 ^ ((n + 1) * w) / 2 ^ m)

The leftover-hash bound for adaptive left-or-right security with Q queries under a uniform public matrix.

noncomputable def Cslib.Crypto.Regev.challengeGame {n m w : ℕ} {State : Type} (keys : PMF (PublicKey n m w)) (adversary : TwoStage (PublicKey n m w) (MessagePair Bool) (Ciphertext n w) Bool State) (bit : Bool) :

The single-challenge experiment: draw a public matrix from keys and run the left-or-right experiment lrExperiment with Regev encryption. Every challenge pair is admissible. The typed adversary's first stage sees the public matrix and chooses a pair of bits and a state; its second stage sees that state and the challenge ciphertext.

structure Cslib.Crypto.Regev.ChallengeState (n w : ℕ) (State : Type) :

The state of LoRAdversary.ofChallenge: the challenge pair and saved state chosen by the first stage, and the challenge ciphertext received (0 before the query is answered).

  • The pair of challenge bits chosen by the first stage.

  • saved : State

    The state saved by the first stage.

  • ciphertext : Ciphertext n w

    The challenge ciphertext.

noncomputable def Cslib.Crypto.Regev.LoRAdversary.ofChallenge {n m w : ℕ} {State : Type} (adversary : TwoStage (PublicKey n m w) (MessagePair Bool) (Ciphertext n w) Bool State) :
LoRAdversary n m w (ChallengeState n w State)

A single-challenge adversary as a one-query left-or-right adversary: the first stage starts the interaction, the only query is its challenge pair, and the second stage guesses from the saved state and the answer.

theorem Cslib.Crypto.Regev.lorGame_ofChallenge {n m w : ℕ} {State : Type} (keys : PMF (PublicKey n m w)) (adversary : TwoStage (PublicKey n m w) (MessagePair Bool) (Ciphertext n w) Bool State) (bit : Bool) :
lorGame keys 1 (LoRAdversary.ofChallenge adversary) bit = challengeGame keys adversary bit

The single-challenge experiment is the one-query left-or-right experiment.

Single-challenge security under a uniform public matrix: advantage at most sqrt(2 ^ ((n + 1) * w) / 2 ^ m).

noncomputable def Cslib.Crypto.Regev.lorDistinguisher {n m w : ℕ} {State : Type} (Q : ℕ) (adversary : LoRAdversary n m w State) (bit : Bool) (A : PublicKey n m w) :

The decision-LWE distinguisher for one challenge bit: run the Q-query experiment on the supplied matrix as public key.

theorem Cslib.Crypto.Regev.lorGame_eq_bind_lorDistinguisher {n m w : ℕ} {State : Type} (keys : PMF (PublicKey n m w)) (Q : ℕ) (adversary : LoRAdversary n m w State) (bit : Bool) :
lorGame keys Q adversary bit = keys.bind (lorDistinguisher Q adversary bit)

The experiment under a key law averages the per-key distinguisher.

theorem Cslib.Crypto.Regev.lorGame_advantage_le {n m w : ℕ} {State : Type} (errorLaw : PMF (ZMod (2 ^ w))) (Q : ℕ) (adversary : LoRAdversary n m w State) :
↑(Game.advantage (lorGame (LWE.publicMatrixLaw n m errorLaw) Q adversary false) (lorGame (LWE.publicMatrixLaw n m errorLaw) Q adversary true)) ≤ ↑(Game.advantage ((LWE.publicMatrixLaw n m errorLaw).bind (lorDistinguisher Q adversary false)) ((Probability.PMF.uniformOfFintype (PublicKey n m w)).bind (lorDistinguisher Q adversary false))) + ↑(Game.advantage ((LWE.publicMatrixLaw n m errorLaw).bind (lorDistinguisher Q adversary true)) ((Probability.PMF.uniformOfFintype (PublicKey n m w)).bind (lorDistinguisher Q adversary true))) + ↑Q * √(2 ^ ((n + 1) * w) / 2 ^ m)

Concrete adaptive Q-query left-or-right security under the actual public-key law: the advantage is at most the decision-LWE advantages of lorDistinguisher Q adversary false and lorDistinguisher Q adversary true, plus the leftover-hash term. The error law errorLaw is arbitrary.