ML-KEM Key Encapsulation Online | Post-Quantum Cryptography (FIPS 203)

Key Exchange
100% client-side. Processed locally in your browser using the Web Crypto API. Nothing is sent to any server.
⚠️ Critical Security: ML-KEM is a post-quantum key encapsulation mechanism — it establishes shared secrets that survive quantum computers. For production use, combine with classical ECDH (hybrid mode) for defense in depth. Use AES-256-GCM for the actual message encryption after key establishment.

How It Works

What Is ML-KEM (Post-Quantum Key Encapsulation)?

ML-KEM (Module-Lattice-Based Key-Encapsulation Mechanism), standardized as FIPS 203 by NIST in August 2024 (formerly known as Kyber), is a post-quantum key agreement mechanism. Unlike ECDH's interactive two-way exchange, ML-KEM is one-shot: the recipient publishes a public key, the sender encapsulates a fresh random 32-byte secret against it producing a single ciphertext, and the recipient decapsulates that ciphertext with their secret key to recover the same secret.

ML-KEM's security rests on the Module Learning With Errors (Module-LWE) problem over module lattices. Shor's algorithm — which breaks ECDH and RSA outright — does not apply to lattice problems. This tool runs the full FIPS 203 workflow in your browser using the @noble/post-quantum library. All computation runs locally.

When to Use ML-KEM

  • Post-quantum key agreement — Establish shared secrets that survive future quantum computer attacks
  • Hybrid key exchange — Combine with X25519 for defense-in-depth (classical + quantum-resistant)
  • TLS 1.3 future-proofing — Chrome, Firefox, OpenSSL, Cloudflare, and Signal already deploy ML-KEM-768 in hybrid mode
  • Long-term confidentiality — Protect data that must remain secret for decades (government, healthcare, financial)
  • Protocol design — Any new protocol should consider post-quantum key agreement
  • When NOT to use — For current-only threat models where quantum computers are not a concern, classical ECDH is faster and simpler

Parameter Set Comparison

Parameter SetSecurityPublic KeySecret KeyCiphertextUsed in
ML-KEM-512128-bit (L1)800 B1632 B768 BBandwidth-constrained
ML-KEM-768192-bit (L3)1184 B2400 B1088 BTLS 1.3, Chrome, Signal
ML-KEM-1024256-bit (L5)1568 B3168 B1568 BTop-secret-grade

Standards Compliance

  • FIPS 203 — Module-Lattice-Based Key-Encapsulation Mechanism (NIST, August 2024)
  • RFC 9180 — Hybrid Public Key Encryption (HPKE) — ML-KEM integration
  • X25519MLKEM768 — TLS 1.3 hybrid key exchange (Chrome, Firefox, Cloudflare)
  • PQXDH — Signal Protocol post-quantum extended triple Diffie-Hellman
  • @noble/post-quantum — Audited JavaScript implementation of FIPS 203

Last updated:

Code Examples

Perform ML-KEM encapsulation in multiple languages:

JavaScript — @noble/post-quantum (Browser)

// ML-KEM-768 with @noble/post-quantum
import { mlkem768 } from '@noble/post-quantum/ml-kem';

const { publicKey, secretKey } = mlkem768.keygen();
const { ciphertext, sharedSecret } = mlkem768.encapsulate(publicKey);
const recovered = mlkem768.decapsulate(ciphertext, secretKey);
// sharedSecret === recovered (both 32 bytes)

Python — pqcrystals-kyber

from pqcrystals_kyber.kyber768 import keygen, encapsulate, decapsulate

pk, sk = keygen()
ciphertext, shared_secret = encapsulate(pk)
recovered = decapsulate(ciphertext, sk)
# shared_secret == recovered

Go — cloudflare/circl

import "github.com/cloudflare/circl/kem/kyber/kyber768"

pk, sk, _ := kyber768.KeyGen()
ct, ss, _ := kyber768.Encapsulate(pk)
recovered, _ := kyber768.Decapsulate(sk, ct)
// ss == recovered

Rust — pqcrypto-kyber

use pqcrypto_kyber::kyber768::*;

let (pk, sk) = keypair();
let (ct, ss) = encapsulate(&pk);
let recovered = decapsulate(&ct, &sk);
// ss == recovered

Node.js — @noble/post-quantum (CommonJS)

const { mlkem768 } = require('@noble/post-quantum/ml-kem');

const { publicKey, secretKey } = mlkem768.keygen();
const { ciphertext, sharedSecret } = mlkem768.encapsulate(publicKey);
const recovered = mlkem768.decapsulate(ciphertext, secretKey);
console.log('Match:', Buffer.from(sharedSecret).equals(Buffer.from(recovered)));

Common Pitfalls

⚠️ Using ML-KEM Alone Without Hybrid Mode: For production, always combine X25519 + ML-KEM-768 and derive transport keys with HKDF. If a weakness is ever found in ML-KEM, the classical half still protects the session.
⚠️ Reusing KEM Keys Across Sessions: The shared secret of one encapsulation must never be reused across sessions without a KDF. Generate fresh key pairs for each session.
⚠️ Using Raw Secret Without KDF: While ML-KEM internally applies a hash-based extractor (unlike raw ECDH), you should still feed the secret into HKDF with session context for production protocols.
⚠️ Confusing KEM with Encryption: ML-KEM establishes a shared key — it does not encrypt your data. Use the derived key with AES-256-GCM or ChaCha20-Poly1305 for actual message encryption.
⚠️ Choosing Wrong Parameter Set: ML-KEM-768 is the practical default (matches TLS 1.3 deployments). ML-KEM-512 is for bandwidth-constrained scenarios only. ML-KEM-1024 is for top-secret-grade security.

Security Notes

ℹ️ Quantum-Resistant: ML-KEM security rests on Module-LWE lattice problems. Shor's algorithm cannot break it — the best known quantum attacks still cost super-polynomial time.
ℹ️ ML-KEM-768 Is the Default: This is the exact parameter set deployed in TLS 1.3 hybrid key agreement by Chrome, Firefox, OpenSSL, Cloudflare, and Signal. It corresponds to security level 3 in the FIPS 203 category ladder.
ℹ️ Hybrid Key Agreement: Combine X25519 (classical) + ML-KEM-768 (post-quantum) for defense in depth. This is exactly what X25519MLKEM768 (TLS) and PQXDH (Signal) do today.
ℹ️ 32-Byte Uniform Secrets: Unlike raw ECDH output, ML-KEM produces uniformly-random 256-bit secrets that can be used directly as AES-256 keys (though HKDF is still recommended for production).

Disclaimer

This tool is provided for educational and development purposes. ML-KEM is a new standard (FIPS 203, August 2024) — implementations should be monitored for updates. For production systems, use well-audited libraries (@noble/post-quantum, cloudflare/circl) and follow hybrid key exchange best practices.

Further Reading

Related Concepts

Related Tools

Want to see the classical half of hybrid key exchange? Try the ECDH Key Exchange tool for X25519 demonstrations. Once you have a shared secret, use AES Encrypt/Decrypt for the actual message encryption. For generating classical ECC keys, try the ECC Key Generator tool.

Frequently Asked Questions

What is ML-KEM and how does it differ from ECDH?

ML-KEM (FIPS 203, standardized by NIST in August 2024 and formerly known as Kyber) is a Key Encapsulation Mechanism. Instead of the interactive two-way dance of Diffie-Hellman, a KEM is one-shot: the recipient publishes a public key, the sender encapsulates a fresh random secret against it producing a single ciphertext, and the recipient decapsulates that ciphertext with their secret key to recover the same secret. Functionally both establish a shared secret — but ML-KEM survives quantum computers, while ECDH does not.

Which parameter set should I choose?

ML-KEM-512 targets 128-bit security, ML-KEM-768 targets 192 bits, and ML-KEM-1024 targets 256 bits. ML-KEM-768 is the practical default: it is the exact set deployed in TLS 1.3 hybrid key agreement by Chrome, Firefox, OpenSSL, Cloudflare, and Signal, and it corresponds to security level 3 in the FIPS 203 category ladder. Use 512 only where bandwidth is extremely tight, and 1024 for top-secret-grade margins.

Why is ML-KEM considered quantum-resistant?

Its security rests on the Module Learning With Errors (Module-LWE) problem over module lattices. The best known quantum attacks (essentially variants of lattice reduction) still cost super-polynomial time, and crucially, Shor's algorithm — which breaks ECDH and RSA outright by computing discrete logs and factoring — does not apply to lattice problems. A future quantum computer therefore cannot recover the shared secret from the public key and ciphertext.

What is hybrid key agreement and why combine ML-KEM with X25519?

Hybrid mode runs both a classical exchange (X25519) and a post-quantum KEM (ML-KEM-768) and combines the two shared secrets into one key. This gives defense in depth: if a weakness is ever found in ML-KEM implementations, classical ECDH still protects the session, and once quantum computers arrive, the lattice half still protects it. This is exactly what TLS 1.3 deployments (X25519MLKEM768) and Signal (PQXDH) do today. Try the X25519 exchange in our ECDH tool to see the classical half.

What should I do with the 32-byte shared secret?

The decapsulated secret is already a uniform, uniformly-random 256-bit value — unlike raw ECDH output, ML-KEM internally applies a hash-based extractor, so it can be used directly as an AES-256 key. In real protocols you would still feed it into a KDF (HKDF) together with transcript context to bind it to the session. Note that a KEM does not encrypt your data itself: it establishes the key; use the AES or ChaCha20 tools for the actual message encryption.

Privacy: This tool runs entirely in your browser — nothing is uploaded or stored. · Disclaimer: For educational purposes only. Not professional security advice.

More in Key Exchange

Learn More