Documentation

CslibFrontier.Crypto.Computational.Paillier.Algebra

The group structure behind Paillier encryption #

Paillier encryption works in the unit group of ZMod (N ^ 2) for a modulus N = p * q. These are the three facts that make up [KL20], Proposition 15.6:

This file proves Claims 15.7 and 15.9. It also proves the identity behind Paillier decryption: raising (1 + N) ^ m * r ^ N to the power φ(N) removes the randomness r and leaves 1 + m * φ(N) * N. The function logOneAdd reads the exponent back off: it is the function L of [KL20], Construction 15.11.

Main definitions #

Main results #

References #

Claim 15.7 #

theorem Cslib.Crypto.Paillier.coprime_totient {p q : ℕ} (hp : Nat.Prime p) (hq : Nat.Prime q) (hne : p ≠ q) (hp2 : 2 < p) (hq2 : 2 < q) (hsize : p.size = q.size) :
(p * q).Coprime (p * q).totient

Claim 15.7 ([KL20]): for distinct odd primes p and q of the same bit length, p * q is coprime to φ(p * q) = (p - 1) * (q - 1).

Claim 15.9 #

The unit 1 + N of ZMod (N ^ 2).

@[simp]
theorem Cslib.Crypto.Paillier.coe_oneAddUnit (N : ℕ) [NeZero N] :
↑(oneAddUnit N) = 1 + ↑N

Powers of 1 + N depend only on the exponent modulo N.

a ↦ (1 + N) ^ a on ZMod N, written multiplicatively.

def Cslib.Crypto.Paillier.liftUnit (N : ℕ) (b : (ZMod N)ˣ) :
(ZMod (N ^ 2))ˣ

A unit modulo N, read through its least representative, is a unit modulo N ^ 2.

@[simp]
theorem Cslib.Crypto.Paillier.coe_liftUnit (N : ℕ) (b : (ZMod N)ˣ) :
↑(liftUnit N b) = ↑(↑b).val

b ↦ b ^ N from the units modulo N to the units modulo N ^ 2, through least representatives.

@[simp]
theorem Cslib.Crypto.Paillier.powSelfHom_unitsMap (N : ℕ) [NeZero N] (s : (ZMod (N ^ 2))ˣ) :
(powSelfHom N) ((ZMod.unitsMap ⋯) s) = s ^ N

The N-th power of a unit modulo N ^ 2 is powSelfHom of its reduction modulo N: it depends only on the unit modulo N.

When gcd(N, φ(N)) = 1, the map (a, b) ↦ (1 + N) ^ a * b ^ N is bijective.

noncomputable def Cslib.Crypto.Paillier.unitsEquiv (N : ℕ) [NeZero N] (hcop : N.Coprime N.totient) :

Claim 15.9 ([KL20]): when gcd(N, φ(N)) = 1, the map (a, b) ↦ (1 + N) ^ a * b ^ N is a group isomorphism Multiplicative (ZMod N) × (ZMod N)ˣ ≃* (ZMod (N ^ 2))ˣ.

theorem Cslib.Crypto.Paillier.coe_unitsEquiv_ofAdd (N : ℕ) [NeZero N] (hcop : N.Coprime N.totient) (a : ZMod N) (b : (ZMod N)ˣ) :
↑((unitsEquiv N hcop) (Multiplicative.ofAdd a, b)) = (1 + ↑N) ^ a.val * ↑(↑b).val ^ N

Claim 15.9 ([KL20]): unitsEquiv sends (a, b) to (1 + N) ^ a * b ^ N.

The decryption identity #

theorem Cslib.Crypto.Paillier.one_add_pow_mul_pow_pow_totient {N r : ℕ} (m : ℕ) (hr : r.Coprime N) :
((1 + ↑N) ^ m * ↑r ^ N) ^ N.totient = 1 + ↑(m * N.totient) * ↑N

Decryption identity ([KL20], Construction 15.11): for r coprime to N, raising (1 + N) ^ m * r ^ N to the power φ(N) gives 1 + m * φ(N) * N in ZMod (N ^ 2).

def Cslib.Crypto.Paillier.logOneAdd (N : ℕ) (x : ZMod (N ^ 2)) :

The discrete logarithm to the base 1 + N on the subgroup it generates ([KL20], the function L of Construction 15.11): x ↦ (x - 1) / N, computed on the least representative of x and read modulo N.

theorem Cslib.Crypto.Paillier.logOneAdd_one_add_natCast_mul {N : ℕ} (hN : 1 < N) (k : ℕ) :
logOneAdd N (1 + ↑k * ↑N) = ↑k

logOneAdd reads k modulo N off 1 + k * N.

logOneAdd inverts a ↦ (1 + N) ^ a.