Documentation

CslibFrontier.Crypto.Computational.Encryption.IVStream.Reduction

The PRF reduction for random-IV modes #

A random-IV mode encrypts as the envelope ivModeEncrypt body of IVStream.lean: it draws a uniform n-bit initial value iv and outputs iv followed by a body computed from the key, iv and the message. Randomized counter mode and output feedback mode are the stream case, whose body XORs the message with a keystream. The reduction of the proof of [BS23], Theorem 5.3, written there for counter mode, works for any such mode built from a pseudorandom function: the PRF distinguisher runs the CPA adversary and answers each admissible left-or-right request itself, drawing the initial value and computing the body with queries to its own function oracle. The modes differ only in the program bodyQueries n iv msg that computes the body of message msg from initial value iv; the program may depend on the message, as CBC mode's does. ivModeToPrfDistinguisher bodyQueries is the reduction for any such program.

  1. The distinguisher is uniform strict oracle PPT whenever the adversary is, bodyQueries is strict oracle PPT on (1ⁿ, iv, msg) and no output of bodyQueries is longer than the message (isOraclePPT_ivModeToPrfDistinguisher).
  2. Against the keyed oracle, if the body queries compute body n k iv msg from every n-bit initial value on whole-block messages, its output law is that of the adversary in the CPA game of ivModeEncrypt body (eval_prfRealGame_ivModeToPrfDistinguisher).
  3. Against a uniform random function, if the body queries compute the bits of the blocks that a typed per-query program computes, it is that program simulated on the adversary read as a block-mode adversary (blockModeWordAdversary) (eval_prfIdealGame_ivModeToPrfDistinguisher). The typed collision bounds of each mode then apply.

The stream case ivStreamToPrfDistinguisher keystreamQueries takes a program keystreamQueries n iv blocks that obtains the keystream of blocks blocks; its three results (isOraclePPT_ivStreamToPrfDistinguisher, eval_prfRealGame_ivStreamToPrfDistinguisher, eval_prfIdealGame_ivStreamToPrfDistinguisher) are instances of the three above.

Main definitions #

Main results #

References #

The PRF distinguisher built from a left-or-right CPA adversary against a random-IV mode with body queries bodyQueries ([BS23], proof of Theorem 5.3): run the adversary and answer every request itself. On an admissible pair it draws a uniform n-bit initial value and answers with that value followed by the body that bodyQueries computes, with queries to the function oracle, for the message selected by bit; it answers an inadmissible request with [] and no query.

Efficiency #

Efficiency of the reduction at a reindexed block length. When blockLen is computable in polynomial time in unary, running ivModeToPrfDistinguisher at block width blockLen n on adversary n [] is uniform strict oracle PPT whenever adversary is.

Efficiency of the reduction. If the body queries are strict oracle PPT on (1ⁿ, iv, msg) and none of their outputs is longer than the message, then for every uniform strict oracle-PPT adversary, ivModeToPrfDistinguisher bodyQueries adversary bit is uniform strict oracle PPT. The length condition is sufficient, not necessary: a mode whose body is longer than the message is not covered.

The real game #

theorem Cslib.Crypto.eval_prfRealGame_ivModeToPrfDistinguisher {bodyQueries : ℕ → List Bool → List Bool → Probability.WordOracleComp Unit (List Bool)} {body : ℕ → List Bool → List Bool → List Bool → List Bool} {family : List Bool → List Bool → List Bool} {n : ℕ} (hbody : ∀ (k : List Bool), k.length = n → ∀ (iv : List Bool), iv.length = n → ∀ (msg : List Bool), msg.length % n = 0 → (ProbOracleComp.run (bodyQueries n iv msg) fun (request : Unit × List Bool) => pure (prfOracle family n k request.2)) = pure (body n k iv msg)) (adversary : OracleDistinguisher) (bit : Bool) :

Real game. If, under every key of length n, the body queries answered by the keyed oracle compute body n k iv msg from every n-bit initial value iv on every whole-block message msg, then against the keyed oracle ivModeToPrfDistinguisher bodyQueries adversary bit has the output law of adversary in the CPA game of ivModeEncrypt body with challenge bit bit.

The ideal game #

theorem Cslib.Crypto.eval_prfIdealGame_ivModeToPrfDistinguisher {bodyQueries : ℕ → List Bool → List Bool → Probability.WordOracleComp Unit (List Bool)} {n ℓ : ℕ} {bit : Bool} {program : BlockModeQuery n → ProbOracleComp (fun (x : BitString n) => BitString n) (BitString n × List (BitString n))} {bodyBlocks : (BitString n → BitString n) → BitString n → List (BitString n) → List (BitString n)} (hprogram : ∀ (f : BitString n → BitString n) (q : BlockModeQuery n), ((program q).run fun (x : BitString n) => pure (f x)) = blockModeOracle (bodyBlocks f) ℓ bit q) (hword : ∀ (f : BitString n → BitString n) (iv : Fin n → Bool) (m : List Bool), m.length % n = 0 → (ProbOracleComp.run (bodyQueries n (List.ofFn iv) m) fun (request : Unit × List Bool) => pure (randomFunctionOracle n f request.2)) = pure (List.flatMap List.ofFn (bodyBlocks f iv (BitString.toBlocks n m)))) (adversary : OracleDistinguisher) (hℓ : ProbOracleComp.QueriesSatisfy (fun (request : Unit × List Bool) => (Turing.MultiTapeTM.unframe request.2).length / n ≤ ℓ) (adversary n [])) :

Ideal game. Suppose that against every function f, the typed program program q answers each block-mode query as the block-mode oracle of bodyBlocks f with cap ℓ and challenge bit bit does, and the body queries from the bits of iv, answered by the random-function oracle of f, compute on every whole-block message m the bits of bodyBlocks f iv applied to the blocks of m. Then against a uniform random function, the reduction is program simulated on the block-mode adversary, for an adversary whose requests have left messages of at most ℓ blocks. The hypothesis hℓ constrains every request, admissible or not.

Stream encryption #

The PRF distinguisher built from a left-or-right CPA adversary against stream encryption with keystream queries keystreamQueries ([BS23], proof of Theorem 5.3): the random-IV reduction ivModeToPrfDistinguisher whose body obtains the keystream of msg.length / n blocks and XORs it with the message.

Efficiency of the reduction. If the keystream queries are strict oracle PPT on (1ⁿ, iv, 1^blocks), then for every uniform strict oracle-PPT adversary, ivStreamToPrfDistinguisher keystreamQueries adversary bit is uniform strict oracle PPT.

theorem Cslib.Crypto.eval_prfRealGame_ivStreamToPrfDistinguisher {keystreamQueries : ℕ → List Bool → ℕ → Probability.WordOracleComp Unit (List Bool)} {keystream : ℕ → List Bool → List Bool → ℕ → List Bool} {family : List Bool → List Bool → List Bool} {n : ℕ} (hks : ∀ (k : List Bool), k.length = n → ∀ (iv : List Bool), iv.length = n → ∀ (blocks : ℕ), (ProbOracleComp.run (keystreamQueries n iv blocks) fun (request : Unit × List Bool) => pure (prfOracle family n k request.2)) = pure (keystream n k iv blocks)) (adversary : OracleDistinguisher) (bit : Bool) :
(prfRealGame id family (ivStreamToPrfDistinguisher keystreamQueries adversary bit) n).eval = (symmetricCPAGameOn blockPairValid BitString.sampleList (ivStreamEncrypt keystream) adversary bit n).eval

Real game. If, under every key of length n, the keystream queries answered by the keyed oracle compute keystream n k iv blocks from every n-bit initial value iv, then against the keyed oracle ivStreamToPrfDistinguisher keystreamQueries adversary bit has the output law of adversary in the CPA game of ivStreamEncrypt keystream with challenge bit bit.

theorem Cslib.Crypto.eval_prfIdealGame_ivStreamToPrfDistinguisher {keystreamQueries : ℕ → List Bool → ℕ → Probability.WordOracleComp Unit (List Bool)} {n : ℕ} {typedQueries : BitString n → ℕ → ProbOracleComp (fun (x : BitString n) => BitString n) (List (BitString n))} {keystreamBlocks : (BitString n → BitString n) → BitString n → ℕ → List (BitString n)} (hlen : ∀ (f : BitString n → BitString n) (iv : BitString n) (blocks : ℕ), (keystreamBlocks f iv blocks).length = blocks) (htyped : ∀ (f : BitString n → BitString n) (iv : BitString n) (blocks : ℕ), ((typedQueries iv blocks).run fun (x : BitString n) => pure (f x)) = pure (keystreamBlocks f iv blocks)) (hword : ∀ (f : BitString n → BitString n) (iv : Fin n → Bool) (blocks : ℕ), (ProbOracleComp.run (keystreamQueries n (List.ofFn iv) blocks) fun (request : Unit × List Bool) => pure (randomFunctionOracle n f request.2)) = pure (List.flatMap List.ofFn (keystreamBlocks f iv blocks))) (adversary : OracleDistinguisher) (bit : Bool) {ℓ : ℕ} (hℓ : ProbOracleComp.QueriesSatisfy (fun (request : Unit × List Bool) => request.2.length ≤ ℓ) (adversary n [])) :
(prfIdealGame id id (ivStreamToPrfDistinguisher keystreamQueries adversary bit) n).eval = (PRF.idealExperiment (blockModeReduction typedQueries ℓ bit (blockModeWordAdversary adversary n))).eval

Ideal game. Suppose that against every function f, the typed keystream program typedQueries iv blocks computes the blocks blocks keystreamBlocks f iv blocks, and the keystream queries from the bits of iv, answered by the random-function oracle of f, compute the bits of those blocks. Then against a uniform random function, the reduction for an adversary whose requests have at most ℓ bits is the typed reduction blockModeReduction typedQueries ℓ bit for the block-mode adversary.