Path: blob/main/foundations/01-modular-arithmetic-groups/break/weak-generator-attack.ipynb
483 views
Break: Weak Generator Attack
Module 01 | Breaking Weak Parameters
A generator that doesn't generate the full group shrinks the key space dramatically.
Why This Matters
Diffie-Hellman requires a generator of the full multiplicative group . This group has order , so a proper generator satisfies .
But what if someone picks carelessly? If has order , then all powers cycle through only distinct values.
The secret exponent now lives in instead of . The attacker's brute-force search space shrinks from down to .
The Scenario
Alice and Bob agree on and pick as their generator. They don't check whether actually generates the full group.
Spoiler: in , not . The key space is cut in half.
The Attack
Alice picks a secret and publishes . Since , we know determines completely. So we only need to search .
Cost Comparison: Weak vs. Proper Generator
The Fix: Always Verify the Generator
Before using in Diffie-Hellman, check that is a primitive root modulo , meaning .
Efficient test (no need to compute the full order):
Factor
For each prime factor , check that
If all checks pass, is a primitive root
Exercise: Explore Further
Other weak generators: Try mod . What are their orders? Which gives the attacker the biggest advantage?
Subgroup structure: The subgroups of have orders dividing . List all possible subgroup orders and find a generator for each.
Real-world defense: In practice, DH often uses a prime (safe prime) and a generator of the order- subgroup. Why is this safe even though doesn't generate the full group?
Summary
| Generator | Order | Key Space | Attacker Cost |
|---|---|---|---|
| (weak) | values | trials | |
| (primitive root) | values | trials |
Key takeaways:
A generator's order determines the effective key space, not .
Using a non-primitive-root as generator shrinks the key space to .
Always verify is a primitive root, or at minimum that is large enough.
The efficient primitive root test checks for each prime factor of .