TExcelTAD
Home › Number Theory & Cryptography › Quantum Computers and Post-Quantum Cryptography

Quantum Computers and Post-Quantum Cryptography

A large quantum computer would break RSA, Diffie-Hellman and elliptic-curve cryptography, everything in parts 8 and 9 of this course. It would only weaken symmetric ciphers and hashes. This lesson explains why, what replaces the broken schemes, and why the migration started years before such a machine exists.

Shor's algorithm

Shor (1994) showed that a quantum computer can find the order of an element modulo NN in polynomial time, using the quantum Fourier transform to detect the period of x↦ax mod Nx \mapsto a^x \bmod N. As shown in The Order of an Element, an even order rr with ar/2≢−1a^{r/2} \not\equiv -1 factors NN through gcd⁡(ar/2−1,N)\gcd(a^{r/2} - 1, N). The same period finding solves discrete logarithms in Zp×\mathbb{Z}_p^\times and on elliptic curves.

Only the period finding needs a quantum computer; the rest is the classical number theory you already know:

python · try it yourself
from math import gcd

def classical_order(a, N):                     # the step a quantum computer would do fast
    r, x = 1, a % N
    while x != 1:
        x, r = x * a % N, r + 1
    return r

N = 10403                                      # 101 * 103
for a in (2, 3, 5, 7):
    if gcd(a, N) != 1:
        continue
    r = classical_order(a, N)
    y = pow(a, r // 2, N)
    if r % 2 == 0 and y != N - 1:
        print(f"a={a}: order {r}, factors {gcd(y - 1, N)} x {gcd(y + 1, N)}")
        break
    print(f"a={a}: order {r} unusable, try another base")
a=2: order 5100, factors 103 x 101

Estimates (Gidney, 2025) put factoring RSA-2048 at under a million noisy physical qubits running for about a week. Today's machines have around a thousand noisy qubits, so the threat is in the future, but data recorded today can be decrypted later ("harvest now, decrypt later"), which is why key exchange is being migrated first.

Grover's algorithm

Grover's search finds a preimage among NN possibilities in about N\sqrt{N} quantum steps. Against a kk-bit symmetric key that is 2k/22^{k/2} work, so AES-256 keeps about 128-bit security; against hash collisions the classical birthday bound remains the better attack. Grover parallelizes badly, so in practice AES-128 is still considered fine by many agencies, though AES-256 is the conservative choice.

The new standards

NIST finished its post-quantum competition in 2024:

Standard Based on Use Public key Ciphertext / signature
ML-KEM-768 (FIPS 203, "Kyber") Module-LWE key exchange 1184 B 1088 B
ML-DSA-65 (FIPS 204, "Dilithium") Module-LWE/SIS signatures 1952 B 3309 B
SLH-DSA-128s (FIPS 205, "SPHINCS+") hash functions only signatures 32 B 7856 B
FN-DSA (draft, "Falcon") NTRU lattices compact signatures 897 B about 666 B
for comparison: X25519 / Ed25519 elliptic curves 32 B 32 B / 64 B
for comparison: RSA-3072 factoring 384 B 384 B

Lattice schemes are fast but larger; hash-based signatures rest on the most conservative assumption (only that the hash is secure) but are big and slow to sign.

Hash-based signatures from scratch

The simplest post-quantum signature is Lamport's one-time signature (1979). It needs only a hash function: the private key is 256 pairs of random secrets, the public key is their hashes, and signing reveals one secret from each pair according to the bits of H(m)H(m).

python · try it yourself
import hashlib

H = lambda b: hashlib.sha256(b).digest()

def keygen(seed):                               # deterministic from a seed, for the demo only
    sk = [[H(seed + bytes([i, j]) + b"sk") for j in (0, 1)] for i in range(256)]
    pk = [[H(x) for x in pair] for pair in sk]
    return sk, pk

def bits_of(msg):
    d = int.from_bytes(H(msg), "big")
    return [(d >> (255 - i)) & 1 for i in range(256)]

def sign(msg, sk):
    return [sk[i][b] for i, b in enumerate(bits_of(msg))]

def verify(msg, sig, pk):
    return all(H(s) == pk[i][b] for i, (s, b) in enumerate(zip(sig, bits_of(msg))))

sk, pk = keygen(b"demo seed: use secrets.token_bytes(32) in real code")
sig = sign(b"release v2.0", sk)
print("signature size:", sum(len(s) for s in sig), "bytes")
print(verify(b"release v2.0", sig, pk), verify(b"release v2.1", sig, pk))
signature size: 8192 bytes
True False

Each key may sign only one message: two signatures reveal both secrets for many positions, letting a forger mix and match. SPHINCS+ (SLH-DSA) builds a stateless many-time scheme from trees of such one-time keys.

Migration in practice

  • Hybrid key exchange: combine X25519 and ML-KEM so the session is secure if either holds; X25519MLKEM768 is the default in Chrome, Firefox and Cloudflare, and OpenSSH uses mlkem768x25519-sha256.
  • Crypto-agility: design protocols and certificates so algorithms can be swapped; inventory where RSA and ECC are used.
  • Signatures migrate later than key exchange, because forging a signature requires a quantum computer at the time of the attack, not years afterwards.

In software

  • OpenSSL 3.5+, BoringSSL, Go 1.24 crypto/mlkem, liboqs and PQClean provide the new algorithms. Signal's PQXDH handshake and Apple's iMessage PQ3 use Kyber, the pre-standard form of ML-KEM, and Signal's 2025 SPQR ratchet uses ML-KEM-768.

Exercises

Exercise 1: What breaks?

Which of these are broken by a large quantum computer: RSA-4096, AES-256, SHA-256, X25519, ML-KEM-768, Ed25519?

Answer

RSA-4096, X25519 and Ed25519.

Solution

Shor's algorithm breaks factoring and discrete logarithms in any size, so all RSA and elliptic-curve schemes fall. AES-256 and SHA-256 lose at most half their bits to Grover, and no efficient quantum attack on ML-KEM is known.

Exercise 2: Harvest now, decrypt later

Why must key exchange migrate before signatures?

Answer

Recorded encrypted traffic can be decrypted once a quantum computer exists; a signature only needs to be unforgeable at verification time.

Solution

An attacker can store today's TLS handshakes and break their (EC)DH later, exposing the data. A forged signature, however, must be created and accepted while the signature is being checked, so signatures can switch closer to the arrival of quantum computers.

Exercise 3: Lamport key reuse (code)

Sign two different messages with the same Lamport key and count for how many of the 256 positions both secrets are now public.

Answer

About half of them: 135 for these two messages.

Solution
python · try it yourself
import hashlib
H = lambda b: hashlib.sha256(b).digest()
bits = lambda m: [(int.from_bytes(H(m), "big") >> (255 - i)) & 1 for i in range(256)]
b1, b2 = bits(b"message one"), bits(b"message two")
print(sum(x != y for x, y in zip(b1, b2)), "positions have both secrets revealed")
135 positions have both secrets revealed

At those positions a forger can choose either bit, so they can sign any message whose hash bits agree with the remaining positions, a search of about 21212^{121} (the 121 positions where only one secret is known) instead of 22562^{256}, and much less after more reuse.

Go further: Post-Quantum Migration: ML-KEM, ML-DSA and SLH-DSA covers the new standards, hybrids and how a migration is planned.

Test yourself

Shor's algorithm breaks RSA by…

  1. searching all keys
  2. finding the order of an element modulo NN efficiently
  3. computing hashes
  4. solving LWE

Against Grover's algorithm, AES-256 offers about…

  1. 0 bits of security
  2. 128 bits
  3. 256 bits
  4. 64 bits

Which post-quantum standard relies only on hash functions?

  1. ML-KEM
  2. ML-DSA
  3. SLH-DSA (SPHINCS+)
  4. X25519