Documentation

CslibFrontier.Crypto.Computational.Encryption.CBCMode

CBC mode with a random IV: typed random-function, random-permutation and keyed bounds #

Cipher block chaining with a random initialization vector ([BS23], Section 5.4.3, printed pp. 194–195) encrypts the blocks m₁, …, m_k under a block function f as c₀ = iv uniform and cᵢ = f (cᵢ₋₁ + mᵢ) (cbcEncryptBlocks). Theorem 5.4 of [BS23] (printed pp. 195–199) states that it is CPA secure for a secure block cipher, with bound (5.22), CPAadv ≤ 2 Q² ℓ² / N + 2 BCadv, for Q queries of at most ℓ blocks over N blocks.

This file proves the concrete typed steps of Theorem 5.4, not the asymptotic theorem: Games 1 to 3 and bound (5.28) against a uniform random function, the resulting bound with the block cipher replaced by a uniform random permutation of BitString n, and the concrete keyed PRF and block-cipher bounds (advantage_cbcCpaGame_prf_le and advantage_cbcCpaGame_le). The security notion is the left-or-right experiment of RandomFunctionHybrid.lean (blockModeCpaExperiment), and the advantage is the distance between the experiments for the two challenge bits, the book's CPAadv. The word-level cipher, the certified oracle-PPT distinguisher and the asymptotic Theorem 5.4 are in CslibFrontier/Crypto/Computational/Encryption/CBCMode/Uniform.lean.

The proof:

  1. The CBC experiment is the real PRF experiment for the reduction cbcReduction, which computes each ciphertext with its oracle (cbcCpaGame_eq_realExperiment, an application of blockModeCpaExperiment_eq_realExperiment_simulate); the reduction makes one oracle call per block (isQueryBounded_cbcReduction).
  2. Against a uniform random function sampled afresh, every ciphertext block is uniform, and a query of k blocks against a table of t inputs repeats an input with probability at most (k t + k.choose 2) / 2 ^ n (toOuterMeasure_badChain_le). The generic step advantage_idealExperiment_simulate_le of RandomFunctionHybrid.lean then bounds the distance to blockModeIdealExperiment by K.choose 2 / 2 ^ n when the queries ask at most K blocks in total (advantage_idealExperiment_cbcReduction_le).
  3. The ideal experiment does not depend on the challenge bit. With the PRP/PRF switching bound PRP.advantage_idealExperiment_prfIdealExperiment_le (Theorem 4.6; the book's proof cites its block-cipher form, Theorem 4.4) for each bit, the advantage against a uniform random permutation is at most 4 K.choose 2 / 2 ^ n (advantage_cbcCpaGame_randomPermutation_le).
  4. For a keyed function F, combining cbcCpaGame_eq_realExperiment with the two random-function hybrids bounds the CPA advantage by the two PRF advantages plus 2 K.choose 2 / 2 ^ n (advantage_cbcCpaGame_prf_le). For a keyed permutation E, applying PRP.prfAdvantage_le_advantage_add (Theorem 4.4) to each K-query reduction gives the keyed bound PRP.advantage E (cbcReduction ℓ false adversary) + PRP.advantage E (cbcReduction ℓ true adversary) + 4 K.choose 2 / 2 ^ n (advantage_cbcCpaGame_le).

The bounds hold for every adversary. The query bound of the reduction is proved (isQueryBounded_cbcReduction); no running-time certificate is claimed here (tracked in #4894 and #5293 section 2).

Comparison with the book:

Main definitions #

Main results #

References #

noncomputable def Cslib.Crypto.cbcCpaGame {n : ℕ} {Key : Type} [Fintype Key] [Nonempty Key] (F : Key → BitString n → BitString n) (ℓ : ℕ) (b : Bool) (adversary : BlockModeAdversary n) :

The CBC left-or-right experiment for the keyed block function F with challenge bit b ([BS23], Attack Game 5.2, Section 5.4.3): a uniform key, then the adversary with access to random-IV CBC encryption under that key.

The CBC ciphertext blocks of ms from chaining value c, computed with one call to the function oracle per block: the input of each call is the previous ciphertext block plus the next message block.

noncomputable def Cslib.Crypto.cbcQueryProgram {n : ℕ} (ℓ : ℕ) (b : Bool) (q : BlockModeQuery n) :

One CBC encryption computed with a function oracle: a private uniform initialization vector, then the ciphertext blocks of the selected plaintext from the oracle.

noncomputable def Cslib.Crypto.cbcReduction {n : ℕ} (ℓ : ℕ) (b : Bool) (adversary : BlockModeAdversary n) :

The PRF distinguisher built from a left-or-right adversary against CBC mode ([BS23], proof of Theorem 5.4, adversary B): run the adversary and answer each query by CBC encryption with the oracle, under the challenge bit b.

theorem Cslib.Crypto.run_cbcChainQueries {n : ℕ} (f : BitString n → BitString n) (c : BitString n) (ms : List (BitString n)) :
((cbcChainQueries c ms).run fun (y : BitString n) => pure (f y)) = pure (cbcEncryptBlocks f c ms)

Answering the chain calls with a fixed function f computes CBC encryption under f.

theorem Cslib.Crypto.cbcCpaGame_eq_realExperiment {n : ℕ} {Key : Type} [Fintype Key] [Nonempty Key] (F : Key → BitString n → BitString n) (ℓ : ℕ) (b : Bool) (adversary : BlockModeAdversary n) :
cbcCpaGame F ℓ b adversary = (PRF.realExperiment F (cbcReduction ℓ b adversary)).eval

The CBC experiment for the keyed block function F is the real PRF experiment for F and the reduction cbcReduction ℓ b adversary.

The chain makes one oracle call per block.

theorem Cslib.Crypto.isQueryBounded_cbcReduction {n : ℕ} (ℓ : ℕ) (b : Bool) {adversary : BlockModeAdversary n} {K : ℕ} (h : OracleComp.IsCostBounded (blockModeCost ℓ) adversary K) :

If the queries of adversary ask at most K blocks in total, the reduction makes at most K oracle calls.

Fresh sampling #

Security of CBC mode #

theorem Cslib.Crypto.advantage_idealExperiment_cbcReduction_le {n : ℕ} (ℓ : ℕ) (b : Bool) {adversary : BlockModeAdversary n} {K : ℕ} (h : OracleComp.IsCostBounded (blockModeCost ℓ) adversary K) :
↑(Game.advantage (PRF.idealExperiment (cbcReduction ℓ b adversary)).eval (blockModeIdealExperiment ℓ adversary).eval) ≤ ↑(K.choose 2) / 2 ^ n

The reduction against a uniform random function ([BS23], proof of Theorem 5.4, Games 1 to 3 and (5.28)). If the queries of adversary ask at most K blocks in total, then with a uniform random function the output of cbcReduction ℓ b adversary is within K.choose 2 / 2 ^ n of blockModeIdealExperiment, whatever the challenge bit b.

theorem Cslib.Crypto.advantage_cbcCpaGame_randomFunction_le {n : ℕ} (ℓ : ℕ) {adversary : BlockModeAdversary n} {K : ℕ} (h : OracleComp.IsCostBounded (blockModeCost ℓ) adversary K) :
↑((cbcCpaGame (fun (f : BitString n → BitString n) => f) ℓ false adversary).advantage (cbcCpaGame (fun (f : BitString n → BitString n) => f) ℓ true adversary)) ≤ 2 * (↑(K.choose 2) / 2 ^ n)

CBC mode with a uniform random function. If the queries of adversary ask at most K blocks in total, its left-or-right advantage against CBC mode with a uniform random block function is at most 2 K.choose 2 / 2 ^ n.

theorem Cslib.Crypto.advantage_cbcCpaGame_prf_le {n : ℕ} {Key : Type} [Fintype Key] [Nonempty Key] (F : Key → BitString n → BitString n) (ℓ : ℕ) {adversary : BlockModeAdversary n} {K : ℕ} (h : OracleComp.IsCostBounded (blockModeCost ℓ) adversary K) :
↑((cbcCpaGame F ℓ false adversary).advantage (cbcCpaGame F ℓ true adversary)) ≤ ↑(PRF.advantage F (cbcReduction ℓ false adversary)) + ↑(PRF.advantage F (cbcReduction ℓ true adversary)) + 2 * (↑(K.choose 2) / 2 ^ n)

Keyed PRF step of [BS23], Theorem 5.4, not the asymptotic theorem (typed reduction without a running-time certificate, tracked in #4894 and #5293 section 2; see CslibFrontier/Crypto/Computational/Encryption/CBCMode/Uniform.lean for the certified uniform theorem). If the queries of adversary ask at most K blocks in total, its left-or-right advantage against CBC mode with the keyed function F is at most the PRF advantages of cbcReduction ℓ false adversary and cbcReduction ℓ true adversary, each making at most K oracle calls (isQueryBounded_cbcReduction), plus 2 K.choose 2 / 2 ^ n.

theorem Cslib.Crypto.advantage_cbcCpaGame_le {n : ℕ} {Key : Type} [Fintype Key] [Nonempty Key] (E : Key → Equiv.Perm (BitString n)) (ℓ : ℕ) {adversary : BlockModeAdversary n} {K : ℕ} (h : OracleComp.IsCostBounded (blockModeCost ℓ) adversary K) :
↑((cbcCpaGame (fun (k : Key) => ⇑(E k)) ℓ false adversary).advantage (cbcCpaGame (fun (k : Key) => ⇑(E k)) ℓ true adversary)) ≤ ↑(PRP.advantage E (cbcReduction ℓ false adversary)) + ↑(PRP.advantage E (cbcReduction ℓ true adversary)) + 4 * (↑(K.choose 2) / 2 ^ n)

Keyed block-cipher step (5.22) of [BS23], Theorem 5.4, not the asymptotic theorem (typed reduction without a running-time certificate, tracked in #4894 and #5293 section 2; see CslibFrontier/Crypto/Computational/Encryption/CBCMode/Uniform.lean for the certified uniform theorem). If the queries of adversary ask at most K blocks in total, its left-or-right advantage against CBC mode with the keyed permutation E is at most the PRP advantages of cbcReduction ℓ false adversary and cbcReduction ℓ true adversary, each making at most K oracle calls (isQueryBounded_cbcReduction), plus 4 K.choose 2 / 2 ^ n. With Q queries of at most ℓ blocks, K ≤ Q ℓ and 4 K.choose 2 ≤ 2 Q ^ 2 ℓ ^ 2, matching (5.22).

theorem Cslib.Crypto.advantage_cbcCpaGame_randomPermutation_le {n : ℕ} (ℓ : ℕ) {adversary : BlockModeAdversary n} {K : ℕ} (h : OracleComp.IsCostBounded (blockModeCost ℓ) adversary K) :
↑((cbcCpaGame (fun (π : Equiv.Perm (BitString n)) => ⇑π) ℓ false adversary).advantage (cbcCpaGame (fun (π : Equiv.Perm (BitString n)) => ⇑π) ℓ true adversary)) ≤ 4 * (↑(K.choose 2) / 2 ^ n)

CBC mode with a uniform random permutation: a step of the proof of [BS23], Theorem 5.4, not the theorem. The block cipher is replaced by a uniform random permutation of BitString n. If the queries of adversary ask at most K blocks in total, its left-or-right advantage is at most 4 K.choose 2 / 2 ^ n: advantage_cbcCpaGame_le for the identity family on Equiv.Perm (BitString n). With Q queries of at most ℓ blocks, K ≤ Q ℓ and 4 K.choose 2 ≤ 2 Q ^ 2 ℓ ^ 2, the additive term of (5.22).