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.

Key takeaways
  • The DLP asks: given a cyclic group, generator gg, and element h=gxh = g^x, find xx — believed hard for well-chosen groups.
  • Exponentiation (gxg^x) is fast via repeated squaring: O(log⁡x)O(\log x) multiplications; inverting it is the hard direction.
  • Generic attacks (baby-step giant-step, Pohlig-Hellman) run in O(n)O(\sqrt{n}) or better only when the group order nn has small factors.
  • Index calculus breaks the DLP in Zp∗\mathbb{Z}_p^* 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.
The core insight

Modular exponentiation is a one-way street: computing gx  pg^x \bmod p is fast, but recovering xx from gx  pg^x \bmod p has no known efficient algorithm in a well-chosen group.

The idea

A group (G,⋅)(G, \cdot) is a set with an associative binary operation, an identity element, and inverses for every element. A group is cyclic if some element g∈Gg \in G, called a generator, produces every element of the group by repeated application of the operation: G={g0,g1,g2,…,gn−1}G = \{g^0, g^1, g^2, \dots, g^{n-1}\}, where n=∣G∣n = |G| is the group's order. The smallest positive kk with gk=eg^k = e (the identity) is the order of gg; if gg generates all of GG, its order equals nn. The two cyclic groups cryptography cares about most are Zp∗\mathbb{Z}_p^* — the nonzero residues modulo a prime pp under multiplication — and the point group of an elliptic curve over a finite field, under an addition-like operation. In Zp∗\mathbb{Z}_p^*, exponentiation is repeated multiplication mod pp; on an elliptic curve, the analogous operation is repeated point addition, often written additively as scalar multiplication xPxP. The Discrete Logarithm Problem is stated as: given a cyclic group GG, a generator gg, and an element h∈Gh \in G known to equal gxg^x for some integer xx, find xx. The value xx is called the discrete logarithm of hh base gg, written x=log⁡ghx = \log_g h. 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 gx  pg^x \bmod p given gg and xx — must itself be efficient for the scheme to be usable. Naively multiplying gg by itself xx times takes O(x)O(x) multiplications, which is exponential in the bit length of xx. 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 xx, so the loop runs O(log⁡x)O(\log x) times, and each iteration does at most two modular multiplications on numbers with O(log⁡p)O(\log p) 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 gg, hh, and the group operation (not any special structure) is limited to generic algorithms. The naive approach — try x=0,1,2,…x = 0, 1, 2, \dots until gx=hg^x = h — takes O(n)O(n) group operations, where nn is the order of gg. Two smarter generic algorithms do much better.

Baby-step giant-step (BSG) trades time for space to reach O(n)O(\sqrt{n}). Let m=⌈n⌉m = \lceil \sqrt{n} \rceil. Write the unknown exponent as x=im+jx = im + j with 0≤i,j<m0 \le i, j < m. Then

h=gim+j  ⟹  h⋅g−j=(gm)i.h = g^{im+j} \implies h \cdot g^{-j} = (g^m)^i .

Precompute all "baby steps" gjg^j for j=0,…,m−1j = 0, \dots, m-1 and store them in a hash table keyed by value. Then take "giant steps" h⋅(g−m)ih \cdot (g^{-m})^i for i=0,1,…i = 0, 1, \dots 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 nn factors into small primes. If n=∏piein = \prod p_i^{e_i}, the discrete log can be solved modulo each pieip_i^{e_i} separately (using BSG or Pollard's rho within each small subgroup) and then recombined with the Chinese Remainder Theorem. Its running time is roughly

O(∑iei(log⁡n+pi)),O\Big(\sum_i e_i \big(\log n + \sqrt{p_i}\big)\Big),

which is efficient whenever every prime factor pip_i of nn is small — even if nn 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 Ω(p)\Omega(\sqrt{p}) for the largest prime p∣np \mid n.

Index calculus: breaking Zp∗\mathbb{Z}_p^* faster than generic bounds

In the specific group Zp∗\mathbb{Z}_p^*, 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 gg that happen to factor completely over the factor base, solving a large sparse linear system for their logs, and then expressing log⁡gh\log_g h in terms of those known logs. Its running time is subexponential,

Lp[1/3,c]=exp⁡ ⁣((c+o(1))(log⁡p)1/3(log⁡log⁡p)2/3),L_p[1/3, c] = \exp\!\big((c + o(1)) (\log p)^{1/3} (\log\log p)^{2/3}\big),

dramatically faster than the O(p)O(\sqrt{p}) 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.

Figure
The DLP as a one-way trapdoor: easy forward via square-and-multiply, hard backward via known attacks
generator g exponent x (secret) square-and-multiply O(log x) — EASY h = g^x mod p public value recover x from h ? believed HARD Known attack strategies Brute force O(n) try every exponent infeasible for n ~ 2^256 Baby-step giant-step O(√n) time & space generic, any cyclic group Pohlig-Hellman if n smooth Index calculus subexponential works in Z_p* no known EC analogue

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 O(log⁡x)O(\log x) modular multiplications, each on numbers with O(log⁡p)O(\log p) bits. Using schoolbook multiplication, each modular multiplication costs O((log⁡p)2)O((\log p)^2) bit operations, giving a total of O((log⁡x)(log⁡p)2)O((\log x)(\log p)^2) — 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,

result⋅basex≡gx0(modp),\text{result} \cdot \text{base}^{x} \equiv g^{x_0} \pmod p,

where x0x_0 is the original exponent and xx, base\text{base}, result\text{result} are the current loop variables. Initially result=1\text{result} = 1, base=g\text{base} = g, x=x0x = x_0, so the invariant holds trivially. If xx is odd, folding one factor of base\text{base} into result\text{result} and halving xx (after squaring base\text{base}) preserves the product; if xx is even, squaring base\text{base} and halving xx preserves it directly, since basex=(base2)x/2\text{base}^x = (\text{base}^2)^{x/2}. When the loop ends, x=0x = 0, so result⋅base0=result=gx0  p\text{result} \cdot \text{base}^0 = \text{result} = g^{x_0} \bmod p, 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 Ω(n)\Omega(\sqrt{n}) group operations; this is a theorem (Shoup, 1997) about generic-group algorithms, not merely an empirical observation, and matches the O(n)O(\sqrt{n}) upper bound of baby-step giant-step and Pollard's rho. Since nn has roughly log⁡n\log n bits, n=2(log⁡n)/2\sqrt{n} = 2^{(\log n)/2} is exponential in the bit length of the group order — this is what "hard" means precisely.

Why group choice matters. The generic Ω(n)\Omega(\sqrt{n}) lower bound is only a lower bound against generic attacks. Pohlig-Hellman shows that if nn factors into small primes, the effective security collapses to the square root of the largest prime factor, not of nn itself — so groups must be chosen with nn (or a large subgroup of it) having a large prime factor. In Zp∗\mathbb{Z}_p^* specifically, index calculus exploits the extra ring structure of the integers (unique factorization) to beat even the generic bound, achieving subexponential Lp[1/3,c]L_p[1/3, c] 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 O(n)O(\sqrt{n}) storage for the hash table, which is often the real bottleneck in practice — Pollard's rho variant achieves the same O(n)O(\sqrt{n}) time with only O(1)O(1) 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: p=23p = 23, and take g=5g = 5, which is a generator of Z23∗\mathbb{Z}_{23}^* (order n=22n = 22).

Step 1 — verify gg is a generator. The powers of 5  235 \bmod 23 must hit all 22 nonzero residues before repeating.

xx5x  235^x \bmod 23xx5x  235^x \bmod 23
151218
221321
3101413
441519
520163
681715
717186
816197
9112012
1092114
1122221

All 22 nonzero residues mod 23 appear exactly once, confirming 55 has order 2222 and generates the full group.

Step 2 — the forward direction. Suppose Alice picks secret exponent x=6x = 6 and publishes h=56  23h = 5^6 \bmod 23. Using square-and-multiply: 6=11026 = 110_2. ``` 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 h=8h = 8, matching the table above (56  23=85^6 \bmod 23 = 8). This took 3 loop iterations instead of 6 multiplications — a small example of the O(log⁡x)O(\log x) savings that becomes dramatic for 256-bit exponents.

Step 3 — the attacker's problem. Eve sees g=5g = 5, p=23p = 23, h=8h = 8, and must find xx with 5x≡8(mod23)5^x \equiv 8 \pmod{23}, knowing nothing else. Brute force would try x=1,2,3,…x = 1, 2, 3, \dots and stop at x=6x = 6 — feasible here because n=22n = 22 is tiny, but this is exactly the approach that becomes hopeless once nn has hundreds of bits. Baby-step giant-step, for illustration: m=⌈22⌉=5m = \lceil \sqrt{22} \rceil = 5. Baby steps — store 5j  235^j \bmod 23 for j=0,…,4j = 0, \dots, 4:

jj5j  235^j \bmod 23
01
15
22
310
44

Giant steps — compute g−m=5−5  23g^{-m} = 5^{-5} \bmod 23. Since 522≡15^{22} \equiv 1, 5−5≡517≡155^{-5} \equiv 5^{17} \equiv 15 (from the table). Compute h⋅(5−5)i  23h \cdot (5^{-5})^i \bmod 23 for i=0,1,2,…i = 0, 1, 2, \dots:

iih⋅15i  23h \cdot 15^i \bmod 23in baby table?
08no
18⋅15=120≡58 \cdot 15 = 120 \equiv 5yes, j=1j=1

Match found at i=1i = 1, j=1j = 1, giving x=im+j=5(1)+1=6x = im + j = 5(1) + 1 = 6 — recovering Alice's secret exponent, exactly as expected, in O(22)≈5O(\sqrt{22}) \approx 5 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 p=23p = 23 is minuscule; real Diffie-Hellman deployments use primes with 2048+ bits, making even O(n)O(\sqrt{n}) generic attacks require roughly 210242^{1024} operations — safely outside any conceivable computational budget.

Common pitfalls & traps

PitfallWhy it breaks security
Using a group order nn with only small prime factorsPohlig-Hellman reduces the attack to O(pmax⁡)O(\sqrt{p_{\max}}) for the largest factor, not O(n)O(\sqrt{n})
Choosing gg that generates a small subgroup, not the full groupThe DLP is only as hard as the subgroup order; small-subgroup attacks can leak key bits
Reusing the same modulus pp across many services without a large prime-order subgroupPrecomputation 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 fieldIndex calculus applies to Zp∗\mathbb{Z}_p^* 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 mmUsing m=⌊n⌋m = \lfloor \sqrt{n} \rfloor instead of ⌈n⌉\lceil \sqrt{n} \rceil can miss valid (i,j)(i, j) pairs when nn is not a perfect square

Pioneers & history

Origins · 1 minWhitfield Diffie and how this was discovered
WD
Whitfield Diffie
born 1944 · American cryptographer, co-inventor of public-key cryptography

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 Zp∗\mathbb{Z}_p^* as exactly such a function, launching the Diffie-Hellman key exchange and the entire field of public-key cryptography.

History
1976
— Diffie and Hellman propose public-key cryptography and the DLP-based key exchange.
1978
— ElGamal-style discrete-log encryption ideas begin circulating; the RSA cryptosystem is published, based on factoring instead.
1985
— Taher ElGamal formalizes discrete-log-based public-key encryption and signatures.
1994
— Index calculus and number field sieve techniques mature, pushing safe DH modulus sizes to 1024+ bits.
2015
— The Logjam attack demonstrates practical downgrade attacks against shared, precomputed 512/768-bit DH primes.

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 Ω(n)\Omega(\sqrt{n}) operations to solve the DLP. This is a genuine mathematical theorem (Shoup, 1997). But real groups like Zp∗\mathbb{Z}_p^* 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 ee-th roots mod nn), 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 Zp∗\mathbb{Z}_p^* 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 gg happens to generate only a small subgroup of Zp∗\mathbb{Z}_p^* — say, one of order qq where qq is small — then the discrete log of any element in that subgroup can be found in roughly O(q)O(\sqrt{q}) steps, regardless of how large the full group Zp∗\mathbb{Z}_p^* is. Protocol designers therefore deliberately choose gg to generate a subgroup of large prime order qq (a "safe prime" setup, where p=2q+1p = 2q + 1), guaranteeing that any discrete log computed inside that subgroup costs at least Ω(q)\Omega(\sqrt{q}) 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 gab  pg^{ab} \bmod p given only gag^a and gbg^b, 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 aa from gag^a and then compute gabg^{ab} 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 Zp∗\mathbb{Z}_p^* 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 Zp∗\mathbb{Z}_p^* 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 Ω(n)\Omega(\sqrt{n}) lower bound is a proven theorem. A concrete group like Zp∗\mathbb{Z}_p^* 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.

Before this

Where this leads