A short Go program tells you which key exchange a TLS server agrees on. I pointed it at three sites on December 3, 2026:
google.com X25519MLKEM768
cloudflare.com X25519MLKEM768
github.com X25519output
Two of them already negotiate a post-quantum hybrid. The third uses classic X25519 only. Traffic to it that someone records today could be decrypted later by a large enough quantum computer. The other two are protected against that even now.
This post takes a small Go service through the same change, one piece at a time, with nothing but the standard library. Each step lists what it costs.
Why this came up now
On December 2, 2026, the NSA, CISA and the Office of the National Cyber Director published a joint statement. It says American AI companies (the statement calls them “SI companies”) had disclosed discoveries that affect some cryptography in use today. In the same statement, the agencies assess that these advances “do not present an immediate and widespread threat”. They ask industry and government to upgrade infrastructure “expeditiously”. The next day, Cloudflare’s CEO posted that moving encrypted systems to post-quantum standards is urgent. A joint statement signed by Amazon, Anthropic, Apple, Cloudflare, Google, Microsoft, OpenAI and Oracle said the same.
Nobody has shown a public break of RSA-2048. The statement isn’t about tomorrow anyway. The concern is data that has to stay secret for years: an attacker can store TLS traffic now and decrypt it once the hardware exists. That’s why the key exchange goes first.
What changes and what stays
Public-key cryptography does two jobs in a typical service, and NIST standardised a replacement for each in August 2024:
| Job | Today | Post-quantum standard |
|---|---|---|
| Agree on a shared secret (TLS, encrypting for a recipient) | X25519, ECDH, RSA-OAEP | ML-KEM (FIPS 203, formerly Kyber) |
| Sign so others can verify | RSA, ECDSA, Ed25519 | ML-DSA (FIPS 204, formerly Dilithium) |
Symmetric cryptography stays. Grover’s algorithm roughly halves the effective strength of a key, so AES-256 still leaves a very large margin. SHA-256 and HMAC stay too.
ML-KEM and ML-DSA rest on the hardness of lattice problems. ML-KEM-768 works with module lattices of rank 3 over polynomials of degree 256, which makes 768 dimensions, plus small random errors. NIST puts it in security category 3. Shor’s algorithm breaks RSA and elliptic curves because both hide a periodic structure that a quantum computer can find. No comparable shortcut is known for these lattice problems.
Reading X25519MLKEM768
Most deployments don’t use ML-KEM alone yet. They run a hybrid: both key exchanges happen, and the two shared secrets are combined, so an attacker has to break both.
| Part | Meaning |
|---|---|
X25519 | the elliptic-curve Diffie-Hellman exchange TLS 1.3 uses today |
MLKEM | the post-quantum key encapsulation mechanism from FIPS 203 |
768 | the parameter set (ML-KEM-512, -768, -1024) |
On the wire it is TLS named group 0x11EC, decimal 4588.
The service
The test subject is a notes API in Go 1.27.3 on a 4-vCPU arm64 Linux VM. Public-key cryptography shows up in three spots:
- It serves HTTPS.
- It encrypts every note before it’s written to storage. A fresh AES-256-GCM key per note, wrapped with the server’s RSA-2048 key.
- It signs the session tokens it hands out with RSA-2048.
To find the same places in your own code, search for the imports:
grep -rn --include='*.go' --exclude='*_test.go' -E '"crypto/(rsa|ecdsa|ed25519|ecdh|tls)"' .
I migrated them in this order: data in transit, then data at rest, then signatures. The first two can be recorded today and broken later. A signature only has to hold at the moment someone verifies it. A forged signature in 2035 doesn’t help an attacker who recorded a session in 2026, so signatures can wait.
Step 1: TLS
The server logs which group each connection negotiated:
http.HandleFunc("/notes", func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s key exchange: %s", r.Method, r.URL.Path, r.TLS.CurveID)
fmt.Fprintln(w, `[{"id":1,"text":"db password rotates friday"}]`)
})
srv := &http.Server{Addr: ":8443", TLSConfig: &tls.Config{MinVersion: tls.VersionTLS13}}
log.Fatal(srv.ListenAndServeTLS("cert.pem", "key.pem"))
Three requests: a Go client, the same client with the hybrid switched off, and curl.
./bin/client https://localhost:8443/notes
GODEBUG=tlsmlkem=0 ./bin/client https://localhost:8443/notes
curl -s --cacert cert.pem https://localhost:8443/notes
GET /notes key exchange: X25519MLKEM768
GET /notes key exchange: X25519
GET /notes key exchange: X25519server
No code change was needed for the first line. crypto/tls has offered X25519MLKEM768 by default since Go 1.24, and SecP256r1MLKEM768 since Go 1.26. When both sides are Go, you get the hybrid. GODEBUG=tlsmlkem=0 turns it off, which is useful if a middlebox chokes on the larger handshake.
curl fell back because of its TLS library, not because of curl itself. That Ubuntu VM ships OpenSSL 3.0.13. OpenSSL added ML-KEM in 3.5, and from 3.5 the default key shares are X25519MLKEM768 and X25519. The same curl on a machine with a newer OpenSSL negotiates the hybrid.
In production the decision usually isn’t made by your Go code at all. If TLS terminates at nginx, a load balancer or a CDN, that component’s TLS library picks the group. Check the edge first.
What it costs on the wire
tshark on the loopback interface shows the ClientHello. tshark 4.2 doesn’t know the group’s name yet and prints Unknown (4588).
| X25519 only | X25519MLKEM768 | |
|---|---|---|
| Key share | 32 bytes | 1,216 bytes |
| ClientHello | 278 bytes | 1,504 bytes |
The 1,216 bytes are the 1,184-byte ML-KEM-768 encapsulation key plus the 32-byte X25519 share. At 1,504 bytes, the ClientHello no longer fits in a single packet on a standard 1,500-byte MTU path. Most stacks handle that fine. A few old middleboxes don’t, and that’s what the GODEBUG switch is for.
Step 2: data at rest
The original code generates a fresh AES key per note and wraps it with RSA-OAEP:
func SealRSA(pub *rsa.PublicKey, note []byte) (wrappedKey, ciphertext []byte, err error) {
key := make([]byte, 32)
rand.Read(key)
wrappedKey, err = rsa.EncryptOAEP(sha256.New(), rand.Reader, pub, key, nil)
if err != nil {
return nil, nil, err
}
block, _ := aes.NewCipher(key)
gcm, _ := cipher.NewGCM(block)
nonce := make([]byte, gcm.NonceSize())
rand.Read(nonce)
return wrappedKey, gcm.Seal(nonce, nonce, note, nil), nil
}
AES-GCM can stay. The RSA wrap is the part a quantum computer would undo. Go 1.27 has HPKE (RFC 9180) in crypto/hpke, including a hybrid KEM that combines ML-KEM-768 with X25519. That replaces the whole function:
var suite = struct {
kem hpke.KEM
kdf hpke.KDF
aead hpke.AEAD
}{hpke.MLKEM768X25519(), hpke.HKDFSHA256(), hpke.AES256GCM()}
func SealPQ(pub hpke.PublicKey, note []byte) ([]byte, error) {
return hpke.Seal(pub, suite.kdf, suite.aead, []byte("notes v2"), note)
}
func OpenPQ(priv hpke.PrivateKey, sealed []byte) ([]byte, error) {
return hpke.Open(priv, suite.kdf, suite.aead, []byte("notes v2"), sealed)
}
The info string ("notes v2") binds the ciphertext to this use. A note sealed for another purpose with the same key won’t open here.
Sealing the same 26-byte note both ways:
RSA-OAEP stored: 310 bytes opened: db password rotates friday
ML-KEM+X25519 stored: 1162 bytes opened: db password rotates fridayoutput
Most of the extra space is the 1,088-byte ML-KEM-768 ciphertext. For short records that’s a fixed overhead of about 850 bytes per item compared with RSA-2048. For large blobs it hardly matters.
Existing data doesn’t migrate itself. Every note sealed before the switch still depends on the RSA key, so a background job has to open each one with the old key and seal it again with the new one. Keep the RSA private key until that job reports zero RSA-wrapped records.
Step 3: signed session tokens
The tokens are a base64url payload, a dot and a base64url signature. Signing the same payload with RSA-2048 and ML-DSA-65:
payload := []byte(`{"sub":"huseyin","role":"admin","exp":1767225600}`)
rsaKey, _ := rsa.GenerateKey(rand.Reader, 2048)
h := sha256.Sum256(payload)
rsaSig, _ := rsa.SignPKCS1v15(rand.Reader, rsaKey, crypto.SHA256, h[:])
pqKey, _ := mldsa.GenerateKey(mldsa.MLDSA65())
pqSig, _ := pqKey.Sign(rand.Reader, payload, crypto.Hash(0))
err := mldsa.Verify(pqKey.PublicKey(), payload, pqSig, nil)
RSA-2048 signature 256 bytes token 409 chars
ML-DSA-65 signature 3309 bytes token 4479 chars verify: trueoutput
The token is now larger than a single cookie can hold. RFC 6265 asks browsers to support at least 4,096 bytes per cookie, and the current draft (6265bis) caps name plus value at 4,096. Firefox and Chrome both enforce that limit, so the browser drops a 4,479-character cookie.
There are two ways out:
- Session IDs. Put a short random ID in the cookie and keep the session data on the server. Nothing has to be signed for the browser, so the signature size stops mattering.
- Keep the signature server-side. If the token must be self-contained for other services, issue it to those services directly instead of round-tripping it through the browser.
Speed
The timings are fine. Medians of five runs with go test -bench . -benchtime 2s -count 5 on the same VM:
| Operation | RSA-2048 | Post-quantum |
|---|---|---|
| Seal a note (wrap key) | 24.0 µs | 75.2 µs (HPKE ML-KEM-768 + X25519) |
| Open a note (unwrap key) | 723 µs | 62.7 µs |
| Sign a token | 1,239 µs | 328 µs (ML-DSA-65) |
| Verify a token | 22.2 µs | 100.6 µs |
Opening and signing get much faster, because those are the RSA private-key operations. Sealing and verifying get slower, because RSA public-key operations with a small exponent are very cheap. None of these numbers would show up next to a database round trip.
Make the next change easier
Every one of these steps was harder than it had to be, because the stored data didn’t say which algorithm produced it. Store an algorithm identifier next to every key, ciphertext and signature ("rsa-oaep-sha256", "hpke-mlkem768x25519-sha256-aes256gcm", "mldsa65"). Then a migration is a matter of adding a case, not guessing which records are which.
What this post doesn’t cover
- Certificates. The TLS step protects the key exchange. The server certificate here is still RSA-2048, and post-quantum certificates on the public web are a separate migration.
- SLH-DSA (FIPS 205), the hash-based signature standard. It’s slower and larger than ML-DSA, and it’s for cases where you want an alternative that doesn’t rely on lattices.
- Key storage. Where the ML-KEM and ML-DSA private keys live (KMS, HSM) depends on what your provider supports.
Repeating it
# which group a host negotiates
go run ./cmd/kx google.com cloudflare.com github.com
# sizes
go run ./cmd/seal
go run ./cmd/token
# timings
go test ./vault -bench . -benchtime 2s -count 5
# the ClientHello on loopback (separate terminal)
sudo tshark -i lo -Y "tls.handshake.type==1" -O tls
I ran everything on Go 1.27.3.
Sources
- Joint Statement on Recent Advances in Cryptographic and Cybersecurity Capabilities (NSA, CISA, ONCD, December 2, 2026)
- FIPS 203: Module-Lattice-Based Key-Encapsulation Mechanism Standard
- FIPS 204: Module-Lattice-Based Digital Signature Standard
- Go crypto/tls package documentation
- Go crypto/hpke package documentation
- RFC 9180: Hybrid Public Key Encryption
- OpenSSL 3.5 release notes
- RFC 6265: HTTP State Management Mechanism