ElGamal Encryption
Statement
Let with generator . Alice's key pair: private , public . To encrypt message , Bob picks random and computes:
Decryption: Alice computes:
The ciphertext hides under the DH shared secret .
Visualization
Parameters: , , (Alice's private key), (Alice's public key). Encrypt with Bob's random .
| Computation | Value |
|---|---|
Decryption:
| Computation | Value |
|---|---|
| inverse in | |
Recovered . Correctness holds: , so the shared secret cancels.
Proof Sketch
-
Expand . Since , we have .
-
Use commutativity. In an abelian group .
-
Cancellation. . In group notation, .
-
Security. Without , an eavesdropper sees and ; recovering requires the DH shared secret , which is computationally hard.
Connections
ElGamal is a direct application of Diffie–HellmanDiffie–HellmanAlice and Bob derive the same shared secret g^(ab) from public keys g^a and g^b in any commutative group.Read more → — the shared secret is precisely the DH shared key. The group law relies on Fermat's Little TheoremFermat's Little TheoremFor prime p, a^p is congruent to a mod pRead more → for the order of elements in . The Chinese Remainder TheoremChinese Remainder TheoremSimultaneous congruences with coprime moduli have a unique solution mod their productRead more → underlies efficient multi-prime implementations.
Lean4 Proof
/-- ElGamal decryption identity in a commutative group:
(m * y^r) * (g^r)^(-a_inv) = m when y = g^a and
we demonstrate the cancellation algebraically. -/
-- Core algebraic fact: in a CommGroup, (g^a)^r = (g^r)^a
theorem elgamal_shared_secret_eq {G : Type*} [CommGroup G] (g : G) (a r : ℕ) :
(g ^ a) ^ r = (g ^ r) ^ a := by
rw [← pow_mul, ← pow_mul, Nat.mul_comm]
/-- Cancellation: m * k * k⁻¹ = m in any group. -/
theorem elgamal_cancel {G : Type*} [Group G] (m k : G) :
m * k * k⁻¹ = m := by
rw [mul_assoc, mul_inv_cancel, mul_one]
/-- Concrete numeric check: decrypt(encrypt(10)) = 10.
c1 = 5^3 mod 23 = 125 mod 23 = 10
y^r = 8^3 mod 23 = 512 mod 23 = 6
c2 = 10 * 6 mod 23 = 60 mod 23 = 14
c1^a = 10^6 mod 23 = 6 (= g^(r*a) = g^(a*r) = y^r)
inv(6) mod 23 = 4 (since 6*4=24≡1 mod 23)
m' = c2 * inv(c1^a) = 14 * 4 mod 23 = 56 mod 23 = 10 -/
example : 5 ^ 3 % 23 = 10 := by decide
example : (8 : ℕ) ^ 3 % 23 = 6 := by decide
example : 10 * 6 % 23 = 14 := by decide
example : (10 : ℕ) ^ 6 % 23 = 6 := by decide -- c1^a = y^r confirmed
example : 56 % 23 = 10 := by decide -- 14 * 4 = 56, recover mReferenced by
- Diffie–HellmanCryptography