Path: blob/main/foundations/01-modular-arithmetic-groups/connect/dh-parameter-selection.ipynb
483 views
Connect: Diffie-Hellman Parameter Selection
Module 01 | Real-World Connections
Generators, orders, and safe primes --- Module 01's concepts determine whether Diffie-Hellman is secure.
Introduction
Diffie-Hellman key exchange lives in , the multiplicative group of integers mod a prime . The security depends on choosing the right and --- and Module 01 taught you exactly what "right" means.
In this notebook, we'll trace how generators, element orders, safe primes, and Lagrange's theorem directly determine whether a Diffie-Hellman instantiation is secure or broken.
Generator = DH Base
In Diffie-Hellman, both parties compute powers of a shared base modulo a prime . For security, must be a generator of --- meaning has order and its powers produce every element of the group.
If is not a generator, then the powers only cover a subgroup, which shrinks the space an attacker must search.
The Key Exchange
Diffie-Hellman lets two parties (Alice and Bob) establish a shared secret over a public channel:
Alice picks a secret , sends .
Bob picks a secret , sends .
Both compute the shared secret: .
An eavesdropper sees , , , and , but computing requires solving the discrete logarithm problem (DLP).
Why Parameters Matter: The Danger of Bad Choices
Not all primes and generators are created equal. If the parameters are poorly chosen, Diffie-Hellman can be broken even without solving the general DLP.
Two key dangers (explored in the break notebooks):
Smooth-order groups: If has only small prime factors, the Pohlig-Hellman algorithm can solve DLP efficiently by working in each small subgroup separately.
Weak generators: If generates a small subgroup of , the shared secret lives in that subgroup, drastically reducing the search space.
This is why we need safe primes and full generators.
Safe Primes: Lagrange's Theorem in Action
A safe prime is a prime where is also prime.
Why does this help? By Lagrange's theorem, every subgroup order must divide the group order . If is prime, the only divisors of are:
So the only subgroups have order (trivial), (just ), (half the group), or (the full group). There are no small subgroups to exploit.
Parameter Validation
Before using DH parameters, you should validate them. Here's a checklist derived directly from Module 01 concepts:
Real-World Parameters: RFC 3526
In practice, DH parameters are not generated on the fly. Standardized groups from RFC 3526 are used --- these specify huge safe primes (1536-bit to 8192-bit) that have been carefully vetted.
For example, the 1536-bit MODP group uses a prime of the form:
The generator is simply . This works because for these carefully chosen primes, is a generator of the full group .
The takeaway: the concepts from Module 01 (generators, orders, safe primes) are exactly what standards bodies check when selecting parameters for worldwide use.
Concept Map: Module 01 Diffie-Hellman
| Module 01 Concept | DH Application |
|---|---|
| Generators | DH base must generate |
| Element order | must have order (full group order) |
| Safe primes | prevents small-subgroup attacks |
| Lagrange's theorem | Constrains subgroup sizes, limits attack surface |
| Modular exponentiation | All DH computations (, , ) |
| Discrete logarithm | Security assumption: given , finding is hard |
What's Next
Module 05 implements full Diffie-Hellman key exchange and the attacks against it --- including Pohlig-Hellman (exploiting smooth orders) and small-subgroup confinement (exploiting weak generators). You'll see firsthand why every parameter choice matters.
Summary
| Concept | Key idea |
|---|---|
| DH group | , the cyclic group we studied all module |
| Base | Must be a generator (order ), ensuring the shared secret can be any group element |
| Safe primes | with prime prevents small-subgroup attacks, a direct consequence of Lagrange's theorem |
| Parameter validation | Checks exactly the properties we learned: primality, generator status, order |
| Real-world standards | RFC 3526 encodes these same mathematical requirements for worldwide use |
The abstract algebra from Module 01 is not background theory. It is the security engineering.