Setup and notation
This note runs Lamport's one-time signature (OTS) end to end with a toy security parameter $n = 8$, so every value fits on one line and students can check each step by hand. Every hash value below is a real Keccak-256 output (the Ethereum variant, not NIST SHA3-256).
Security parameter. $n = 8$ bits. Messages are first hashed to an 8-bit digest, so a key pair has 8 positions, each with a "0" slot and a "1" slot.
Hash function. We use Keccak-256 and keep only the last $n = 8$ bits of its output, i.e. its final byte (the last two hex characters):
$$ H : \{0,1\}^* \rightarrow \{0,1\}^8, \qquad H(x) = \mathrm{Keccak256}(x) \bmod 2^8 $$
Example: Keccak256(0x3a) = 0x96d2…650c, so $H(\texttt{0x3a})$ = 0x0c = 00001100.
Encoding conventions.
- Secret values are single bytes (8 bits, matching $n$). Each is hashed as a 1-byte input, e.g. $H(\texttt{0x3a})$ hashes the byte
0x3a. - The message is hashed as its ASCII bytes, e.g. "PQ" =
0x5051. - Digest bits are read most-significant first and indexed $i = 1, \dots, 8$.
Notation.
| Symbol | Meaning |
|---|---|
| $sk_{i,b}$ | secret value for position $i$, bit $b \in \{0,1\}$ |
| $pk_{i,b}$ | public value $H(sk_{i,b})$ |
| $d = d_1 d_2 \dots d_8$ | the 8-bit message digest $H(m)$ |
| $\sigma_i$ | the $i$-th signature component |
Key generation
The signer samples $2n = 16$ random 8-bit secrets and publishes their hashes; the secrets are the private key, the hashes are the public key.
Step 1: sample the private key. For each position $i$ and each bit value $b$, draw a uniformly random $n$-bit string:
$$ sk_{i,b} \xleftarrow{R} \{0,1\}^{8}, \qquad i \in \{1,\dots,8\},\; b \in \{0,1\} $$
$$ SK = \begin{pmatrix} sk_{1,0} & sk_{2,0} & \cdots & sk_{8,0} \\ sk_{1,1} & sk_{2,1} & \cdots & sk_{8,1} \end{pmatrix} $$
Step 2: derive the public key. Hash every secret:
$$ pk_{i,b} = H(sk_{i,b}) = \mathrm{Keccak256}(sk_{i,b}) \bmod 2^8 $$
$$ PK = \begin{pmatrix} pk_{1,0} & pk_{2,0} & \cdots & pk_{8,0} \\ pk_{1,1} & pk_{2,1} & \cdots & pk_{8,1} \end{pmatrix} $$
The concrete key pair. The secrets below were chosen for this example (in practice they come from a CSPRNG). The "last byte" column is $H(sk)$, the public value.
| $i$ | $b$ | $sk_{i,b}$ | Keccak256($sk_{i,b}$) | $pk_{i,b}$ (last byte) | $pk_{i,b}$ (bits) |
|---|---|---|---|---|---|
| 1 | 0 | 0x3a | 96d280011b274d9410ea6c6fc28e2bb076b01d2fac329c49c4b29a719ec4650c | 0x0c | 00001100 |
| 1 | 1 | 0x7e | a28a3f816fdcab5fa5d9e32081c451a5b738cbc6380020cfae2633e4bd78ded0 | 0xd0 | 11010000 |
| 2 | 0 | 0x91 | 42c246a07c1a207f14480f4d3c8c9fe2e8e851cb168eefb997992ac70ba4e0bf | 0xbf | 10111111 |
| 2 | 1 | 0x13 | 62af204a12d42fdc0d1452abd76e3d611b00a98ccdab368ef149b27224b2f281 | 0x81 | 10000001 |
| 3 | 0 | 0x5c | 731553fa98541ade8b78284229adfe09a819380dee9244baac20dd1e0aa24095 | 0x95 | 10010101 |
| 3 | 1 | 0xa9 | 6c2e99637a1486db6c2cdcdab56c017faedb132f9b25b3581728fe138c9c8868 | 0x68 | 01101000 |
| 4 | 0 | 0xe7 | 1e591f1c32712482d7eee6a5127936c1a0f4295a996e228af11b42605d5a81bc | 0xbc | 10111100 |
| 4 | 1 | 0x46 | e61d9a3d3848fb2cdd9a2ab61e2f21a10ea431275aed628a0557f9dee697c37a | 0x7a | 01111010 |
| 5 | 0 | 0x08 | d33e25809fcaa2b6900567812852539da8559dc8b76a7ce3fc5ddd77e8d19a69 | 0x69 | 01101001 |
| 5 | 1 | 0xcb | 6a076a720fa33aaa82d2d04e1769c345d172ef2967ef160f9a899729572b45c5 | 0xc5 | 11000101 |
| 6 | 0 | 0xb4 | d98227c7cf5fb8eab709662bbef7b515ab1c1fb48ca0964c893febe2b5c97bd4 | 0xd4 | 11010100 |
| 6 | 1 | 0x2d | d3b8281179950f98149eefdb158d0e1acb56f56e8e343aa9fefafa7e36959561 | 0x61 | 01100001 |
| 7 | 0 | 0x6f | 53a63b3ee437e1aa804722ac8f2f57053ac47e1bb887f095340cf5990e7faad3 | 0xd3 | 11010011 |
| 7 | 1 | 0xf0 | e1a2e60e5ec02ee00476530d8c06cb0cf5ef1a20c00c583b81a2a1d1cec2f558 | 0x58 | 01011000 |
| 8 | 0 | 0xd2 | 9ad263ae43881ba28ed7ce1c8d76614d2b21b3756573ad348964cdde6b3ae6df | 0xdf | 11011111 |
| 8 | 1 | 0x85 | 22bd73c565cfab984c8a998ab033d7fbb605bb3d22a5a732051025dc68a5596d | 0x6d | 01101101 |
Written as matrices (row 1 = bit 0, row 2 = bit 1):
$$ SK = \begin{pmatrix} \texttt{3a} & \texttt{91} & \texttt{5c} & \texttt{e7} & \texttt{08} & \texttt{b4} & \texttt{6f} & \texttt{d2} \\ \texttt{7e} & \texttt{13} & \texttt{a9} & \texttt{46} & \texttt{cb} & \texttt{2d} & \texttt{f0} & \texttt{85} \end{pmatrix} $$
$$ PK = \begin{pmatrix} \texttt{0c} & \texttt{bf} & \texttt{95} & \texttt{bc} & \texttt{69} & \texttt{d4} & \texttt{d3} & \texttt{df} \\ \texttt{d0} & \texttt{81} & \texttt{68} & \texttt{7a} & \texttt{c5} & \texttt{61} & \texttt{58} & \texttt{6d} \end{pmatrix} $$
$SK$ is kept secret; $PK$ is published. Size: $2n \times n = 16 \times 8 = 128$ bits each.
Signing the message m = "PQ"
The signature on "PQ" is (0x7e, 0x13, 0x5c, 0xe7, 0xcb, 0xb4, 0x6f, 0x85): for each digest bit, reveal the secret from the matching slot.
Step 1: hash the message.
$$ \mathrm{Keccak256}(\texttt{0x5051}) = \texttt{0c088ee3e597b050\ldots 631edcba49c970c9} $$
(full value: 0c088ee3e597b05023b0a84f6e0823b558a1511cf0624f02631edcba49c970c9)
$$ d = H(m) = \texttt{0xc9} = 1100\,1001_2 $$
Step 2: split the digest into bits (most significant first):
| $i$ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| $d_i$ | 1 | 1 | 0 | 0 | 1 | 0 | 0 | 1 |
Step 3: reveal one secret per position. The rule is
$$ \sigma_i = sk_{i,\,d_i}, \qquad i = 1,\dots,8 $$
$$ \sigma = \mathrm{Sign}(SK, m) = (\sigma_1, \sigma_2, \dots, \sigma_8) $$
Applied to $d = 11001001$:
| $i$ | $d_i$ | Selected secret | $\sigma_i$ |
|---|---|---|---|
| 1 | 1 | $sk_{1,1}$ | 0x7e |
| 2 | 1 | $sk_{2,1}$ | 0x13 |
| 3 | 0 | $sk_{3,0}$ | 0x5c |
| 4 | 0 | $sk_{4,0}$ | 0xe7 |
| 5 | 1 | $sk_{5,1}$ | 0xcb |
| 6 | 0 | $sk_{6,0}$ | 0xb4 |
| 7 | 0 | $sk_{7,0}$ | 0x6f |
| 8 | 1 | $sk_{8,1}$ | 0x85 |
$$ \sigma = (\texttt{7e}, \texttt{13}, \texttt{5c}, \texttt{e7}, \texttt{cb}, \texttt{b4}, \texttt{6f}, \texttt{85}) $$
The signer publishes $(m, \sigma)$. Half of $SK$ is now public; the other half (the unselected slots) stays secret. That exposure is why the key must never sign again: a second signature on a different digest reveals more secrets, and the mix of the two lets an attacker sign new digests. Hash-Based Signature Schemes walks through that attack.
Verification
The verifier accepts: all 8 hashed signature components match the public key in the slots the digest selects.
Inputs: $PK$, the message $m$ = "PQ", the signature $\sigma$. The verifier never sees $SK$.
Step 1: recompute the digest. The verifier hashes $m$ independently: $d = H(\text{"PQ"}) = \texttt{0xc9} = 11001001$.
Step 2: check every position.
$$ \mathrm{Verify}(PK, m, \sigma) = \begin{cases} 1 & \text{if } H(\sigma_i) = pk_{i,\,d_i} \;\; \forall\, i \in \{1,\dots,8\} \\ 0 & \text{otherwise} \end{cases} $$
| $i$ | $d_i$ | $\sigma_i$ | $H(\sigma_i)$ | $pk_{i,d_i}$ | Match |
|---|---|---|---|---|---|
| 1 | 1 | 0x7e | 0xd0 | $pk_{1,1}$ = 0xd0 | ✓ |
| 2 | 1 | 0x13 | 0x81 | $pk_{2,1}$ = 0x81 | ✓ |
| 3 | 0 | 0x5c | 0x95 | $pk_{3,0}$ = 0x95 | ✓ |
| 4 | 0 | 0xe7 | 0xbc | $pk_{4,0}$ = 0xbc | ✓ |
| 5 | 1 | 0xcb | 0xc5 | $pk_{5,1}$ = 0xc5 | ✓ |
| 6 | 0 | 0xb4 | 0xd4 | $pk_{6,0}$ = 0xd4 | ✓ |
| 7 | 0 | 0x6f | 0xd3 | $pk_{7,0}$ = 0xd3 | ✓ |
| 8 | 1 | 0x85 | 0x6d | $pk_{8,1}$ = 0x6d | ✓ |
$$ \mathrm{Verify}(PK, \text{"PQ"}, \sigma) = 1 \quad \text{(accept)} $$
Why this is sound. Producing a valid $\sigma_i$ for a slot whose secret was never revealed means finding a preimage of $pk_{i,b}$ under $H$. Security therefore rests only on preimage resistance of $H$ (plus collision resistance for the message hash). No number-theoretic assumption is used, which is why Lamport is post-quantum: Grover's algorithm only speeds preimage search from $2^n$ to about $2^{n/2}$.
With $n = 8$ this example is of course trivially breakable: there are only 256 possible inputs, so anyone can invert $H$ by trying them all. Real deployments use $n = 256$.