Skip to content
Post-quantumml-kem-1024

ML-KEM-1024

The largest ML-KEM parameter set (NIST Security Category 5): 1568-byte encapsulation key and ciphertext. Required by CNSA 2.0.

Why it's safe

ML-KEM-1024 gives the highest security margin and is the only ML-KEM parameter set allowed for US national security systems under CNSA 2.0. The cost is larger keys and ciphertexts than ML-KEM-768.

Used for
Key exchange
Family
Lattice (Module-LWE)
Classical security
256 bits
Against a quantum computer
~256 bits
Standards
FIPS 203, CNSA 2.0
Read the guideThe new standards: ML-KEM, ML-DSA, SLH-DSA and friends

Migration guides

How to adopt ML-KEM-1024. Pick your stack.

cryptography (pyca) · pythonPython: replace RSA-OAEP / ECDH key wrapping with ML-KEM-768 in pyca/cryptography (48+)Production-ready

Why

Data encrypted to an RSA or elliptic-curve public key can be stored now and decrypted once a large quantum computer exists. ML-KEM (FIPS 203) replaces that step. cryptography (pyca) added an ML-KEM module in 47.0.0 (AWS-LC and BoringSSL backends) and extended it to the regular OpenSSL backend (OpenSSL 3.5.0 or later) in 48.0.0. The PyPI wheels bundle a recent OpenSSL, so pip install "cryptography>=48" gives you ML-KEM-768 and ML-KEM-1024 on Linux, macOS and Windows.

Steps

  1. pip install -U "cryptography>=48" and pin it.
  2. Recipient: MLKEM768PrivateKey.generate(); publish public_key().public_bytes_raw() (1,184 bytes) or the SPKI encoding.
  3. Sender: shared_secret, ciphertext = public_key.encapsulate(); derive an AES key with HKDF; encrypt with AES-256-GCM.
  4. Recipient: private_key.decapsulate(ciphertext) gives the same secret.
  5. For a hybrid (recommended during the transition), also do an X25519 exchange and feed both secrets into HKDF, as below.

Before

python
from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import hashes
import os

priv = rsa.generate_private_key(public_exponent=65537, key_size=2048)
data_key = os.urandom(32)
oaep = padding.OAEP(mgf=padding.MGF1(hashes.SHA256()), algorithm=hashes.SHA256(), label=None)
wrapped = priv.public_key().encrypt(data_key, oaep)
assert priv.decrypt(wrapped, oaep) == data_key

After (hybrid ML-KEM-768 + X25519 → HKDF → AES-256-GCM)

python
import os
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric.mlkem import MLKEM768PrivateKey
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey, X25519PublicKey
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from cryptography.hazmat.primitives.kdf.hkdf import HKDF

# Recipient key pairs (store the private keys like any other secret)
pq_priv = MLKEM768PrivateKey.generate()
ec_priv = X25519PrivateKey.generate()
pq_pub, ec_pub = pq_priv.public_key(), ec_priv.public_key()

def derive(ss_pq: bytes, ss_ec: bytes, transcript: bytes) -> bytes:
    return HKDF(algorithm=hashes.SHA256(), length=32, salt=None,
                info=b"myapp/hybrid-seal/v1" + transcript).derive(ss_pq + ss_ec)

def seal(plaintext: bytes, aad: bytes = b"") -> dict:
    ss_pq, kem_ct = pq_pub.encapsulate()                     # (shared_secret, ciphertext)
    eph = X25519PrivateKey.generate()
    eph_pub = eph.public_key().public_bytes_raw()
    ss_ec = eph.exchange(ec_pub)
    key = derive(ss_pq, ss_ec, eph_pub + kem_ct)
    nonce = os.urandom(12)
    return {"kem_ct": kem_ct, "eph_pub": eph_pub, "nonce": nonce,
            "body": AESGCM(key).encrypt(nonce, plaintext, aad)}

def open_(msg: dict, aad: bytes = b"") -> bytes:
    ss_pq = pq_priv.decapsulate(msg["kem_ct"])
    ss_ec = ec_priv.exchange(X25519PublicKey.from_public_bytes(msg["eph_pub"]))
    key = derive(ss_pq, ss_ec, msg["eph_pub"] + msg["kem_ct"])
    return AESGCM(key).decrypt(msg["nonce"], msg["body"], aad)

assert open_(seal(b"hello")) == b"hello"

Gotchas

  • Return order. encapsulate() returns (shared_secret, ciphertext); mixing them up gives silently wrong keys.
  • Implicit rejection. decapsulate() does not raise on a tampered ciphertext; you find out when AES-GCM raises InvalidTag.
  • Sizes. ML-KEM-768 ciphertext 1,088 bytes, public key 1,184 bytes; ML-KEM-1024: 1,568 and 1,568. Private keys serialise as a 64-byte seed (private_bytes_raw()).
  • Backend support. If your cryptography is built against a system OpenSSL older than 3.5 (some distro packages), generate() raises UnsupportedAlgorithm. Check in CI.
  • Hazmat. These are low-level primitives; the HKDF info label and transcript binding above matter. Prefer a reviewed higher-level protocol (HPKE, TLS) when one fits.
  • No ML-KEM-512 class in this module; use 768 (recommended) or 1024 (CNSA 2.0).

Verify

python
from cryptography.hazmat.primitives.asymmetric.mlkem import MLKEM768PrivateKey
k = MLKEM768PrivateKey.generate()
ss, ct = k.public_key().encapsulate()
assert k.decapsulate(ct) == ss and len(ct) == 1088