Your browser has been doing post-quantum cryptography for two years and you probably never noticed. The padlock in your address bar now negotiates a hybrid key exchange — classical X25519 plus the lattice-based ML-KEM-768 — on most of the web. Cloudflare's Radar page puts the share of HTTPS traffic protected by post-quantum key agreement at 72.7% in the week to November 30, 2026. The standards behind it have been final since August 2024. The libraries ship it. And the deadlines are no longer theoretical: on December 2, eight tech giants issued a joint statement on the post-quantum transition, the NSA urged an immediate move, and Cloudflare's CEO warned that RSA and elliptic-curve crypto are on borrowed time. The NSA's first hard gate — new national-security-system acquisitions must be quantum-resistant — lands on January 1, 2027, four weeks from today.

This tutorial closes the gap between reading those headlines and actually touching the algorithms. You will run ML-KEM-768 key encapsulation and ML-DSA-65 digital signatures in Python, build the exact hybrid key exchange your browser negotiates, encrypt a message with the resulting key, and audit your own machine to see where it stands. Every command below was executed in a sandbox on December 3, 2026, and every output is quoted verbatim. No account, no API key, no GPU, no cost.

What you'll need#

  • Python 3.10 or newer. The tutorial was verified on Python 3.12. Any recent Linux, macOS, or Windows machine works.
  • pip and about 10 MB of disk. One package: cryptography==51.0.0, pinned exactly, because the post-quantum API changed between releases and the code below is written against 51.0.0.
  • About 30 minutes. Most of that is reading; the code runs in under a second.
  • No accounts, no API keys, no GPU, no cost. Everything here runs on your own machine. Nothing phones home.

The 60-second background#

Post-quantum cryptography replaces the two public-key jobs that a sufficiently powerful quantum computer would break: agreeing on a secret key, and signing things. RSA and elliptic-curve cryptography both fall to Shor's algorithm; symmetric crypto like AES does not, provided the keys are long enough. So the migration is about two new primitives, both standardized by NIST in August 2024 after an eight-year competition:

  • ML-KEM (FIPS 203) — a key encapsulation mechanism, derived from CRYSTALS-Kyber. It does not encrypt your message. It lets two parties agree on a shared secret over a public channel, which then feeds a symmetric cipher. This is what replaces RSA and ECDH key exchange.
  • ML-DSA (FIPS 204) — a digital signature algorithm, derived from CRYSTALS-Dilithium. It proves who wrote a message and that it was not altered. This is what replaces RSA and ECDSA signatures. A third signature standard, SLH-DSA (FIPS 205, from SPHINCS+), exists as a hash-based backup in case ML-DSA ever fails.

The practical shock is size. Post-quantum keys and signatures are far bigger than the classical ones they replace — and that size is the thing that breaks naive migrations, from TLS handshakes to database columns sized for 256-byte RSA signatures. Here are the real numbers, measured in the sandbox for this tutorial:

AlgorithmPublic keyPrivate key*Ciphertext / signature
ML-KEM-7681,184 bytes64 bytes1,088 bytes (ciphertext)
ML-KEM-10241,568 bytes64 bytes1,568 bytes (ciphertext)
ML-DSA-441,312 bytes32 bytes2,420 bytes (signature)
ML-DSA-651,952 bytes32 bytes3,309 bytes (signature)
ML-DSA-872,592 bytes32 bytes4,627 bytes (signature)
RSA-2048 (for comparison)294 bytes—256 bytes (signature)

*Private keys are shown in their seed form, as this library stores them. The 44 / 65 / 87 in ML-DSA and 768 / 1024 in ML-KEM are the parameter sets — roughly, security levels 2, 3, and 5. ML-KEM-768 is the level the web standardized on, which is why it appears in the TLS group name below.

One more concept before the code: a KEM works differently from the encryption you are used to. Nobody encrypts a message with ML-KEM directly. The sender encapsulates a random secret against the receiver's public key, producing a ciphertext and the secret. The receiver decapsulates the ciphertext with the private key and recovers the same secret. The secret is never sent; only the ciphertext crosses the wire.

Diagram of a key encapsulation mechanism: sender encapsulates, ciphertext of 1,088 bytes is transmitted, receiver decapsulates, both end with the same 32-byte shared secret
How a KEM works: encapsulate, transmit the ciphertext, decapsulate. Both sides end up with the same 32-byte shared secret, and the secret itself never crosses the wire. Diagram: AI Frontier Post.

1. Install and verify#

Create a virtual environment and install the pinned library. Pinning matters here: the post-quantum API in cryptography has changed names and return orders between releases, and the code in this tutorial is written against 51.0.0, the version verified below.

python3 -m venv pqc-venv
source pqc-venv/bin/activate
pip install "cryptography==51.0.0"

Confirm the install and that the post-quantum modules are present:

python -c "import cryptography; print(cryptography.__version__)"
python -c "from cryptography.hazmat.primitives.asymmetric import mlkem, mldsa; print('ML-KEM + ML-DSA available')"
51.0.0
ML-KEM + ML-DSA available

If the second command fails with an ImportError, you have an older cryptography installed somewhere on your path — check pip show cryptography and make sure the virtual environment is activated. Two honest limits of this release, verified in the sandbox: it ships ML-KEM-768 and ML-KEM-1024 only (no ML-KEM-512), and ML-DSA-44/65/87 only (no SLH-DSA yet). That covers everything this tutorial needs.

2. ML-KEM-768, end to end#

Save this as pqc_hands_on.py. It is the whole tutorial in one file — the later steps extend it, so keep it open.

from cryptography.hazmat.primitives.asymmetric import mlkem, mldsa

kem_priv = mlkem.MLKEM768PrivateKey.generate()
kem_pub = kem_priv.public_key()
shared_secret, ciphertext = kem_pub.encapsulate()
recovered = kem_priv.decapsulate(ciphertext)
print(f"public key:    {len(kem_pub.public_bytes_raw()):,} bytes")
print(f"ciphertext:    {len(ciphertext):,} bytes")
print(f"shared secret: {len(shared_secret)} bytes")
print(f"secrets match: {shared_secret == recovered}")
python pqc_hands_on.py
public key:    1,184 bytes
ciphertext:    1,088 bytes
shared secret: 32 bytes
secrets match: True

Three things to notice. First, the whole exchange is four calls: generate, encapsulate, decapsulate, compare. Second, watch the return order of encapsulate(): in version 51 it returns (shared_secret, ciphertext) — secret first. Older versions and most documentation return them the other way round, and swapping them produces a confusing ValueError: Invalid ML-KEM-768 ciphertext when you hand the 32-byte secret to decapsulate() as if it were the 1,088-byte ciphertext. That error cost me a debugging round while writing this tutorial; if you hit it, you have the tuple backwards. Third, the speed: key generation plus encapsulation measured around 0.2 milliseconds per round trip on a 2-core sandbox VM. The lattice math is fast — the cost of post-quantum crypto is size, not time.

3. ML-DSA-65 signatures — and a tamper test#

Add the signing step to the same file. Sign a message, verify it, then verify a tampered copy and watch it fail:

dsa_priv = mldsa.MLDSA65PrivateKey.generate()
dsa_pub = dsa_priv.public_key()
message = b"Deploy the post-quantum build on Friday."
signature = dsa_priv.sign(message)
print(f"public key: {len(dsa_pub.public_bytes_raw()):,} bytes")
print(f"signature:  {len(signature):,} bytes")
dsa_pub.verify(signature, message)
print("signature verifies: True")
try:
    dsa_pub.verify(signature, b"Deploy the post-quantum build on Monday.")
    print("tampered message verifies: True  <-- BAD")
except Exception:
    print("tampered message verifies: False (rejected, as it should be)")
public key: 1,952 bytes
signature:  3,309 bytes
signature verifies: True
tampered message verifies: False (rejected, as it should be)

The signature is 3,309 bytes for a 39-byte message — roughly thirteen times the size of an RSA-2048 signature. That ratio is the whole migration story for signatures: anywhere a signature is stored, transmitted, or size-limited — certificates, JWTs, firmware images, database columns, DNS records — the new signatures need roughly an order of magnitude more room. ML-DSA-44 (2,420-byte signatures) is the smaller option when size hurts; ML-DSA-87 (4,627 bytes) is the top security level the NSA's CNSA 2.0 suite mandates for national security systems. ML-DSA-65, used here, is the middle parameter set and the sensible default.

4. Build the hybrid KEM your browser uses#

Nothing in production runs pure ML-KEM yet. The deployed design is a hybrid: run the classical exchange and the post-quantum encapsulation side by side, then combine both shared secrets into one session key. The combination is the point — the session stays secret unless both algorithms break. That is what TLS 1.3 negotiates as the group X25519MLKEM768 (codepoint 0x11EC, standardized as RFC 10024 in August 2026): an X25519 share of 32 bytes plus an ML-KEM-768 share of 1,184 bytes, 1,216 bytes in the client's key share where X25519 alone used 32.

Extend the script with the hybrid step, then use the resulting key to actually encrypt something with AES-GCM — the part ML-KEM itself never does:

from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.kdf.hkdf import HKDF
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

ecdh_priv = X25519PrivateKey.generate()
ecdh_pub = X25519PrivateKey.generate().public_key()  # the peer's public key
ecdh_shared = ecdh_priv.exchange(ecdh_pub)
hybrid_key = HKDF(
    algorithm=hashes.SHA256(),
    length=32,
    salt=None,
    info=b"hybrid-x25519-mlkem768",
).derive(ecdh_shared + shared_secret)
print(f"hybrid session key: {len(hybrid_key)} bytes")

aes = AESGCM(hybrid_key)
nonce = b"\x00" * 12  # demo only — never reuse a nonce with the same key
plaintext = b"The launch codes are: rotate your keys by 2030."
sealed = aes.encrypt(nonce, plaintext, None)
opened = aes.decrypt(nonce, sealed, None)
print(f"ciphertext: {len(sealed)} bytes | decrypted: {opened.decode()}")
hybrid session key: 32 bytes
ciphertext: 63 bytes | decrypted: The launch codes are: rotate your keys by 2030.

The HKDF step is doing real work: it takes two shared secrets of different shapes — 32 bytes from X25519, 32 bytes from ML-KEM — and derives one uniform 32-byte key, bound to the context string hybrid-x25519-mlkem768. Concatenating the two secrets directly and using the result as an AES key would also work, but HKDF is the standard way to do it and it is what the TLS key schedule does in spirit. The full script, all three steps together, is 40 lines. You have now done, in miniature, exactly what happens inside every TLS 1.3 handshake your browser performs today.

Diagram of hybrid TLS key exchange: the client and server exchange an X25519 share of 32 bytes and an ML-KEM-768 share of 1,184 bytes, combining into one session key
Hybrid key exchange in TLS 1.3: the X25519 share and the ML-KEM-768 share travel together and combine into one session key. Either half alone must hold for the session to stay secret. Diagram: AI Frontier Post.

5. Audit your own stack#

The code above proves the algorithms work. The next question is where your systems stand, and the answer is usually a version number. Start with OpenSSL, the library behind most of the internet's TLS:

openssl version
python3 -c "import ssl; print('Python ssl links:', ssl.OPENSSL_VERSION)"
OpenSSL 3.0.13 30 Jan 2024
Python ssl links: OpenSSL 3.0.13 30 Jan 2024

That output is from the sandbox this tutorial was verified in — and it is the point. OpenSSL 3.0 has no post-quantum support at all. Ask it for the hybrid group and it fails outright:

echo | openssl s_client -groups X25519MLKEM768 -connect cloudflare.com:443 2>&1 | head -2
Call to SSL_CONF_cmd(-groups, X25519MLKEM768) failed
40279CBCFA7D0000:error:0A080106:SSL routines:gid_cb:passed invalid argument:../ssl/t1_lib.c:750:group 'X25519MLKEM768' cannot be set

On a machine with OpenSSL 3.5 or later, the same command negotiates the hybrid group and the handshake succeeds — 3.5, released April 8, 2025 and supported as a long-term release until April 8, 2030, ships native ML-KEM, ML-DSA, and SLH-DSA and offers X25519MLKEM768 by default. The difference between the two outputs above is, for most organizations, the entire TLS migration: a toolchain upgrade, not new code. Check your own numbers against this table:

StackHybrid X25519MLKEM768 on by default since
Chrome / EdgeVersion 131 (November 2024)
Firefox132 on desktop, 145 on Android; HTTP/3 from 135
SafariVersion 26 (iOS 26, macOS Tahoe 26)
OpenSSL3.5.0 (April 8, 2025)
Go1.24 (February 2025)
Node.js24.5.0 and 22.20.0
CloudflareHybrid key agreement on all TLS 1.3 zones; 72.7% of HTTPS traffic PQ-protected (week to Nov 30, 2026)

The split in Cloudflare's numbers is the story of the migration so far: clients moved first, servers lag. Browsers have negotiated the hybrid group by default for two years, but only about 29% of origin servers Cloudflare connects to support it. Your traffic is probably already quantum-resistant on the way to you. The server you run may not be.

6. The migration checklist#

If you own anything that encrypts or signs, the work is a sequence, not a single upgrade. The order matters more than the speed:

  1. Inventory your cryptography. List every place your systems use public-key crypto: TLS endpoints, SSH keys, code signing, document signing, VPNs, encrypted backups, JWTs, certificate authorities. Most organizations discover crypto in places they forgot — that is the point of the exercise.
  2. Protect long-lived data first. The threat is harvest-now-decrypt-later: an adversary records your encrypted traffic today and decrypts it when a capable quantum computer exists. Data that must stay secret for ten years — health records, trade secrets, state secrets — is already at risk from traffic captured now. Short-lived session data can wait.
  3. Upgrade the toolchain before rewriting code. OpenSSL 3.5, Go 1.24, Node 24.5, current browsers: the hybrid group arrives with the upgrade. This is the step that closes the TLS gap in section 5.
  4. Go hybrid, not pure. Combine classical and post-quantum, as in step 4. A hybrid fails only if both halves break; a pure post-quantum deployment bets everything on algorithms standardized two years ago.
  5. Leave certificates for last. Post-quantum certificates — ML-DSA in X.509 — are the slowest-moving piece, and the reason the web did key exchange first. The standards and the CA ecosystem are still catching up; plan for it, do not block on it.

The dates to plan against, all from NSA and NIST publications:

DateWhat happens
January 1, 2027New national-security-system acquisitions must be CNSA 2.0 compliant (CNSSP 15)
December 31, 2030NIST deprecates RSA and elliptic-curve crypto; equipment that cannot support CNSA 2.0 must be phased out; software/firmware signing and networking equipment exclusively post-quantum
December 31, 2031CNSA 2.0 algorithms mandated across national security systems
2033Browsers, servers, cloud services, and operating systems exclusively post-quantum
2035Quantum-vulnerable public-key algorithms disallowed under NIST guidance; NSA expects the overall transition complete

Those are government dates, and they bind national security systems, not your company. But they are the most specific published timeline in existence, and the December 2 joint statement from eight tech giants — plus the NSA's public urging the same day — is the industry aligning behind it. Treat the dates as the planning horizon, not a deadline to start.

Which approach should you use?#

ApproachWhat it isPick it when
Hybrid now (X25519 + ML-KEM-768)Classical and post-quantum together, as in step 4Almost always. It is what browsers, OpenSSL 3.5, and Go already do by default — usually just a version upgrade
Pure ML-KEM / ML-DSAPost-quantum only, no classical halfYou are bound by CNSA 2.0, which names pure ML-KEM-1024 and ML-DSA-87 as the end state for national security systems
Wait and watchStay on classical crypto, monitor the standardsOnly for data with a short secrecy lifetime and no regulatory exposure — and even then, inventory first, because the harvest-now risk applies to data you already sent

The common mistake is treating this as a research project. It is not. The standards are final, the libraries ship the algorithms, the browsers already negotiate them, and the code in this tutorial is 40 lines. The work is inventory and upgrades, not invention.

Reading the results honestly#

  • Nothing here is a production system. The script is a teaching demo: the AES nonce is fixed at zero, keys live in memory, and there is no key storage, rotation, or authentication. Do not ship it.
  • The timing numbers are sandbox measurements, not benchmarks. The ~0.2 ms ML-KEM round trip was measured on a 2-core sandbox VM; treat it as evidence that the algorithms are fast, not as a performance claim.
  • The library is still catching up to the standards. Version 51.0.0 of cryptography has no ML-KEM-512 and no SLH-DSA. If you need either, OpenSSL 3.5's command line or liboqs covers them today.
  • No quantum computer can break RSA today. The public record shows zero RSA-2048 keys broken by a quantum computer and zero breaches attributed to a quantum attack. The migration is about data captured now and decrypted later — which is exactly why it starts before the threat arrives.
  • Hybrid is a hedge, not a guarantee. ML-KEM and ML-DSA are two years old as standards. They have survived intense cryptanalysis, but they are young compared with RSA's five decades. The hybrid design exists precisely because of that youth.

The takeaway#

You have run the two algorithms the next decade of cryptography is built on, combined them the way your browser does, and measured the one number that makes the migration real: a 1,184-byte public key and a 3,309-byte signature where RSA used 294 and 256. The standards are final, the code is 40 lines, and the first government deadline is four weeks away. The remaining work is not cryptographic — it is finding every place your systems still use RSA and elliptic curves, upgrading the libraries, and letting the hybrid defaults do their job. Start with the audit in step 5. Your browser already did.