Path: blob/main/foundations/05-discrete-log-diffie-hellman/sage/05d-computational-hardness-cdh-ddh.ipynb
483 views
Notebook 05d: Computational Hardness. CDH and DDH
Module 05. The Discrete Logarithm and Diffie-Hellman
Motivating Question. Diffie-Hellman's security requires that Eve cannot compute from and . But is this really equivalent to solving the discrete log? Could there be a clever way to compute without finding or ? And could Eve perhaps not even compute , but still distinguish it from a random group element? These questions lead to a precise hierarchy of hardness assumptions: DLP, CDH, and DDH.
Prerequisites. You should be comfortable with:
The discrete logarithm problem (notebook 05a)
Diffie-Hellman key exchange (notebook 05c)
Learning objectives. By the end of this notebook you will be able to:
State the CDH (Computational Diffie-Hellman) problem and assumption.
State the DDH (Decisional Diffie-Hellman) problem and assumption.
Explain the hierarchy: DDH CDH DLP.
Build an experimental DDH distinguisher game.
Understand where DDH fails (e.g., groups with efficient pairings).
1. Three Problems, One Hierarchy
Let be a cyclic group of prime order . We define three problems of increasing difficulty:
| Problem | Given | Task | Intuition |
|---|---|---|---|
| DLP | Find | "Invert the exponentiation" | |
| CDH | Compute | "Combine two exponentiations" | |
| DDH | Decide if | "Detect a DH tuple" |
The hardness hierarchy is:
Equivalently (contrapositively):
Each arrow is believed to be strict (not reversible) in general, though proving this remains open.
2. The CDH Problem
Computational Diffie-Hellman (CDH): Given , compute .
This is exactly what an eavesdropper needs to do to break Diffie-Hellman. If you can solve the DLP (recover from ), you can trivially solve CDH: just compute . But maybe you can compute through some other route, without ever learning or ?
No such method is known for well-chosen groups.
Checkpoint 1. Can you think of any algebraic operation on and that would give without knowing or ? For example, does work? (Answer: in general.)
3. The DDH Problem
Decisional Diffie-Hellman (DDH): Given , decide whether or is a random group element.
DDH is a weaker requirement than CDH: you don't need to compute , you just need to recognise it. If DDH is hard, then DH tuple looks indistinguishable from a random tuple, which is exactly what we need for DH-based encryption schemes like ElGamal.
Misconception alert. "CDH and DDH are the same thing." No! DDH is strictly easier than CDH. If you can compute (CDH), you can certainly decide whether (DDH). But being able to distinguish does not mean you can compute. There are groups where DDH is easy but CDH is hard (e.g., groups with bilinear pairings. Module 07).
Looking at those numbers, can you tell which are real DH tuples and which are random? Without solving the DLP, you cannot, that's exactly the DDH assumption.
4. The Hierarchy: DLP CDH DDH
Let us verify the implications experimentally.
DLP CDH: If we can solve DLP, we can solve CDH.
CDH DDH: If we can solve CDH, we can solve DDH (just compute and compare with ).
5. Statistical DDH Test
Let us run many DDH challenges and see if a naive distinguisher (random guessing) can do better than 50%.
Checkpoint 2. In the DDH game, what if someone proposes the following "distinguisher": compute and check if ? Does this work? (Answer: No, in general, so this test has no useful signal.)
6. When DDH Breaks: Quadratic Residues
In with a safe prime , the DDH assumption holds in the order- subgroup (quadratic residues). But in the full group , DDH can be broken using the Legendre symbol.
The key observation: the Legendre symbol tells us whether is a quadratic residue. Since is a QR iff is even, and is a QR iff is even, we can leak information about the parity of from the Legendre symbols of .
Notice that always holds for real DH tuples. For a random , this relation holds only half the time. This gives a distinguisher with advantage . DDH is broken in the full group!
Solution: work in the order- subgroup (quadratic residues), where the Legendre symbol is always and provides no information.
Bridge to Module 07. In elliptic curve groups with bilinear pairings, DDH is also easy (the pairing gives a DDH oracle). This is why pairing-based crypto uses different hardness assumptions, but CDH can still be hard in those groups!
Checkpoint 3. The Legendre distinguisher gets about 75% accuracy. Can you explain why it's 75% and not 100%? (Hint: real tuples always pass the test, but random tuples also pass the test half the time by coincidence.)
7. Which Assumption Does What?
Different cryptographic schemes rely on different assumptions:
| Scheme | Assumption Needed | Why |
|---|---|---|
| DH key exchange | CDH | Eve must not be able to compute |
| ElGamal encryption | DDH | Ciphertext must be indistinguishable from random |
| Schnorr signatures | DLP | Forger must not be able to recover the secret key |
| Pedersen commitments | DLP | Opener must not be able to find two different openings |
Crypto foreshadowing. In Module 09 (Sigma protocols), Schnorr signatures rely on DLP hardness. In Module 07 (Pairings), the pairing operation breaks DDH but preserves CDH, enabling constructions like BLS signatures and identity-based encryption.
8. Exercises
Exercise 1 (Worked): CDH from DLP
Problem. Given , solve CDH by first solving the DLP.
Solution.
Solve : try since .
Compute .
Exercise 2 (Guided): DDH Experiment
Problem. Run the DDH distinguishing game 500 times with and a primitive root .
Use the Legendre-symbol distinguisher.
Record the accuracy.
Now repeat, but generate challenges in the order- subgroup (use as the base). Does the Legendre distinguisher still work?
Hint: In the QR subgroup, every element has Legendre symbol , so the test always returns "real".
Exercise 3 (Independent): Is CDH Strictly Harder Than DDH?
Problem. We showed that solving CDH lets you solve DDH. But is the converse true?
Explain why a DDH oracle (which only gives yes/no) cannot directly compute .
However, show that a DDH oracle can recover one bit at a time. (Hint: consider for known values and use the DDH oracle to check.)
Research: in which groups is the gap between CDH and DDH known to be strict?
Summary
| Concept | Key Fact |
|---|---|
| DLP | Given , find |
| CDH | Given , compute |
| DDH | Given , decide if |
| Hierarchy | DDH hard CDH hard DLP hard |
| DDH breaks | Legendre symbol breaks DDH in full ; work in QR subgroup instead |
| Applications | DH needs CDH; ElGamal needs DDH; signatures need DLP |
We now understand the theoretical hardness that protects Diffie-Hellman. But how fast can an attacker actually solve the DLP? The next two notebooks study concrete algorithms: baby-step giant-step (a generic attack) and Pohlig-Hellman (exploiting smooth group orders).