The Discrete Logarithm Problem
Imagine a padlock that anyone can build in seconds. Yet it takes billions of years to pick apart. Public-key cryptography needs exactly this kind of asymmetry. It requires an operation trivial to run forward. It must be computationally hopeless to run backward. The Discrete Logarithm Problem (DLP) supplies one of the two or three foundational asymmetries. Modern cryptography rests on these, alongside the hardness of factoring large integers. The setup is deceptively simple. Fix a finite cyclic group and a generator of that group. Raising the generator to a chosen exponent is fast. It takes only a handful of multiplications using repeated squaring. Given only the result, however, recovering the exponent appears very hard. It seems to require effort exponential in the size of the group. This holds for every algorithm anyone has found. Over forty years of trying have not changed this. That gap between "easy forward" and "hard backward" matters greatly. It lets two strangers agree on a shared secret in public. They can do this in full view of an eavesdropper. They need never meet or exchange a private key in advance. This single hardness assumption underwrites Diffie-Hellman Key Exchange. It also underwrites the ElGamal encryption and signature schemes. In its elliptic-curve incarnation, it underwrites nearly all of modern TLS. It also underpins SSH and cryptocurrency signing. Understanding exactly what the DLP is matters greatly. So does understanding why it resists the algorithms we know. Knowing where its assumed hardness can quietly fail matters too. This is essential to understanding why these systems are trusted at all. This article builds the DLP up from Modular Arithmetic and Primes for Cryptography. It defines cyclic groups and generators precisely. It walks through the best known attacks with real complexity bounds. These include baby-step giant-step, Pohlig-Hellman, and index calculus. It shows exactly how group choice matters. That choice can make the difference between a secure system and a broken one.
- The DLP asks: given a cyclic group, generator , and element , find — believed hard for well-chosen groups.
- Exponentiation () is fast via repeated squaring: multiplications; inverting it is the hard direction.
- Generic attacks (baby-step giant-step, Pohlig-Hellman) run in or better only when the group order has small factors.
- Index calculus breaks the DLP in subexponentially — that's why prime fields need ~2048-bit moduli.
- Elliptic curve groups avoid index calculus, so equivalent security needs far smaller keys (~256 bits).
- The DLP's assumed hardness is the engine behind Diffie-Hellman, ElGamal, DSA, and elliptic-curve cryptography.
Modular exponentiation is a one-way street: computing is fast, but recovering from has no known efficient algorithm in a well-chosen group.
The idea
A group is a set with an associative binary operation, an identity element, and inverses for every element. A group is cyclic if some element , called a generator, produces every element of the group by repeated application of the operation: , where is the group's order. The smallest positive with (the identity) is the order of ; if generates all of , its order equals . The two cyclic groups cryptography cares about most are — the nonzero residues modulo a prime under multiplication — and the point group of an elliptic curve over a finite field, under an addition-like operation. In , exponentiation is repeated multiplication mod ; on an elliptic curve, the analogous operation is repeated point addition, often written additively as scalar multiplication . The Discrete Logarithm Problem is stated as: given a cyclic group , a generator , and an element known to equal for some integer , find . The value is called the discrete logarithm of base , written . This mirrors the ordinary logarithm's role as the inverse of exponentiation, except the arithmetic happens inside a finite group rather than over the reals — and that finiteness is precisely what makes inversion hard rather than a one-line calculus fact. The Discrete Logarithm Assumption (DLA) is the conjecture that no probabilistic polynomial-time algorithm solves the DLP with non-negligible probability, for appropriately chosen groups of appropriately large order.
How it works
Computing the easy direction: modular exponentiation
The forward direction — computing given and — must itself be efficient for the scheme to be usable. Naively multiplying by itself times takes multiplications, which is exponential in the bit length of . The standard trick, square-and-multiply (repeated squaring), exploits the binary expansion of the exponent. ``` function ModExp(g, x, p):
# computes g^x mod p result = 1 base = g mod p while x > 0: if x is odd: result = (result base) mod p base = (base base) mod p x = x // 2 # integer division return result ``` Each loop iteration halves , so the loop runs times, and each iteration does at most two modular multiplications on numbers with bits. This is the operation that makes Diffie-Hellman, ElGamal, and DSA computationally cheap for honest parties, while the reverse problem remains (believed) intractable.
The hard direction: generic discrete-log algorithms
An attacker who only knows , , and the group operation (not any special structure) is limited to generic algorithms. The naive approach — try until — takes group operations, where is the order of . Two smarter generic algorithms do much better.
Baby-step giant-step (BSG) trades time for space to reach . Let . Write the unknown exponent as with . Then
Precompute all "baby steps" for and store them in a hash table keyed by value. Then take "giant steps" for and check for a match in the table. ``` function BabyStepGiantStep(g, h, n): m = ceil(sqrt(n)) table = empty hash map
# baby steps: store g^j -> j for j = 0..m-1 e = 1 for j in 0 .. m-1: table[e] = j e = (e * g) mod p
# giant steps: look for h (g^-1)^(mi) matching a table entry factor = ModExp(ModInverse(g, p), m, p) # g^{-m} mod p gamma = h mod p for i in 0 .. m-1: if gamma in table: j = table[gamma] return (i m + j) mod n gamma = (gamma factor) mod p return "no solution found" # should not happen if h is truly in
Pohlig-Hellman attacks groups whose order factors into small primes. If , the discrete log can be solved modulo each separately (using BSG or Pollard's rho within each small subgroup) and then recombined with the Chinese Remainder Theorem. Its running time is roughly
which is efficient whenever every prime factor of is small — even if itself is astronomically large. This is precisely why real systems insist that the group order have a large prime factor: it forces every generic attack back up to for the largest prime .
Index calculus: breaking faster than generic bounds
In the specific group , attackers are not limited to generic algorithms, because the integers have extra structure (factorization into small primes). Index calculus exploits this: it finds the discrete logs of many small primes (a "factor base") by collecting relations from random powers of that happen to factor completely over the factor base, solving a large sparse linear system for their logs, and then expressing in terms of those known logs. Its running time is subexponential,
dramatically faster than the generic bound. This subexponential attack is the reason prime-field Diffie-Hellman and DSA require moduli of roughly 2048–3072 bits for long-term security, whereas elliptic-curve groups — which currently admit no known subexponential algorithm — achieve comparable security with 256–384-bit keys.
Complexity & correctness
Forward direction (modular exponentiation). Square-and-multiply performs one squaring per bit of the exponent and at most one extra multiplication per set bit, so the total is modular multiplications, each on numbers with bits. Using schoolbook multiplication, each modular multiplication costs bit operations, giving a total of — polynomial in the input size. This efficiency is not optional: without it, no honest party could compute their own public key or shared secret in practice.
Correctness of square-and-multiply. The invariant maintained by the loop is that at the start of each iteration,
where is the original exponent and , , are the current loop variables. Initially , , , so the invariant holds trivially. If is odd, folding one factor of into and halving (after squaring ) preserves the product; if is even, squaring and halving preserves it directly, since . When the loop ends, , so , as required.
Reverse direction (discrete log). No polynomial-time algorithm is known for a generic cyclic group. The best generic algorithms — those using only group operations and equality tests, not the internal representation of elements — provably require group operations; this is a theorem (Shoup, 1997) about generic-group algorithms, not merely an empirical observation, and matches the upper bound of baby-step giant-step and Pollard's rho. Since has roughly bits, is exponential in the bit length of the group order — this is what "hard" means precisely.
Why group choice matters. The generic lower bound is only a lower bound against generic attacks. Pohlig-Hellman shows that if factors into small primes, the effective security collapses to the square root of the largest prime factor, not of itself — so groups must be chosen with (or a large subgroup of it) having a large prime factor. In specifically, index calculus exploits the extra ring structure of the integers (unique factorization) to beat even the generic bound, achieving subexponential time; no such factor-base structure is known for generic elliptic curve groups, which is the entire reason Elliptic-Curve Cryptography achieves the same security with dramatically smaller keys.
Space. Baby-step giant-step needs storage for the hash table, which is often the real bottleneck in practice — Pollard's rho variant achieves the same time with only space by using a pseudo-random walk and cycle detection, trading a constant-factor slowdown for eliminating the table.
Worked example
Let's work entirely inside a small, fully checkable group so every step is verifiable by hand: , and take , which is a generator of (order ).
Step 1 — verify is a generator. The powers of must hit all 22 nonzero residues before repeating.
| 1 | 5 | 12 | 18 |
| 2 | 2 | 13 | 21 |
| 3 | 10 | 14 | 13 |
| 4 | 4 | 15 | 19 |
| 5 | 20 | 16 | 3 |
| 6 | 8 | 17 | 15 |
| 7 | 17 | 18 | 6 |
| 8 | 16 | 19 | 7 |
| 9 | 11 | 20 | 12 |
| 10 | 9 | 21 | 14 |
| 11 | 22 | 22 | 1 |
All 22 nonzero residues mod 23 appear exactly once, confirming has order and generates the full group.
Step 2 — the forward direction. Suppose Alice picks secret exponent and publishes . Using square-and-multiply: . ``` base = 5, result = 1, x = 6 (110) x even: base = 5^2 = 25 mod 23 = 2, x = 3 x odd: result = 12 = 2, base = 2^2 = 4, x = 1 x odd: result = 24 = 8, base = 4^2=16, x = 0 -> stop result = 8 ``` So , matching the table above (). This took 3 loop iterations instead of 6 multiplications — a small example of the savings that becomes dramatic for 256-bit exponents.
Step 3 — the attacker's problem. Eve sees , , , and must find with , knowing nothing else. Brute force would try and stop at — feasible here because is tiny, but this is exactly the approach that becomes hopeless once has hundreds of bits. Baby-step giant-step, for illustration: . Baby steps — store for :
| 0 | 1 |
| 1 | 5 |
| 2 | 2 |
| 3 | 10 |
| 4 | 4 |
Giant steps — compute . Since , (from the table). Compute for :
| in baby table? | ||
|---|---|---|
| 0 | 8 | no |
| 1 | yes, |
Match found at , , giving — recovering Alice's secret exponent, exactly as expected, in steps of table-building plus a handful of giant steps, rather than checking all 22 candidates. This toy example is fully breakable by hand precisely because is minuscule; real Diffie-Hellman deployments use primes with 2048+ bits, making even generic attacks require roughly operations — safely outside any conceivable computational budget.
Common pitfalls & traps
| Pitfall | Why it breaks security |
|---|---|
| Using a group order with only small prime factors | Pohlig-Hellman reduces the attack to for the largest factor, not |
| Choosing that generates a small subgroup, not the full group | The DLP is only as hard as the subgroup order; small-subgroup attacks can leak key bits |
| Reusing the same modulus across many services without a large prime-order subgroup | Precomputation attacks (e.g., against common 1024-bit DH primes) amortize index-calculus cost across all users of that prime |
| Assuming elliptic-curve-strength security from a same-bit-length prime field | Index calculus applies to but not (known) to generic elliptic curves — bit lengths are not comparable |
| Treating "hard to invert" as "proven hard" | The DLP's hardness is an unproven assumption, not a theorem; only generic-model lower bounds are proven |
| Off-by-one in baby-step giant-step's | Using instead of can miss valid pairs when is not a perfect square |
Pioneers & history
Origins · 1 minWhitfield Diffie and how this was discovered
Diffie, working with Martin Hellman at Stanford, recognized in the early 1970s that secure communication without prior shared secrets required a fundamentally new kind of one-way function. Their 1976 paper "New Directions in Cryptography" proposed the discrete logarithm in as exactly such a function, launching the Diffie-Hellman key exchange and the entire field of public-key cryptography.
Where this matters
The DLP is not an abstract curiosity — it is running, right now, inside nearly every encrypted connection on the internet. TLS 1.3 uses (elliptic-curve) Diffie-Hellman for its default key exchange, relying on the DLP over curves like X25519 or the NIST P-256 curve. SSH sessions negotiate ephemeral shared secrets the same way. Signal and WhatsApp use variants of Diffie-Hellman (the X3DH and Double Ratchet protocols) to establish and continuously refresh encryption keys between messaging endpoints. Digital signature schemes — DSA, ECDSA, and EdDSA — invert the same hardness assumption: signing uses a private discrete-log-style secret, and forging a signature would require solving essentially the same DLP. Cryptocurrencies such as Bitcoin and Ethereum secure every transaction with ECDSA signatures over the secp256k1 curve, meaning the entire security of a blockchain ledger reduces, in the end, to the presumed hardness of the elliptic-curve discrete logarithm. Understanding the DLP is therefore the direct on-ramp to both Diffie-Hellman Key Exchange and Elliptic-Curve Cryptography, the two technologies that carry this hardness assumption into deployed systems.
Ask the tutor: How does the Diffie-Hellman key exchange use the Discrete Logarithm Problem to let two parties agree on a shared secret over a public channel?
Is the Discrete Logarithm Problem proven to be hard?
No — it is a conjecture, not a theorem. What is proven is a weaker statement: in the generic group model, where an algorithm can only perform group operations and equality tests without exploiting any special representation of elements, any algorithm needs operations to solve the DLP. This is a genuine mathematical theorem (Shoup, 1997). But real groups like have extra structure — the integers' unique factorization — that generic-model attackers cannot use but index calculus can, achieving subexponential time. No proof rules out an even faster algorithm being discovered tomorrow, which is why cryptographers describe the DLP as an assumption, continually stress-tested rather than mathematically settled.
How does the DLP relate to the RSA problem?
Both are believed-hard number-theoretic problems used to build public-key cryptography, but they are structurally different. RSA's hardness rests on factoring large composite integers (or the closely related RSA problem of computing -th roots mod ), while the DLP rests on inverting exponentiation inside a cyclic group. No proof shows one problem reduces to the other in general, so they are treated as independent assumptions. Interestingly, both admit subexponential attacks in their "classical" settings — the number field sieve for factoring, index calculus for discrete logs — while elliptic curve discrete logs currently resist both quantum-safe subexponential classical attacks, though Shor's algorithm breaks both on a quantum computer.
Why must the generator g have large prime order, not just be "some element" of the group?
If happens to generate only a small subgroup of — say, one of order where is small — then the discrete log of any element in that subgroup can be found in roughly steps, regardless of how large the full group is. Protocol designers therefore deliberately choose to generate a subgroup of large prime order (a "safe prime" setup, where ), guaranteeing that any discrete log computed inside that subgroup costs at least generically. Skipping this check is exactly how small-subgroup confinement attacks recover secret key bits from careless implementations.
What is the relationship between the DLP and Diffie-Hellman key exchange specifically?
Diffie-Hellman does not directly ask either party to solve the DLP; it asks an eavesdropper to compute given only and , which is called the Computational Diffie-Hellman (CDH) problem. CDH is at least as easy as the DLP — if you can solve discrete logs, you can trivially recover from and then compute directly. Whether CDH is exactly as hard as the DLP in general is a subtler open question, but for the groups used in practice, no method is known to solve CDH without effectively solving the DLP, so the two are treated as equivalent in security arguments.
Why did the field move toward elliptic curves instead of just increasing prime sizes?
Because index calculus attacks on run in subexponential time, security there grows slowly as the modulus grows — doubling the key size does not double the attacker's work by anywhere near the amount it does for a purely exponential-time attack. This forces prime-field Diffie-Hellman and DSA into unwieldy 2048–3072-bit keys for modern security levels. Elliptic curve groups admit no known subexponential discrete-log algorithm, so their security scales with the square root of the group order exactly as the generic bound predicts, letting 256-bit curves match roughly 3072-bit prime-field security. This translates into faster computation, smaller keys, and less bandwidth — decisive advantages for mobile and embedded systems.
Can quantum computers solve the Discrete Logarithm Problem efficiently?
Yes. Shor's algorithm, originally developed for integer factorization, extends directly to the discrete logarithm problem in any abelian group, including and elliptic curve groups, running in polynomial time on a sufficiently large fault-tolerant quantum computer. This means that once large-scale quantum computers exist, Diffie-Hellman, DSA, ECDSA, and all DLP-based schemes become insecure — a major motivation for post-quantum cryptography research into lattice-based and other quantum-resistant alternatives that do not rely on the discrete logarithm or factoring assumptions.
What's the difference between "hard" in the generic group model and "hard" for a specific concrete group?
The generic group model treats the group as a black box: an algorithm can add, negate, and compare elements but sees no representation-specific structure, and in this idealized world the lower bound is a proven theorem. A concrete group like is not a black box — its elements are literal integers with factorization structure that index calculus exploits, breaking the generic lower bound entirely with a subexponential algorithm. This is precisely why cryptographers distinguish "provably generic-hard" from "conjectured hard in practice," and why elliptic curves — which so far behave much more like ideal generic groups — are preferred over prime fields at equivalent claimed security levels.