Skip to content

SLH-DSA

Header: #include <cryptopp/slhdsa.h> | Namespace: CryptoPP
Since: cryptopp-modern 2026.3.0; external pure interface since 2026.7.0
Thread Safety: Not thread-safe if the same instance is shared across threads; use one instance per thread, or guard shared instances with a lock

SLH-DSA (Stateless Hash-Based Digital Signature Algorithm) is a NIST post-quantum signature standard, FIPS 205, based on SPHINCS+. Its security rests only on properties of the underlying hash functions, which makes it a conservative choice for signatures that must hold up against quantum computers, at the cost of large signatures and slow signing.

Signature format changed in 2026.7.0. SLH-DSA now signs and verifies using the FIPS 205 external pure interface, so signatures interoperate with OpenSSL, X.509, and CMS. Signatures produced by 2026.3.0 through 2026.6.0 used the internal message form and will not verify under 2026.7.0, or vice versa. Re-sign stored SLH-DSA signatures with 2026.7.0.

Key Features

  • Post-quantum - Designed to resist attack by quantum computers
  • Stateless - No per-signature state to manage (unlike XMSS and LMS)
  • Conservative security - Based only on hash function assumptions
  • 12 parameter sets - SHA2 and SHAKE variants at 3 security categories
  • Two variants per category - “fast” (f) and “small” (s)

Parameter Sets

SHA2 Based

Parameter SetSecurity CategoryPublic KeySecret KeySignature
SLH-DSA-SHA2-128f132 bytes64 bytes17,088 bytes
SLH-DSA-SHA2-128s132 bytes64 bytes7,856 bytes
SLH-DSA-SHA2-192f348 bytes96 bytes35,664 bytes
SLH-DSA-SHA2-192s348 bytes96 bytes16,224 bytes
SLH-DSA-SHA2-256f564 bytes128 bytes49,856 bytes
SLH-DSA-SHA2-256s564 bytes128 bytes29,792 bytes

Type names follow the header naming (e.g., SLHDSA_SHA2_128f corresponds to “SLH-DSA-SHA2-128f”). The category 1 sets use SHA-256; the category 3 and 5 sets use SHA-512 as well as SHA-256.

SHAKE Based

SHAKE parameter sets use SHAKE256 and have identical sizes to their SHA2 counterparts:

  • SLHDSA_SHAKE_128f, SLHDSA_SHAKE_128s
  • SLHDSA_SHAKE_192f, SLHDSA_SHAKE_192s
  • SLHDSA_SHAKE_256f, SLHDSA_SHAKE_256s

Variant guide:

  • “f” (fast) - Larger signatures, faster signing
  • “s” (small) - Smaller signatures, slower signing

Quick Example

#include <cryptopp/slhdsa.h>
#include <cryptopp/osrng.h>
#include <cryptopp/secblock.h>
#include <iostream>
#include <string>

int main() {
    using namespace CryptoPP;

    AutoSeededRandomPool rng;

    // Generate key pair (SHA2-128f)
    SLHDSASigner<SLHDSA_SHA2_128f> signer(rng);
    SLHDSAVerifier<SLHDSA_SHA2_128f> verifier(signer);

    // Sign a message
    std::string message = "Hello, Post-Quantum World!";
    SecByteBlock signature(signer.SignatureLength());

    size_t sigLen = signer.SignMessage(rng,
        (const byte*)message.data(), message.size(),
        signature.begin());

    std::cout << "Signature length: " << sigLen << " bytes" << std::endl;

    // 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;
}

Usage Guidelines

Do:

  • Use SLH-DSA where conservative, hash-only security matters more than signature size or signing speed
  • Start with SLHDSA_SHA2_128f, or SLHDSA_SHA2_128s if signature size matters more than signing time
  • Store private keys securely (for example an OS key store or HSM); SecByteBlock protects in-memory buffers but is not storage
  • Verify signatures before trusting signed data

Avoid:

  • High-throughput signing; signatures are large and signing is slow
  • Category 5 parameter sets unless you need them
  • Designs with no room for signatures of 8 to 50 KB
  • Signing very large messages directly; this implementation buffers the whole message

When to Use SLH-DSA

Use SLH-DSA when:

  • You want security assumptions limited to hash functions
  • Signatures are made rarely and must be trusted for a long time, such as firmware, software releases or root certificates
  • You want a second post-quantum signature that does not share ML-DSA’s lattice assumptions

ML-DSA is the better choice if you need smaller signatures (3,309 bytes for ML-DSA-65 against 7,856 bytes or more) or faster signing.

If quantum attackers are not part of your threat model, Ed25519 has 64-byte signatures and no post-quantum security.


Class: SLHDSASigner

Sign messages with SLH-DSA private key.

Template Parameter

template <class PARAMS>
struct SLHDSASigner;

PARAMS is one of:

  • SLHDSA_SHA2_128f, SLHDSA_SHA2_128s
  • SLHDSA_SHA2_192f, SLHDSA_SHA2_192s
  • SLHDSA_SHA2_256f, SLHDSA_SHA2_256s
  • SLHDSA_SHAKE_128f, SLHDSA_SHAKE_128s
  • SLHDSA_SHAKE_192f, SLHDSA_SHAKE_192s
  • SLHDSA_SHAKE_256f, SLHDSA_SHAKE_256s

Constants

CRYPTOPP_CONSTANT(SECRET_KEYLENGTH = PARAMS::SECRET_KEY_SIZE);   // 64-128 bytes
CRYPTOPP_CONSTANT(PUBLIC_KEYLENGTH = PARAMS::PUBLIC_KEY_SIZE);   // 32-64 bytes
CRYPTOPP_CONSTANT(SIGNATURE_LENGTH = PARAMS::SIGNATURE_SIZE);    // 7,856-49,856 bytes

Constructors

Default Constructor

SLHDSASigner();

Create a signer with no key. Generate or load a key before use.

Constructor with RNG

SLHDSASigner(RandomNumberGenerator& rng);

Generate a new key pair.

Example:

AutoSeededRandomPool rng;
SLHDSASigner<SLHDSA_SHA2_128f> signer(rng);

Constructor with Private Key

SLHDSASigner(const byte* privateKey, size_t privateKeyLen);

Load an existing private key.

Example:

SecByteBlock privateKey(64);
// ... load key from storage ...
SLHDSASigner<SLHDSA_SHA2_128f> signer(privateKey.begin(), privateKey.size());

Methods

SignMessage

size_t SignMessage(RandomNumberGenerator& rng,
                   const byte* message, size_t messageLen,
                   byte* signature) const;

Sign a message. This is a convenience method inherited from PK_Signer. The lower-level SignAndRestart() is also available.

Parameters:

  • rng - Random number generator (used for randomised signing)
  • message - Message to sign
  • messageLen - Message length
  • signature - Output buffer (must be at least SignatureLength() bytes)

Returns: Signature length

Example:

SLHDSASigner<SLHDSA_SHA2_128f> signer(rng);

std::string message = "Document to sign";
SecByteBlock signature(signer.SignatureLength());

size_t sigLen = signer.SignMessage(rng,
    (const byte*)message.data(), message.size(),
    signature.begin());

Signing with a context

SignMessage signs with an empty context, which suits most callers. SLH-DSA signs over the FIPS 205 external message, and an optional context string (up to 255 bytes) can be bound into the signature. Set it on a message accumulator before signing, and set the same context on the verifier’s accumulator:

#include <cryptopp/slhdsa.h>
#include <cryptopp/osrng.h>
#include <cryptopp/secblock.h>
#include <cryptopp/smartptr.h>
#include <iostream>
#include <string>

int main() {
    using namespace CryptoPP;

    AutoSeededRandomPool rng;
    SLHDSASigner<SLHDSA_SHA2_128f> signer(rng);
    SLHDSAVerifier<SLHDSA_SHA2_128f> verifier(signer);

    std::string context = "example-app-v1";
    std::string message = "Document to sign";

    // Sign with context
    member_ptr<PK_MessageAccumulator> acc(signer.NewSignatureAccumulator(rng));
    dynamic_cast<SLHDSA_MessageAccumulator<SLHDSA_SHA2_128f>&>(*acc)
        .SetContext((const byte*)context.data(), context.size());
    acc->Update((const byte*)message.data(), message.size());

    SecByteBlock signature(signer.SignatureLength());
    size_t sigLen = signer.SignAndRestart(rng, *acc, signature.begin());

    // Verify with the same context
    member_ptr<PK_MessageAccumulator> vacc(verifier.NewVerificationAccumulator());
    dynamic_cast<SLHDSA_MessageAccumulator<SLHDSA_SHA2_128f>&>(*vacc)
        .SetContext((const byte*)context.data(), context.size());
    verifier.InputSignature(*vacc, signature.begin(), sigLen);
    vacc->Update((const byte*)message.data(), message.size());
    bool valid = verifier.VerifyAndRestart(*vacc);

    // The plain call uses an empty context, so it must reject this signature
    bool plain = verifier.VerifyMessage(
        (const byte*)message.data(), message.size(), signature.begin(), sigLen);

    std::cout << "With context: " << (valid ? "valid" : "invalid") << std::endl;
    std::cout << "Without context: " << (plain ? "valid" : "invalid") << std::endl;

    return (valid && !plain) ? 0 : 1;
}

SignatureLength

size_t SignatureLength() const;

Get the signature size in bytes.

AccessPrivateKey / GetPrivateKey

PrivateKey& AccessPrivateKey();
const PrivateKey& GetPrivateKey() const;

Access the private key object for key generation or export.

GetKey / AccessKey

const SLHDSAPrivateKey<PARAMS>& GetKey() const;
SLHDSAPrivateKey<PARAMS>& AccessKey();

Get the private key with full type information.

Example:

// Get public key from signer
const byte* pkBytes = signer.GetKey().GetPublicKeyBytePtr();
size_t pkLen = signer.GetKey().GetPublicKeySize();

AlgorithmName

std::string AlgorithmName() const;

Get the algorithm name (e.g., “SLH-DSA-SHA2-128f”). Useful for logging and runtime identification.


Class: SLHDSAVerifier

Verify SLH-DSA signatures.

Template Parameter

template <class PARAMS>
struct SLHDSAVerifier;

Constants

CRYPTOPP_CONSTANT(PUBLIC_KEYLENGTH = PARAMS::PUBLIC_KEY_SIZE);
CRYPTOPP_CONSTANT(SIGNATURE_LENGTH = PARAMS::SIGNATURE_SIZE);

Constructors

Default Constructor

SLHDSAVerifier();

Create a verifier with no key. Set the public key before use.

Constructor with Public Key

SLHDSAVerifier(const byte* publicKey, size_t publicKeyLen);

Load a public key for verification.

Example:

SecByteBlock publicKey(32);
// ... receive from sender ...
SLHDSAVerifier<SLHDSA_SHA2_128f> verifier(publicKey.begin(), publicKey.size());

Constructor from Signer

SLHDSAVerifier(const SLHDSASigner<PARAMS>& signer);

Extract public key from signer.

Example:

SLHDSASigner<SLHDSA_SHA2_128f> signer(rng);
SLHDSAVerifier<SLHDSA_SHA2_128f> verifier(signer);

Methods

VerifyMessage

bool VerifyMessage(const byte* message, size_t messageLen,
                   const byte* signature, size_t signatureLen) const;

Verify a signature on a message. This is a convenience method inherited from PK_Verifier. The lower-level VerifyAndRestart() is also available.

Parameters:

  • message - Message that was signed
  • messageLen - Message length
  • signature - Signature to verify
  • signatureLen - Signature length. Any length other than SignatureLength() throws InvalidArgument.

Returns: true if valid, false if invalid

Example:

bool valid = verifier.VerifyMessage(
    (const byte*)message.data(), message.size(),
    signature.begin(), signature.size());

if (!valid) {
    std::cerr << "Invalid signature!" << std::endl;
}

AccessPublicKey / GetPublicKey

PublicKey& AccessPublicKey();
const PublicKey& GetPublicKey() const;

Access the public key object to set or retrieve key bytes.

AccessKey / GetKey

SLHDSAPublicKey<PARAMS>& AccessKey();
const SLHDSAPublicKey<PARAMS>& GetKey() const;

Access the public key with full type information.

AlgorithmName

std::string AlgorithmName() const;

Get the algorithm name (e.g., “SLH-DSA-SHA2-128f”).


Class: SLHDSAPrivateKey

Holds the secret key material for signing.

Methods

GetAlgorithmID

OID GetAlgorithmID() const;

Get the algorithm OID for this key type. Used in ASN.1/DER encoding.

GenerateRandom

void GenerateRandom(RandomNumberGenerator &rng, const NameValuePairs &params);

Generate a new random key pair.

Example:

SLHDSAPrivateKey<SLHDSA_SHA2_128f> privateKey;
privateKey.GenerateRandom(rng, g_nullNameValuePairs);

GetPublicKeyBytePtr / GetPublicKeySize

const byte* GetPublicKeyBytePtr() const;
size_t GetPublicKeySize() const;

Get the embedded public key.

GetPrivateKeyBytePtr / GetPrivateKeySize

const byte* GetPrivateKeyBytePtr() const;
size_t GetPrivateKeySize() const;

Get the private key bytes.

Save / Load

void Save(BufferedTransformation &bt) const;
void Load(BufferedTransformation &bt);

Serialize/deserialize in ASN.1 DER format (PKCS#8 OneAsymmetricKey).


Class: SLHDSAPublicKey

Holds the public key material for verification.

Methods

SetPublicKey

void SetPublicKey(const byte *key, size_t len);

Set the public key bytes.

GetPublicKeyBytePtr / GetPublicKeySize

const byte* GetPublicKeyBytePtr() const;
size_t GetPublicKeySize() const;

Get the public key bytes.

Save / Load

void Save(BufferedTransformation &bt) const;
void Load(BufferedTransformation &bt);

Serialize/deserialize in ASN.1 DER format (X.509 SubjectPublicKeyInfo).


Key Serialization

Raw bytes are suitable for internal storage when you also store the parameter set alongside them. ASN.1 DER (PKCS#8/X.509) is the recommended interchange format for compatibility with other systems.

Saving Keys (Raw Bytes)

Requires: <cstring> for std::memcpy

// Generate key pair
SLHDSASigner<SLHDSA_SHA2_128f> signer(rng);
const auto& privKey = signer.GetKey();

// Save private key (KEEP SECURE!)
SecByteBlock privateKeyBytes(privKey.GetPrivateKeySize());
std::memcpy(privateKeyBytes.begin(),
            privKey.GetPrivateKeyBytePtr(),
            privateKeyBytes.size());

// Save public key (can be shared)
SecByteBlock publicKeyBytes(privKey.GetPublicKeySize());
std::memcpy(publicKeyBytes.begin(),
            privKey.GetPublicKeyBytePtr(),
            publicKeyBytes.size());

Loading Keys (Raw Bytes)

// Load private key (for signing)
SLHDSASigner<SLHDSA_SHA2_128f> signer(
    privateKeyBytes.begin(), privateKeyBytes.size());

// Load public key (for verification)
SLHDSAVerifier<SLHDSA_SHA2_128f> verifier(
    publicKeyBytes.begin(), publicKeyBytes.size());

Saving Keys (ASN.1 DER)

Requires: <cryptopp/files.h> for FileSink and FileSource

// Save private key to file
FileSink privFile("slhdsa_private.der");
signer.GetKey().Save(privFile);

// Save public key to file
FileSink pubFile("slhdsa_public.der");
SLHDSAPublicKey<SLHDSA_SHA2_128f> pubKey;
pubKey.SetPublicKey(signer.GetKey().GetPublicKeyBytePtr(),
                    signer.GetKey().GetPublicKeySize());
pubKey.Save(pubFile);

Loading Keys (ASN.1 DER)

// Load private key from file
FileSource privFile("slhdsa_private.der", true);
SLHDSASigner<SLHDSA_SHA2_128f> signer;
signer.AccessKey().Load(privFile);

// Load public key from file
FileSource pubFile("slhdsa_public.der", true);
SLHDSAVerifier<SLHDSA_SHA2_128f> verifier;
verifier.AccessKey().Load(pubFile);

Loading Keys from a std::string (in-memory)

The StringSource overload trap that affects ML-KEM Save/Load applies here too. See the ML-KEM Loading Keys section for the safe forms. Substitute SLHDSAPublicKey or SLHDSAPrivateKey for the ML-KEM class names.


Convenience Type Aliases

All 12 parameter sets have pre-defined signer and verifier types:

// SHA2 based signers
typedef SLHDSASigner<SLHDSA_SHA2_128f> SLHDSA_SHA2_128f_Signer;
typedef SLHDSASigner<SLHDSA_SHA2_128s> SLHDSA_SHA2_128s_Signer;
typedef SLHDSASigner<SLHDSA_SHA2_192f> SLHDSA_SHA2_192f_Signer;
typedef SLHDSASigner<SLHDSA_SHA2_192s> SLHDSA_SHA2_192s_Signer;
typedef SLHDSASigner<SLHDSA_SHA2_256f> SLHDSA_SHA2_256f_Signer;
typedef SLHDSASigner<SLHDSA_SHA2_256s> SLHDSA_SHA2_256s_Signer;

// SHA2 based verifiers
typedef SLHDSAVerifier<SLHDSA_SHA2_128f> SLHDSA_SHA2_128f_Verifier;
typedef SLHDSAVerifier<SLHDSA_SHA2_128s> SLHDSA_SHA2_128s_Verifier;
typedef SLHDSAVerifier<SLHDSA_SHA2_192f> SLHDSA_SHA2_192f_Verifier;
typedef SLHDSAVerifier<SLHDSA_SHA2_192s> SLHDSA_SHA2_192s_Verifier;
typedef SLHDSAVerifier<SLHDSA_SHA2_256f> SLHDSA_SHA2_256f_Verifier;
typedef SLHDSAVerifier<SLHDSA_SHA2_256s> SLHDSA_SHA2_256s_Verifier;

// SHAKE based (same pattern)
typedef SLHDSASigner<SLHDSA_SHAKE_128f> SLHDSA_SHAKE_128f_Signer;
typedef SLHDSASigner<SLHDSA_SHAKE_128s> SLHDSA_SHAKE_128s_Signer;
// ... etc

Example using convenience types:

SLHDSA_SHA2_128f_Signer signer(rng);
SLHDSA_SHA2_128f_Verifier verifier(signer);

Choosing a Parameter Set

Starting Points

Use CaseParameter Set
General purposeSLHDSA_SHA2_128f
Smaller signaturesSLHDSA_SHA2_128s
Category 3SLHDSA_SHA2_192f or SLHDSA_SHA2_192s
Category 5SLHDSA_SHA2_256f or SLHDSA_SHA2_256s
SHA-3 family onlySLHDSA_SHAKE_128f and the other SHAKE sets

Decision Factors

Choose an “f” (fast) variant when:

  • Signing time matters
  • Storage and bandwidth can take the larger signature

Choose an “s” (small) variant when:

  • Signature size matters most
  • Many signatures are stored or transmitted
  • Signing happens rarely, so the slower signing is acceptable

Choose the security category by requirement:

  • Category 1: comparable to a key search on AES-128
  • Category 3: comparable to a key search on AES-192
  • Category 5: comparable to a key search on AES-256

cryptest b benchmarks SLH-DSA-SHA2-128f and SLH-DSA-SHAKE-128f on your own hardware. Signing with an “s” set is slower than with the matching “f” set.

Comparison with Other Signature Algorithms

AlgorithmPublic KeySignaturePost-quantum
Ed2551932 bytes64 bytesNo
RSA-2048256-byte modulus256 bytesNo
ECDSA P-25665 bytes uncompressed64 bytesNo
ML-DSA-651,952 bytes3,309 bytesYes
SLH-DSA-SHA2-128s32 bytes7,856 bytesYes
SLH-DSA-SHA2-128f32 bytes17,088 bytesYes

Security Considerations

Security Assumptions

SLH-DSA security relies on the difficulty of finding preimages for its hash functions, and on several related properties of the same functions. It needs no number-theoretic or lattice assumption.

This is a conservative basis compared to lattice-based schemes (ML-DSA), which rely on the hardness of lattice problems.

Security Levels (NIST Categories)

Parameter setsNIST categoryComparable to a key search on
128s, 128f1AES-128
192s, 192f3AES-192
256s, 256f5AES-256

Security Notes

  1. Stateless design - Unlike XMSS and LMS, no state has to be tracked between signatures.

  2. Probabilistic signing - This implementation uses randomness during signing, so the same message will normally produce different signatures.

  3. Signature limit - The FIPS 205 parameter sets are designed for up to 2^64 signatures per key, far more than ordinary use reaches.

  4. Hash function choice - The SHA2 and SHAKE sets target the same security categories. Choose by the hash family your environment prefers or already accelerates.


Thread Safety

Not thread-safe if the same instance is shared across threads. Use one instance per thread, or guard shared instances with a lock.


Object Identifiers (OIDs)

Each parameter set has a NIST-assigned OID for use in ASN.1/DER encoding. OIDs are library-provided via accessors:

SHA2 Variants

Parameter SetOIDAccessor
SLH-DSA-SHA2-128s2.16.840.1.101.3.4.3.20ASN1::id_slh_dsa_sha2_128s()
SLH-DSA-SHA2-128f2.16.840.1.101.3.4.3.21ASN1::id_slh_dsa_sha2_128f()
SLH-DSA-SHA2-192s2.16.840.1.101.3.4.3.22ASN1::id_slh_dsa_sha2_192s()
SLH-DSA-SHA2-192f2.16.840.1.101.3.4.3.23ASN1::id_slh_dsa_sha2_192f()
SLH-DSA-SHA2-256s2.16.840.1.101.3.4.3.24ASN1::id_slh_dsa_sha2_256s()
SLH-DSA-SHA2-256f2.16.840.1.101.3.4.3.25ASN1::id_slh_dsa_sha2_256f()

SHAKE Variants

Parameter SetOIDAccessor
SLH-DSA-SHAKE-128s2.16.840.1.101.3.4.3.26ASN1::id_slh_dsa_shake_128s()
SLH-DSA-SHAKE-128f2.16.840.1.101.3.4.3.27ASN1::id_slh_dsa_shake_128f()
SLH-DSA-SHAKE-192s2.16.840.1.101.3.4.3.28ASN1::id_slh_dsa_shake_192s()
SLH-DSA-SHAKE-192f2.16.840.1.101.3.4.3.29ASN1::id_slh_dsa_shake_192f()
SLH-DSA-SHAKE-256s2.16.840.1.101.3.4.3.30ASN1::id_slh_dsa_shake_256s()
SLH-DSA-SHAKE-256f2.16.840.1.101.3.4.3.31ASN1::id_slh_dsa_shake_256f()

Usage:

// Get OID from key object
OID oid = privateKey.GetAlgorithmID();

// Get OID statically from parameter set
OID staticOid = SLHDSA_SHA2_128f::StaticAlgorithmOID();

// Compare OIDs
if (oid == ASN1::id_slh_dsa_sha2_128f()) {
    // SLH-DSA-SHA2-128f key
}

Exceptions

  • InvalidArgument - A key has the wrong length; a context string is longer than 255 bytes; or a signature passed to the verifier is not exactly SignatureLength() bytes
  • BERDecodeErr - Load() was given a malformed encoding

A signature of the right length that does not verify is reported by the return value (false), not by an exception. Check the length of a signature from an outside source before passing it to the verifier, or catch InvalidArgument.


Specification Compliance

This implementation targets NIST FIPS 205:

  • Interface: The external, pure slh_sign and slh_verify functions, with an optional context string. The pre-hash variant (HashSLH-DSA) is not provided.
  • Hash Functions: SHA-256 and SHA-512 for the SHA2 sets, SHAKE256 for the SHAKE sets
  • Parameters: All 12 parameter sets

See Also

  • ML-DSA - Lattice-based post-quantum signatures
  • ML-KEM - Post-quantum key encapsulation
  • X-Wing - Hybrid KEM (X25519 + ML-KEM-768)
  • Ed25519 - Classical signatures
  • PQC Overview - Algorithm comparison and guidance

References

  1. FIPS 205: Stateless Hash-Based Digital Signature Standard
  2. SPHINCS+: Submission to the NIST post-quantum project, v3.1