Documentation

CslibFrontier.Crypto.Computational.Encryption.OFBMode

CPA Security of Output Feedback (OFB) Mode #

Output Feedback mode ([KL20], Section 3.6.3, Figure 3.8) encrypts a message of k blocks under a block function f and a uniform initialization vector iv by adding the keystream f iv, f (f iv), … to the message blocks. [KL20] (Section 3.6.3, p. 92) states that OFB mode is CPA-secure whenever f is a pseudorandom function; this file proves a concrete version of that statement.

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. By [KL20], Theorem 3.23, this is equivalent to CPA security.

The proof follows the template of [KL20], Theorem 3.33 (CTR mode):

  1. The OFB experiment is the real PRF experiment for a reduction that encrypts with its oracle (ofbCpaGame_eq_realExperiment); the reduction makes one oracle call per encrypted block (isQueryBounded_ofbReduction).
  2. Against a uniform random function, sampled lazily, the reduction's view differs from fresh uniform ciphertexts only when some keystream input repeats an earlier input. The chain collision bound toOuterMeasure_badChain_le limits this event to probability K (K + ℓ) / 2 ^ n when the queries ask at most K blocks in total and at most ℓ blocks each (advantage_idealExperiment_ofbReduction_le).
  3. Fresh uniform ciphertexts do not depend on the challenge bit, so the hybrids and the two PRF advantages give the final bound (advantage_ofbCpaGame_le).

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_ofbWordEncrypt, is in CslibFrontier/Crypto/Computational/Encryption/OFBMode/Uniform.lean, which reuses advantage_idealExperiment_ofbReduction_le.

Main definitions #

Main results #

References #

Section 1: The OFB Left-or-Right Experiment #

noncomputable def Cslib.Crypto.ofbOracle {n : ℕ} (ℓ : ℕ) (f : BitString n → BitString n) (b : Bool) (q : BlockModeQuery n) :

The OFB left-or-right oracle for the block function f and the challenge bit b: a fresh uniform initialization vector and the OFB encryption of the selected plaintext ([KL20], Section 3.6.3, Figure 3.8).

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

The OFB left-or-right experiment for the keyed block function F with challenge bit b ([KL20], Definition 3.22): a uniform key, then the adversary with oracle access to OFB encryption under that key.

Section 2: The Reduction to a Pseudorandom Function #

The OFB keystream of length k from x, computed with k calls to a function oracle.

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

One OFB encryption computed with a function oracle: a private uniform initialization vector, then the keystream from the oracle, added to the selected plaintext.

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

The PRF distinguisher built from a left-or-right adversary ([KL20], proof of Theorem 3.33): run the adversary and answer each query by OFB encryption with the oracle, under the challenge bit b.

theorem Cslib.Crypto.run_ofbChainQueries {n : ℕ} (f : BitString n → BitString n) (x : BitString n) (k : ℕ) :
((ofbChainQueries x k).run fun (y : BitString n) => pure (f y)) = pure (ofbChain f x k)

Answering the keystream calls with a fixed function f computes the OFB chain of f.

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

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

The keystream program makes exactly k oracle calls.

theorem Cslib.Crypto.isQueryBounded_ofbReduction {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.

Section 3: The Collision Bound for Fresh Sampling #

Section 4: Security of OFB Mode #

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

The reduction against a uniform random function. If the queries of adversary ask at most K blocks in total, then with a uniform random function the output of the reduction ofbReduction ℓ b adversary is within K (K + ℓ) / 2 ^ n of blockModeIdealExperiment, whatever the challenge bit b.

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

OFB mode with a uniform random function ([KL20], Section 3.6.3). If the queries of adversary ask at most K blocks in total and at most ℓ blocks each, its left-or-right advantage against OFB mode with a uniform random block function is at most 2 K (K + ℓ) / 2 ^ n.

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

OFB mode is CPA-secure for a pseudorandom function ([KL20], Section 3.6.3, following the proof of Theorem 3.33). If the queries of adversary ask at most K blocks in total and at most ℓ blocks each, its left-or-right advantage against OFB mode with the keyed function F is at most the PRF advantages of the reductions ofbReduction ℓ false adversary and ofbReduction ℓ true adversary, each making at most K oracle calls (isQueryBounded_ofbReduction), plus 2 K (K + ℓ) / 2 ^ n.