✖

Elliptic curves in cryptography: adding points and encryption made simple

An elliptic curve is a curve given by the equation y2 = x3 + ax + b. Cryptography is interested in it because its points can be added: from two points of the curve a simple construction produces a third. If you add a point to itself a huge number of times, say a number with 70 digits, you can work out the result easily, but nobody can find out that number from the result. Most encrypted connections on the internet rest on this difference today, from your bank’s website to WhatsApp, and so do the signatures in Bitcoin.

What an elliptic curve looks like

It has nothing to do with an ellipse. It inherited the name from elliptic integrals, which are used to calculate the arc length of an ellipse and from which these curves once emerged. Take, for example, the curve

y2=x3−x+1.

For each x we work out the right-hand side and take the square root, and y can be positive or negative. Where the right-hand side comes out negative, the curve has no points. The curve is therefore symmetric about the x-axis: with every point (x, y) on it, the point (x, −y) lies on it too. The point P(0, 1) lies on it, because 12 = 0 − 0 + 1. So does the point Q(1, −1), as (−1)2 = 1 − 1 + 1.

The curve y² = x³ − x + 1, bent into an arch on the left, with its branches spreading upwards and downwards on the right. A blue line passes through the blue points P and Q and crosses the curve a third time at an orange point at the bottom right. A dashed vertical segment leads from the orange point to the red point P + Q above it The curve y² = x³ − x + 1, bent into an arch on the left, with its branches spreading upwards and downwards on the right. A blue line passes through the blue points P and Q and crosses the curve a third time at an orange point at the bottom right. A dashed vertical segment leads from the orange point to the red point P + Q above it

Adding points

We add the points P and Q like this:

  1. Draw a line through the points P and Q.
  2. The line crosses the curve at one more point, a third one.
  3. Reflect that point in the x-axis. The result is the point P + Q.

The exception is a vertical line, which has no third point. For it we introduce a special “point at infinity”, to which we will return below.

Let us work it out. The line through the points (0, 1) and (1, −1) has the equation y = 1 − 2x. We substitute it into the equation of the curve:

(1−2x)2=x3−x+1

Expand the left-hand side:

1−4x+4x2=x3−x+1

Move everything to one side:

x3−4x2+3x=0

Factor out x, and what remains in the brackets is a quadratic equation with roots 1 and 3:

x⋅(x2−4x+3)=x⋅(x−1)⋅(x−3)=0

An equation of the third degree has at most three roots, so the line crosses the curve at most three times. We already know the roots 0 and 1: they are the points P and Q. The third intersection has x = 3 and y = 1 − 2 · 3 = −5. We reflect it in the x-axis and we have the result:

P+Q=(3,5)

Check: 52 = 25 and 33 − 3 + 1 = 25. It works, so the point lies on the curve.

Why such a complicated way, and not, say, simply add the coordinates? Because the point (0 + 1, 1 − 1) = (1, 0) does not lie on the curve, so “adding coordinates” would take us off the curve. The construction with the line always ends up on the curve again and behaves like ordinary addition: the order and the brackets do not matter. If you want to add a point to itself, P + P, you take the tangent at the point P instead of the line.

If you add a point G to itself many times, you get its multiple: 2G = G + G, 3G = G + G + G and so on. All of cryptography on curves rests on this.

A curve on a clock face

A computer does not calculate with a curve using real numbers, but with remainders after division, just as with the RSA cipher. Take a smaller curve y2 = x3 + 2x + 2 and treat everything as a remainder after division by 17. The coordinates are then only whole numbers from 0 to 16, and the curve falls apart into a handful of points. There are 18 of them, and a special point at infinity is added to them. It plays the role of zero in addition: it comes out as the sum of a point and its mirror image, for example (5, 1) + (5, 16), because 16 on the clock face is the same as −1.

Addition follows the same procedure as in the plane, only everything is taken as a remainder after division by 17, and instead of dividing, we look for the number that gives remainder 1 when multiplied. We start with the point G(5, 1) and keep adding it to itself:

G=(5,1),2G=(6,3),3G=(10,6),4G=(3,1),5G=(9,16), …

A 17 by 17 grid with eighteen points of the curve y² = x³ + 2x + 2 calculated with remainders after division by 17. The red point G at the bottom left is numbered 1, and the other blue points are numbered 2 to 18 according to which multiple of G they are. The numbers jump around the grid without rhyme or reason: 2 is a little above G, 3 is on the right in the middle, 4 at the bottom left, 5 at the top A 17 by 17 grid with eighteen points of the curve y² = x³ + 2x + 2 calculated with remainders after division by 17. The red point G at the bottom left is numbered 1, and the other blue points are numbered 2 to 18 according to which multiple of G they are. The numbers jump around the grid without rhyme or reason: 2 is a little above G, 3 is on the right in the middle, 4 at the bottom left, 5 at the top

The points jump around the grid without rhyme or reason. The eighteenth multiple is 18G = (5, 16), the nineteenth is the point at infinity, and the twentieth is G again, so the cycle repeats. The picture shows why the opposite direction is hard: if someone shows you the point (13, 10) and asks which multiple of G it is, you have no choice but to try. Here it is 11G, but you find that out essentially only by going through the multiples one after another.

Real curves calculate with remainders after division by a number with about 77 digits, which in binary has 256 digits, that is, 256 bits. They have roughly as many points. Calculating a multiple kG is fast even for a huge k, but nobody can find k from the result. This is called the elliptic curve discrete logarithm problem. A multiple is not calculated by adding one at a time, but by doubling: from G we make 2G, from that 4G, 8G and so on. The number k is written in binary, and according to its digits G is occasionally added between the doublings. For a k with 77 digits, about 256 doublings and at most as many additions are therefore enough. Nobody knows a trick like that for the opposite direction.

Key exchange on a curve

The same game as in the Diffie–Hellman key exchange can be played on a curve. Adam and Bára agree publicly on a curve and a point G, here on the curve modulo 17 with the point (5, 1).

  1. Adam secretly chooses a number a = 3 and sends Bára the point 3G = (10, 6).
  2. Bára secretly chooses b = 10 and sends Adam the point 10G = (7, 11).
  3. Adam takes Bára’s point and multiplies it by his three: 3 · (10G) = 30G.
  4. Bára takes Adam’s point and multiplies it by her ten: 10 · (3G) = 30G.

Both have 30G. Because the multiples repeat after nineteen steps, this is the same as 11G = (13, 10), and that is their shared secret. The coordinates of this point then serve them as the key for an ordinary cipher. Eva has seen G, 3G and 10G. She can add them, but 3G + 10G = 13G, not 30G. Points can be added, but not multiplied by one another, and Eva can get to 30G only by finding a secret number from one of the points. We showed what that means in the picture: try and try again.

Why a shorter key is enough

With RSA, numbers of 2048 or 3072 bits are used today. On an elliptic curve 256 bits are enough, and the security is roughly the same as for RSA with 3072 bits. Why the difference?

Factorising numbers has clever shortcuts that are much faster than trying divisors; they are described in the article on prime factorisation. That is why RSA keys have to be so long. On elliptic curves nobody has found any such shortcut. The best known attack needs roughly the square root of the number of points. That is much less than blind trying, but for a curve with 2256 points it is still 2128 steps, a number with 39 digits. If each of a billion computers tried a billion steps a second, it would take roughly eight hundred times longer than the universe has existed. Shorter keys mean faster calculations and smaller messages, and that is why curves have almost everywhere pushed RSA out of key exchange.

Where you come across elliptic curves

They were proposed independently by Neal Koblitz and Victor Miller in 1985. Today they are almost everywhere:

  • X25519 is a key exchange on the curve Curve25519, which Daniel J. Bernstein proposed in 2005. Most HTTPS connections agree keys with it, as do the Signal and WhatsApp apps and encrypted SSH connections.
  • P-256 is a curve from the US NIST standard. You will find it in website certificates and in passkeys, which are increasingly used to log in instead of a password.
  • secp256k1 is used by Bitcoin. A wallet’s private key is a secret number k, and the address is derived from the point kG.

Curves also have a darker chapter. The random number generator Dual_EC_DRBG, built on elliptic curves, was approved by NIST as a standard in 2006. In 2013 documents from Edward Snowden showed that the American NSA had most likely built a backdoor into it: anyone who knew a secret relationship between two points in the standard could predict the numbers the generator would produce. NIST withdrew the standard in 2014. Since then cryptographers have preferred curves where you can see where every number in the definition came from. Curve25519 is one of them.

And a quantum computer?

Elliptic curves have the same weakness as RSA. A quantum computer would find the number k with Shor’s algorithm, and estimates even say that it will need fewer qubits for curves than for RSA. That is why X25519 is now accompanied by the post-quantum cipher ML-KEM: the connection is safe for as long as at least one of them holds out.

Elliptic curves are not just a tool for cryptographers, though. They play the main role in the proof of Fermat’s Last Theorem, and one of the most famous open questions in mathematics, the Birch and Swinnerton-Dyer conjecture, asks how many points with rational coordinates, that is, with fractions, lie on them, and from how many starting points all of them can be worked out.

See also