The Case of the Mystery Seeds · Chapter 2

What is an elliptic curve, really?

In Chapter 1 we scrambled numbers by walking around a clock. Elliptic-curve cryptography plays the same game, but the steps are taken between points on a curve. The rule for taking a step is a little piece of geometry you can do with a ruler.

Nib says: Don't let the name scare you; these curves aren't ellipses. (The name comes from old formulas for measuring the length of an ellipse.) Tap the first toy to drop points on the curve and watch them add up. Then we'll move the whole thing onto a clock.

The curve

An elliptic curve is every point (x, y) that satisfies one equation:

y² = x³ + a·x + b

Pick two numbers a and b and you get a curve. Because the left side is y squared, the curve is a mirror image of itself above and below the horizontal axis: if (x, y) is on it, so is (x, −y). Depending on a and b, it's either one smooth swoop or a swoop plus a separate oval.

Adding two points

Here's the surprising part. You can add points on the curve, and the answer is another point on the curve. The rule:

1. Draw a straight line through the two points, P and Q. On these curves, that line almost always hits the curve at exactly one more spot.
2. Flip that third spot to the other side of the horizontal axis. The flipped point is P + Q.

The point adder

Tap near the curve to place P, tap again to place Q. The dashed gold line hits the curve a third time; flip it (rust) to get P + Q.

Two special cases complete the rule. To add a point to itself, use the line that just touches the curve there, the tangent. And when the line is perfectly vertical, as it is for P and −P, it never comes back down. Mathematicians add one extra, imaginary "point at infinity" for vertical lines to hit. It plays the role of zero: P + (−P) = 0, and P + 0 = P.

It's a small miracle that this rule behaves like real addition. It doesn't matter which order you add things in, or how you group them: (P + Q) + R always equals P + (Q + R). That last fact is not at all obvious from the picture, and proving it takes some real work. But it's what makes everything else possible.

Walking the curve

Now do what we did on the clock: start at a point G and keep adding it. G, then G + G = 2G, then 3G, and so on. Writing kG for "G added to itself k times" gives us our forward step. Using the same doubling shortcut as before, even an astronomically large k takes only a few hundred doublings and additions.

On the smooth curve above, though, the points drift in a fairly orderly way, and the numbers turn into ever-messier fractions. Cryptography needs something more scrambled, with whole numbers only. So we put the curve on a clock.

The curve on a clock

Keep the same equation, but do every calculation mod p for a prime p, exactly like the clocks in Chapter 1. Now x and y can only be whole numbers from 0 to p − 1, and the curve stops being a curve. It becomes a scatter of dots. Division still works, because on a prime-sized clock every number except 0 has a partner it multiplies with to make 1. The same add-two-points formulas keep working, dot to dot.

The curve on a clock

Every dot is a solution of y² = x³ + 2x + 3 (mod p). The gold dot is G. Slide k to watch kG hop between dots.

See how kG jumps around with no pattern a human could spot? That's our one-way function. Given G and k, finding kG is quick. Given G and the point kG, finding k is the elliptic curve discrete logarithm problem. On a well-chosen curve, the best known methods take roughly as many steps as the square root of the number of points. Notice the mirror symmetry, too: every dot at height y has a twin at p − y, the clock version of flipping across the axis.

How many dots are there? Always roughly p: a theorem by Helmut Hasse says the count is within 2√p of p + 1. So a curve on a gigantic clock has a gigantic number of points, and walking it backward becomes hopeless.

Meet P-256

P-256 is exactly this, scaled up. Its clock size is a prime with 78 digits, chosen with a special binary shape so that computers can do the wraparound quickly. Its number of points is another prime, also about 1077, so the best known attacks need around 2128 steps. Its a is −3, a common choice that makes the doubling formula faster. And its b is a seemingly random 78-digit number.

You don't have to take any of this on faith. The toy below holds P-256's real numbers and does the arithmetic in your browser.

Check P-256 yourself

These are the published parameters. Press the buttons to test them with real 256-bit arithmetic.

p, the clock size (2256 − 2224 + 2192 + 296 − 1)
a
−3
b (in hexadecimal)
G, the starting point: x and y

Press a button.

So where did that b come from? Not from a person typing digits. According to the standard, it was produced by feeding a 20-byte seed into a hash function, a kind of digital blender. Here is P-256's seed:

c49d3608 86e70493 6a6678e1 139d26b7 819f7e90

Why would anyone make a curve from a blended seed? Because a few special kinds of curves are known to be weak, and a dishonest designer might try to slip one in. Chapter 3 shows how a seed is supposed to prove nobody did that, and we'll blend P-256's seed into P-256's b right here in the browser. Then comes the real question of this case: where did the seed come from?

Words in this chapter

Tap any word with a dotted gold underline to see what it means. Here they all are in one place.

Three things to keep

Check yourself

If (2, 3) is on a curve, which other point must be on it?

(2, −3), its mirror image across the horizontal axis. On a clock with p hours, that mirror point is (2, p − 3).

What do you get when you add a point to its mirror image?

The point at infinity, which acts like zero. The line through them is vertical, so it never meets the curve a third time.

Why can't we use the smooth curve on real numbers for cryptography?

On the real numbers the multiples of G drift in a fairly orderly way you can follow, and the coordinates become fractions with ever more digits. On a prime clock everything stays a whole number below p, and the hops look scrambled.

Go deeper