kemspotter Check a site

Learn Lesson 1 of 5 about 4 minutes

Two strangers, one secret

How a browser and a server agree on a key while everyone can listen

  1. Lesson 1: Two strangers, one secret
  2. Lesson 2: A machine that hears the rhythm
  3. Lesson 3: Recorded today, read later
  4. Lesson 4: A new kind of hard problem
  5. Lesson 5: Two locks on one door
In one sentence

Your browser and a website can agree on a secret key in the open, because mixing numbers is easy and unmixing them is hard.

When your browser opens a page it has never spoken to that server before, and everything the two of them say crosses networks that other people run. A fraction of a second later they are both holding a secret key that nobody in between can know. The step that produces it is called a key exchange, and the web's version rests on an idea published in 1976.

The idea is to find an operation that is easy to do and hard to undo. Mixing paint is the usual picture. Anyone can stir two colours together. Nobody can look at the result and pull the two colours back apart.

The figure below does the mixing with numbers, which is what your browser does. Both sides start from the same public number. Each stirs in a private number of its own and sends the result across. Then each stirs its private number into what it received. They arrive at the same final value, and that value never travelled.

Try thisMove either slider. What crosses the network changes and the two final values stay equal. Then let the eavesdropper try.

Your browser

keeps … to itself

sends ……

ends with ……

The network, where anyone can read

the public start: ……

browser to server: …

server to browser: …

the secret itself: never sent

The server

keeps … to itself

sends ……

ends with ……

She has the public start and both numbers that crossed. To get the secret she needs one of the private numbers, and the only general way to find it is to try them one after another.

A key exchange in miniature. Each colour stands for the number beside it. Move either private number: what crosses the network changes, and the two final values stay equal to each other.

With numbers this small the eavesdropper is finished before you blink. A real exchange uses numbers about 77 digits long. The best method anyone knows for those takes around 2126 steps, and a machine doing a billion billion steps every second would need roughly two hundred times the age of the universe. That distance between doing and undoing is the whole of the security.

The version the web uses today is called X25519. It swaps the multiplying for points on an elliptic curve, and the picture stays the same. Forwards is one quick calculation. Backwards has no known shortcut.

What to remember

  • Every private connection starts by agreeing on a key in public.
  • It works because one direction is easy and the other is hard.
  • The web's version is called X25519.

Words used here: key exchange, key share, X25519, elliptic curve.