SLH-DSA (SPHINCS+)
A stateless hash-based signature standard whose security rests only on hash functions; tiny keys (32-64 bytes) but large, slow signatures (about 7.8 KB to 50 KB).
Why it's safe
SLH-DSA relies only on well-understood hash-function properties, so it is the conservative choice if lattice assumptions are ever weakened. Its large signatures and slow signing make it best for low-volume, long-lived uses such as firmware, root certificates and archives. Figures shown are for the 128-bit parameter sets; 192- and 256-bit sets exist.
- Used for
- Signature
- Family
- Hash-based (stateless)
- Classical security
- 128 bits
- Against a quantum computer
- ~128 bits
- Standards
- FIPS 205
Migration guides
How to adopt SLH-DSA (SPHINCS+). Pick your stack.
OpenSSL 3.5+ (libcrypto EVP) · cC/C++ with OpenSSL 3.5+: ML-KEM and ML-DSA through the EVP API and the command lineProduction-ready
Why
OpenSSL 3.5+ implements ML-KEM (FIPS 203), ML-DSA (FIPS 204) and SLH-DSA (FIPS 205) in its default provider, reachable through the same EVP APIs you use for RSA and EC. The EVP_PKEY_encapsulate/EVP_PKEY_decapsulate KEM API has existed since OpenSSL 3.0, so the code shape is familiar.
Steps
- Link against OpenSSL 3.5 or later and check the version at runtime.
- Generate keys with
EVP_PKEY_Q_keygen(NULL, NULL, "ML-KEM-768")/"ML-DSA-65". - Encapsulate/decapsulate with the EVP KEM API; sign with
EVP_PKEY_sign_message_init+EVP_PKEY_sign(orEVP_DigestSign*as for Ed25519). - Store keys as PKCS#8/SPKI PEM (
PEM_write_bio_PrivateKey,PEM_write_bio_PUBKEY).
Before
EVP_PKEY *rsa = EVP_RSA_gen(2048);
/* ... EVP_PKEY_encrypt with RSA-OAEP to wrap a data key ... */After: ML-KEM-768 encapsulation
#include <openssl/evp.h>
EVP_PKEY *kem = EVP_PKEY_Q_keygen(NULL, NULL, "ML-KEM-768");
/* Sender (with the recipient's public key) */
EVP_PKEY_CTX *ectx = EVP_PKEY_CTX_new_from_pkey(NULL, kem, NULL);
unsigned char *ct = NULL, *ss = NULL;
size_t ctlen = 0, sslen = 0;
EVP_PKEY_encapsulate_init(ectx, NULL);
EVP_PKEY_encapsulate(ectx, NULL, &ctlen, NULL, &sslen); /* sizes: 1088, 32 */
ct = OPENSSL_malloc(ctlen);
ss = OPENSSL_malloc(sslen);
EVP_PKEY_encapsulate(ectx, ct, &ctlen, ss, &sslen);
/* Recipient (with the private key) */
EVP_PKEY_CTX *dctx = EVP_PKEY_CTX_new_from_pkey(NULL, kem, NULL);
unsigned char ss2[32];
size_t ss2len = sizeof(ss2);
EVP_PKEY_decapsulate_init(dctx, NULL);
EVP_PKEY_decapsulate(dctx, ss2, &ss2len, ct, ctlen);
/* ss == ss2: feed into HKDF (EVP_KDF "HKDF") to derive an AES-256-GCM key */After: ML-DSA-65 signature
EVP_PKEY *key = EVP_PKEY_Q_keygen(NULL, NULL, "ML-DSA-65");
EVP_PKEY_CTX *sctx = EVP_PKEY_CTX_new_from_pkey(NULL, key, NULL);
EVP_SIGNATURE *alg = EVP_SIGNATURE_fetch(NULL, "ML-DSA-65", NULL);
size_t siglen = 0;
EVP_PKEY_sign_message_init(sctx, alg, NULL); /* params may carry a "context-string" */
EVP_PKEY_sign(sctx, NULL, &siglen, msg, msglen); /* 3309 */
unsigned char *sig = OPENSSL_malloc(siglen);
EVP_PKEY_sign(sctx, sig, &siglen, msg, msglen);
EVP_SIGNATURE_free(alg);Check every return value (<= 0 means failure) in real code; it is omitted above for brevity.
Command line
openssl genpkey -algorithm ML-DSA-65 -out mldsa.key
openssl pkey -in mldsa.key -pubout -out mldsa.pub
openssl pkeyutl -sign -rawin -inkey mldsa.key -in msg.txt -out msg.sig
openssl pkeyutl -verify -rawin -pubin -inkey mldsa.pub -in msg.txt -sigfile msg.sig
openssl genpkey -algorithm ML-KEM-768 -out kem.key
openssl pkey -in kem.key -pubout -out kem.pub
openssl pkeyutl -encap -pubin -inkey kem.pub -out ct.bin -secret ss1.bin
openssl pkeyutl -decap -inkey kem.key -in ct.bin -secret ss2.bin
cmp ss1.bin ss2.bin && echo same-secretGotchas
- Private key formats. OpenSSL can store ML-KEM/ML-DSA private keys as seed, expanded key, or both; provider parameters such as
ml-kem.retain_seedandml-kem.prefer_seedcontrol this. Other tools (Cloudflare uploads, some HSMs, other libraries) may require the seed-only form, so test interop. - Implicit rejection in ML-KEM: a bad ciphertext yields a random secret, not an error.
- Sizes: ML-KEM-768 ct 1,088 B / ek 1,184 B; ML-DSA-65 sig 3,309 B / pk 1,952 B.
- oqs-provider is no longer needed for these algorithms; loading both can cause name clashes. Remove it unless you need other algorithms.
- HSMs via PKCS#11 need vendor support for the new mechanisms; check before moving keys.
Verify
openssl list -kem-algorithms | grep -i ml-kem
openssl list -signature-algorithms | grep -i ml-dsa.NET 10 System.Security.Cryptography · csharp.NET: ML-KEM and ML-DSA in .NET 10 (MLKem, MLDsa)Production-ready
Why
.NET 10 (LTS, November 2025) added post-quantum types to System.Security.Cryptography: MLKem (FIPS 203), MLDsa (FIPS 204), SlhDsa (FIPS 205) and CompositeMLDsa (IETF draft). They are thin wrappers over the operating system's cryptography: Windows CNG on recent Windows 11 / Windows Server builds, and OpenSSL 3.5 or newer on Linux. The Microsoft.Bcl.Cryptography package brings the same API surface to older target frameworks.
Status in .NET 10: MLKem and MLDsa are supported at the class level (a few members, such as some PKCS#8/SPKI import-export helpers and ML-DSA pre-hash signing, are still marked [Experimental]), while SlhDsa and CompositeMLDsa are [Experimental] (diagnostic SYSLIB5006).
Steps
- Target
net10.0(or referenceMicrosoft.Bcl.Cryptographyfor older targets). - Check
MLKem.IsSupported/MLDsa.IsSupportedat startup and log the result: support depends on the OS and its crypto library. - Replace RSA-OAEP/ECDH key wrapping with
MLKem, and RSA/ECDSA signatures withMLDsa, keeping algorithm identifiers next to stored data.
Before
using var rsa = RSA.Create(2048);
byte[] wrapped = rsa.Encrypt(dataKey, RSAEncryptionPadding.OaepSHA256);
using var ecdsa = ECDsa.Create(ECCurve.NamedCurves.nistP256);
byte[] sig = ecdsa.SignData(data, HashAlgorithmName.SHA256);After
using System.Security.Cryptography;
if (!MLKem.IsSupported || !MLDsa.IsSupported)
throw new PlatformNotSupportedException("Needs Windows with PQC support or Linux with OpenSSL 3.5+");
// ML-KEM-768
using MLKem receiver = MLKem.GenerateKey(MLKemAlgorithm.MLKem768);
byte[] encapsulationKey = receiver.ExportEncapsulationKey(); // 1184 bytes, publish this
using MLKem sender = MLKem.ImportEncapsulationKey(MLKemAlgorithm.MLKem768, encapsulationKey);
sender.Encapsulate(out byte[] ciphertext, out byte[] senderSecret); // 1088-byte ciphertext, 32-byte secret
byte[] receiverSecret = receiver.Decapsulate(ciphertext);
// Derive the AES-256-GCM key: HKDF.DeriveKey(HashAlgorithmName.SHA256, receiverSecret, 32, info: "myapp/seal/v1"u8.ToArray())
// ML-DSA-65
using MLDsa signer = MLDsa.GenerateKey(MLDsaAlgorithm.MLDsa65);
byte[] signature = signer.SignData(data); // 3309 bytes
bool ok = signer.VerifyData(data, signature);
byte[] publicKey = signer.ExportMLDsaPublicKey(); // 1952 bytesGotchas
- Platform support varies. macOS is not supported in .NET 10; Linux needs OpenSSL 3.5+ (older LTS distributions ship 3.0); Windows needs a build with PQC in CNG. Always branch on
IsSupported. - TLS is separate.
SslStreamuses the OS TLS stack (SChannel on Windows, OpenSSL on Linux), so hybrid key exchange follows the OS and its configuration, not these classes. ML-DSA certificates in TLS need TLS 1.3 and support on both ends. - Experimental members raise SYSLIB5006 warnings; avoid depending on them in production code until they are stable.
- Dispose keys (
using) so native handles and key material are released. - Sizes: plan storage and message limits for 3.3 KB signatures and ~1.1 KB ciphertexts.
Verify
Console.WriteLine(senderSecret.AsSpan().SequenceEqual(receiverSecret)); // True
Console.WriteLine($"{ciphertext.Length} {signature.Length}"); // 1088 3309Bouncy Castle (bcprov) · javaJava on older JDKs: ML-KEM, ML-DSA and SLH-DSA with Bouncy Castle (1.79+)Production-ready
Why
If you are on JDK 21 or older, the JDK has no ML-KEM/ML-DSA. Bouncy Castle added the final FIPS 203/204/205 algorithms (ML-KEM, ML-DSA, SLH-DSA, including pre-hash variants) in 1.79 (October 2024) and has continued to add encodings, CMS and certificate support since. It plugs into the standard JCA APIs, so the code looks like the JDK 24+ code.
Steps
- Add
org.bouncycastle:bcprov-jdk18on(andbcpkix-jdk18onfor certificates/CMS) at a current version, at least 1.79. - Register the provider once at startup.
- Use the same
KeyPairGenerator,KEM/KeyGeneratorandSignaturepatterns as the JDK guide, naming theBCprovider.
Before
Signature s = Signature.getInstance("SHA256withECDSA");After
import java.security.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jcajce.spec.MLDSAParameterSpec;
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kpg = KeyPairGenerator.getInstance("ML-DSA", "BC");
kpg.initialize(MLDSAParameterSpec.ml_dsa_65, new SecureRandom());
KeyPair kp = kpg.generateKeyPair();
Signature sig = Signature.getInstance("ML-DSA", "BC");
sig.initSign(kp.getPrivate());
sig.update(message);
byte[] signature = sig.sign();For ML-KEM, use KeyPairGenerator.getInstance("ML-KEM", "BC") with MLKEMParameterSpec.ml_kem_768, then wrap or derive keys via Bouncy Castle's KEM support (KeyGenerator with KEMGenerateSpec/KEMExtractSpec) or, on JDK 21+, the javax.crypto.KEM API if your BC version provides a KEM SPI. Check the BC documentation for the version you install, as these APIs have evolved.
Gotchas
- Old class names. Pre-1.79 BC exposed
Kyber/Dilithium(round 3), which are not compatible with ML-KEM/ML-DSA. Search forKyberParameterSpec,DilithiumParameterSpecand migrate. - FIPS. The general BC provider is not FIPS-validated; the separate BC-FJA (FIPS) distribution has its own release schedule for PQC.
- Sizes are the same as everywhere else (ML-DSA-65 signature 3,309 B).
- Keep provider choice in configuration so you can move to the JDK's built-in implementation when you upgrade to JDK 25+.
Verify
Signature v = Signature.getInstance("ML-DSA", "BC");
v.initVerify(kp.getPublic());
v.update(message);
System.out.println(v.verify(signature) + " " + signature.length); // true 3309node:crypto / @noble/post-quantum · javascriptNode.js: sign and verify with ML-DSA-65 (node:crypto on Node 24.6+, or @noble/post-quantum)Production-ready
Why
ECDSA, Ed25519 and RSA signatures will be forgeable once a large quantum computer exists. Signatures are not exposed to "harvest now, decrypt later", but anything that must stay trustworthy for years (software updates, firmware, documents, long-lived API keys, internal PKI) needs a post-quantum path. ML-DSA (FIPS 204) is the standard general-purpose replacement; ML-DSA-65 is the common default.
Node.js supports ML-DSA natively in node:crypto from 24.6.0 (key generation, crypto.sign, crypto.verify) when built with OpenSSL 3.5+, which all official Node 24 and 26 builds are. @noble/post-quantum works on any runtime, including Node 22 and browsers.
Steps
- Add an algorithm identifier to everything you sign (a header field, a key ID that maps to an algorithm), so verifiers know which algorithm to use. This is the crypto-agility step that makes later swaps cheap.
- Generate an ML-DSA-65 key pair and distribute the public key alongside (not instead of) the old one.
- Sign new artifacts with ML-DSA, or with both algorithms during the transition ("dual signing"); teach verifiers to accept either.
- Once all verifiers understand ML-DSA, stop issuing classical signatures.
Before
import { generateKeyPairSync, sign, verify } from 'node:crypto';
const { publicKey, privateKey } = generateKeyPairSync('ed25519');
const sig = sign(null, data, privateKey); // 64 bytes
const ok = verify(null, data, publicKey, sig);After: node:crypto (Node 24.6+)
import { generateKeyPairSync, sign, verify } from 'node:crypto';
const { publicKey, privateKey } = generateKeyPairSync('ml-dsa-65');
const sig = sign(null, data, privateKey); // algorithm must be null/undefined: 3309 bytes
const ok = verify(null, data, publicKey, sig);
// Optional domain separation (FIPS 204 "context", up to 255 bytes; Node 24.8+):
const sig2 = sign(null, data, { key: privateKey, context: Buffer.from('myapp/release/v1') });
verify(null, data, { key: publicKey, context: Buffer.from('myapp/release/v1') }, sig2);
// Keys export as usual
const spkiPem = publicKey.export({ type: 'spki', format: 'pem' });After: @noble/post-quantum (any runtime)
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';
const keys = ml_dsa65.keygen(); // publicKey 1952 B, secretKey 4032 B
const sig = ml_dsa65.sign(data, keys.secretKey); // 0.5.x argument order: (message, secretKey)
const ok = ml_dsa65.verify(sig, data, keys.publicKey);Gotchas
- Size. ML-DSA-65 signatures are 3,309 bytes and public keys 1,952 bytes, against 64 and 32 bytes for Ed25519 and 256 bytes for an RSA-2048 signature. Check HTTP header limits (many proxies cap headers at 8-16 KB), JWT/cookie sizes, database columns (
VARBINARY(256)will not do) and QR codes. - Need tiny signatures or extreme conservatism? FN-DSA (Falcon, FIPS 206) will give ~666-byte signatures but is not final yet. SLH-DSA (FIPS 205) relies only on hashes but signatures are 7.8-50 KB.
- Context strings must match on both sides, or verification fails.
- Pre-hash variants (HashML-DSA) are different algorithms with different signatures; use plain ML-DSA unless a protocol requires otherwise.
- HSM/KMS support for ML-DSA is arriving but uneven; check your provider before moving signing keys.
- Verifiers first. Roll out verification support everywhere before switching signers, otherwise old clients reject new artifacts.
Verify
import assert from 'node:assert';
assert.equal(sig.length, 3309);
assert.ok(verify(null, data, publicKey, sig));
assert.ok(!verify(null, Buffer.from('tampered'), publicKey, sig));liboqs-python (Open Quantum Safe) · pythonPython: prototype post-quantum algorithms with liboqs-pythonExperimental
Why
liboqs-python wraps liboqs from the Open Quantum Safe project. It exposes many algorithms (ML-KEM, ML-DSA, SLH-DSA, Falcon, HQC, Classic McEliece, ...) behind one API, which makes it useful for experiments, benchmarks and interoperability tests. The OQS project itself describes liboqs as intended for research and prototyping, not production. For production Python code prefer pyca/cryptography 48+ (ML-KEM, ML-DSA).
Steps
- Install liboqs (the C library) and then
pip install liboqs-python, following the project's README; the wrapper needs a matching liboqs shared library. - List what your build supports:
oqs.get_enabled_kem_mechanisms(),oqs.get_enabled_sig_mechanisms(). - Use the FIPS names (
"ML-KEM-768","ML-DSA-65"), not the pre-standard"Kyber768"/"Dilithium3".
Before
from cryptography.hazmat.primitives.asymmetric.x25519 import X25519PrivateKey
a, b = X25519PrivateKey.generate(), X25519PrivateKey.generate()
shared = a.exchange(b.public_key())After
import oqs
# Key encapsulation
with oqs.KeyEncapsulation("ML-KEM-768") as receiver, oqs.KeyEncapsulation("ML-KEM-768") as sender:
public_key = receiver.generate_keypair()
ciphertext, ss_sender = sender.encap_secret(public_key)
ss_receiver = receiver.decap_secret(ciphertext)
assert ss_sender == ss_receiver
# Signatures
message = b"hello"
with oqs.Signature("ML-DSA-65") as signer, oqs.Signature("ML-DSA-65") as verifier:
signer_public_key = signer.generate_keypair()
signature = signer.sign(message)
assert verifier.verify(message, signature, signer_public_key)Gotchas
- Not for production according to its maintainers; no FIPS validation.
- Algorithm availability depends on build flags; check the enabled lists rather than assuming.
- Secret key export:
export_secret_key()returns raw bytes that you must protect yourself. - Use it to test sizes and speed, then move the real implementation to a maintained library.
Verify
import oqs
print("ML-KEM-768" in oqs.get_enabled_kem_mechanisms(), "ML-DSA-65" in oqs.get_enabled_sig_mechanisms())