Diffie–Hellman
Statement
Let be a commutative group (written multiplicatively) with generator . Alice picks private exponent , publishes . Bob picks private exponent , publishes . The shared secret is:
Both parties can compute this value; an eavesdropper seeing only and must solve the discrete logarithm problem to find or .
Visualization
Parameters: , (prime), (Alice), (Bob).
| Party | Private | Public | Shared secret computation |
|---|---|---|---|
| Alice | — wait, uses | ||
| Bob |
Computing the shared secret:
- Alice computes:
- Bob computes:
Both arrive at shared secret :
Public: g=5, p=23
Alice: a=6 -> A = 5^6 mod 23 = 8
Bob: b=15 -> B = 5^15 mod 23 = 19
| |
Alice: K = 19^6 mod 23 = 2
Bob: K = 8^15 mod 23 = 2 <-- same!
Proof Sketch
-
Commutativity of exponents. In any monoid, (associativity of repeated multiplication). In a commutative group, , so .
-
One-line proof. Rewrite via
pow_mul: . -
Security relies on discrete log hardness. The equality is trivial group theory; the security assumption is that finding from and is computationally hard.
Connections
The commutativity argument is a direct consequence of the group axioms; see Cayley's TheoremCayley's TheoremEvery group embeds into a symmetric groupRead more → for the embedding perspective. The hardness assumption connects to Fermat's Little TheoremFermat's Little TheoremFor prime p, a^p is congruent to a mod pRead more → — working in of order . ElGamal encryption (see ElGamal EncryptionElGamal EncryptionDecryption recovers plaintext because c2/c1^a = m·g^(ab)/g^(ab) = m in any commutative group.Read more →) builds directly on DH. The Chinese Remainder TheoremChinese Remainder TheoremSimultaneous congruences with coprime moduli have a unique solution mod their productRead more → lets one work component-wise in factored-order groups.
Lean4 Proof
/-- Diffie–Hellman commutativity: in any commutative monoid,
(g^a)^b = (g^b)^a. This is the core algebraic identity. -/
theorem dh_correct {G : Type*} [CommMonoid G] (g : G) (a b : ℕ) :
(g ^ a) ^ b = (g ^ b) ^ a := by
rw [← pow_mul, ← pow_mul, Nat.mul_comm]
/-- Numeric check: 5^(6*15) mod 23 = 5^(15*6) mod 23. -/
example : 5 ^ (6 * 15) % 23 = 5 ^ (15 * 6) % 23 := by
rw [Nat.mul_comm]
/-- Verify concrete values: Bob and Alice both compute 2. -/
example : (8 ^ 15) % 23 = 2 := by native_decide
example : (19 ^ 6) % 23 = 2 := by native_decideReferenced by
- Digital Signature (Schnorr)Cryptography
- One-Way FunctionCryptography
- ElGamal EncryptionCryptography
- Modular ExponentiationCryptography