Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Diffie–Hellman and RSA both work, but to stay ahead of the best attacks their keys have grown large: 2048 to 3072 bits. Elliptic curve cryptography (ECC) gets the same security with keys about a tenth of that size. Smaller keys mean less computing, less battery and shorter messages, which is why phones, messaging apps and most HTTPS connections now use it.

NIST’s recommended key sizes (from NIST SP 800-57) show the difference. The security level means roughly “as hard as brute-forcing a symmetric key of this many bits.”

Security levelSymmetric keyRSA or Diffie–Hellman mod ppElliptic curve
112 bitsTriple DES (now retired)2048 bits224 bits
128 bitsAES-1283072 bits256 bits
192 bitsAES-1927680 bits384 bits
256 bitsAES-25615360 bits512 bits

The plan for this section: what an elliptic curve is, how to “add” two points on one, why that addition works with integers mod pp, and then Diffie–Hellman rebuilt on a curve. You don’t need anything beyond the modular arithmetic you already know.

What Is an Elliptic Curve?

That rule rules out curves with a sharp point or a place where the curve crosses itself. Despite the name, an elliptic curve has nothing to do with ellipses. (The name comes from the history of calculating the lengths of curved arcs of ellipses.)

Here’s the curve y2=x3−x+1y^2 = x^3 - x + 1:

Source
<Figure size 640x480 with 1 Axes>

Two features matter. The curve is symmetric about the xx-axis, because yy and −y-y give the same y2y^2. And a straight line usually crosses it in exactly three points.

Adding Two Points

The key operation is a way to “add” two points PP and QQ on the curve to get a third point on the curve:

For example, on y2=x3−x+1y^2 = x^3 - x + 1, take P=(−1,1)P = (-1, 1) and Q=(0,1)Q = (0, 1). The line through them is y=1y = 1. Setting y=1y = 1 in the equation gives 1=x3−x+11 = x^3 - x + 1, so x3−x=0x^3 - x = 0, and x=−1x = -1, 0 or 1. The third point is R=(1,1)R = (1, 1), and reflecting it gives P+Q=(1,−1)P + Q = (1, -1).

Source
<Figure size 640x480 with 1 Axes>

It’s a strange definition, but it behaves like addition: P+Q=Q+PP + Q = Q + P, and (P+Q)+S=P+(Q+S)(P + Q) + S = P + (Q + S). (The second fact is surprisingly hard to prove, but you can just use it.)

Adding a point to itself. To compute P+P=2PP + P = 2P there’s only one point, so use the line that is tangent to the curve at PP instead. On y2=x3−x+1y^2 = x^3 - x + 1 at P=(1,1)P = (1, 1), the tangent line is y=xy = x. It crosses the curve again at R=(−1,−1)R = (-1, -1), and reflecting gives 2P=(−1,1)2P = (-1, 1).

The point at infinity. If PP and QQ are reflections of each other, the line through them is vertical and never hits a third point. We say P+Q=∞P + Q = \infty, the point at infinity. It acts like zero: P+∞=PP + \infty = P. That’s why the curves below always count ∞\infty as one extra point.

The Formulas

The pictures turn into formulas using slopes, which is how a computer adds points. Let P=(x1,y1)P = (x_1, y_1) and Q=(x2,y2)Q = (x_2, y_2). The slope of the line is

λ=y2−y1x2−x1if P≠Q,λ=3x12+a2y1if P=Q\lambda = \frac{y_2 - y_1}{x_2 - x_1} \quad \text{if } P \neq Q, \qquad \lambda = \frac{3x_1^2 + a}{2y_1} \quad \text{if } P = Q

(the second one is the slope of the tangent line, from calculus). Then P+Q=(x3,y3)P + Q = (x_3, y_3), already reflected, where

x3=λ2−x1−x2y3=λ(x1−x3)−y1x_3 = \lambda^2 - x_1 - x_2 \qquad y_3 = \lambda(x_1 - x_3) - y_1

Check with the picture: P=(−1,1)P = (-1, 1) and Q=(0,1)Q = (0, 1) give λ=0\lambda = 0, so x3=0−(−1)−0=1x_3 = 0 - (-1) - 0 = 1 and y3=0−1=−1y_3 = 0 - 1 = -1. That’s P+Q=(1,−1)P + Q = (1, -1).

The important thing about these formulas is that they only add, subtract, multiply and divide. So they work just as well with integers mod pp.

Elliptic Curves Mod pp

For cryptography, use the same equation with integers mod a prime pp. Instead of a smooth curve you get a scatter of points. Here are all the points on y2=x3+4x+20(mod29)y^2 = x^3 + 4x + 20 \pmod{29}:

36 points, plus the point at infinity
[(0, 7), (0, 22), (1, 5), (1, 24), (2, 6), (2, 23), (3, 1), (3, 28), (4, 10), (4, 19), (5, 7), (5, 22), (6, 12), (6, 17), (8, 10), (8, 19), (10, 4), (10, 25), (13, 6), (13, 23), (14, 6), (14, 23), (15, 2), (15, 27), (16, 2), (16, 27), (17, 10), (17, 19), (19, 13), (19, 16), (20, 3), (20, 26), (24, 7), (24, 22), (27, 2), (27, 27)]
Source
<Figure size 600x600 with 1 Axes>

There are 36 points, plus ∞\infty, for 37 in all. You can check any of them by hand: for (1,5)(1, 5), 13+4⋅1+20=25=521^3 + 4 \cdot 1 + 20 = 25 = 5^2. The mirror symmetry is still there, but now the reflection of (x,y)(x, y) is (x,p−y)(x, p - y), shown by the dotted line at y=14.5y = 14.5.

“Dividing” in the slope formula means multiplying by an inverse mod pp, exactly like ElGamal decryption and finding RSA’s dd. Python’s pow(k, -1, p) does it. Here are the formulas as Python functions, with None standing for the point at infinity:

Example. Add P=(2,6)P = (2, 6) and Q=(5,7)Q = (5, 7) on y2=x3+4x+20(mod29)y^2 = x^3 + 4x + 20 \pmod{29}.

  • The slope is λ=7−65−2=13\lambda = \frac{7 - 6}{5 - 2} = \frac{1}{3}. The inverse of 3 mod 29 is 10 (since 3⋅10=30=29+13 \cdot 10 = 30 = 29 + 1), so λ=10\lambda = 10.

  • x3=102−2−5=93≡6(mod29)x_3 = 10^2 - 2 - 5 = 93 \equiv 6 \pmod{29}.

  • y3=10⋅(2−6)−6=−46≡12(mod29)y_3 = 10 \cdot (2 - 6) - 6 = -46 \equiv 12 \pmod{29}.

So P+Q=(6,12)P + Q = (6, 12). Check that it’s on the curve: 122=144≡2812^2 = 144 \equiv 28, and 63+4⋅6+20=260≡28(mod29)6^3 + 4 \cdot 6 + 20 = 260 \equiv 28 \pmod{29}.

Doubling PP uses the tangent slope λ=3⋅22+42⋅6=1612≡11(mod29)\lambda = \frac{3 \cdot 2^2 + 4}{2 \cdot 6} = \frac{16}{12} \equiv 11 \pmod{29}, which gives 2P=(1,5)2P = (1, 5).

(6, 12)
(1, 5)

Multiplying a Point: kPkP

kPkP means PP added to itself kk times. Starting from G=(1,5)G = (1, 5), the multiples jump around the curve with no obvious pattern:

1G = (1, 5)
2G = (4, 19)
3G = (20, 3)
4G = (15, 27)
5G = (6, 12)
6G = (17, 19)
7G = (24, 22)
8G = (8, 10)

Computing kPkP for a huge kk doesn’t mean doing k−1k - 1 additions. Use double and add, the same trick as square and multiply: to find 13G13G, write 13=8+4+113 = 8 + 4 + 1, so 13G=8G+4G+G13G = 8G + 4G + G, and get 2G2G, 4G4G and 8G8G by doubling three times. For a 256-bit kk that’s about 256 doublings plus some additions, which is fast for a computer.

13G = (16, 27)
37G = None

On this curve 37G=∞37G = \infty, so the multiples of GG cycle through all 37 points.

The Hard Problem

This is the elliptic curve version of the discrete log problem.

  • Easy direction: given kk and GG, compute kGkG with double and add.

  • Hard direction: given GG and a point QQ, find the kk with kG=QkG = Q.

On a 37-point curve you could just try every kk. On a real curve with about 2256 points, the best known methods take about 2128 steps, which is far out of reach. Compare the mod pp version from Diffie–Hellman: given gg and ga mod pg^a \bmod p, find aa. The structure is identical; “multiply by gg” became “add GG.”

Elliptic Curve Diffie–Hellman

Here’s Diffie–Hellman rebuilt on a curve (called ECDH). The curve y2=x3+4x+20(mod29)y^2 = x^3 + 4x + 20 \pmod{29} and the point G=(1,5)G = (1, 5) are public.

  • Alice picks a secret a=6a = 6 and sends A=6G=(17,19)A = 6G = (17, 19).

  • Bob picks a secret b=10b = 10 and sends B=10G=(13,23)B = 10G = (13, 23).

  • Alice computes 6B6B and Bob computes 10A10A. Both get (5,7)(5, 7), because a(bG)=b(aG)=(ab)Ga(bG) = b(aG) = (ab)G.

Usually the xx-coordinate of the shared point becomes the key for a symmetric cipher like AES. Eve sees GG, AA and BB, and would need aa or bb, which is the hard problem.

Alice sends (17, 19)  Bob sends (13, 23)
Alice computes (5, 7)
Bob computes   (5, 7)

Everything from the man-in-the-middle section carries over, so ECDH still needs signatures to check whose public point you received.

Why Can the Keys Be So Small?

The answer is about the best known attacks. For RSA and mod pp Diffie–Hellman, the number field sieve and related methods are much faster than brute force, so the numbers have to be thousands of bits long. For a well-chosen elliptic curve, nobody has found anything much better than general methods that take about N\sqrt{N} steps for a curve with NN points. So a 256-bit curve gives about 128 bits of security. “Well-chosen” matters: some special curves are weak, which is why everyone uses a few carefully studied standard curves.

Elliptic Curves in Real Life

ECC is now the default almost everywhere.

  • X25519 (Diffie–Hellman on a curve called Curve25519) is the most common key exchange in TLS 1.3. Signal and SSH use it too.

  • ECDSA on the NIST curve P-256 is widely used to sign web certificates, and Ed25519 is common for SSH keys and signing code. These are the elliptic curve versions of the RSA signatures from earlier in this chapter.

  • Bitcoin and Ethereum sign transactions with elliptic curve signatures on a curve called secp256k1.

What About Quantum Computers?

In 1994 Peter Shor found an algorithm that, on a large enough quantum computer, would factor nn and solve both kinds of discrete log problem efficiently. RSA, Diffie–Hellman and ECC would all break. (Symmetric ciphers like AES aren’t broken this way; they just need longer keys.) No quantum computer anywhere near that size exists, but an attacker could record encrypted traffic now and decrypt it later, so the switch has already started. In 2024 NIST published its first post-quantum standards: ML-KEM for sharing keys (FIPS 203) and ML-DSA for signatures (FIPS 204). They’re built on problems about lattices instead of factoring or curves. Many browsers and messaging apps already combine X25519 with ML-KEM, so a connection stays safe as long as either one holds up.