HSM / PKCS#11 / Stateful Hash Signatures

What you will do: Choose an SP 800-208 LMS/HSS parameter set (hash, height, W, levels), Sign Message to advance the one-time key counter, Simulate State Loss, then verify a Rust-signed signature with the C++ engine.

Worked example: With the default LMS_SHA256_M32_H5 / LMOTS_W8 key each Sign Message moves the Signature Counter toward 32; at 32 the panel shows KEY EXHAUSTED, and Simulate State Loss names the leaf indexes that would be reused.

Runtime and privacy: The cryptographic exercise runs in this browser. Review the site privacy terms before entering sensitive material; use synthetic inputs for learning and evaluation.

Browse all Crypto Lab tools · Learn with Stateful Hash Signatures

For your role

Developer / Engineer
Use the HSS / LMS Explorer to pick the hash (SHA-256 or SHAKE-256), tree height and Winternitz parameter, sign with Sign Message, and watch the Signature Counter: the token returns CKR_KEY_EXHAUSTED when the state runs out, which is the error your code has to handle.
Security Architect
Press Simulate State Loss after a few signatures: the What happens if state is lost panel shows why a stateful key can never be restored from backup, which decides where these keys may live in your design.
Researcher / Academic
Sign with the Rust engine and press Verify Signature (C++ engine), then tick Tamper with message or Tamper with signature: the cross-engine verification shows the exact byte flip that breaks C_Verify.
Certification & Validation Engineer
Sign until the Signature Counter runs out and the token returns CKR_KEY_EXHAUSTED, then press Simulate State Loss: state handling is what a module that signs with LMS has to get right, and a stateful key can never be restored from backup.

Initializing SoftHSM…

C_Initialize → C_InitToken → C_OpenSession → C_Login

Stateful Hash Signatures

Strictly operating under PKCS#11 v3.2: CKM_HSS and CKM_XMSS.

Scroll sideways to see all sections →

Strict PKCS#11 v3.2 Compliance

Under PKCS#11 v3.2, LMS does not have a standalone capability. It is mapped as an HSS tree with exactly 1 level (L=1).

State Exhaustion Handling

State exhaustion is managed by the WASM boundary natively returning CKR_KEY_EXHAUSTED when the Final Node is consumed. Note: this browser WASM engine is an educational sandbox with volatile memory, not a CMVP-validated production HSM with non-volatile monotonic state storage (SP 800-208 §6.2).

State Management Simulator

Select an SP 800-208 parameter set, then sign messages to watch the one-time key counter advance. See what happens at exhaustion, and how the HSM answers an attempt to roll the state back.

Signing key parameters
Hash
m / n
Height
W
Levels

NSA CNSA 2.0 approves only single-tree LMS and XMSS for National Security Systems; the multi-tree HSS is not allowed (FAQ v2.2, p. 11). L2 and L3 are shown for education.

W (Winternitz parameter) controls the time–bandwidth trade-off in LMOTS — the one-time signature that protects each leaf node. Each OTS signature is built from 34 independent hash chains; W determines how many bits each chain encodes.

Each chain encodes W bits of the message hash and is 2^W − 1 hash steps long (RFC 8554 §4.1). The signer applies up to 2^W − 1 steps to produce the signature; the verifier completes the remaining steps. Larger W → fewer chains needed → smaller signature bytes → but each chain requires more hash steps → slower to sign and verify.

W1
265 chains
1 step/chain
W2
133 chains
≤3 steps
W4
67 chains
≤15 steps
W8
34 chains
≤255 steps

SP 800-208 approves W = 1, 2, 4 and 8. Larger W gives smaller signatures at a higher hash cost: RFC 8554 §4.1 puts one-time public-key generation at p × (2^W − 1) + 1 hashes, with signing and verifying about half that on average. For M32 that is 266 hashes at W=1 and 8,671 at W=8, about 33× as many. W has little effect on security (RFC 8554 §4.1) — only size and speed change.

LMS_SHA256_M32_H5 / LMOTS_W8·32 signatures max·1.3 KB/sig·n = 32: collision bound 2^128 (SP 800-208 §9.2)

Signature Counter

0 / 32
Used: 0Remaining: 32

Simulate State Loss asks the HSM to take this key back to an earlier signature, as a backup restore or a cloned key would, and shows how it answers.

Signature Log

No signatures yet. Click "Sign Message" to begin.

Active Key Info

SchemeLMS_SHA256_M32_H5 / LMOTS_W8
Tree HeightH=5
Max Signatures32
State Storage4 bytes (monotonic leaf index counter)

How does an engineer check that a leaf cannot be reused?

A leaf represents a one-time signing key. After using leaf 42, the signer must remember not to use it again—even after a crash. Skipping a leaf wastes capacity; reusing it breaks the single-use rule.

NIST requirement: SP 800-208 §8.1 requires incrementing and durably storing the leaf index before exporting a signature or accepting another signing request. It prohibits generating more than one signature with the same one-time key. This is the NIST profile, not a universal CC/EUCC test procedure.

Practical assessment methods—not a prescribed NIST test checklist:

  • Design and code review: trace the counter update, persistent write and signature output. Check saving failures; a cached write may not survive power loss.
  • Crash and power-loss tests: interrupt around the state update, restart and sign again. Check that consumed leaves cannot be reused.
  • Concurrent requests: check that two requests cannot reserve the same leaf.
  • Recovery and rollback: examine whether restore, failover or cloning can make consumed leaves available again.

Reading results: associate signature leaf indices with the signing key and, for multi-tree schemes, the relevant tree. Two different messages signed with the same one-time key demonstrate failure even if both signatures verify. Repeated appearance of a stored parent-tree signature is not by itself evidence of generating it again.

No reuse observed in finite tests does not prove reuse impossible. Combine results with design and implementation evidence. An algorithm-test pass alone does not establish crash-safe state management.

Hub limit: this exercise does not perform hardware power-loss testing or prove validated hardware, persistent-storage guarantees or rollback resistance—even when live signing succeeds.

NIST SP 800-208 (October 2020), §§8.1 and 9.1

Cross-Engine Verification — Rust Signs · C++ Verifies

1Select Key Pairgenerated above · public key imported into C++ on selection

No keys yet — generate a key pair in the HSS / LMS Explorer above first.

2Message & Signaturecopy signature hex from signing log above
3Verify SignatureC_VerifyInit + C_Verify · C++
Tamper Controls
Tamper Controls

Verify is waiting: select a key pair in step 1.

No keys yet — click Execute to run the provisioning flow.

No keys yet — click Execute to run the provisioning flow.

Production Tool Capabilities & Verification Requirements

What this sample check establishes: Demonstrates NIST SP 800-208 / RFC 8554 Leighton-Micali (LMS / HSS) Merkle-tree key generation, one-time leaf index advancement, and signature verification.

Browser sandbox limitation (non-certification boundary): Browser state resets on reload; in production, reusing a single LMS leaf index due to VM rollback or NVRAM failure allows signature forgery and breaks the key's security.

What to require and test in your production tools:

  • A FIPS 140 Level 3+ hardware module that stores the incremented LMS/HSS leaf index in non-volatile memory before releasing any signature (SP 800-208 §8); a monotonic counter is a useful aid, not a requirement.
  • No export, backup or cloning of LMS/HSS/XMSS private keying material (SP 800-208 §8); use multi-tree HSS/XMSS^MT with sub-trees on separate modules for redundancy.
  • Automated exhaustion alerting when remaining LMS leaf capacity drops below operational thresholds.

Try it

  1. 1. Predict before you run it.
  2. 2. Run or change the tool above.
  3. 3. Explain what the result shows.

A signing device used leaf 12 after its backup was taken. Why is restoring that old signing state unsafe?

A sample LMS key has one unused leaf. The token gets two signing requests at the same time. What evidence would allow the maintainer to accept the test?

Next step

Keep learning: SLH-DSA: Stateless Hash Signatures

SLH-DSA: Stateless Hash Signatures follows Stateful Hash Signatures, the module this tool practises, in the Software Infrastructure track.