PLAIN QUANTUM
Search

ADVANCED · ML-KEM · 60 MIN

ML-KEM II: Fujisaki-Okamoto, implicit rejection, decryption failure

Terms in this lesson

  • IND-CPA
  • IND-CCA
  • malleable
  • Fujisaki-Okamoto (FO) transform
  • derandomised encryption
  • re-encryption check
  • implicit rejection
  • decapsulation failure
  • failure oracle

What you’ll learn

  • State what IND-CPA and IND-CCA security ask of an encryption scheme or KEM, and show with one changed coefficient that K-PKE on its own is not IND-CCA.
  • Read ML-KEM's encapsulation and decapsulation line by line, and derive why re-encrypting and comparing turns a tampered ciphertext into a useless one.
  • Explain implicit rejection: what decapsulation returns when the check fails, and why it must not say so.
  • Derive the noise term that decides decryption, compute its exact distribution at toy size, and turn it into a failure rate.
  • Say what ML-KEM's stated failure rates mean, and why a failure that an attacker can observe is information about the secret key.

Prerequisites. P3: K-PKE (Algorithms 13–15), the noise w − μ = eTy + e2 − sTe1 (+ compression errors), the decoding windows, and baby Kyber (n = 4, q = 17, k = 2). M-C unit 4 for the centred binomial distribution and for hash functions. Site: What is ML-KEM?.

Notation. As in P3. Because e1 already names a vector, the entries of e and e1 are written e[i] and e1[i]. G, H and J are the hash functions of FIPS 203 §4.1: H(s) = SHA3-256(s) (32 bytes), J(s) = SHAKE256(s, 8 · 32) (32 bytes), G(c) = SHA3-512(c), whose 64-byte output is split into two 32-byte halves, (a, b) ← G(c). ‖ joins byte strings. ek and dk are the encapsulation and decapsulation keys.

1. What K-PKE does not protect against

Two security notions

Both are games between a challenger and an attacker who knows the public key.

  • IND-CPA (indistinguishability under chosen-plaintext attack). The attacker picks two messages m0, m1; the challenger encrypts one of them, chosen by a fair coin b, and hands back the ciphertext c*. The attacker must guess b. The scheme is IND-CPA if no efficient attacker guesses right with probability non-negligibly better than 1/2. The attacker can encrypt anything himself, since the key is public; he cannot decrypt.
  • IND-CCA (under chosen-ciphertext attack). The same game, but the attacker may also ask for the decryption of any ciphertext he likes, except c* itself. For a KEM the game is the same with keys: the challenger sends c* together with either the real key K or a uniformly random 32-byte string, and the attacker, who may ask for the decapsulation of any c ≠ c*, must say which.

IND-CCA is the notion a key-exchange protocol needs: a server that decapsulates whatever ciphertext arrives is, in effect, a decapsulation oracle (gloss: an oracle answers every query of one kind; here, 'decapsulate this ciphertext'). FIPS 203 §3.2 describes K-PKE as a component that is "converted into a key-encapsulation mechanism using the so-called Fujisaki-Okamoto (FO) transform", so that "the resulting KEM provides security in a significantly more general attack model than the PKE scheme".

Derivation: K-PKE is malleable

Malleable means an attacker can change a ciphertext into a valid ciphertext of a related message without knowing the message. In K-PKE, add ⌈q/2⌋ to coefficient i of v and leave u alone. Decryption computes

w′ = v′ − sTu

= (v − sTu) + ⌈q/2⌋ Xi

= w + ⌈q/2⌋ Xi,

so coefficient i moves by ⌈q/2⌋, half-way round the circle of residues, and every other coefficient is unchanged.

  • If bit i was 1, wi = ⌈q/2⌋ + N with N in the bit-1 window, and w′i ≡ 2⌈q/2⌋ + N ≡ 1 + N (q odd). That is in the bit-0 window: the bit becomes 0.
  • If bit i was 0, w′i = ⌈q/2⌋ + N, which decodes to 1 whenever N is also inside the bit-1 window. At q = 3329 the windows are −832 … 832 (bit 0) and −832 … 831 (bit 1, P3 section 2), so the flip fails only at the single extreme value N = 832.

So one added constant flips bit i of the plaintext, with no knowledge of s or m.

In baby Kyber (P3 section 5; ⌈17/2⌋ = 9): the ciphertext of m = (1, 0, 1, 1) has v = (5, 9, 3, 13). Change it to v′ = (14, 9, 3, 13). Decryption gives w′ = (16, 14, 8, 6) instead of (7, 14, 8, 6), and 16 decodes to 0: the plaintext is now (0, 0, 1, 1). Figure 1 shows why.

Half a turn flips the bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 +9 half a turn decodes to 0 decodes to 1 w0 = 7 → 1 w′0 = 16 → 0 Half a turn flips the bit 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 +9 half a turn decodes to 1 decodes to 0 w0 = 7 → 1 w′0 = 16 → 0
Figure 1. Half a turn flips the bit (baby Kyber, q = 17). Decryption reads which arc w lands in: 5 to 12 means 1, anything else 0. The honest ciphertext gives w0 = 7, a 1. Adding ⌈17/2⌋ = 9 to v0 moves w0 nine steps round the circle, a little more than half a turn, to 16: now it decodes to 0. No key and no knowledge of m were needed.

Why this breaks IND-CCA. Take the challenge c* = (u, v), flip the first bit of the plaintext (add ⌈q/2⌋ to v0) to get c′ ≠ c*, and ask for the decryption of c′. The answer is m with its first bit flipped; flip it back and you have m. One query recovers the whole message, so the attacker wins the IND-CCA game with probability 1 (or, at q = 3329, with probability at least 1 minus the chance that one noise coefficient equals exactly 832). IND-CPA is not affected: without a decryption oracle the flipped ciphertext is useless.

Pause and recall optional

Which game lets the attacker ask for decryptions?

Show answer

IND-CCA, for any ciphertext except the challenge.

What does adding ⌈q/2⌋ to one coefficient of v do to the plaintext?

Show answer

It flips that bit, almost always.

2. The Fujisaki-Okamoto transform in ML-KEM

The FO transform (Fujisaki and Okamoto, CRYPTO 1999) and its later variants turn a public-key scheme with only chosen-plaintext security, such as K-PKE, into one secure against chosen-ciphertext attacks in the random oracle model (gloss: a proof model in which the hash functions are treated as truly random functions). ML-KEM uses one variant of it (FIPS 203 Appendix C.1 lists the FO variant among the differences between ML-KEM and the CRYSTALS-KYBER submission). It has three ingredients.

  1. Derandomised encryption. The sender does not pick y, e1, e2 freely. He picks a random 32-byte m, and the randomness r for K-PKE is derived from m by hashing. Encryption with a given r is deterministic, so anyone who knows m and ek can recompute the exact ciphertext.
  2. Re-encryption check. The receiver decrypts, recomputes r from the decrypted message, encrypts again, and accepts only if the result is byte-for-byte the ciphertext received.
  3. Implicit rejection (section 3): if the check fails, the receiver returns a pseudorandom key instead of an error.

Line by line (FIPS 203 §6, Algorithms 17 and 18)

Algorithm 17, ML-KEM.Encaps_internal(ek, m):

LineFIPS 203 (verbatim)
1(K, r) ← G(m‖H(ek)) ▷ derive shared secret key K and randomness r
2c ← K-PKE.Encrypt(ek, m, r) ▷ encrypt m using K-PKE with randomness r
3return (K, c)

The public algorithm ML-KEM.Encaps (Algorithm 20, §7) draws m as 32 random bytes and calls this; ML-KEM.Decaps (Algorithm 21) calls Algorithm 18 on checked inputs.

Algorithm 18, ML-KEM.Decaps_internal(dk, c):

LineFIPS 203 (verbatim)
1dkPKE ← dk[0 : 384k] ▷ extract (from KEM decaps key) the PKE decryption key
2ekPKE ← dk[384k : 768k + 32] ▷ extract PKE encryption key
3h ← dk[768k + 32 : 768k + 64] ▷ extract hash of PKE encryption key
4z ← dk[768k + 64 : 768k + 96] ▷ extract implicit rejection value
5m′ ← K-PKE.Decrypt(dkPKE, c) ▷ decrypt ciphertext
6(K′, r′) ← G(m′‖h)
7K̄ ← J(z‖c)
8c′ ← K-PKE.Encrypt(ekPKE, m′, r′) ▷ re-encrypt using the derived randomness r′
9if c ≠ c′ then
10K′ ← K̄ ▷ if ciphertexts do not match, "implicitly reject"
11end if
12return K′

Figure 2 draws Algorithm 18 as a flow.

Decapsulation: one loop, one branch Decrypt line 5 G(m′||h) line 6 Encrypt line 8 c m′ r′ c′ = c ? line 9 c′ the received c K′ line 6 K = J(z||c) lines 7, 10 yes no error either way, a 32-byte key Decapsulation: one loop, one branch Decrypt line 5 G(m′||h) line 6 Encrypt line 8 c m′ r′ c′ = c ? line 9 c′ the received c K′ line 6 K = J(z||c) lines 7, 10 yes no either way, a 32-byte key no error is ever returned
Figure 2. Algorithm 18 as a flow. Decapsulation decrypts c, derives r′ (and K′) from m′ by G, encrypts m′ again and compares the result c′ with the c it received. Only a ciphertext that the re-encryption reproduces byte for byte gets K′; any other gets K̄ = J(z‖c). Both answers are 32-byte keys of the same shape, and no error is returned (section 3).

Derivation: why the decapsulation key holds what it holds

Read off Algorithm 18. Line 5 needs the K-PKE secret dkPKE (384k bytes). Line 8 re-encrypts, so it needs the K-PKE public key ekPKE = ek (384k + 32 bytes). Line 6 must hash m′ together with the same H(ek) that the sender used in Algorithm 17, line 1; storing h (32 bytes) saves hashing ek on every call. Line 7 needs the secret z (32 bytes). So

|dk| = 384k + (384k + 32) + 32 + 32

= 768k + 96 bytes: 1,632,

2,400 and 3,168 for k = 2, 3, 4,

These are the sizes in FIPS 203 Table 3, and the four parts, in this order, are the layout dk = dkPKE ‖ ek ‖ H(ek) ‖ z of Algorithm 16 (§6.1). This answers P3's exercise H2.

Derivation: what the check buys

Suppose decapsulation returns K′ from line 6 (the check passed). Then c = K-PKE.Encrypt(ek, m′, r′) with (K′, r′) = G(m′‖h): c is exactly the honest encapsulation of m′. Anyone can produce such a ciphertext only by choosing m′ and computing G(m′‖h), and whoever did that already knows K′. So an answer that passes the check tells the attacker nothing he did not know. Every other ciphertext, including every modified version of c*, fails the check, and its answer is K̄ = J(z‖c), which depends on the secret z and looks random to anyone who does not know z.

This is the intuition. The security theorems make it precise. Hofheinz, Hövelmanns and Kiltz (TCC 2017) analyse FO-type transformations, including a KEM with implicit rejection, in the random oracle model; their quantum random oracle results (gloss: the same model with an attacker who can query the hash functions in superposition) are for variants that add an extra hash to the ciphertext, which ML-KEM does not have. Jiang, Zhang, Chen, Wang and Ma (CRYPTO 2018) prove two FO transformations with implicit rejection and no extra hash secure in the quantum random oracle model, assuming only that the encryption scheme is one-way against chosen-plaintext attacks (given the encryption of a random m, an attacker cannot recover m). In one of them the key is a hash of m alone and a rejected ciphertext gets a pseudorandom key computed from c, the shape of Algorithms 17 and 18; ML-KEM differs in that it also feeds H(ek) into G, and this lesson does not say which published result covers ML-KEM's exact variant. Both papers' bounds carry a term for the scheme's decryption error, so the proofs hold only if failures are rare (section 4).

Worked example: toy ML-KEM on baby Kyber

Take P3's baby Kyber key and replace ML-KEM's encodings by simple stand-ins: ek is the coefficient bytes of t and A, m is 4 bits in one byte padded to 32, and r is expanded into the 20 small coefficients of y, e1, e2 by SHAKE256 and the coin-minus-coin rule of CBD1. G, H and J are the real FIPS 203 functions. The code below runs Algorithms 17 and 18 on three ciphertexts:

  • valid: the encapsulation of m = (1, 1, 0, 1). Decapsulation returns the sender's key.
  • bit-flip: the same ciphertext with ⌈q/2⌋ = 9 added to v0 (section 1). K-PKE decrypts it to m′ = (0, 1, 0, 1). G(m′‖h) gives new randomness, the re-encryption is a different ciphertext, and decapsulation implicitly rejects. The attacker's flipped ciphertext now returns a key unrelated to m or to K.
  • small u: the valid ciphertext with 1 added to the first coefficient of u0. Here K-PKE still decrypts to m′ = m, because the change moves w by only a small amount. The re-encryption is therefore the original ciphertext, which differs from the one received in that coefficient, and decapsulation rejects again. The check rejects every change to c, not only those that change the plaintext.
import hashlib
q, n, HALF = 17, 4, 9                       # baby Kyber of P3; Decompress_1(1) = 9
def mul(a, b):                              # product in Z_q[X]/(X^4 + 1)
    r = [0] * n
    for i in range(n):
        for j in range(n):
            if i + j < n: r[i + j] += a[i] * b[j]
            else:         r[i + j - n] -= a[i] * b[j]
    return [x % q for x in r]
add = lambda *p: [sum(c) % q for c in zip(*p)]
A = [[[10, 4, 12, 1], [2, 3, 11, 1]], [[16, 6, 1, 2], [13, 13, 2, 7]]]
s = [[-1, 1, 0, -1], [1, -1, -1, 1]]; e = [[1, 1, -1, 1], [1, 0, -1, -1]]
t = [add(mul(A[i][0], s[0]), mul(A[i][1], s[1]), e[i]) for i in range(2)]
G = lambda b: hashlib.sha3_512(b).digest()          # as FIPS 203 §4.1
H = lambda b: hashlib.sha3_256(b).digest()
J = lambda b: hashlib.shake_256(b).digest(32)
ek = bytes(x for p in t for x in p) + bytes(x for row in A for p in row for x in p)
h, z = H(ek), hashlib.sha3_256(b"P4 toy z").digest()
def small(r):                               # toy stand-in for the PRF and CBD_1
    st = hashlib.shake_256(r).digest(40)
    b = [(st[i // 8] >> (i % 8)) & 1 for i in range(40)]
    v = [b[2 * i] - b[2 * i + 1] for i in range(20)]
    return [v[0:4], v[4:8]], [v[8:12], v[12:16]], v[16:20]
def encrypt(m, r):                          # K-PKE.Encrypt, no compression
    y, e1, e2 = small(r)
    u = [add(mul(A[0][j], y[0]), mul(A[1][j], y[1]), e1[j]) for j in range(2)]
    v = add(mul(t[0], y[0]), mul(t[1], y[1]), e2, [HALF * x for x in m])
    return u, v
def decrypt(u, v):                          # K-PKE.Decrypt
    w = [(a - b) % q for a, b in zip(v, add(mul(s[0], u[0]), mul(s[1], u[1])))]
    return [1 if q / 4 < x < 3 * q / 4 else 0 for x in w]
mb = lambda m: bytes([m[0] + 2 * m[1] + 4 * m[2] + 8 * m[3]]) + bytes(31)
cb = lambda c: bytes(c[0][0] + c[0][1] + c[1])
def encaps(m):                              # Algorithm 17
    g = G(mb(m) + h); return g[:32], encrypt(m, g[32:])
def decaps(c):                              # Algorithm 18
    m2 = decrypt(*c); g = G(mb(m2) + h)
    reject = cb(encrypt(m2, g[32:])) != cb(c)
    return (J(z + cb(c)) if reject else g[:32]), reject, m2
K, c = encaps([1, 1, 0, 1])
K2, rej, _ = decaps(c)
print("valid:    rejected = %s, same key = %s" % (rej, K2 == K))
u, v = c; flipped = (u, [(v[0] + HALF) % q] + v[1:])
print("bit-flip: rejected = %s, m' = %s" % decaps(flipped)[1:])
nudged = ([[(u[0][0] + 1) % q] + u[0][1:], u[1]], v)
print("small u:  rejected = %s, m' = %s" % decaps(nudged)[1:])

Output:

valid:    rejected = False, same key = True
bit-flip: rejected = True, m' = [0, 1, 0, 1]
small u:  rejected = True, m' = [1, 1, 0, 1]
Pause and recall optional

Where does K-PKE's randomness r come from in ML-KEM?

Show answer

The second half of G(m‖H(ek)).

What four parts make up dk, and which line of Algorithm 18 needs each?

Show answer

dkPKE: line 5; ek: line 8; h: line 6; z: line 7.

3. Implicit rejection

When the check fails, ML-KEM does not return an error. Line 10 replaces K′ by K̄ = J(z‖c), a hash of the ciphertext with the secret 32-byte value z stored in dk. FIPS 203 §3.2 says decapsulation "will never explicitly fail, meaning that both ML-KEM.Encaps and ML-KEM.Decaps will each output a 256-bit value" (for inputs that pass the input checks of §7.2 and §7.3). §6.3 adds that the "implicit reject" flag computed in line 9 "is a secret piece of intermediate data", and that returning it "as an output in any form is not permitted".

Why not return an error? An error message turns decapsulation into a failure oracle: it says, for any ciphertext the attacker submits, whether it passed the check. Section 4 shows that an honest ciphertext can still fail to decrypt, and section 5 that whether it fails depends on the secrets s and e. An oracle that reports failures leaks information about them; implicit rejection removes the report. With implicit rejection the two parties simply end up with different keys, and the protocol above the KEM (for example the TLS handshake of P9) fails at its next authenticated step, without saying why. The same reasoning is why the flag must not leak through timing either: the comparison in line 9 and the choice in line 10 must take the same time whatever the outcome (P10).

Pause and recall optional

What does decapsulation return when the check fails?

Show answer

K̄ = J(z‖c).

May an implementation report the failure?

Show answer

No: FIPS 203 §6.3 forbids outputting the flag in any form.

4. Decryption failure

Derivation: the noise, again

P3 section 2 derived what decryption computes. Without compression,

w − μ = eTy + e2 − sTe1,

and with compression two more terms appear, cv − sTcu, where cu and cv are the rounding errors of u and v. Bit i decodes correctly exactly when coefficient i of this noise lies in its window (P3: −832 … 832 for a 0 and −832 … 831 for a 1 at q = 3329). If any of the 256 coefficients falls outside, K-PKE returns m′ ≠ m.

Under FO a decryption failure becomes a decapsulation failure, the event FIPS 203 §3.2 names: "The event that K′ ≠ K under these conditions is called a decapsulation failure" (gloss: honest keys from key generation and a ciphertext from an honest encapsulation). The receiver decrypts m′ ≠ m, so G(m′‖h) gives different randomness, the re-encryption differs from c, and line 10 returns K̄. The ciphertext was honest; the parties still disagree on the key.

In the toy. With P3's key, the honest encapsulation of m = (1, 0, 1, 1) (its randomness now comes from G, so this is not P3's ciphertext of the same message from section 1, which decrypts correctly) has noise (4, 4, −2, 3). Coefficient 0 carries a 1 with noise +4, outside the bit-1 window −4 … 3 at q = 17, so it decodes to 0 and decapsulation returns J(z‖c) instead of the sender's key. For this key, 4 of the 16 possible messages fail.

Derivation: the exact distribution of one noise coefficient

In baby Kyber every small value is drawn from CBD1: −1, 0, 1 with probabilities 1/4, 1/2, 1/4. Coefficient i of e[0]·y0 is a signed sum of 4 products of one coefficient of e[0] and one of y0 (the negacyclic rule only flips signs), and each coefficient of e[0] and of y0 appears in exactly one of them. The same holds for e[1]·y1, s0·e1[0] and s1·e1[1]. So one noise coefficient is a sum of 16 independent products of two CBD1 values, plus one CBD1 value (e2). A product xy is ±1 when both are non-zero:

P(xy = 1) = P(xy = −1)

= 2 · (1/4)(1/4)

= 1/8,

P(xy = 0) = 3/4.

Each product has variance 1/4 and e2 has variance 1/2, so the noise has variance 16 · 1/4 + 1/2 = 9/2 and lies in −17 … 17. Convolving the 17 distributions gives the exact distribution, and from it the probability that one coefficient decodes wrongly:

q⌈q/2⌋bit 0 correct iff N inbit 1 correct iff N inP(one coefficient fails), random bitper message (4 bits), if the bits were independentsimulated, 1 message = 4 bits
179−4 … 4−4 … 30.04850.18035,362 / 200,000 = 0.177
4121−10 … 10−10 … 92.9 × 10−61.2 × 10−57 / 1,000,000
9749−24 … 24−24 … 2300—

Three things to read off:

  • q = 97 cannot fail. The noise never exceeds 17 in size, and 17 < 97/4. Failure is impossible, not merely unseen.
  • A 1 fails more often than a 0. ⌈q/2⌋ sits half a step above the midpoint q/2, so the bit-1 window is one value shorter on the positive side. At q = 17 the per-coefficient failure is 0.0328 for a 0 and 0.0643 for a 1.
  • The independence column is an approximation. The four coefficients of one message share s, e, y and e1, so their failures are not independent. At q = 17 the simulation (seed 2611; standard error 0.0009) sits about 4 standard errors below 0.180, so the dependence is visible; the approximation is still the right size.

Figure 3 draws the q = 17 row: the noise against both windows.

The noise against the windows a 0 is sent fails 0.0328 window −4 … 4 −8 −4 0 4 8 a 1 is sent fails 0.0643 window −4 … 3 0.0315 −8 −4 0 4 8 N, one noise coefficient, q = 17 The noise against the windows a 0 is sent fails 0.0328 window −4 … 4 −8 −4 0 4 8 a 1 is sent fails 0.0643 window −4 … 3 0.0315 −8 −4 0 4 8 N, one noise coefficient, q = 17
Figure 3. The exact distribution of one noise coefficient N in baby Kyber (variance 9/2), bars to scale, against the decoding windows at q = 17. Bars outside the shaded window are failures. A 0 sent at 0 fails when N is outside −4 … 4, with chance 0.0328. A 1 sent at 9 has the window −4 … 3, one value shorter, so N = 4 (0.0315) fails too: 0.0643. Values beyond ±8 together have a chance below 1 in 10,000.

The trade-off is the one P1 described: larger errors make the lattice problem harder and failures more likely. A larger q makes failures rarer for the same errors, but at the same dimension it also makes the problem easier, because the errors are then smaller compared with q. In ML-KEM the failure probability is a design parameter, set together with q, η1, η2, du and dv.

What ML-KEM states

FIPS 203 §3.2, Table 1, gives the decapsulation failure rates: 2−138.8 (ML-KEM-512), 2−164.8 (ML-KEM-768), 2−174.8 (ML-KEM-1024). They are stated "under the heuristic assumption that hash functions and XOFs behave like uniformly random functions", and FIPS 203 refers to Theorem 1 of Bos et al. (2018) and to the Kyber security-estimate scripts for the computation. They are far too small to measure by sampling (P3 exercise H1); they are computed from the noise distribution, as the table above is at toy size.

Pause and recall optional

Why can baby Kyber at q = 97 never fail?

Show answer

The noise is at most 17 in size, and 17 < 97/4.

Why does a 1 fail more often than a 0?

Show answer

⌈q/2⌋ is half a step above q/2, so the bit-1 window is one value shorter.

5. Why a visible failure is dangerous

Look at the noise again: eTy + e2 − sTe1. The receiver's secrets s and e enter linearly, multiplied by the sender's y and e1. A ciphertext fails when this sum is large in some coefficient, which is more likely when y happens to line up with e, or e1 with s (up to sign). So each observed failure says something about the direction of (s, e); many of them, collected, narrow it down. D'Anvers, Guo, Johansson, Nilsson, Vercauteren and Verbauwhede (PKC 2019) describe "a generic framework for secret key recovery based on decryption failures" against IND-CCA lattice schemes, and conclude that "an attacker could significantly reduce the security of lattice based schemes that have a relatively high failure rate", while "for most of the NIST Post-Quantum Proposals, the number of required oracle queries is above practical limits".

Two features of ML-KEM keep this attack out of reach.

  • FO takes the choice of y and e1 away from the attacker. They come from G(m‖H(ek)). The attacker can only try many m and keep those whose y and e1 are large, paying one hash evaluation per try (exercise H1 measures what that buys at toy size).
  • The rates are tiny. At 2−138.8, even 264 honest encapsulations under one key are expected to produce 264 · 2−138.8 = 2−74.8 failures (exercise H2).

And implicit rejection means a failure is not announced: the attacker sees at most that a later protocol step failed.

Pause and recall optional

Who chooses y and e1 in ML-KEM?

Show answer

Nobody directly: they are derived from G(m‖H(ek)), so an attacker can only try many m.

How many failures do 264 honest ML-KEM-512 encapsulations produce on average?

Show answer

2−74.8.

Exercises

All use baby Kyber (P3 section 5) and the toy ML-KEM of section 2 unless stated. Try each before opening its solution.

Easy

E1. The valid toy ciphertext for m = (1, 1, 0, 1) has u0 = (14, 1, 11, 10), u1 = (14, 9, 2, 16), v = (7, 7, 0, 16). An attacker sends ca with u0 = (15, 1, 11, 10) and the rest unchanged. Walk through Algorithm 18 for c and for ca: which line first differs, what does each return, and what does the attacker learn?

Show solution, E1

For c: line 5 gives m′ = (1, 1, 0, 1) = m; line 6 gives the sender's (K, r); line 8 re-encrypts to c itself; line 9 finds c = c′ and line 12 returns K. For the tampered ca: line 5 still gives m′ = (1, 1, 0, 1) (the change of 1 in u0 moves w by a small amount, inside the windows), so lines 6 and 8 produce the same r and the same re-encryption as before, which is the original c with 14 in that coefficient. Line 9 compares it with the received ca, which has 15: they differ, so line 10 sets K′ = J(z‖ca). Before line 9 only line 7 gives a different value, because K̄ hashes the received ciphertext; that value is used only if the check fails. Line 9 is the first line whose outcome differs. The attacker learns nothing: the key returned for ca depends on z, which he does not know, and is unrelated to K.

Easy

E2. Using section 1's derivation, give the plaintext of the baby-Kyber ciphertext (u, v′) with v′ = (5, 1, 3, 13), where (u, v) encrypts (1, 0, 1, 1) and w = (7, 14, 8, 6). (Hint: which coefficient of v changed, and by how much?)

Show solution, E2

v′ − v = (0, 1 − 9, 0, 0) ≡ (0, 9, 0, 0): ⌈17/2⌋ = 9 was added to coefficient 1. So w′ = w + 9X = (7, 14 + 9, 8, 6) ≡ (7, 6, 8, 6), and 6 decodes to 1. Coefficient 1 carried a 0 with noise −3, which lies inside the bit-1 window −4 … 3, so it now decodes to 1: the plaintext is (1, 1, 1, 1).

Medium

M1. A developer changes line 10 to "return ⊥ (error)". Explain, using sections 3 and 5, what an attacker gains, and what FIPS 203 says about it.

Show solution, M1

The error turns decapsulation into a failure oracle: for any submitted ciphertext the attacker learns whether it passed the re-encryption check. Honest-looking ciphertexts that fail to decrypt are exactly the ones that fail the check, and failures correlate with the secret (section 5), so the oracle reports key-dependent events. FIPS 203 §3.2 says decapsulation "will never explicitly fail" (for inputs that pass the checks of §7.3), and §6.3 that the implicit-reject flag is secret and that returning it "as an output in any form is not permitted". The same holds for any side channel that reveals it, such as timing (P10).

Medium

M2. At q = 41, compute from the exact noise distribution the per-coefficient failure probability for a 0, for a 1, and for a random bit. Turn it into a per-message figure under the independence approximation, compare it with the simulation (7 failures in 1,000,000), and say why the per-message figure needs either the approximation or a simulation.

Show solution, M2

Windows at q = 41 (⌈41/2⌋ = 21): a 0 is correct iff −10 ≤ N ≤ 10, a 1 iff −10 ≤ N ≤ 9. From the exact distribution: P(fail | 0) = P(|N| ≥ 11) = 9.2 × 10−7; P(fail | 1) = P(N ≥ 10 or N ≤ −11) = 4.9 × 10−6; random bit: 2.9 × 10−6. Per message of 4 bits, if independent: 1 − (1 − 2.9 × 10−6)4 ≈ 1.2 × 10−5. The simulation's 7 in 1,000,000 (7 × 10−6, with a standard error of about 2.6 × 10−6) is of that size. The per-message figure is not a product of four independent probabilities because the four coefficients share s, e, y and e1; computing it exactly means summing over the joint distribution of all 20 small coefficients and the key, so in practice it is approximated or simulated.

Medium

M3. Why must K-PKE.Encrypt be deterministic once r is fixed? What would go wrong in Algorithm 18 if it drew fresh randomness inside?

Show solution, M3

Line 8 must reproduce the sender's ciphertext byte for byte from m′ and r′ alone. If encryption drew fresh randomness, the re-encryption of an honest ciphertext would almost never equal it, so every honest ciphertext would be rejected. Determinism given r, and r = G(m‖H(ek)) on both sides, is what makes the comparison meaningful.

Hard

H1. (a) Sketch how an attacker with a failure oracle could recover information about s, and what FO forces him to do to raise his chances. (b) At q = 41, call a toy ciphertext "heavy" if every one of the 20 coefficients of y, e1 and e2 is non-zero. Compute the noise variance and the per-coefficient failure probability (random bit) for heavy ciphertexts, compare with section 4, and give the probability that a random m yields a heavy ciphertext.

Show solution, H1

(a) A ciphertext fails when a coefficient of eTy + e2 − sTe1 is large. For chosen y and e1, whether that happens depends on (s, e): failures are more likely when y and e1 point in directions correlated with e and s. An attacker who observes failures can collect the (y, e1) of failing ciphertexts and use them to estimate the direction of (s, e); D'Anvers et al. (2019) give a general framework for this. Under FO he cannot choose y and e1: they come from G(m‖H(ek)). He can only try many m, compute the resulting y and e1, and submit those with large coefficients, at the cost of one hash evaluation per try.

(b) If every coefficient of y and e1 is ±1, each product e·y or s·e1 is ±1 with probability 1/4 each and 0 with probability 1/2, so it has variance 1/2; e2 is ±1 with variance 1. Total variance 16 · 1/2 + 1 = 9, twice the 9/2 of section 4. The exact per-coefficient failure at q = 41 is then 4.8 × 10−4 for a random bit, about 168 times the 2.9 × 10−6 of a random ciphertext. A random m gives a heavy ciphertext with probability (1/2)20 = 2−20 ≈ 9.5 × 10−7, since each of the 20 coefficients is non-zero with probability 1/2. So the attacker pays about a million hash evaluations per heavy ciphertext to raise its failure chance about 168-fold: the toy version of the trade-off that real failure attacks face.

Hard

H2. Show that ML-KEM-512's stated rate rules out a practical failure attack using honest encapsulations: compute the expected number of decapsulation failures over 264 honest encapsulations under one key. Do the same for ML-KEM-768.

Show solution, H2

Expected failures = number of encapsulations × failure rate = 264 · 2−138.8 = 2−74.8 ≈ 3.0 × 10−23 for ML-KEM-512, and 264 · 2−164.8 = 2−100.8 for ML-KEM-768. Even an attacker who could watch 264 honest exchanges under one key would expect to see no failure at all.

What this lesson does not cover

The security proofs of the FO transform (stated and cited, not proved); the exact differences between ML-KEM's FO variant and the Kyber submission's (FIPS 203 Appendix C); the full computation of ML-KEM's failure rates, with compression errors and the real distributions CBD2 and CBD3 (cited); concrete failure-boosting attacks and their costs; input checking of ek and dk (FIPS 203 §7.2–7.3, which ML-KEM.Encaps and ML-KEM.Decaps require); constant-time implementation of the check (P10). Where the real difficulty lies: in making the check apply to every ciphertext while keeping its outcome secret. Every ciphertext must be decrypted, re-encrypted and compared, and the outcome must stay secret in the output, the timing and the error handling; one leak turns rare decryption failures into a key-recovery oracle.

Sources

  • Section 1. NIST FIPS 203, Module-Lattice-Based Key-Encapsulation Mechanism Standard, 13 August 2024, https://doi.org/10.6028/NIST.FIPS.203: §3.2 (the FO sentence and "a significantly more general attack model"). E. Fujisaki and T. Okamoto, "Secure integration of asymmetric and symmetric encryption schemes", CRYPTO '99, LNCS 1666, pp. 537–554, https://doi.org/10.1007/3-540-48405-1_34 (abstract: a conversion giving "indistinguishability against adaptive chosen-ciphertext attacks in the random oracle model").
  • Section 2. FIPS 203 §4.1 (G, H, J); §6.1 Algorithm 16 (dk layout); §6 Algorithms 17 and 18 and the §6.3 discussion; §7 Algorithms 19–21; §8 Table 3 (dk sizes); Appendix C.1 (FO variant). D. Hofheinz, K. Hövelmanns and E. Kiltz, "A modular analysis of the Fujisaki-Okamoto transformation", TCC 2017, https://doi.org/10.1007/978-3-319-70500-2_12; IACR ePrint 2017/604 (revised 2 November 2021): §1.1.1 and §3.2.2 (the KEM with implicit rejection), §2.1 (δ-correctness), §4 (quantum random oracle model: transformation T and the two QUm transformations, with explicit and with implicit rejection, whose ciphertexts carry the extra hash d = H′(m)). H. Jiang, Z. Zhang, L. Chen, H. Wang and Z. Ma, "IND-CCA-secure key encapsulation mechanism in the quantum random oracle model, revisited", CRYPTO 2018, https://doi.org/10.1007/978-3-319-96878-0_4; IACR ePrint 2017/1096 (last revised 3 July 2019): abstract; §1.1; §3, Figs. 3 and 4 (KEM-I with K = H(m, c), KEM-II with K = H(m) and rejection key f(k, c)), Theorems 1 and 2 (OW-CPA and δ-correct PKE to IND-CCA KEM in the quantum random oracle model).
  • Section 3. FIPS 203 §3.2 ("will never explicitly fail"), §6.1 and §6.3 (implicit rejection; the flag is secret and must not be output).
  • Section 4. FIPS 203 §3.2 (definition of decapsulation failure; Table 1 and its heuristic assumption), citing J. Bos, L. Ducas, E. Kiltz, T. Lepoint, V. Lyubashevsky, J. M. Schanck, P. Schwabe, G. Seiler, D. Stehlé, "CRYSTALS-Kyber: a CCA-secure module-lattice-based KEM", IEEE EuroS&P 2018, Theorem 1, https://doi.org/10.1109/EuroSP.2018.00032, and L. Ducas and J. Schanck, security-estimate scripts for Kyber and Dilithium (2021).
  • Section 5. J.-P. D'Anvers, Q. Guo, T. Johansson, A. Nilsson, F. Vercauteren and I. Verbauwhede, "Decryption failure attacks on IND-CCA secure lattice-based schemes", PKC 2019, LNCS 11443, pp. 565–598, https://doi.org/10.1007/978-3-030-17259-6_19 (abstract).
  • Every number, every hand step and every exercise answer is checked by this lesson's code; the code block above runs as printed.
Next in the advanced track

P5 · ML-DSA: Fiat-Shamir with aborts (coming soon)