Chapter 5ML-KEM

Key Generation

August 25, 20264 min readbeginner

Module-LWE hands us a trapdoor almost directly, and key generation is mostly that observation plus engineering.

Module-LWE hands us a trapdoor almost directly, and key generation is mostly that observation plus engineering.

Pick a uniform matrix A∈Rqk×kA \in R_q^{k \times k} and a short secret vector s∈Rqk\mathbf{s} \in R_q^k. Compute

t  =  As+e\mathbf{t} \;=\; A\mathbf{s} + \mathbf{e}

with a short error e\mathbf{e}. The Module-LWE assumption from Chapter 4 says the pair (A,t)(A, \mathbf{t}) is indistinguishable from uniform to any polynomial-time attacker, classical or quantum. So (A,t)(A, \mathbf{t}) is a public key, and s\mathbf{s} is the trapdoor.

Everything below is the practical version of that.

01.The steps

K1. Derive two seeds. Start from 32 random bytes dd and hash:

(ρ,σ)  =  G(d),(\rho, \sigma) \;=\; G(d),

where GG is SHA3-512, whose 64 output bytes split into two 32-byte halves. The first seed ρ\rho will produce the matrix, the second σ\sigma will produce the secret and error.

K2. Expand ρ\rho into AA. Feed ρ\rho into SHAKE128, an extendable output function that produces an arbitrarily long pseudorandom byte stream, and rejection-sample that stream into elements of Zq\mathbb{Z}_q. The result is a matrix AA whose k2k^2 ring elements are uniform over RqR_q.

Rejection sampling is needed because the stream produces 12-bit values in [0,4095][0, 4095] and only those below q=3329q = 3329 are usable. Values at or above qq are discarded rather than reduced, because reducing would make small residues more likely than large ones and the matrix would not be uniform. The cost is that roughly one in five candidates is thrown away.

The important property is that this is deterministic. Anybody holding ρ\rho reconstructs exactly the same AA.

That is worth a moment, because it is the first of several "regenerate rather than transmit" decisions. Storing AA outright would cost k2⋅n⋅12/8k^2 \cdot n \cdot 12 / 8 bytes, which at k=3k = 3 is 34563456 bytes. Storing ρ\rho costs 3232. The matrix travels as a seed and is rebuilt at both ends.

K3. Sample s\mathbf{s} and e\mathbf{e}. From σ\sigma, draw every coefficient of both vectors from the centred binomial distribution CBDη1\text{CBD}_{\eta_1} described in Chapter 3. For η1=2\eta_1 = 2 each coefficient is

a1+a2−b1−b2a_1 + a_2 - b_1 - b_2

with the four values independent uniform bits, giving a small symmetric distribution on {−2,−1,0,1,2}\{-2, -1, 0, 1, 2\} peaked at zero.

Both vectors are short. That is what makes s\mathbf{s} usable as a trapdoor, and it is why the scheme is a lattice scheme rather than linear algebra.

K4. Compute t=As+e\mathbf{t} = A\mathbf{s} + \mathbf{e}. This is k2k^2 ring multiplications, and they are done in the NTT domain using Chapter 4's transform. Both AA and t\mathbf{t} are kept in NTT domain afterwards.

K5. Serialise.

pk  =  (ρ,  t^),sk  =  s^,pk \;=\; (\rho,\; \hat{\mathbf{t}}), \qquad sk \;=\; \hat{\mathbf{s}},

where the hat marks NTT representation.

For k=3k = 3 that gives a public key of 32+3⋅384=118432 + 3 \cdot 384 = 1184 bytes, and a secret key of 11521152 bytes for the encryption layer, which the wrapper in The Fujisaki-Okamoto Wrapper later extends.

02.Why the public key is stored transformed

Step K4 said AA and t\mathbf{t} stay in the NTT domain, and FIPS 203 specifies the public key that way on the wire. That is not an implementation detail, it is part of the standard.

The reason is that the public key is used repeatedly. Every client that ever connects to Bob runs encryption against the same pkpk, and encryption needs AA and t\mathbf{t} in transformed form. If the key were stored in coefficient form, every client would begin by performing k2+kk^2 + k forward transforms that produce the same result every time.

Storing it transformed removes all of them. It is the pattern flagged in Chapter 4: keep data in the NTT domain as long as possible, and let the transform boundaries fall where data genuinely enters or leaves.

There is a small cost. The transformed representation is not compressible in the way the coefficient form would be, which is part of why public keys are not compressed while ciphertexts are. Compression and Ciphertext Size returns to that.

03.Where the security sits

Restating what an attacker faces after key generation.

They see ρ\rho, from which they can reconstruct AA exactly. They see t^\hat{\mathbf{t}}. They want s\mathbf{s}.

That is precisely a Module-LWE instance: recover the short secret from (A,As+e)(A, A\mathbf{s} + \mathbf{e}). By the assumption, and via Regev's reduction behind it, doing so is at least as hard as approximating the shortest vector in a lattice of dimension k⋅256k \cdot 256.

Nothing about publishing ρ\rho helps them, because AA was never secret. The secret is s\mathbf{s}, and it is hidden by e\mathbf{e}.

FeedbackBook mode
post-quantum-cryptographycryptographymathematics