Post-Quantum Cryptography
Since: cryptopp-modern 2026.3.0
Post-Quantum Cryptography (PQC) provides cryptographic algorithms designed to be secure against attacks by both classical and quantum computers. cryptopp-modern implements the NIST PQC standards FIPS 203, 204 and 205, the LMS and HSS stateful hash-based signatures of RFC 8554 and SP 800-208, and the X-Wing hybrid KEM from an Internet-Draft.
The examples on these pages show the library calls. They are not complete protocols: a real design also has to authenticate keys, bind context into key derivation and handle errors.
Why Post-Quantum Cryptography?
A sufficiently large quantum computer would change which algorithms are safe:
- RSA, ECDSA, ECDH, Ed25519, X25519 - All would be broken by Shor’s algorithm
- AES, SHA-2, SHA-3, BLAKE3 - Not broken; Grover’s algorithm gives a limited speed-up for key and preimage search, which larger keys and outputs absorb
The “Harvest Now, Decrypt Later” Threat: An adversary can record encrypted traffic today and decrypt it once a quantum computer exists. This is a threat to confidentiality, so it bears on key establishment first: data that must stay secret for many years is the case for adopting post-quantum key exchange early. Signatures are affected differently, since a signature only has to resist forgery while it is relied on.
Available Algorithms
Key Encapsulation (Key Exchange)
| Algorithm | Standard | Security Basis | Recommended For |
|---|---|---|---|
| ML-KEM | FIPS 203 | Module lattices | Post-quantum key exchange to a published standard |
| X-Wing | Internet-Draft | Hybrid (X25519 + ML-KEM-768) | Defence in depth where both ends implement the draft |
Digital Signatures (Stateless)
| Algorithm | Standard | Security Basis | Recommended For |
|---|---|---|---|
| ML-DSA | FIPS 204 | Module lattices | General-purpose signatures |
| SLH-DSA | FIPS 205 | Hash functions | Conservative security (no lattice assumptions) |
Digital Signatures (Stateful)
| Algorithm | Standard | Security Basis | Recommended For |
|---|---|---|---|
| LMS/HSS | RFC 8554, SP 800-208 | Hash functions | Bounded signing (firmware, code signing, certificates) |
Stateful schemes require explicit state management. Each signature consumes a one-time index that must never be reused. See the LMS/HSS page and the Stateful Signing Integration Guide for details.
Quick Comparison
Key Encapsulation Mechanisms
| Property | ML-KEM-768 | X-Wing | X25519 (classical) |
|---|---|---|---|
| Public key | 1184 bytes | 1216 bytes | 32 bytes |
| Private key as held by this library | 2400 bytes | 2464 bytes | 32 bytes |
| Private key seed | 64 bytes | 32 bytes | Not applicable |
| Ciphertext | 1088 bytes | 1120 bytes | 32 bytes (the sender’s public key) |
| Shared secret | 32 bytes | 32 bytes | 32 bytes |
| Secure against a quantum attacker | Yes | Yes | No |
| Security if lattices are broken | No | Classical only (X25519) | Not applicable |
Digital Signatures
| Property | ML-DSA-65 | SLH-DSA-SHA2-128f | HSS L=2 H5/W8 | Ed25519 (classical) |
|---|---|---|---|---|
| Public key | 1952 bytes | 32 bytes | 60 bytes | 32 bytes |
| Private key | 4032 bytes | 64 bytes | 48 bytes | 32 bytes |
| Signature | 3309 bytes | 17,088 bytes | 2,644 bytes | 64 bytes |
| Secure against a quantum attacker | Yes | Yes | Yes | No |
| Security basis | Lattices | Hash functions | Hash functions | Elliptic curves |
| Stateful | No | No | Yes | No |
cryptest b benchmarks ML-KEM, ML-DSA, X-Wing and two SLH-DSA sets (SLH-DSA-SHA2-128f and SLH-DSA-SHAKE-128f) on your own hardware; it has no LMS/HSS benchmark. As a guide to relative cost, SLH-DSA signing is far slower than ML-DSA signing, and the “s” SLH-DSA sets are slower to sign than the “f” sets.
Choosing the Right Algorithm
For a worked decision tree covering hybrid vs pure post-quantum key exchange and signature selection, see Post-Quantum Cryptography: Choosing an Algorithm.
In summary:
- Key encapsulation: X-Wing is designed to stay secure if either X25519 or ML-KEM-768 is broken, and suits systems where you control both ends. Use ML-KEM directly where FIPS 203 is required or a post-quantum-only design is acceptable.
- Stateless signatures: ML-DSA-65 covers the general case. Pick SLH-DSA when you want hash-only security and can accept larger signatures.
- Stateful signatures: LMS/HSS for bounded signing volumes where you can manage signer state durably. See LMS/HSS and the Stateful Signing Guide.
- Category 5: ML-KEM-1024, ML-DSA-87 or the SLH-DSA 256 sets.
Security Categories
NIST defines five security categories by comparison with a generic attack on a symmetric primitive:
| Category | Comparable to | Algorithms |
|---|---|---|
| 1 | Key search on AES-128 | ML-KEM-512, SLH-DSA 128 sets |
| 2 | Collision search on SHA-256 | ML-DSA-44 |
| 3 | Key search on AES-192 | ML-KEM-768, ML-DSA-65, SLH-DSA 192 sets |
| 5 | Key search on AES-256 | ML-KEM-1024, ML-DSA-87, SLH-DSA 256 sets |
ML-KEM-768 and ML-DSA-65, both category 3, are common general-purpose choices.
Quick Examples
Hybrid Key Exchange with X-Wing
#include <cryptopp/xwing.h>
#include <cryptopp/osrng.h>
#include <cryptopp/secblock.h>
#include <iostream>
int main() {
using namespace CryptoPP;
// Recipient generates key pair
AutoSeededRandomPool rng;
XWingDecapsulator recipient(rng);
// Extract public key to send to sender
SecByteBlock publicKey(recipient.GetKey().GetPublicKeySize());
recipient.GetKey().GetPublicKey(publicKey.begin());
// Sender encapsulates (creates shared secret + ciphertext)
XWingEncapsulator sender(publicKey.begin(), publicKey.size());
SecByteBlock ciphertext(sender.CiphertextLength());
SecByteBlock senderSecret(sender.SharedSecretLength());
sender.Encapsulate(rng, ciphertext.begin(), senderSecret.begin());
// Recipient decapsulates to get the same shared secret
SecByteBlock recipientSecret(recipient.SharedSecretLength());
recipient.Decapsulate(ciphertext.begin(), recipientSecret.begin());
bool same = (senderSecret == recipientSecret);
std::cout << "Shared secrets match: " << (same ? "YES" : "NO") << std::endl;
return same ? 0 : 1;
}Derive session keys from the shared secret with a KDF; see Using with a KDF.
Post-Quantum Signatures with ML-DSA
#include <cryptopp/mldsa.h>
#include <cryptopp/osrng.h>
#include <cryptopp/secblock.h>
#include <iostream>
#include <string>
int main() {
using namespace CryptoPP;
AutoSeededRandomPool rng;
// Generate key pair
MLDSASigner<MLDSA_65> signer(rng);
MLDSAVerifier<MLDSA_65> verifier(signer);
// Sign a message
std::string message = "Important document";
SecByteBlock signature(signer.SignatureLength());
size_t sigLen = signer.SignMessage(rng,
(const byte*)message.data(), message.size(),
signature.begin());
// Verify the signature
bool valid = verifier.VerifyMessage(
(const byte*)message.data(), message.size(),
signature.begin(), sigLen);
std::cout << "Signature valid: " << (valid ? "YES" : "NO") << std::endl;
return valid ? 0 : 1;
}Migration Strategy
Hybrid first
A hybrid combines a classical and a post-quantum algorithm so that an attacker has to break both:
- Key exchange: X-Wing (X25519 + ML-KEM-768)
- Signatures: two signatures, for example Ed25519 and ML-DSA, with both required to verify
If a weakness is found in the newer post-quantum algorithm, the classical one still protects against today’s attackers.
Post-quantum only
Where a published standard is required, or the classical algorithm is no longer wanted:
- Key exchange: ML-KEM-768 or ML-KEM-1024
- Signatures: ML-DSA, SLH-DSA or LMS/HSS
What to move first
Data that must stay confidential for many years is exposed to recorded-traffic attacks today, so its key establishment is the first candidate. Long-lived signing keys, such as firmware roots of trust and certificate authorities, come next because they are slow to replace.
Thread Safety
PQC class instances are not thread-safe. Use one instance per thread:
void signInThread(const byte* privateKey, size_t privateKeyLen) {
AutoSeededRandomPool rng;
MLDSASigner<MLDSA_65> signer(privateKey, privateKeyLen); // One per thread
// ... sign ...
}Stateful LMS/HSS signers have additional rules; see the LMS/HSS page.
Algorithm Details
ML-KEM (FIPS 203)
Module-Lattice-Based Key-Encapsulation Mechanism, derived from CRYSTALS-Kyber.
- Three parameter sets: ML-KEM-512, ML-KEM-768, ML-KEM-1024
- IND-CCA2 design with implicit rejection
- ML-KEM-768 for most applications
ML-DSA (FIPS 204)
Module-Lattice-Based Digital Signature Algorithm, derived from CRYSTALS-Dilithium.
- Three parameter sets: ML-DSA-44, ML-DSA-65, ML-DSA-87
- Designed to be strongly unforgeable (SUF-CMA); randomised signing
- ML-DSA-65 for most applications
SLH-DSA (FIPS 205)
Stateless Hash-Based Digital Signature Algorithm, based on SPHINCS+.
- 12 parameter sets: SHA2 or SHAKE, three security categories, fast or small
- Security based only on hash function properties
- SLH-DSA-SHA2-128f for faster signing, SLH-DSA-SHA2-128s for smaller signatures
LMS/HSS (RFC 8554, SP 800-208)
Stateful hash-based signatures.
- Small signatures for a hash-based scheme, with a fixed number of signatures per key
- Signer state must never be reused or rolled back
X-Wing
Hybrid key encapsulation combining X25519 and ML-KEM-768.
- Designed to be secure if either algorithm is secure
- Specified in an Internet-Draft; not yet an RFC
Standards
| Algorithm | Specification | Status |
|---|---|---|
| ML-KEM | FIPS 203 | Final (13 August 2024) |
| ML-DSA | FIPS 204 | Final (13 August 2024) |
| SLH-DSA | FIPS 205 | Final (13 August 2024) |
| LMS/HSS | RFC 8554, NIST SP 800-208 | Published (2019, 2020) |
| X-Wing | draft-connolly-cfrg-xwing-kem | Internet-Draft |
See Also
- ML-KEM API Reference - Key encapsulation
- ML-DSA API Reference - Digital signatures
- SLH-DSA API Reference - Hash-based signatures
- X-Wing API Reference - Hybrid key encapsulation
- LMS/HSS API Reference - Stateful hash-based signatures
- X25519 - Classical key exchange
- Ed25519 - Classical signatures
References
- FIPS 203: Module-Lattice-Based Key-Encapsulation Mechanism Standard
- FIPS 204: Module-Lattice-Based Digital Signature Standard
- FIPS 205: Stateless Hash-Based Digital Signature Standard
- NIST SP 800-208: Recommendation for Stateful Hash-Based Signature Schemes
- RFC 8554: Leighton-Micali Hash-Based Signatures
- X-Wing: general-purpose hybrid post-quantum KEM (draft-connolly-cfrg-xwing-kem)