← Back to section · Foundations of Cryptography
Choosing DH Groups and Parameters: Safe Primes, Curves, and Named Groups
Half of Diffie–Hellman's security lives in the protocol, the other half in the parameters: pick the wrong group and no protocol elegance will save you. This article covers safe primes and subgroup traps in finite-field DH, the selection logic for elliptic-curve groups, and why modern protocols allow only named groups.
The Diffie–Hellman protocol itself is a few lines long: each side picks a private key, exchanges public keys, and performs one exponentiation. But which group the protocol runs in, and who chose the parameters, decides whether those few lines are secure. The worst historical DH failures — Logjam, small-subgroup attacks, invalid-curve attacks — were never protocol-logic errors. Every one of them was a parameter error. This article works through how to choose the group.
Finite-field DH: prime moduli and the subgroup trap
Classical DH works in the multiplicative group Z_p*, where p is prime. The group order is p − 1, which is necessarily even and usually has many small factors. That is exactly where the trouble starts: the difficulty of the discrete logarithm problem is governed by the largest prime factor of the group order. If an attacker can squeeze your public key into a small subgroup, the Pohlig–Hellman algorithm solves the discrete logarithm factor by factor, and a discrete log in a tiny subgroup is trivial.
The standard defence is a safe prime: p = 2q + 1, where q is also prime. The group order then has only the factors 1, 2, q, and 2q, and by working in the order-q subgroup of quadratic residues, the discrete-log difficulty is carried entirely by the size of q. Private exponents should also be drawn at the scale of the subgroup, and every received public key must be verified to actually lie in the subgroup (one exponentiation check) — otherwise a peer can probe with an order-2 element and leak low-order bits of your private key via a small-subgroup attack.
A second hazard is where the parameters come from. Who generated p and the generator g? If one party supplies parameters freely, the other cannot rule out a trapdoor prime — a p deliberately constructed so that p − 1 is entirely smooth, making discrete logs instantly solvable. The standard groups from NIST and the IETF ship with verifiable generation procedures (for example, derivation from a fixed seed via hashing) precisely to eliminate this distrust.
Bigger is not automatically better: size, performance, and the Logjam lesson
Finite-field discrete logarithms admit the subexponential Number Field Sieve, so security grows slowly with modulus size: a 1024-bit modulus gives roughly 80 bits of security, 2048 bits about 112, and only at 3072 bits do you reach the 128-bit class. The 2015 Logjam attack fixed the practical meaning of this curve: researchers showed that 512-bit groups could be broken in near real time (some servers still accepted export-grade parameters), and that 1024-bit groups were within reach of nation-state precomputation.
Logjam’s sharper point was precomputation reuse: most of the Number Field Sieve’s cost depends only on the prime p, not on the individual target. At the time, the overwhelming majority of servers shared a handful of fixed 1024-bit groups, so an attacker could pay one expensive precomputation per group and then solve discrete logs for masses of connections in bulk. “Everyone uses these parameters” is not a security endorsement — it is an invitation to industrial-scale attack.
The practical conclusion: finite-field DH today should use groups of at least 2048 bits, preferably 3072 or more; and where elliptic curves are available, prefer them — a 256-bit elliptic-curve group delivers roughly 128-bit security at a fraction of the computation and bandwidth of a 3072-bit finite-field group.
Elliptic-curve groups: the curve is the parameter
On elliptic curves, “choosing the group” becomes “choosing the curve”. The discrete logarithm problem becomes ECDLP, for which no subexponential algorithm is known (generic attacks are square-root Pollard rho), so parameters can be much smaller. But curve selection has its own trap list:
- The group order needs a large prime factor. As in finite fields, if the curve’s group order is smooth, Pohlig–Hellman applies. Standard curves publish a large prime factor of the order (the cofactor is usually tiny).
- Avoid anomalous and singular curves. Anomalous curves, whose order equals p, fall to polynomial-time attacks, and singular curves degenerate into easy groups — both are excluded at selection time.
- Validate that peer public keys are on the curve. Invalid-curve attacks make the victim perform scalar multiplication on a weak attacker-chosen curve, leaking the private key. Implementations must validate points, or use a Montgomery-form curve with an x-only ladder that dissolves the validation problem structurally — which is exactly the route X25519 takes.
- Parameter provenance must be auditable. The seed provenance of the NIST curves triggered a long-running trust debate, while Curve25519 advertises “rigid” generation: every constant has a public, minimal justification. Choosing a curve is partly mathematics and partly trust.
The modern answer: named groups only
Collecting these lessons, modern protocols converge on one approach: abolish parameter negotiation; allow selection only from a fixed list. The supported_groups extension in TLS 1.3 lists nothing but named groups — the finite-field ffdhe2048 through ffdhe8192 (parameters fixed by RFC 7919 with verifiable provenance) and the elliptic curves secp256r1, secp384r1, x25519, and x448. Peers exchange numbers, not parameters; a group outside the list terminates the connection.
This removes three risk classes at once: peers supplying trap parameters, downgrade to weak groups, and implementation divergence from parameter parsing. IKEv2 and SSH have taken the same road. The cost is flexibility — new groups arrive only through standards updates — but history has shown repeatedly that in key exchange, a negotiable parameter space is attack surface.
After receiving a peer’s public key: the validation checklist
Choosing the group is the work done in advance; there is also work to do afterwards that is just as indispensable: every time a peer’s public key arrives, confirm it really is an element of the expected group. In finite fields, verify that the public key lies in the order-q subgroup — concretely, raise it to the power q and check that the result is one — while excluding degenerate values such as one or p minus one. On elliptic curves, verify that the point’s coordinates satisfy the curve equation, that the point is not the point at infinity, and, when the cofactor is not one, perform a subgroup-membership check. These checks cost far less than one full scalar multiplication, yet they close the door on small-subgroup and invalid-curve attacks in a single stroke. The root cause of several real vulnerabilities was precisely that implementers omitted these steps as dispensable optimisations — they are indeed inconspicuous in benchmarks, but to an attacker they are an open front door. The correct attitude is that parameter validation is part of the protocol, not an engineering option that may be trimmed.
The decision order compresses to one sentence: prefer named elliptic-curve groups (x25519 is today’s default answer); if you must use finite fields, use only standard named groups of 2048 bits or more; and always verify that a peer’s public key lies in the expected group. The protocol is a few lines long — it only stands up when the parameters are right.
Tags: Diffie-HellmanFinite FieldsNamed GroupsParameter Selection