Post-quantum crypto explained: RSA, elliptic curves and ML-KEM you can play with

Why quantum computers threaten RSA and elliptic curve key exchange but not lattices, explained with five interactive toys: RSA, curve hops, X25519, scale and ML-KEM.

Sorin Curescu
Written by Product engineer and IT consultant
  • 9 min read
  • 2 views

In my last post I went through what changed in post-quantum crypto this week and the checks to run on your servers. This one is about the why. What is the math under TLS, SSH and WireGuard, why does a quantum computer break some of it, and what makes ML-KEM different?

You don't need any math background. Every idea below comes with a small toy you can poke at. The toys use tiny numbers so you can see what's going on. The full-size versions are the same ideas with numbers too big to draw.

Harvest now, decrypt later

When your browser connects to a site, both sides first agree on a secret key. That step is called key exchange. Everything after it, every page and every password, is encrypted with that key.

Someone who records that traffic today can't read it, but they can store it. If they break the key exchange in ten years, they decrypt everything they recorded. That's "harvest now, decrypt later". The first post covers why it puts key exchange ahead of signatures, so this post sticks to key exchange.

One-way doors

Every key exchange is built on a one-way door: something easy to do and very hard to undo, unless you hold a secret.

Think of mixing paint. Pour yellow into blue and you get green in a second. Give someone a can of green and ask them to separate it back into exactly that yellow and that blue, and they're stuck.

Three one-way doors carry most of the internet:

  • RSA: multiplying two primes is easy. Factoring the result back into those primes is hard.
  • Elliptic curves: hopping between points on a curve k times is easy. Working out k from where you landed is hard.
  • ML-KEM: adding a little noise to a point in a grid is easy. Finding the nearest grid point in 768 dimensions is hard.

Here's each one up close.

RSA: multiply easily, factor painfully

RSA picks two secret primes, p and q, and multiplies them to get n. The number n is public. So is a second number, e. Together they form the public key.

To encrypt a message m (a number smaller than n), you compute m to the power e, and keep only the remainder after dividing by n. Anyone can do that.

To decrypt, you need a private number d. Working out d needs a number called φ(n), which is (p − 1) × (q − 1), so it needs p and q. If you only have n, you have to factor it first.

Interactive · RSA

Build an RSA key and break it, step by step

  1. 01

    Pick two secret primes and multiply them into n

    Only you know p and q. Multiplying them is instant, and n becomes part of the public key.

    n = p × q · public

    3,233

    61 × 53 = 3,233

Try changing p and q, at the start or in the attack, and watch every value update.

Step through it with the defaults first: p = 61 and q = 53 give n = 3,233. Encrypt 65 and you get 2,790. Decrypt with d and you're back at 65. In the last step, factor n: with primes this small, testing one divisor after another finds 53 in 52 attempts. The best factoring methods are far smarter than that, but for a 617-digit n they're still out of reach for ordinary computers.

Today's TLS 1.3 uses RSA only for signatures. Older TLS versions also used it to send the session key, and sessions recorded back then are what harvest now, decrypt later is after.

Elliptic curves: hops you can't count backwards

An elliptic curve here is a set of points that satisfy one equation. The toy below uses y² = x³ + 2x + 3, with all the math done "mod 97", which means every result wraps around at 97, the way hours on a clock wrap around at 12.

There's a rule for "adding" two points on the curve to get a third one. Everyone agrees on a starting point, G. Adding G to itself over and over gives G, 2G, 3G and so on. I'll call each addition a hop. Your secret is a number k. Your public key is kG, where you land after k hops.

Interactive · Elliptic curve

Hop forward, then work backwards

y² = x³ + 2x + 3 mod 9799 pointsG = (0, 10) reaches 49 of them

Points on y² = x³ + 2x + 3 mod 97All 99 points of the toy curve. The path shows G, 2G and so on up to 7G, which ends at (10, 76).G7G
Check the equation for 7G

y² = 76² mod 97 = 53

x³ + 2x + 3 = 10³ + 2×10 + 3 mod 97 = 53

7

7G · public key

(10, 76)

Doubling route

k = 7 = 111 in binary

G → 2G → 3G → 6G → 7G

6 additions hop by hop vs 4 operations with doubling

Toy: possible k
49
X25519: secret k
255 bits
Forward, X25519
≈ 380 ops
Backward, classical
≈ 2¹²⁶ steps
Try Drag k and watch the path and the doubling route change. Then switch to Work backwards and find k from the public point alone.

In Hop forward, move the slider and look at the path. Each hop lands somewhere that looks unrelated to the one before. Keep going to 50 and you reach a special "point at infinity", which acts like zero: one more hop and you're back at G.

The doubling route under the slider shows why going forward is fast: doubling lets you jump to 2G, 4G, 8G and combine those, so a 255-bit k takes a few hundred steps. Going backwards has no shortcut like that. You try values of k until one fits. The smartest known methods need about the square root of the number of options, which for a full-size curve is still far too many.

Switch to Work backwards and the toy hides k and asks you to find it. With only 49 possible values you'll get there by trial and error. X25519, the elliptic curve half of today's default hybrid key exchanges, uses 255-bit secrets.

How Alice and Bob agree on a key

Now the part that makes elliptic curves useful. Two people who have never met can agree on a shared secret while someone listens to everything they say.

  1. Alice picks a secret a. Bob picks a secret b.
  2. Alice computes A = aG. Bob computes B = bG. These are their public keys.
  3. They send A and B to each other in the open.
  4. Alice adds Bob's B to itself a times. Bob adds Alice's A to itself b times.
  5. Both end up at the same point, abG, because a lots of b hops is the same as b lots of a hops.

Eve, who sees the channel, has G, A and B. To get the shared point she needs a or b, which means working backwards from A or B. That's the one-way door again.

Interactive · Key exchange

Agree on a key in the open

Alice

Bob

  1. 1Each side picks a secret

    12

    Open channel (Eve)

    Nothing. a and b stay on Alice’s and Bob’s devices.
    31
  2. 2Each side computes a public key

    Public key A = aG

    (74, 20)

    12 × G = (74, 20)

    Open channel (Eve)

    The curve and the starting point G = (0, 10). Both are public.

    Public key B = bG

    (85, 71)

    31 × G = (85, 71)

  3. 3They swap A and B in the open

    Receives B

    (85, 71)

    Open channel (Eve)

    A → Bob

    (74, 20)

    B → Alice

    (85, 71)

    Eve copies both packets.

    Receives A

    (74, 20)

  4. 4Each side combines with its own secret

    Shared point aB

    (32, 7)

    12 × (85, 71) = (32, 7)

    Open channel (Eve)

    Without a or b she can’t do either calculation.

    Shared point bA

    (32, 7)

    31 × (74, 20) = (32, 7)

  5. 5Both land on the same point

    Alice and Bob both hold (32, 7). Eve has only G, A and B.

    12 × 31 × G = 372G = 22G = (32, 7)

    The path returns to G every 50 hops, so 372 hops land where 22 hops do.

    • G, the starting point
    • A and B, the public keys
    • The shared point
    G, A, B and the shared point on the toy curveG is at (0, 10), A is (74, 20), B is (85, 71) and the shared point is (32, 7).GABshared
Try Drag either secret or press Random. Every value below the sliders updates, and Alice and Bob always end on the same point.

Each numbered row matches the list above. Whatever secrets you pick, Eve's column never holds more than G, A and B.

This is X25519 key exchange with small numbers. X25519 itself uses 32-byte keys. Two details matter in practice:

  • Run the shared point through a KDF. A key derivation function such as HKDF turns the raw shared value into clean keys for encryption. You never use the raw point directly.
  • Use fresh keys for each session. TLS and SSH generate new a and b values for every connection and throw them away afterwards. If a server's long-term signing key leaks later, past sessions stay safe. This is called forward secrecy. It doesn't help against harvest now, decrypt later, though: that attacker breaks the exchange itself.

Why the toys are easy to break and the full-size versions aren't

Everything you broke above, you broke by trying all the options. That works because the toys have so few. The full-size versions have so many that trying them all stops being a question of faster hardware.

Interactive · Scale

Toy sizes next to sizes in use

Sizes

number of points, in digits

Toy
3 digits100 points
In use
77 digitsabout 2²⁵⁵ points (X25519)

Log scale: each extra digit makes the number ten times bigger. X25519 has about 10⁷⁵ times as many points as the toy curve.

size of n, in digits

Toy
4 digitsn = 3,233 (61 × 53)
In use
617 digitsRSA-2048

Log scale. The RSA-2048 n is about 10⁶¹³ times the toy n. Breaking RSA means splitting n into its two primes.

dimensions

Toy
2 dimensionsLattice toy further down
In use
768 dimensionsML-KEM-768

Dimensions, not a log scale. The lattice toy further down uses 2 so you can see the grid. Finding the nearest grid point gets much harder with every dimension added.

What the keys look like

Toy · public key 12G

(74, 20)

In use · X25519 public key, 32 bytes · 44 characters

$ cat wg0.conf[Peer]
PublicKey = Q4BdwhmyReXf5CktGnF2BQp87CQmUegIwhICU7s+oB4=

Each tab is the same 32-byte key: the line WireGuard puts in its config, the PEM file OpenSSL prints, and the number itself. Generated with OpenSSL for this post. Only the public part is shown.

Attacker speed

Pick how many guesses one machine makes per second and how many machines the attacker runs.

Total guesses per second

1.0 × 10²¹

1.0 × 10²¹ ≈ 2⁷⁰ guesses per second

Time to break

Each time is the number of guesses divided by the total guesses per second above.

  • Toy curve: G repeats every 50 hops, so try 49 secretsunder a second
    Guesses
    49, fewer than the cards in a deck
    Time
    faster than a blink
  • X25519: best known classical attack, about 2¹²⁶ steps2.7 × 10⁹ years
    Guesses
    8.5 × 10³⁷, the atoms in 12 billion human bodies
    Time
    19% of the age of the universe
  • X25519: try every 255-bit secret1.8 × 10⁴⁸ years
    Guesses
    5.8 × 10⁷⁶, the atoms in 4.4 × 10²⁶ Earths
    Time
    1.3 × 10³⁸ times the age of the universe, a number with 39 digits

Each extra bit doubles the count, so 1,000 times more machines covers only about 10 more bits. 2²⁵⁵ is 2¹²⁹ times 2¹²⁶, so the last card is about 6.8 × 10³⁸ times the one above it.

Try Switch between X25519, RSA-2048 and ML-KEM-768 to see each public key in use. Then raise the guesses per second or the machines: trying every 255-bit secret still takes far longer than the age of the universe.

The calculator starts at a billion machines, each doing a trillion guesses per second. The best known attack on X25519 with ordinary, or "classical", computers takes about 2¹²⁶ steps, which still comes out at billions of years.

So why worry at all? Because a quantum computer goes after the structure of the problem instead of guessing.

What a quantum computer does differently

The quantum attack that matters here is Shor's algorithm. It finds hidden repeating patterns.

For RSA, pick any number and keep multiplying it by itself mod n. The results repeat after a while, and how long that cycle is depends on p and q. Shor's algorithm measures the length of the cycle, and from it the factors of n follow with some ordinary math.

For elliptic curves the cycle you saw in the toy (50 hops back to the start) is public, so it gives nothing away. Shor looks at a different pattern instead: all the combinations of some hops of G plus some hops of your public key. Those combinations repeat in a pattern that depends on k, and finding it hands over k.

A large enough quantum computer does both in a practical amount of time. Nobody has one that large today. But traffic recorded now will still be around when someone does.

Quantum computers aren't the only risk. On December 5, Anthropic and OpenAI said their unreleased models had found weaknesses in the math behind some of today's cryptography, though not in the post-quantum standards. There's a summary in the first post.

ML-KEM: noise on a lattice

ML-KEM is the post-quantum key exchange NIST standardized in 2024 as FIPS 203. KEM stands for key encapsulation mechanism: one side wraps up a fresh secret using the other side's public key, and only the private key can unwrap it.

It's built on lattices. A lattice is a grid of points made by taking a few direction arrows and adding them together in every combination. In ML-KEM the lattice is public.

Here's the idea, simplified:

  1. The receiver's private key is a short secret vector. The public key mixes it into the lattice with a little noise, so it can't be pulled back out.
  2. The sender uses that public key to wrap a secret. What gets sent is the secret plus more noise.
  3. The receiver's private key cancels almost everything, leaving the secret plus a little leftover noise. Rounding to the nearest grid point removes that noise.

An attacker without the private key faces the hard version: given a noisy point, find the grid point it came from, in 768 dimensions.

Interactive · Lattice

Noise on a lattice, rounded back

Rounding a noisy point back to the latticeLattice dots with the short arrows b1 and b2 drawn from the origin. The secret dot is at (158, 92) and the sent point is 14 units away at (148, 101). It rounds back to the secret. Dots away from the edges are buttons that move the secret.b₁b₂
  • secret
  • sent
  • rounded to
  • rounding cell
14 units

b₁ and b₂ are 59 and 58 units long and nearly perpendicular. Rounding always works for noise up to 29 units.

Decrypts: the sent point rounds back to the secret.

short arrows decrypt

100%

long arrows decrypt

41%

Share of 360 noise directions at this noise that round back to the secret. Early lattice schemes used short arrows as the private key; ML-KEM's private key is a short secret vector that cancels most of the scrambling, leaving only small noise to round off.

Cells next to each point: 3ᵈ − 1 in d dimensions

2 dimensions

8

10 dimensions

59,048

768 dimensions

≈ 2.7 × 10³⁶⁶

ML-KEM-768

dimensions · k × n

3 × 256 = 768

coordinates wrap at q

3,329

noise per coordinate

−2 to +2

The cell count is not the cost of the best attack, but it shows why guessing by eye stops working. No known algorithm, classical or quantum, finds the nearest lattice point efficiently in 768 dimensions.

Try Raise the noise until the short arrows fail, then switch to the long arrows at the same noise. Click a dot to move the secret. In Attack, hide a point and pick the dot the sent point came from.

The toy shows that last step: a point, some noise, and rounding back to the grid, with short arrows or with long, skewed ones that describe the same lattice. Push the noise up until decryption fails. That's why ML-KEM keeps its noise tiny: −2 to +2 per coordinate, while the numbers wrap around at 3,329. Then switch to Attack, hide a point and guess which dot the sent point came from. In two dimensions you can do it by eye. ML-KEM-768 works in 768 dimensions, where there's nothing to look at.

Lattice problems have no known repeating cycle for Shor's algorithm to find. The best known quantum attacks only shave a little off the classical ones, which is why lattices replaced curves in the post-quantum standards.

They're not untouchable, though. The lattice papers from this week found a faster quantum algorithm against the math behind ML-KEM, at a scale the paper itself calls "galactic". It's no practical threat, but it's a reason not to rely on one algorithm alone.

Hybrid key exchange: X25519 plus ML-KEM

What everyone ships today is hybrid key exchange. Each side runs X25519 and ML-KEM at the same time, then feeds both shared secrets into a KDF to get the final key.

To read the traffic, an attacker has to break both. X25519 has twenty years of scrutiny behind it but falls to a big quantum computer. ML-KEM resists quantum attacks but is younger. As long as either one holds, the key is safe.

The cost is size. An ML-KEM-768 public key is 1,184 bytes and its ciphertext (the wrapped secret) is 1,088 bytes, compared with 32 bytes for an X25519 key. The final shared secret is also 32 bytes.

In TLS the hybrid is called X25519MLKEM768. In SSH it's mlkem768x25519-sha256.

Where things stand today

Hybrid key exchange is already the default in current OpenSSH, OpenSSL, Go and Chrome. The versions and the NIST and EU deadlines are in the first post.

WireGuard is the exception. It has no built-in ML-KEM, and its post-quantum option is the PresharedKey field, a shared secret you distribute yourself.

Check your own setup

The quickest check is SSH. Connect with verbose output, run nothing, and look for the key exchange line:

ssh -v yourserver.example exit 2>&1 | grep 'kex: algorithm'

If it prints debug1: kex: algorithm: mlkem768x25519-sha256, that connection used the ML-KEM hybrid. sntrup761x25519-sha512 (with an @openssh.com suffix before 9.9) is an older post-quantum hybrid, the default in OpenSSH 9.0 to 9.9. A plain curve25519-sha256 means no post-quantum protection, usually because one side is out of date. The full checklist for SSH, TLS, VPNs and certificates is in the first-steps post.

The short version

Every key exchange is a one-way door. RSA and elliptic curves hide a repeating pattern, and a large quantum computer can find it. Lattices have no known pattern like that, which is why ML-KEM is taking over, paired with X25519 until it has earned the same trust.

For most of us the fix is already shipped. The job is to make sure every server, client and VPN is on a version that uses it.

If you'd like a hand checking that across your own infrastructure, that's part of the consulting work I do.

Questions people ask

Why can a quantum computer break RSA?
RSA is safe because multiplying two primes is easy and splitting the result back into them is not. Shor's algorithm, on a large enough quantum computer, finds the hidden repeating pattern you get by multiplying a number by itself modulo n, and the factors of n follow from the length of that pattern.
Can quantum computers break elliptic curve cryptography like X25519?
Yes. A version of Shor's algorithm recovers the secret number k from a public key kG by finding a repeating pattern in combinations of hops from G and from the public key. Elliptic curves fall to a large quantum computer just like RSA.
What is ML-KEM?
ML-KEM is the post-quantum key exchange NIST standardised in 2024 as FIPS 203, based on the Kyber design. It hides a shared secret behind small noise on a lattice. The private key removes most of the scrambling so only small noise is left to round off. Without it, recovering the secret means solving a lattice problem that no known classical or quantum algorithm solves efficiently at these sizes.
Why is lattice cryptography considered quantum-safe?
Shor's algorithm works by finding a hidden repeating pattern, and RSA and elliptic curves have one. The noisy lattice problems behind ML-KEM have no known pattern like that, and the best known attacks, classical or quantum, stay out of reach at ML-KEM's sizes.
What is X25519MLKEM768?
It is the hybrid key exchange used in TLS today. Each side runs X25519 and ML-KEM-768 and combines both shared secrets into the final key, so an attacker has to break both. In SSH the same idea is called mlkem768x25519-sha256.
How big is an ML-KEM-768 public key?
1,184 bytes, with a 1,088-byte ciphertext, compared with 32 bytes for an X25519 public key. The final shared secret is 32 bytes either way.