Nonce-based counter mode and Theorem 5.6 #
Nonce-based counter mode ([BS23], Section 5.5.2, printed pp. 203–204) recasts the
randomized counter-mode cipher of Section 5.4.2 (ctrWordKeystream in
CslibFrontier.Crypto.Computational.Encryption.CTRMode.Uniform) to encrypt a sequence of n-bit
blocks m[0], …, m[v - 1] under an n-bit PRF key k and a unique nonce N with zero ciphertext
expansion. Both variants below share the deterministic constructor nonceStreamCipher family n toIV
and differ only in the nonce-to-initial-counter map toIV:
- As [BS23] observes on printed p. 203, using the nonce directly as the initial counter
x := N(unscaledNonceCTRCipher,nonce ↦ nonce) fails for multi-block messages because two distinct nonces can yield overlapping counter intervals{x₁, …, x₁ + ℓ - 1}and{x₂, …, x₂ + ℓ - 1}and reuse keystream bits (for instance, in our concrete attack below, nonces0and1on 2-block messages both evaluateF(k, 1)). - Instead, when
ℓ = 2 ^ (n - s)divides2 ^ n(s ≤ n), the nonce space has size2 ^ n / ℓ = 2 ^ s(s-bit nonces) andnonceCTRCiphertranslatesnonceto the scaled initial counternonceCTRCounter n s nonce 0(BitString.lowBits (n - s) 0 ++ nonce, representingx := N · ℓ). At block offsetj < 2 ^ (n - s),ctrWordCounterfrom that initial value equalsnonceCTRCounter n s nonce j(ctrWordCounter_nonceCTRCounter_zero), whose little-endian value isN · ℓ + j(lsbValue_nonceCTRCounter).
- Construction, correctness, and polynomial-time algorithms (
nonceCTRCounter,nonceStreamCipher,nonceCTRCipher,nonceCTRValid,nonceCTRValidNonce):nonceStreamCipher family n toIVXORs messages withctrWordKeystreamfromtoIV nonceand satisfiesNonceCipher.Correctunconditionally (correct_nonceStreamCipher). Both encryption and decryption ofnonceCTRCipherare computable in deterministic polynomial time wheneverfamilyandnonceLenare (computableInPolyTime_encrypt_nonceCTRCipher,computableInPolyTime_decrypt_nonceCTRCipher). - Exact reduction and CPA security (
nonceCTRToPRF,isOraclePPT_nonceCTRToPRF,advantage_cpaExperiment_nonceCTRCipher_eq_two_mul,PseudorandomFunction.indcpa_nonceCTR) ([BS23], Theorem 5.6, printed pp. 203–204, and inequality(5.32), printed p. 204): [BS23] leaves the proof of Theorem 5.6 as an exercise (p. 204), noting that it adapts the proof of Theorem 5.3 (p. 203) withBan elementary wrapper aroundA(p. 204). HerenonceCTRToPRF nonceLen Asamples a uniform hidden bitb, simulates the stateful CPA word challenger forAviactrKeystreamQueriesagainst its external function oracle, and outputs whetherok && guessmatchesb. Against a uniform random function, distinct nonces andblocks ≤ 2 ^ (n - nonceLen n)make every counter query fresh, sook && guessis independent ofband the distinguisher outputstruewith probability1 / 2. Because Attack Game 5.3's two-world CPA advantage (2 · nCPAadv*by(5.30), printed p. 202) agrees withGame.advantage, this yields the exact identity $$\mathrm{Adv}_{\mathrm{nCPA}}(A, \mathcal{E}) = 2 \cdot \mathrm{Adv}_{\mathrm{PRF}}(B_A, F),$$ whose.ledirection is(5.32)(printed p. 204), and henceNonceCipher.INDCPAfor every uniformPseudorandomFunction. - Counter-overlap separation for unscaled nonces (
unscaledNonceCTRCipher,unscaledNonceCTRAdversary,isOraclePPT_unscaledNonceCTRAdversary,advantage_cpaExperiment_unscaledNonceCTRAdversary,not_indcpa_unscaledNonceCTRCipher): instantiating the overlapping-interval failure noted in [BS23], Section 5.5.2 (printed p. 203), our concrete 2-query uniform strictIsOraclePPTdistinguisherunscaledNonceCTRAdversaryqueries nonces0and1on 2-block messages (underblockPairValidwith no block cap) to achieve CPA advantage1for everyn ≥ 1, refutingNonceCipher.INDCPAforunscaledNonceCTRCipher.
Main definitions #
Cslib.Crypto.nonceCTRCounter: little-endian block counterN · 2 ^ (n - s) + j.Cslib.Crypto.nonceStreamCipher,Cslib.Crypto.nonceCTRCipher,Cslib.Crypto.unscaledNonceCTRCipher: deterministic counter-mode stream cipher parameterized by the nonce-to-counter map, and its scaled (x := N · ℓ) and unscaled (x := N) specializations.Cslib.Crypto.nonceCTRValid,Cslib.Crypto.nonceCTRValidNonce: whole-block message-pair predicate (blocks ≤ 2 ^ (n - nonceLen n)) andnonceLen n-bit nonce predicate.Cslib.Crypto.nonceCTRToPRF: single-distinguisher PRF wrapper adapting the Theorem 5.3 reduction to Theorem 5.6.Cslib.Crypto.unscaledNonceCTRAdversary: concrete 2-query counter-overlap distinguisher.
Main results #
Cslib.Crypto.lsbValue_nonceCTRCounter,Cslib.Crypto.ctrWordCounter_nonceCTRCounter_zero: little-endian valuelsbValue nonce * 2 ^ (n - s) + jand agreement ofctrWordCounterfrom the scaled initial counter withnonceCTRCounterbelow2 ^ (n - s).Cslib.Crypto.correct_nonceStreamCipher: decryption inverts encryption for every nonce-to-counter map.Cslib.Crypto.computableInPolyTime_encrypt_nonceCTRCipher,Cslib.Crypto.computableInPolyTime_decrypt_nonceCTRCipher: polynomial-time efficiency of encryption and decryption.Cslib.Crypto.isOraclePPT_nonceCTRToPRF: uniform strict oracle-PPT certificate for the PRF reduction.Cslib.Crypto.advantage_cpaExperiment_nonceCTRCipher_eq_two_mul: exact CPA-to-PRF advantage identity whose.ledirection is(5.32)(printed p. 204).Cslib.Crypto.PseudorandomFunction.indcpa_nonceCTR: nonce-based counter mode satisfiesNonceCipher.INDCPAfor everyPseudorandomFunction(Theorem 5.6).Cslib.Crypto.isOraclePPT_unscaledNonceCTRAdversary,Cslib.Crypto.advantage_cpaExperiment_unscaledNonceCTRAdversary,Cslib.Crypto.not_indcpa_unscaledNonceCTRCipher: certified counter-overlap attack on unscaled nonce-CTR.
References #
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Version 0.6,
Section 5.4.2 and Theorem 5.3 (printed pp. 189, 191–192), Section 5.5 (Attack Game 5.3,
Definition 5.3, and
(5.30), printed p. 202), and Section 5.5.2 (nonce-based counter mode, counter-overlap failure of unscaled nonces, Theorem 5.6, and(5.32), printed pp. 203–204).
Nonce-based counter mode #
The j-th counter input of nonce-based counter mode at block width n and nonce width s
([BS23], Section 5.5.2, printed p. 203): the (n - s)-bit little-endian offset j
followed by nonce, representing lsbValue nonce * 2 ^ (n - s) + j when j < 2 ^ (n - s).
When s ≤ n and nonce has s bits, nonceCTRCounter n s nonce j has n bits.
Little-endian numeric value of nonceCTRCounter n s nonce j for j < 2 ^ (n - s), matching
x = N · ℓ + j with ℓ = 2 ^ (n - s) ([BS23], Section 5.5.2, printed p. 203).
For an s-bit nonce (s ≤ n) and block offset j < 2 ^ (n - s), advancing
ctrWordCounter n from the scaled initial counter nonceCTRCounter n s nonce 0 (x = N · ℓ)
produces nonceCTRCounter n s nonce j (N · ℓ + j).
Deterministic nonce-based counter-mode stream cipher at block width n under
nonce-to-initial-counter map toIV: encrypt (or decrypt) a word of length len by XORing it with
(len + n - 1) / n blocks of ctrWordKeystream family n k (toIV nonce), truncated or zero-padded
to len bits.
Deterministic nonce-based counter-mode cipher ([BS23], Section 5.5.2, printed p. 203)
at block width n and nonce width s: nonceStreamCipher under the scaled nonce translation
nonce ↦ nonceCTRCounter n s nonce 0 (x := N · ℓ with ℓ = 2 ^ (n - s)).
Admissible challenge-pair predicate for nonce-based counter mode with nonce-length schedule
nonceLen ([BS23], Section 5.5.2, printed p. 203): equal-length messages of whole n-bit
blocks (blockPairValid n m₀ m₁) with block count m₀.length / n ≤ 2 ^ (n - nonceLen n).
Efficiency of the honest algorithms #
Nonce-based counter-mode encryption is computable in polynomial time on (n, k, msg, nonce).
Nonce-based counter-mode decryption is computable in polynomial time on (n, k, ct, nonce).
The PRF reduction for Theorem 5.6 #
Single-distinguisher PRF wrapper for nonce-based counter mode, adapting the bit-guessing
reduction of [BS23], Theorem 5.3 (printed pp. 191–192) to Theorem 5.6 (whose proof
[BS23], Section 5.5.2, printed pp. 203–204 leaves as an exercise, describing B as an
elementary wrapper around A): sample a uniform hidden bit b, simulate the stateful CPA word
challenger for adversary via ctrKeystreamQueries against the external function oracle, and
output whether ok && guess equals b.
Efficiency of the Theorem 5.6 reduction. When nonceLen is computable in polynomial time
in unary and adversary is uniform strict oracle PPT, nonceCTRToPRF nonceLen adversary is
uniform strict oracle PPT.
Real and ideal PRF worlds and Theorem 5.6 #
Exact CPA-to-PRF advantage identity for nonce-based counter mode (strengthening inequality
(5.32) of [BS23], Theorem 5.6, printed p. 204, to an equality): for any
length-preserving family, parameter n with nonceLen n ≤ n, and distinguisher adversary, the
two-world CPA advantage of unitCPACodec.adapt (adversary n []) against
nonceCTRCipher family n (nonceLen n) equals twice the PRF advantage of
nonceCTRToPRF nonceLen adversary. Applying .le gives (5.32) directly (Attack Game 5.3's
two-world advantage, printed p. 202, equals Game.advantage and is twice the bit-guessing
advantage (5.30)).
Nonce-based counter mode is CPA-secure for a pseudorandom function ([BS23],
Section 5.5.2, Theorem 5.6, printed pp. 203–204): in the standard model against uniform strict
oracle-PPT adversaries, if family is a PseudorandomFunction (n-bit keys and n-bit inputs to
n-bit outputs) and nonceLen is computable in polynomial time in unary with nonceLen n ≤ n,
then nonceCTRCipher family n (nonceLen n) satisfies NonceCipher.INDCPA on whole-block message
pairs of at most ℓ = 2 ^ (n - nonceLen n) blocks under nonceLen n-bit nonces (the power-of-two
case ℓ ∣ 2 ^ n noted on printed p. 203).
Counter-overlap attack on unscaled nonce-based counter mode #
The unscaled first attempt at nonce-based counter mode ([BS23], Section 5.5.2,
printed p. 203): nonceStreamCipher under the identity nonce translation nonce ↦ nonce
(x := N), using the n-bit nonce directly as the initial counter of ctrWordKeystream without
multiplying by the maximum block count ℓ.
Concrete two-query counter-overlap CPA distinguisher against unscaledNonceCTRCipher,
instantiating the overlapping-interval observation of [BS23], Section 5.5.2, printed
p. 203:
- Query
(0^(2n), 0^(2n))under noncelowBits n 0to observeF(k, 1)as the secondn-bit ciphertext block. - Query
(0^(2n), 1^n ++ 0^n)under distinct noncelowBits n 1, whose first counter block is alsolowBits n 1, and check whether the firstn-bit ciphertext block equals the second block of reply 1.
unscaledNonceCTRAdversary is uniform strict oracle PPT (IsOraclePPT encBool).
At every parameter n ≥ 1, unscaledNonceCTRAdversary achieves CPA advantage 1 against
unscaledNonceCTRCipher family n for any length-preserving family on whole-block message
pairs.
Unscaled nonce-based counter mode is not CPA-secure ([BS23], Section 5.5.2,
printed p. 203): for every length-preserving family family, using n-bit nonces directly as
initial counters without scaling fails NonceCipher.INDCPA on whole-block message pairs (with no
block cap; unscaledNonceCTRAdversary uses 2-block queries).