Skip to content
Post-Quantum Plan

Back to the Lab

Key exchange playground: ML-KEM-768 next to X25519

Key exchange is the part of encryption that a future quantum computer breaks first, and the part attackers can already record today. Run both the classical X25519 and the new post-quantum ML-KEM-768 here, step by step, and see what changes: sizes, speed, and what happens when something goes wrong.

This is a teaching tool, not an audit. It runs real ML-KEM-768 and X25519 code in your browser, but it is not a secure channel and you should not use these keys for anything.

Generate key pairs

The receiver makes one key pair per algorithm and publishes the public keys. Secret keys never leave the receiver.

Encapsulate (sender)

The sender uses the receiver's public key to create a shared secret and the data needed to recover it. For X25519 that data is the sender's own temporary public key; for ML-KEM it is a ciphertext.

Decapsulate (receiver)

The receiver combines the secret key with what it received and gets the same shared secret.

Flip one bit in the ML-KEM ciphertext

Damage the ciphertext in transit by changing a single bit, then decapsulate again.

Hybrid: combine both secrets

Derive one session key from the X25519 secret followed by the ML-KEM secret, using HKDF with SHA-256.

Compare sizes and speed

Sizes are fixed by the algorithms. Timings are measured on your device when you press the button.

Sizes in bytes and median timings for X25519, ML-KEM-768 and RSA-3072
X25519ML-KEM-768RSA-3072 (reference)
Public key (bytes)321,184384
Ciphertext or key share (bytes)321,088384
Shared secret (bytes)323232
Key generation (ms)--not measured
Encapsulation (ms)--not measured
Decapsulation (ms)--not measured

Median of 15 samples (each averaging 8 calls) after one warm-up call, using JavaScript implementations (@noble libraries) with the performance.now clock, which browsers coarsen. Use the numbers to compare, not as benchmarks. RSA-3072 values are static references: the 384-byte modulus size, and RSA-OAEP ciphertexts are the same size; the shared secret is chosen by the sender (32 bytes typical).

What this shows

A key encapsulation mechanism (KEM) lets two parties agree on a secret without sending it. One side publishes a public key; the other uses it to produce a ciphertext and a shared secret; the first side recovers the same secret from the ciphertext with its private key. X25519 does this with elliptic-curve arithmetic, which Shor's algorithm breaks on a large quantum computer. ML-KEM (FIPS 203) does it with lattice problems, for which no efficient quantum attack is known.

The cost is size. An ML-KEM-768 public key is 1,184 bytes and its ciphertext 1,088 bytes, against 32 bytes for X25519. That is why migration touches protocol limits, MTUs and handshake sizes, not only algorithm names. Speed is rarely the problem: ML-KEM is fast, often faster than X25519.

Flipping a bit shows implicit rejection. ML-KEM does not report an error for a damaged ciphertext; it returns a pseudorandom secret derived from the ciphertext and a hidden value, so an attacker learns nothing from failed attempts. Both sides then simply hold different keys and the connection fails later.

The hybrid step is what browsers and servers deploy today (X25519MLKEM768 in TLS). Feeding both secrets into a key derivation function means the session key stays safe if either algorithm holds. If ML-KEM turned out to have a flaw, X25519 still protects against today's attackers; if a quantum computer breaks X25519, ML-KEM still protects the recorded traffic.