Path: blob/main/foundations/04-number-theory-rsa/break/wieners-attack-small-d.ipynb
483 views
Break: Wiener's Attack on Small Private Exponent
Module 04 | Breaking Weak Parameters
Use continued fractions to recover when .
Why This Matters
RSA decryption computes . When is large (as it should be), this is expensive --- especially on constrained devices like smart cards.
A tempting optimization: choose a small to make decryption fast, and let be the large value. After all, the public key is used for encryption, and the server does the heavy lifting for decryption... right?
Wrong. Michael Wiener showed in 1990 that if , the private key can be recovered from the public key alone, using nothing more than the continued fraction expansion of .
The attack is elegant, fast, and devastating.
The Setup: RSA with a Deliberately Small
We generate an RSA modulus and deliberately choose a small private exponent , then compute .
The attacker sees only the public key and must recover .
Step 1: The Key Relationship
Since , there exists an integer such that:
Dividing both sides by :
Since (they differ by ), we get:
So is a very good rational approximation to . Continued fractions are guaranteed to find all such good approximations as convergents.
Step 2: Compute the Continued Fraction Expansion of
The continued fraction of a rational number is a sequence of integers such that:
The convergents are the best rational approximations with small denominators. Wiener's theorem guarantees that appears among them.
Step 3: Test Each Convergent
For each convergent , the attacker checks whether is the correct private key. The test is:
If , skip (not meaningful).
Compute . If this isn't an integer, skip.
If is an integer, try to factor using , which gives . Solve the quadratic .
If the roots are integers and their product is , we found .
The Fix: Standard Key Generation
The defense is simple: use standard RSA key generation where is small (typically ) and is large (roughly the same size as ).
With standard key generation:
, so
The continued fraction expansion has convergents
None of them will have a denominator close to
Wiener's attack only works when . For a 2048-bit RSA key, this means must be less than 512 bits --- a standard is around 2048 bits.
Exercises
Boundary testing: Try generating keys where is just above . At what point does the attack start failing? Does it fail abruptly or gradually?
Key sizes: Run the attack on 512-bit, 1024-bit, and 2048-bit RSA keys with small . How does the attack time scale with key size?
Boneh-Durfee extension: Wiener's bound is . Boneh and Durfee (1999) extended this to using lattice techniques. How much more of the key space does this cover?
Summary
| Component | Role in the Attack |
|---|---|
| Creates the approximation | |
| Continued fractions | Efficiently enumerate all good rational approximations |
| Convergent test | Check each candidate by trying to factor |
| Small bound | guarantees appears as a convergent |
Key takeaways:
Choosing a small for fast decryption is catastrophically insecure.
Wiener's attack recovers in polynomial time using only the public key.
The attack also recovers the factorization of as a bonus.
Standard RSA key generation (small , large ) is immune to this attack.
The beautiful mathematics: the theory of continued fractions, developed by Euler in the 1700s, directly breaks a modern cryptosystem when parameters are chosen poorly.
Back to Module 04: Number Theory and RSA