Path: blob/main/foundations/05-discrete-log-diffie-hellman/break/partial-bit-leakage.ipynb
483 views
Break: Recovering DH Secrets from Partial Bit Leakage
Module 05 | Breaking Weak Parameters
Leaking even a fraction of the secret exponent's bits can compromise Diffie-Hellman.
Why This Matters
In theory, Diffie-Hellman is secure if the secret exponent is completely hidden. In practice, side-channel attacks can leak partial information:
Timing attacks reveal bits through computation time differences
Power analysis measures electrical consumption during exponentiation
Cache attacks observe memory access patterns
Cold boot attacks recover partial memory contents
If the attacker learns the top half of the bits of , the remaining bits can be brute-forced in instead of . If even more bits leak, the search shrinks further.
The Scenario
Alice performs DH with secret exponent . A side-channel attack leaks the top bits of . The attacker knows:
where is the leaked top bits, is the number of unknown bits, and .
We use small numbers to make the attack concrete and observable.
Meet-in-the-Middle: Even Faster with Partial Knowledge
If the attacker knows the top and bottom bits (but not the middle), a meet-in-the-middle approach works:
Split the unknown middle into two halves. Precompute one half, then search the other. This gives time and space instead of .
Even when only the top bits are known, we can apply a BSGS-style meet-in-the-middle on the unknown portion.
The Fix: Constant-Time Implementations
Preventing bit leakage requires:
Constant-time modular exponentiation: every bit of the exponent must take the same time to process (e.g., Montgomery ladder).
Blinding: multiply the base by a random value before exponentiation, then remove it afterward. This decorrelates side-channel signals from the secret.
Key erasure: delete ephemeral secrets immediately after use. This limits the window for cold boot or memory dump attacks.
The lesson: even if the DLP is computationally hard, side channels can give the attacker a shortcut by leaking bits of the answer.
Exercises
Bottom bits leaked: Suppose the attacker knows the bottom 5 bits instead of the top 5. Modify the attack. Is the search equally efficient?
Scattered bits: What if the attacker knows bits 0, 2, 4, 6, 8 (every other bit)? How would you structure the search? (Hint: the unknown bits are interleaved, so simple splitting doesn't apply directly.)
Larger example: Use (a 17-bit prime). Set a random 16-bit secret. Leak the top 8 bits and brute-force the bottom 8. How long does it take?
Summary
| Leaked bits | Search space | Attack cost |
|---|---|---|
| 0 (none) | Full DLP | |
| Half | Feasible brute force | |
| All but | Trivial |
Key takeaways:
Each leaked bit halves the attacker's search space.
Leaking half the bits reduces the DLP from to .
Meet-in-the-middle further improves the attack when partial bits are known.
Side-channel resistance (constant-time code, blinding) is essential.
Mathematical hardness alone does not guarantee security --- implementation matters.