Documentation

CslibFrontier.Crypto.Computational.Encryption.OFBMode.Uniform

Output feedback mode from a uniform pseudorandom function #

Output feedback (OFB) mode ([BS23], Exercise 5.15(b), printed p. 212) encrypts a message of v blocks m[1], …, m[v] under a key k by drawing a uniform initial value x₀ and sending (x₀, c[1], …, c[v]) with xᵢ = F(k, xᵢ₋₁) and c[i] = m[i] ⊕ xᵢ. Here the security parameter n is the block length: the PRF family takes n-bit keys and n-bit inputs to n-bit outputs. A message is any word made of whole blocks. ofbWordEncrypt outputs the word x₀ ++ c, and ofbWordDecrypt inverts it; both are the shared envelope ivStreamEncrypt, ivStreamDecrypt with the chain keystream ofbWordKeystream. Each chain value is truncated to n bits (ofbWordStep). For keys of length n this changes nothing; for other keys it keeps the chain, and so encryption, polynomial-time.

Security is many-query left-or-right CPA security (SymmetricINDCPAOn, Attack Game 5.2) on equal-length pairs of whole blocks (blockPairValid), in the standard model, against uniform strict oracle-PPT adversaries. The PRF distinguisher ofbToPrfDistinguisher adversary bit is the shared stream reduction ivStreamToPrfDistinguisher with the chain keystream queries ofbKeystreamQueries: it runs the adversary and answers each admissible request itself, drawing the initial value and obtaining each chain value with one query to its own function oracle on the previous one, keeping at most n bits of the reply.

  1. It is uniform strict oracle PPT whenever the adversary is (isOraclePPT_ofbToPrfDistinguisher).
  2. Against the keyed oracle, its output law is that of the adversary in the CPA game with challenge bit bit (eval_prfRealGame_ofbToPrfDistinguisher).
  3. Against a uniform random function, it is the typed reduction ofbReduction of OFBMode.lean run on the adversary read as a block-mode adversary (blockModeWordAdversary), and the typed chain-collision bound advantage_idealExperiment_ofbReduction_le applies. This gives the concrete bound advantage_ofbWordCPAGame_le and then PseudorandomFunction.indcpa_ofbWordEncrypt.

Deviations from Exercise 5.15(b) #

Main definitions #

Main results #

References #

The cipher #

def Cslib.Crypto.ofbWordStep (family : List Bool → List Bool → List Bool) (n : ℕ) (k : List Bool) (state : List Bool × List Bool) :

One OFB chain step under family k: the next chain value is the image of the current one, truncated to n bits, and it is appended to the keystream so far.

def Cslib.Crypto.ofbWordKeystream (family : List Bool → List Bool → List Bool) (n : ℕ) (k iv : List Bool) (blocks : ℕ) :

The keystream of blocks blocks under family k from initial value iv: the chain values x₁, …, x_blocks after x₀ = iv, concatenated.

noncomputable def Cslib.Crypto.ofbWordEncrypt (family : List Bool → List Bool → List Bool) :

OFB encryption ([BS23], Exercise 5.15(b)): draw a uniform n-bit initial value iv and output iv followed by the message XORed with the keystream of msg.length / n blocks.

OFB decryption: accept an n-bit initial value followed by whole blocks, and XOR the blocks with the keystream from that initial value.

theorem Cslib.Crypto.length_ofbWordKeystream {family : List Bool → List Bool → List Bool} (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) {n : ℕ} {k : List Bool} (hk : k.length = n) {iv : List Bool} (hiv : iv.length = n) (blocks : ℕ) :
(ofbWordKeystream family n k iv blocks).length = blocks * n

Under a key of length n, a family with n-bit outputs on n-bit inputs produces a keystream of blocks * n bits from an n-bit initial value.

theorem Cslib.Crypto.ofbWordDecrypt_ofbWordEncrypt {family : List Bool → List Bool → List Bool} (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) {n : ℕ} {k : List Bool} (hk : k.length = n) {msg : List Bool} (hmsg : msg.length % n = 0) {ct : List Bool} (hct : ct ∈ (ofbWordEncrypt family n k msg).eval.support) :
ofbWordDecrypt family n k ct = some msg

Decryption inverts encryption on whole-block messages under keys of length n.

Efficiency of the honest algorithms #

The keystream is computable in polynomial time from the family's evaluator: every chain value has at most n bits, so each step grows the encoded state by at most 3 n bits.

The reduction to the PRF game #

One chain value from the function oracle: query the current chain value, keep at most n bits of the reply as the next one and append it to the keystream so far.

The keystream of blocks blocks from the function oracle, with one query per block.

@[reducible, inline]

The PRF distinguisher built from a left-or-right CPA adversary against OFB mode: the shared stream reduction ivStreamToPrfDistinguisher with the chain keystream queries ofbKeystreamQueries.

theorem Cslib.Crypto.run_ofbKeystreamQueries {n : ℕ} (g : List Bool → List Bool) (iv : List Bool) (blocks : ℕ) :
(ProbOracleComp.run (ofbKeystreamQueries n iv blocks) fun (request : Unit × List Bool) => pure (g request.2)) = pure ((fun (state : List Bool × List Bool) => (List.take n (g state.1), state.2 ++ List.take n (g state.1)))^[blocks] (iv, [])).2

Answered by a deterministic oracle g, the keystream queries iterate the chain step that replaces the chain value by g of it, truncated to n bits.

theorem Cslib.Crypto.run_ofbKeystreamQueries_prfOracle {family : List Bool → List Bool → List Bool} (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) {n : ℕ} {k : List Bool} (hk : k.length = n) {iv : List Bool} (hiv : iv.length = n) (blocks : ℕ) :
(ProbOracleComp.run (ofbKeystreamQueries n iv blocks) fun (request : Unit × List Bool) => pure (prfOracle family n k request.2)) = pure (ofbWordKeystream family n k iv blocks)

Answered by the keyed oracle under a key of length n, the keystream queries from an n-bit initial value compute the keystream.

theorem Cslib.Crypto.eval_prfRealGame_ofbToPrfDistinguisher {family : List Bool → List Bool → List Bool} (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) (adversary : OracleDistinguisher) (bit : Bool) (n : ℕ) :

Real game. Against the keyed oracle, ofbToPrfDistinguisher adversary bit has the output law of adversary in the OFB CPA game with challenge bit bit.

Efficiency of the reduction. For every uniform strict oracle-PPT adversary, ofbToPrfDistinguisher adversary bit is uniform strict oracle PPT.

The ideal game #

theorem Cslib.Crypto.advantage_ofbWordCPAGame_le {family : List Bool → List Bool → List Bool} (hlen : ∀ (key query : List Bool), query.length = key.length → (family key query).length = key.length) (adversary : OracleDistinguisher) {n Q L : ℕ} (hQ : ProbOracleComp.IsQueryBounded (adversary n []) Q) (hL : ProbOracleComp.QueriesSatisfy (fun (request : Unit × List Bool) => request.2.length ≤ L) (adversary n [])) :

Concrete CPA bound for OFB mode, after [BS23], Exercise 5.15(b), which asks for CPA security and states no concrete bound. At parameter n, an adversary making at most Q requests of at most L bits has CPA advantage against ofbWordEncrypt family at most the PRF advantages of ofbToPrfDistinguisher adversary false and ofbToPrfDistinguisher adversary true plus 2 (Q L) (Q L + L) / 2 ^ n, from the typed chain-collision bound.

OFB mode is CPA-secure for a pseudorandom function ([BS23], Exercise 5.15(b)): if family is a PseudorandomFunction, OFB mode with n-bit blocks at security parameter n has negligible many-query left-or-right CPA advantage on equal-length pairs of whole blocks, against every uniform strict oracle-PPT adversary. The exercise fixes the number of blocks ℓ; here every number of blocks is admitted.