Path: blob/main/foundations/01-modular-arithmetic-groups/python/break-smooth-order-attack.ipynb
483 views
Break: Smooth-Order Attack
Module 01 | Breaking Weak Parameters
When has only small prime factors, the discrete log problem becomes easy.
Why This Matters
Diffie-Hellman key exchange relies on the discrete logarithm problem (DLP) being hard: given , , and , find .
But hardness depends critically on the structure of the group. If factors into only small primes (we call smooth), an attacker can:
Solve the DLP independently in each small-prime subgroup (cheap!)
Combine the partial results using the Chinese Remainder Theorem
This is the Pohlig-Hellman algorithm (1978). It reduces a hard DLP into many trivially small DLPs.
The Scenario
Alice uses Diffie-Hellman with a deliberately bad prime where is smooth (has only small factors). She thinks her secret exponent is safe because is prime.
Your job: recover Alice's secret key using the Pohlig-Hellman attack.
Step 1: Factor the Group Order
The group has order .
The largest prime power is just . This means we never need to brute-force more than 9 possibilities in any subgroup. Compare this to brute-forcing all 2520!
Step 2: Solve the DLP in Each Subgroup
For each prime power dividing , we project both and into the subgroup of order :
Now has order , and we need to find such that .
Since is small, we can just brute force this.
Step 3: Combine with the Chinese Remainder Theorem
We now have a system of congruences:
Since the moduli are pairwise coprime and their product is , the CRT gives us a unique solution modulo .
Cost Comparison
How much work did the attacker actually do?
The Fix: Safe Primes
A safe prime is a prime such that is also prime. Then , which has only two prime factors: and the large prime .
The Pohlig-Hellman attack can only extract the secret modulo (trivial) and modulo (requires solving a DLP of size , essentially as hard as the original problem).
Exercise: Try It Yourself
Change the secret: Set
secretto a different value and re-run the attack. Does it still work? Why?Bigger smooth prime: Try
p = 55441where . How does the attack cost change?Partially smooth: What if has one large factor and several small ones? How much does the attacker learn?
Summary
| Smooth | Safe prime | |
|---|---|---|
| Factorization of | Many small primes | (large prime) |
| Pohlig-Hellman cost | Sum of small factors | |
| DLP difficulty | Easy | Hard |
Key takeaways:
The DLP is only as hard as the largest prime factor of the group order.
The Pohlig-Hellman algorithm decomposes the DLP into independent sub-problems.
Safe primes (, prime) defend against this attack.
Modern DH standards (RFC 3526, RFC 7919) mandate safe primes for exactly this reason.