← Back to Cryptography & ZKP notes

Lamport One-Time Signatures: A Worked Example

Post-Quantum Cryptography Hash-Based Signatures Lamport Digital Signatures

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.

SymbolMeaning
$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)
100x3a96d280011b274d9410ea6c6fc28e2bb076b01d2fac329c49c4b29a719ec4650c0x0c00001100
110x7ea28a3f816fdcab5fa5d9e32081c451a5b738cbc6380020cfae2633e4bd78ded00xd011010000
200x9142c246a07c1a207f14480f4d3c8c9fe2e8e851cb168eefb997992ac70ba4e0bf0xbf10111111
210x1362af204a12d42fdc0d1452abd76e3d611b00a98ccdab368ef149b27224b2f2810x8110000001
300x5c731553fa98541ade8b78284229adfe09a819380dee9244baac20dd1e0aa240950x9510010101
310xa96c2e99637a1486db6c2cdcdab56c017faedb132f9b25b3581728fe138c9c88680x6801101000
400xe71e591f1c32712482d7eee6a5127936c1a0f4295a996e228af11b42605d5a81bc0xbc10111100
410x46e61d9a3d3848fb2cdd9a2ab61e2f21a10ea431275aed628a0557f9dee697c37a0x7a01111010
500x08d33e25809fcaa2b6900567812852539da8559dc8b76a7ce3fc5ddd77e8d19a690x6901101001
510xcb6a076a720fa33aaa82d2d04e1769c345d172ef2967ef160f9a899729572b45c50xc511000101
600xb4d98227c7cf5fb8eab709662bbef7b515ab1c1fb48ca0964c893febe2b5c97bd40xd411010100
610x2dd3b8281179950f98149eefdb158d0e1acb56f56e8e343aa9fefafa7e369595610x6101100001
700x6f53a63b3ee437e1aa804722ac8f2f57053ac47e1bb887f095340cf5990e7faad30xd311010011
710xf0e1a2e60e5ec02ee00476530d8c06cb0cf5ef1a20c00c583b81a2a1d1cec2f5580x5801011000
800xd29ad263ae43881ba28ed7ce1c8d76614d2b21b3756573ad348964cdde6b3ae6df0xdf11011111
810x8522bd73c565cfab984c8a998ab033d7fbb605bb3d22a5a732051025dc68a5596d0x6d01101101

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$12345678
$d_i$11001001

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$
11$sk_{1,1}$0x7e
21$sk_{2,1}$0x13
30$sk_{3,0}$0x5c
40$sk_{4,0}$0xe7
51$sk_{5,1}$0xcb
60$sk_{6,0}$0xb4
70$sk_{7,0}$0x6f
81$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
110x7e0xd0$pk_{1,1}$ = 0xd0✓
210x130x81$pk_{2,1}$ = 0x81✓
300x5c0x95$pk_{3,0}$ = 0x95✓
400xe70xbc$pk_{4,0}$ = 0xbc✓
510xcb0xc5$pk_{5,1}$ = 0xc5✓
600xb40xd4$pk_{6,0}$ = 0xd4✓
700x6f0xd3$pk_{7,0}$ = 0xd3✓
810x850x6d$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$.

← Back to Cryptography & ZKP notes