← Back to Cryptography & ZKP notes

Hash-Based Signature Schemes

Post-Quantum Cryptography Hash-Based Signatures LMS SPHINCS+ Digital Signatures

These are my study notes from the Hash-Based Signature Schemes module of Cryptography 101. They follow the course from Lamport's one-time signature to LMS/HSS and the stateless SPHINCS+ design.

1. Signatures and why hash-based ones

A digital signature lets anyone check two things about some data: that it has not been changed, and who wrote it. A signature scheme has three algorithms:

AlgorithmInputOutput
Key generationrandomnessprivate key, public key
Signingprivate key, message $M$signature $\sigma$
Verificationpublic key, $M$, $\sigma$accept or reject

Why hash-based. The security of a hash-based scheme rests only on properties of a hash function (preimage and second-preimage resistance). Hash functions are much better understood than the assumptions behind newer post-quantum families such as lattices, and a quantum computer is not known to break them. That conservative footing makes them attractive for long-lived systems such as blockchains.

The cost. Public keys and signatures are much larger than in RSA or elliptic-curve schemes.

The standards

SchemeKindStandard
LMS / HSS (Leighton–Micali)statefulIETF RFC 8554 (2019), NIST SP 800-208 (2020)
XMSS / XMSS^MT (eXtended Merkle Signature Scheme)statefulIETF RFC 8391, NIST SP 800-208
SPHINCS+ (SLH-DSA)statelessNIST FIPS 205

2. Lamport one-time signatures

Lamport's OTS gets its security from a hash function rather than a number-theoretic assumption. The hash function ties each secret value to a public one: anyone can check $H(x) = y$, but nobody can find $x$ from $y$.

Let $H : \{0,1\}^* \to \{0,1\}^n$.

Key generation. Pick $2n$ random $n$-bit secrets, two for every bit position, and hash each one:

$$ sk = \big(x_{i,0},\, x_{i,1}\big)_{i=0}^{n-1}, \qquad pk = \big(y_{i,b} = H(x_{i,b})\big)_{i,b} $$

Signing. Hash the message to a fixed-length digest $h = H(M) = (h_0, \dots, h_{n-1})$. For each bit, reveal the secret that matches it: $\sigma = (x_{0,h_0}, x_{1,h_1}, \dots, x_{n-1,h_{n-1}})$.

Verification. Recompute $h = H(M)$ and accept iff $H(\sigma_i) = y_{i,h_i}$ for every $i$.

A toy run

Take $n = 3$ so the digest has three bits, and say $H(M) = 101$.

Bit position $i$012
Digest bit $h_i$101
Revealed secret$x_{0,1}$$x_{1,0}$$x_{2,1}$
Verifier checks$H(\sigma_0) = y_{0,1}$$H(\sigma_1) = y_{1,0}$$H(\sigma_2) = y_{2,1}$

Half of the secrets are now public. If the same key signs a second message with digest $011$, the attacker also learns $x_{0,0}$ and $x_{1,1}$, which already lets them sign the digests $001$ and $111$. That is why a Lamport key must be used only once.

For a full run with real Keccak-256 values, see Lamport One-Time Signatures: A Worked Example.

Security

A one-time signature scheme is secure if it is existentially unforgeable by a computationally bounded adversary who may obtain the signature of one message of their choice. Lamport meets this as long as $H$ is preimage resistant (for the revealed and unrevealed secrets) and the message hash is collision resistant.

Efficiency

QuantityCost
Private key$2n$ values of $n$ bits $= 2n^2$ bits
Public key$2n^2$ bits
Signature$n$ values $= n^2$ bits
Key generation$2n$ hash evaluations
Signing1 hash evaluation (the message)
Verification$n + 1$ hash evaluations

With $n = 256$: each key is $2 \cdot 256^2 = 131{,}072$ bits $= 16{,}384$ bytes, and a signature is $8{,}192$ bytes.

3. Lamport's problems and their fixes

Lamport's three biggest drawbacks:

  1. Large public and private keys.
  2. Large signatures.
  3. A private key can be used only once.

Fixing the private key size: derive it from a seed

Instead of storing $2n$ random secrets, store one random $n$-bit seed and derive every component with a pseudorandom function:

$$ x_{i,j} = \mathrm{PRF}(\mathit{seed},\, i,\, j) $$

The seed is kept secret and saved for later use. The stored private key drops from $2n^2$ bits to $n$ bits, which is 32 bytes for $n = 256$. (The signature does not get smaller; the secrets are regenerated when signing.)

Fixing the public key and signature size: Winternitz chains

Keys are $2n^2$ bits and signatures $n^2$ bits because Lamport signs one bit at a time. Winternitz's idea (published by Merkle in 1979) is to sign $H(M)$ one $w$-bit block at a time using hash chains. One chain covers $w$ bits, so a signature needs about $n/w$ values instead of $n$, plus a short checksum that stops an attacker from moving forward along a chain. This is the Winternitz One-Time Signature (WOTS).

I cover WOTS in detail in Understanding the Winternitz One-Time Signature Scheme, so I won't repeat it here.

Fixing one-time use: trees

The third problem is fixed by authenticating many one-time public keys under one root, using a Merkle tree. The rest of this note is about how LMS, HSS and SPHINCS+ do that.

4. LM-OTS: the Leighton–Micali one-time signature

LMS combines WOTS with a Merkle tree, plus extra inputs to every hash that improve security. RFC 8554 defines three layers:

  • LM-OTS: the one-time signature.
  • LMS: LM-OTS keys at the leaves of a Merkle tree.
  • HSS (Hierarchical Signature System): LMS trees stacked into a hypertree.

LM-OTS is essentially WOTS with a few changes. Every hash call is prefixed with:

  • $I$: a 16-byte identifier for the key pair,
  • $q$: the number of the leaf (the one-time key) inside the LMS tree,
  • the chain index $i$ and step $j$, or a domain-separation constant.

Because every hash is unique to its key, leaf, chain and step, an attacker can't reuse work across positions or across users ("multi-target" attacks).

Parameters. $n$ is the hash output length in bits, $w$ is the Winternitz width, $u = \lceil n/w \rceil$ is the number of message blocks, and $\ell$ is $u$ plus the number of checksum blocks.

ConstantName in RFC 8554Used for
0x8080D_PBLChashing the chain ends into the public key
0x8181D_MESGhashing the message
0x8282D_LEAFLMS leaf nodes
0x8383D_INTRLMS internal nodes

Key generation

for i = 0 to ℓ-1:
    select x_i ∈_R {0,1}^n
    tmp ← x_i
    for j = 0 to 2^w - 2:
        tmp ← H(I, q, i, j, tmp)
    y_i ← tmp

K ← H(I, q, 0x8080, y_0, y_1, ..., y_{ℓ-1})

private key: x = (x_0, x_1, ..., x_{ℓ-1})
public key:  (I, q, K)

Each chain has $2^w - 1$ hash steps from the secret $x_i$ to the end $y_i$.

Signature generation

To sign $M \in \{0,1\}^*$, Alice:

  1. Selects a randomizer $C \in_R \{0,1\}^n$.
  2. Computes $h = H(I, q, \texttt{0x8181}, C, M)$ and splits it into $w$-bit blocks $(h_0, \dots, h_{u-1})$.
  3. Computes the checksum $\mathrm{csum}(h) = \sum_{i=0}^{u-1} (2^w - 1 - h_i)$ and appends its $w$-bit blocks $(h_u, \dots, h_{\ell-1})$.
  4. Walks each chain $h_i$ steps from the secret:
for i = 0 to ℓ-1:
    tmp ← x_i
    for j = 0 to h_i - 1:
        tmp ← H(I, q, i, j, tmp)
    s_i ← tmp

Alice's signature on $M$ is $(C, s_0, s_1, \dots, s_{\ell-1})$.

Verification

Given $(C, s_0, \dots, s_{\ell-1})$ on $M$, Bob:

  1. Computes $h = H(I, q, \texttt{0x8181}, C, M)$ and its blocks $(h_0, \dots, h_{u-1})$.
  2. Computes $\mathrm{csum}(h)$ and its blocks $(h_u, \dots, h_{\ell-1})$.
  3. Finishes each chain from where the signature left off:
for i = 0 to ℓ-1:
    tmp ← s_i
    for j = h_i to 2^w - 2:
        tmp ← H(I, q, i, j, tmp)
    y'_i ← tmp

K' ← H(I, q, 0x8080, y'_0, y'_1, ..., y'_{ℓ-1})
return K' == K

The checksum is what makes this one-time secure. Raising any message block $h_i$ (which an attacker can do, by hashing further along a chain) lowers the checksum, and lowering a checksum block would mean walking a chain backwards, which means inverting $H$.

In full LMS, Bob doesn't hold $K$ directly. He uses the recomputed $K'$ as a leaf and checks that it leads to the tree's root (next section).

5. LMS: one-time keys under a Merkle tree

  • An LMS tree has height $h$ and $2^h$ leaves. Leaf $q$ is tied to the LM-OTS public key $K_q$, for $q = 0, \dots, 2^h - 1$.
  • SP 800-208 allows heights $h \in \{5, 10, 15, 20, 25\}$.
  • Private keys come from one 256-bit random secret $\mathit{SEED}$. Component $i$ of the one-time key for leaf $q$ is

$$ x_{q,i} = H(I,\, q,\, i,\, \texttt{0xff},\, \mathit{SEED}) $$

The tree. Nodes are numbered from 1 (the root). Node $r$ has children $2r$ and $2r+1$, and the leaves are nodes $2^h$ to $2^{h+1} - 1$:

$$ \text{leaf node } r: \quad T_r = H\big(I,\, r,\, \texttt{0x8282},\, K_{r - 2^h}\big) $$

$$ \text{internal node } r: \quad T_r = H\big(I,\, r,\, \texttt{0x8383},\, T_{2r},\, T_{2r+1}\big) $$

The LMS public key is $(I, T_1)$. A signature with leaf $q$ is the LM-OTS signature plus the authentication path: the $h$ sibling nodes needed to climb from leaf $q$ to $T_1$.

LMS is stateful. The signer must remember which leaves are used and never sign twice with the same $q$. Losing that counter (a restored backup, a cloned VM) means reusing a one-time key, which breaks security.

6. HSS: the hypertree version of LMS

HSS stacks LMS trees: the top tree's leaves sign the roots of trees below, and the bottom trees sign messages. Only the top root is the public key. SP 800-208 permits hypertrees with up to 8 layers.

HSS has two main uses:

  1. Many signatures from one public key. Only the top tree needs computing at key generation; lower trees are built when needed. That makes very large key capacities practical.
  2. Delegating signing. One public key can hand separate lower trees to different signers (devices, HSMs). Each signer uses only its own tree, which lowers the risk of two signers reusing the same one-time key.

7. SPHINCS+: a stateless scheme

LMS/HSS and XMSS/XMSS^MT are all stateful. SPHINCS+, standardised as SLH-DSA, is stateless: the signer keeps no counter.

Main idea. Use a hypertree with a huge number of leaves, so many that picking a leaf at random almost never repeats. To sign, the signer pseudorandomly selects one of those leaf key pairs. A limit on the total number of signatures keeps the chance of reuse negligible.

SPHINCS+ has many optimisations. The two main ones are few-time signatures and virtual hypertrees.

Few-time signature schemes (FTS)

An FTS can be used a small number of times (for example 5 or 10) before its security degrades, unlike an OTS, which can be used only once. This matters for SPHINCS+: if a random leaf is occasionally picked twice, an FTS at the leaf still holds up.

The idea is that each signature reveals only a small fraction of the private key, whereas a Lamport signature reveals half of it. Examples: HORS, HORST, PORS, FORS (the one SPHINCS+ uses) and HORSIC+.

HORS: Hashing to Obtain a Random Subset

HORS is due to Reyzin and Reyzin (2002). It uses:

  • a preimage-resistant hash function $G : \{0,1\}^n \to \{0,1\}^n$,
  • a second-preimage-resistant hash function $H : \{0,1\}^* \to \{0,1\}^n$.

Parameters. $k$ is a divisor of $n$, $m = n/k$ and $t = 2^m$. For example, $n = 256$, $k = 16$, $m = 16$, $t = 65{,}536$.

Key generation. Alice:

  • selects $x_i \in_R \{0,1\}^n$ for $0 \le i \le t-1$,
  • computes $y_i = G(x_i)$ for $0 \le i \le t-1$.

Her private key is $(x_0, \dots, x_{t-1})$ and her public key is $Y = (y_0, \dots, y_{t-1})$.

Signing $M \in \{0,1\}^*$. Alice:

  1. selects a randomizer $C \in_R \{0,1\}^n$,
  2. computes $h = H(C, M)$,
  3. writes $h = (h_0, h_1, \dots, h_{k-1})$ with each $h_j \in \{0,1\}^m$, read as a number in $[0, t)$,
  4. sets $s = (s_0, \dots, s_{k-1})$ with $s_j = x_{h_j}$.

The signature is $(C, s)$. It reveals at most $k$ of the $t$ private components ($16$ of $65{,}536$ in the example).

Verification of $(C, s)$ on $M$. Bob:

  1. obtains an authentic copy of Alice's public key $Y$,
  2. computes $h = H(C, M)$ and writes $h = (h_0, \dots, h_{k-1})$,
  3. accepts iff $G(s_j) = y_{h_j}$ for all $0 \le j \le k-1$.

Why "few-time". A forger needs secrets for all $k$ indices of a new digest. After a few signatures only a small subset of the $t$ secrets is public, so the chance that a fresh digest lands entirely inside it stays tiny. It grows with every signature, so the key must be retired after a few uses.

The drawback: a huge public key. $Y$ has $t$ values, which is $65{,}536 \times 32$ bytes $= 2$ MiB in the example.

HORST (HORS with Tree). Put the $t$ values of $Y$ at the leaves of a Merkle tree of height $m$ (since $t = 2^m$). The root is now Alice's public key, a single $n$-bit value. Each revealed $s_j$ is sent with its authentication path, so the verifier can recompute $y_{h_j} = G(s_j)$ and climb to the root. The public key shrinks and the signature grows.

Virtual hypertrees

A virtual hypertree has $L$ layers, numbered from the top. Each layer is made of Merkle trees of height $d$.

  • Every leaf in layers $1$ to $L-1$ is an OTS key pair. Each OTS private key signs the root of the tree beneath it.
  • Every leaf in layer $L$ (the bottom) is an FTS key pair. FTS private keys sign messages.
  • The root $R$ of the top tree is the user's long-term public key.

All OTS and FTS private keys are derived from a secret seed with a pseudorandom function, applied to a unique index for each key: the layer number, the tree's identifier within that layer, and the key's position within that tree.

So once the seed is chosen the whole hypertree is fully defined, even though it is far too large to ever build. That is the sense in which it is virtual. Any single Merkle tree can still be constructed on demand from the seed, by deriving its OTS or FTS key pairs and then hashing up to compute its nodes.

Virtual hypertree: L layers of Merkle trees. In each tree an authentication path climbs from leaf k_i to its root; each OTS key k_i signs the root of the tree below, and the FTS key k_L at the bottom signs the message M. The top root R is the public key.

Signature generation

To sign $M$, Alice:

  1. Selects a random FTS public key $k_L$ in the bottom layer and signs $M$ with the matching FTS private key.
  2. Derives the root $R_L$ of the Merkle tree containing $k_L$, and the authentication path $P_L$ for $k_L$.
  3. Derives the OTS public key $k_{L-1}$ in the layer above, and signs $R_L$ with its private key.
  4. Reconstructs the root $R_{L-1}$ of the tree containing $k_{L-1}$, and derives its authentication path $P_{L-1}$.
  5. Continues upward, layer by layer, until reaching $R$.

Her signature on $M$ contains:

  • the FTS signature on $M$,
  • all the intermediate OTS signatures,
  • the public keys $k_1, \dots, k_L$,
  • the authentication paths $P_1, \dots, P_L$.

Signature verification

Bob works from the top down:

  1. Validates the authentication path $P_1$ from $k_1$ to $R$.
  2. Verifies the OTS signature on $R_2$ using $k_1$, then validates $P_2$ from $k_2$ to its Merkle root $R_2$.
  3. Continues downward, layer by layer, until he reaches $k_L$.
  4. He is now confident that the FTS public key $k_L$ is authentic.
  5. Finally, he verifies the FTS signature on $M$ with $k_L$.

(In SPHINCS+ itself the one-time public keys are not sent; the verifier recomputes each one from its OTS signature, which keeps signatures smaller. The logic is the same.)

8. Summary

SchemeTypeUses per keyStateMain idea
LamportOTS1n/areveal one of two secrets per digest bit
WOTS / LM-OTSOTS1n/ahash chains sign $w$ bits at once; checksum
HORS / HORST / FORSFTSa fewn/areveal $k$ of $t$ secrets; tree shrinks the public key
LMS / XMSSmany-time$2^h$statefulone-time keys under a Merkle tree
HSS / XMSS^MTmany-time$2^{\text{total height}}$statefultrees of trees (hypertree)
SPHINCS+ / SLH-DSAmany-timebounded, very largestatelessrandom leaf in a virtual hypertree; FTS at the bottom

9. What I want to explore next

  • Survey the main hash-based one-time signature schemes in depth, and try to design a better one.
  • Find efficient ways to build a many-time signature scheme from a one-time scheme, both stateful and stateless.

References

← Back to Cryptography & ZKP notes