CPA Security of Counter (CTR) Mode #
Counter mode ([KL20], Section 3.6.3, Figure 3.9) encrypts a message of k blocks under
a block function f, a counter schedule counter : BitString n → ℕ → BitString n, and a uniform
initialization vector iv by XORing the keystream f (counter iv 0), f (counter iv 1), … with
the plaintext blocks. [KL20] (Section 3.6.3, Theorem 3.33, p. 93) proves that CTR mode
is CPA-secure whenever f is a pseudorandom function.
The security notion is the left-or-right multiple-encryption experiment of [KL20],
Definition 3.22, using the shared block-mode query/cost/ideal-experiment interface
(BlockModeQuery, BlockModeAdversary, blockModeSelect, blockModeBlocks, blockModeCost,
blockModeIdealExperiment) from RandomFunctionHybrid.lean.
The proof works for any counter schedule counter : BitString n → ℕ → BitString n satisfying
within-query distinctness (∀ iv i j, i < ℓ → j < ℓ → i ≠ j → counter iv i ≠ counter iv j) and
per-offset injectivity in the IV (∀ i < ℓ, Function.Injective (fun iv => counter iv i)), and is
instantiated on the canonical modular counter schedule ctrModCounter when ℓ ≤ 2 ^ n:
- The CTR experiment is the real PRF experiment for a reduction encrypting with its oracle
(
ctrCpaGame_eq_realExperiment), making at mostKoracle calls (isQueryBounded_ctrReduction). - Against a lazily sampled uniform random function, the reduction's view differs from fresh
uniform ciphertexts only when some
counter iv ihits an earlier queried input. Within-query distinctness rules out intra-query collisions, and per-offset injectivity bounds inter-query collisions byK ^ 2 / 2 ^ n(advantage_idealExperiment_ctrReduction_le). - Combining the ideal hybrids with the two PRF advantages yields the concrete bound
(
advantage_ctrCpaGame_le, andadvantage_ctrCpaGame_ctrModCounter_leforctrModCounter).
The PRF experiments are the concrete ones of Cslib.Crypto.PRF ([BS23], Chapter 4). The
reductions here are typed ProbOracleComp programs without an efficiency certificate. The uniform
statement, with a certified word-level reduction and the asymptotic theorem
PseudorandomFunction.indcpa_ctrWordEncrypt, is in
CslibFrontier/Crypto/Computational/Encryption/CTRMode/Uniform.lean, which reuses
advantage_idealExperiment_ctrReduction_le.
Main definitions #
Cslib.Crypto.ctrOracle,Cslib.Crypto.ctrCpaGame: real CTR left-or-right oracle and experiment.Cslib.Crypto.ctrMaskQueriesFrom,Cslib.Crypto.ctrQueryProgram,Cslib.Crypto.ctrReduction: the PRF distinguisher built from aBlockModeAdversary.Cslib.Crypto.ctrModCounter: canonical modular-addition counteriv + i mod 2 ^ n.
Main results #
Cslib.Crypto.ctrCpaGame_eq_realExperiment,Cslib.Crypto.isQueryBounded_ctrReduction: exact real-PRF equivalence and oracle-call bound.Cslib.Crypto.advantage_idealExperiment_ctrReduction_le: random-function idealization boundK ^ 2 / 2 ^ nagainstblockModeIdealExperiment.Cslib.Crypto.advantage_ctrCpaGame_randomFunction_le,Cslib.Crypto.advantage_ctrCpaGame_le: concrete CTR left-or-right CPA security bounds.Cslib.Crypto.ctrModCounter_injective_left,Cslib.Crypto.ctrModCounter_injOn,Cslib.Crypto.advantage_ctrCpaGame_ctrModCounter_randomFunction_le,Cslib.Crypto.advantage_ctrCpaGame_ctrModCounter_le: specializations toctrModCounterforℓ ≤ 2 ^ n.
References #
- J. Katz, Y. Lindell, Introduction to Modern Cryptography, 3rd ed., Section 3.6.3 (Figure 3.9, p. 92), Definition 3.22 (p. 74), Theorem 3.23 (p. 75), and Theorem 3.33 (p. 93).
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Chapter 4.
Section 1: The CTR Left-or-Right Experiment #
The CTR left-or-right experiment for keyed block function F and challenge bit b
([KL20], Definition 3.22).
Section 2: The Reduction to a Pseudorandom Function #
One CTR encryption computed with a function oracle: sample a uniform IV, evaluate the keystream
masks via oracle queries starting at offset 0, and XOR with the selected plaintext.
The PRF distinguisher built from a CTR left-or-right adversary ([KL20], proof of Theorem 3.33).
Answering ctrMaskQueriesFrom counter iv i k with a fixed function f evaluates
(List.range' i k).map (fun j => f (counter iv j)).
Answering ctrMaskQueriesFrom counter iv 0 k with f computes ctrMaskBlocks f counter iv k.
The CTR experiment for keyed function F equals the real PRF experiment for F and
ctrReduction counter ℓ b adversary.
ctrMaskQueriesFrom counter iv i k makes at most k oracle queries.
If adversary asks at most K blocks in total, ctrReduction counter ℓ b adversary makes at
most K oracle calls.
Section 3: Inter-Query Collision Bound for Fresh CTR Sampling #
Section 4: Security of CTR Mode and Modular Counter Instantiation #
The CTR reduction against a uniform random function. If the queries of adversary ask at
most K blocks in total, and counter has no intra-query collisions below ℓ and is injective in
iv at every offset below ℓ, then the reduction's output is within K ^ 2 / 2 ^ n of
blockModeIdealExperiment for each challenge bit b.
CTR mode with a uniform random function ([KL20], Section 3.6.3): when
adversary asks at most K blocks in total and at most ℓ blocks per query, its left-or-right
advantage is at most 2 * K ^ 2 / 2 ^ n.
CTR mode is CPA-secure for a pseudorandom function ([KL20], Section 3.6.3,
Theorem 3.33, p. 93): if adversary asks at most K blocks in total and at most ℓ blocks per
query, its left-or-right advantage against CTR mode with keyed function F is at most the PRF
advantages of the two reductions ctrReduction counter ℓ false adversary and
ctrReduction counter ℓ true adversary (each making at most K queries by
isQueryBounded_ctrReduction) plus 2 * K ^ 2 / 2 ^ n.
For every offset i, ctrModCounter · i is injective on the initialization vector iv.
Whenever ℓ ≤ 2 ^ n, distinct offsets below ℓ yield distinct ctrModCounter iv i blocks.
Modular CTR mode with a uniform random function when ℓ ≤ 2 ^ n.
Modular CTR mode is CPA-secure for any pseudorandom function F whenever ℓ ≤ 2 ^ n
([KL20], Section 3.6.3, Theorem 3.33).