Documentation

CslibFrontier.Crypto.Computational.Paillier

Paillier encryption #

Paillier's public-key encryption scheme ([KL20], Construction 15.11) over a modulus generator gen that outputs valid descriptions (p, q) of balanced moduli N = p * q:

Decryption is correct because raising c to the power φ(N) removes the randomness and leaves 1 + m * φ(N) * N modulo N ^ 2. Multiplying two ciphertexts modulo N ^ 2 preserves plaintext addition under decryption modulo N.

The randomness r is drawn from n + |N| fair coins with ProbComp.sampleModNat; a draw that is not a unit modulo N is replaced by 1, so decryption is correct on every ciphertext in the support. Decryption computes φ(N)⁻¹ mod N as φ(N) ^ (φ(N) - 1) mod N, which is the inverse by Euler's theorem because gcd(N, φ(N)) = 1. Modular exponentiation is square-and-multiply.

The modulus generator is a parameter: validity of its outputs is part of their type, and its efficiency is a hypothesis of the polynomial-time statements. Constructing such a generator is not part of this file.

Main definitions #

Main results #

Scope and limitations #

References #

Arithmetic on natural numbers #

The Paillier ciphertext (1 + N) ^ m * r ^ N mod N ^ 2 ([KL20], Construction 15.11).

Paillier decryption of c with modulus N and totient t ([KL20], Construction 15.11): ((c ^ t mod N ^ 2) - 1) / N * t⁻¹ mod N, where t⁻¹ mod N is computed as t ^ (t - 1) mod N.

theorem Cslib.Crypto.Paillier.natCast_ciphertext {N : ℕ} (hN : N ≠ 0) (m r : ℕ) :
↑(ciphertext N m r) = (1 + ↑N) ^ m * ↑r ^ N

A Paillier ciphertext is (1 + N) ^ m * r ^ N modulo N ^ 2.

theorem Cslib.Crypto.Paillier.decryptNat_eq {N c m r : ℕ} (hN : 1 < N) (hcop : N.Coprime N.totient) (hr : r.Coprime N) (hc : ↑c = (1 + ↑N) ^ m * ↑r ^ N) :
decryptNat N N.totient c = m % N

Correctness of Paillier decryption ([KL20], Construction 15.11): if c ≡ (1 + N) ^ m * r ^ N (mod N ^ 2) for some r coprime to N, and gcd(N, φ(N)) = 1, then decryption with the totient φ(N) returns m mod N.

The scheme on binary words #

Paillier key generation ([KL20], Construction 15.11) over a modulus generator gen: draw (p, q) ← gen n and output the public key N = p * q and the secret key ⟨N, φ(N)⟩, with φ(N) = (p - 1) * (q - 1).

noncomputable def Cslib.Crypto.Paillier.encrypt (n : ℕ) (pk : List Bool) (m : ℕ) :

Paillier encryption ([KL20], Construction 15.11) of m under the public key pk = N: draw r < N from n + |N| fair coins, use 1 instead if r is not a unit modulo N, and output (1 + N) ^ m * r ^ N mod N ^ 2.

Paillier decryption ([KL20], Construction 15.11) of ct under the secret key sk = ⟨N, φ(N)⟩.

Homomorphic addition: multiply two ciphertexts modulo N ^ 2, for the public key pk = N.

Efficiency #

Squaring is computable in polynomial time.

Correctness and the additive homomorphism #

Ciphertexts in the support of encrypt n (encNat N) m are ciphertext N m r' for some r' coprime to N.

theorem Cslib.Crypto.Paillier.decrypt_encrypt {gen : ℕ → ProbComp BalancedModulus.Desc} {n : ℕ} {keys : List Bool × List Bool} (hkeys : keys ∈ (keyGen gen n).eval.support) {m : ℕ} (hm : m < Turing.MultiTapeTM.ofBits keys.1) {ct : List Bool} (hct : ct ∈ (encrypt n keys.1 m).eval.support) :

Perfect correctness of Paillier encryption ([KL20], Construction 15.11): for every key pair in the support of keyGen gen n, every message m < N, and every ciphertext ct in the support of encrypt n pk m, decryption returns m.

theorem Cslib.Crypto.Paillier.decrypt_addCiphertexts {gen : ℕ → ProbComp BalancedModulus.Desc} {n : ℕ} {keys : List Bool × List Bool} (hkeys : keys ∈ (keyGen gen n).eval.support) {m₁ m₂ : ℕ} {ct₁ ct₂ : List Bool} (hct₁ : ct₁ ∈ (encrypt n keys.1 m₁).eval.support) (hct₂ : ct₂ ∈ (encrypt n keys.1 m₂).eval.support) :
decrypt keys.2 (addCiphertexts keys.1 ct₁ ct₂) = Turing.MultiTapeTM.encNat ((m₁ + m₂) % Turing.MultiTapeTM.ofBits keys.1)

Preservation of plaintext addition under decryption ([KL20], Definition 15.14 and the discussion of Paillier encryption that follows it): for every key pair in the support of keyGen gen n and ciphertexts ct₁, ct₂ in the supports of encrypt n pk m₁ and encrypt n pk m₂, the product addCiphertexts pk ct₁ ct₂ decrypts to (m₁ + m₂) mod N.

Note: [KL20], Definition 15.14 additionally requires equality of the multiplied-ciphertext distribution with fresh encryptions of the sum. That distribution clause is not established here (and fails for the dyadic sampler plus unitOrOne: at N = 143, n = 0, and m₁ = m₂ = 0, fresh encNat 1 has probability mass 44 / 256 = 11 / 64, whereas multiplying two independent encryptions yields mass 2316 / 65536 = 579 / 16384). The fixed-modulus scheme in CslibFrontier.Crypto.Computational.Paillier.Finite satisfies it (Cslib.Crypto.eval_mul_paillierEncrypt). For the word algorithm, Cslib.Crypto.Paillier.closeTo_addCiphertexts in Paillier.Statistical bounds the statistical distance by 10 / 2 ^ n when both modulus factors have at least n bits.