Lesson
The theory — Diffie–Hellman: A Secret Agreed in Public
In a Diffie–Hellman key exchange two parties agree a secret number over a channel anyone can read. They fix a prime p and a base g in public. Each picks a private exponent, publishes g to that power mod p, and raises the other's published number to their own exponent: (gᵇ)ᵃ = (gᵃ)ᵇ = gᵃᵇ mod p. Undoing it means solving a discrete logarithm: given A = gᵃ mod p, find an x with gˣ ≡ A (mod p). Diffie and Hellman wrote in 1976 that they could see no way to get the shared secret from the public numbers without one, and had no proof that there is none. The order of g is the least n ≥ 1 with gⁿ ≡ 1 (mod p); g is a generator when its order is p − 1.
What each symbol means
p- the prime modulus, public
g- the base, public
a, b- Alice's and Bob's private exponents
A, B- their public numbers, gᵃ mod p and gᵇ mod p
x- the exponent Eve finds; any x with gˣ ≡ A works, so she finds a mod the order of g
ord(g)- the order of g: how many different values the shared secret can take
- Assumes
- p is a prime from 5 to 1,999, g any base from 2 to p − 2, and a and b run from 1 to p − 2. A try is one comparison of a computed power with a target, and both counts include the try that succeeds. Each Pohlig–Hellman digit is found by trying its candidates in order, which is how Pohlig and Hellman describe it for a small factor; for a large one they also give a search that trades memory for time, and the page does not run it. Diffie and Hellman's own example was a prime of about 200 bits, for which they put a logarithm at around 2¹⁰⁰ operations.
Problem solved in full
-
Recover Alice's secret at p = 101 5 steps
Alice and Bob use p = 101 and g = 2. Eve sees A = 12 and B = 53. Find an x with 2ˣ ≡ 12 (mod 101) by Pohlig–Hellman, count the tries, and use x to get the shared secret. Then say what the same attack would cost at p = 65,537.
-
100 = 2² · 5², so x is fixed by x mod 4 and x mod 25. The order of 2 divides 100, and 2⁵⁰ = 100 and 2²⁰ = 95 are both different from 1, so the order is 100 itself: 2 is a generator.
-
Mod 4, γ = 2⁵⁰ = 100, which is −1. The first binary digit: 12⁵⁰ = 100, so d = 1, on the second try. Take it out: 12 · 2⁻¹ = 12 · 51 = 612 ≡ 6, and 6²⁵ = 100, so the next digit is 1 as well, again on the second try. x ≡ 1 + 1 · 2 = 3 (mod 4).
-
Mod 25, γ = 2²⁰ = 95, whose powers are 1, 95, 36, 87, 84. The first base-5 digit: 12²⁰ = 95, so d = 1, on the second try. Take it out: 6⁴ = 1,296 ≡ 84, so the next digit is 4, on the fifth try. x ≡ 1 + 4 · 5 = 21 (mod 25).
-
The numbers below 100 that are 21 mod 25 are 21, 46, 71 and 96, and only 71 is 3 mod 4. So x = 71, after 2 + 2 + 2 + 5 = 11 tries, where the worst case is 2·2 + 2·5 = 14. Brute force would have tried 0 to 71, 72 tries. The shared secret is 53⁷¹ mod 101 = 35.
-
65,537 = 2¹⁶ + 1 is prime, and p − 1 = 2¹⁶. Pohlig–Hellman takes its sixteen binary digits one at a time, two candidates each: at worst 32 tries, where brute force could need 65,536. Pohlig and Hellman worked this very case, p = 2ⁿ + 1, before the general one.
Answer
x = 71, after 11 tries (at worst 14), and the shared secret is 35. At p = 65,537 the attack needs at most 32 tries. The page stops at 1,999, so that figure is arithmetic and not a run.
-
Learning path
How codes are broken
References (2)
- The exchange itself, the definition's sentence that its authors could see no way round a logarithm and had no proof, and the 200-bit example in `assumes`: Whitfield Diffie and Martin E. Hellman, "New Directions in Cryptography," IEEE Transactions on Information Theory 22(6), 644–654, November 1976. §III, p. 649.
- The second insight's quotation, the digit-by-digit search the page runs, and the worked problem's p = 2ⁿ + 1: Stephen C. Pohlig and Martin E. Hellman, "An Improved Algorithm for Computing Logarithms over GF(p) and Its Cryptographic Significance," IEEE Transactions on Information Theory 24(1), 106–110, January 1978. §III–IV, pp. 107–110.