Post-quantum protection¶
Data encrypted today may be recorded and stored until a quantum computer can break the key exchange that protected it (“harvest now, decrypt later”). AES-256 itself is not the weak point; the public-key algorithms that wrap the data key are. A hybrid recipient wraps the data key with ML-KEM (FIPS 203) and a classical key exchange together, so it stays confidential while either of the two holds.
Hybrid recipients¶
|
Combination |
Notes |
|---|---|---|
|
ML-KEM-768 with X25519 (X-Wing) |
The general recommendation: compact and fast. |
|
ML-KEM-1024 with P-384 |
The largest ML-KEM parameters and NIST curves only; admitted by |
|
Classical only |
For compatibility and for systems without ML-KEM. |
Hybrid keys need a pyca/cryptography build with ML-KEM; check with
post_quantum_available().
from cryptography_suite import EncryptionContext, KeyRef, Policy, Protector
from cryptography_suite.providers.hpke import (
HpkeKem,
HpkeRecipientProvider,
generate_private_key,
post_quantum_available,
)
assert post_quantum_available()
identity = generate_private_key(HpkeKem.MLKEM768_X25519)
provider = HpkeRecipientProvider()
key = provider.add_identity("archive", identity)
protector = Protector(provider=provider, policy=Policy(), primary_key=key)
context = EncryptionContext({"tenant": "acme"}, purpose="archive")
envelope = protector.seal(b"retained for 30 years", context=context)
assert protector.open(envelope, context=context) == b"retained for 30 years"
Nothing else changes: the envelope format, the API, and the other recipients are the same.
Add post-quantum protection to existing data¶
Envelopes are confidential while every recipient is. An envelope wrapped for a classical key and a hybrid key is only as strong as the classical one, so the goal is to end with post-quantum recipients only:
Seal new data to the hybrid key, for example as an additional recipient next to the current primary key.
Rewrap existing envelopes to it, or re-encrypt them (below).
rewrapreplaces a recipient without touching the ciphertext.Remove classical recipients, keeping them in
decryption_keysuntil the rewrap or re-encryption is complete.
classical = provider.add_identity("archive-classic", generate_private_key(HpkeKem.X25519))
old = Protector(provider=provider, policy=Policy(), primary_key=classical)
legacy_envelope = old.seal(b"sealed before the migration", context=context)
pq = Protector(
provider=provider,
policy=Policy(),
primary_key=key,
decryption_keys=[classical],
)
upgraded = pq.rewrap(legacy_envelope, destination_key=key)
assert [r.key_id for r in pq.inspect(upgraded).recipients] == ["archive"]
Rewrap changes who can unwrap, not the data key. rewrap wraps the
same data key (DEK) for the hybrid recipient. Envelopes stored after the
rewrap are protected by it, but a copy of an envelope captured before the
rewrap is still protected only by the old classical recipient: whoever later
breaks that recipient recovers the data key, which opens that copy and the
rewrapped envelope alike, because both hold the same ciphertext. Where such a
copy may exist, because the envelope was sent or stored where it could have
been recorded, re-encrypt instead of rewrapping: open and seal again, which
creates a new data key.
reencrypted = pq.seal(pq.open(legacy_envelope, context=context), context=context)
assert [r.key_id for r in pq.inspect(reencrypted).recipients] == ["archive"]
assert pq.open(reencrypted, context=context) == b"sealed before the migration"
Re-encryption needs the context and decrypts the content, so it runs where
the application runs; rewrap needs neither. The same distinction applies
to a compromised key (Incident runbooks).
Keys in a key service¶
Google Cloud KMS holds ML-KEM-768, ML-KEM-1024, and X-Wing keys whose private
key never leaves the service. cryptography-suite-gcp-kms encapsulates
locally on the public key and calls Decapsulate to open; see
Key services.
Store hybrid keys¶
A hybrid private key is two keys. private_key_pem writes both as PKCS #8
PEM blocks, encrypted with one password, and load_private_key_pem reads
them back. The public key is shared as one line of text:
from cryptography_suite.providers.hpke import (
load_private_key_pem,
private_key_pem,
public_key_text,
)
pem_bundle = private_key_pem(identity, password=b"a long passphrase")
assert pem_bundle.count(b"-----BEGIN ENCRYPTED PRIVATE KEY-----") == 2
restored = load_private_key_pem(pem_bundle, password=b"a long passphrase")
shared = public_key_text(identity.public_key())
print(shared[:25]) # cs4hpke1-mlkem768-x25519:
Signatures that outlast quantum computers¶
The audit trail can be signed with Ed25519 and ML-DSA-65 (FIPS 204) together, so records stay unforgeable even if one of the two is broken. See Audit and observability. Quorum custodians can also hold hybrid keys; see Quorum recovery.