Documentation

CslibFrontier.Crypto.Computational.Encryption.CBCMode.Uniform

Cipher block chaining with a random IV from a uniform block cipher #

Cipher block chaining (CBC) with a random initialization vector ([BS23], Section 5.4.3, printed p. 194) encrypts a message of v blocks m[0], …, m[v - 1] under a key k by drawing a uniform initial value c[0] = iv and computing c[j + 1] = E(k, c[j] ⊕ m[j]), outputting c[0] ++ c[1] ++ … ++ c[v]; decryption recovers m[j] = c[j] ⊕ D(k, c[j + 1]). Unlike CTR and OFB modes, CBC decryption applies the block cipher's inverse D, so the cipher (BlockCipher.cbcEncrypt, BlockCipher.cbcDecrypt) is parameterized by an arbitrary uniform E : BlockCipher with key length E.keyLen n and block length E.blockLen n (with no id restriction on either schedule), built from the width-parameterized core cbcWordEncrypt and cbcWordDecrypt via ivModeEncrypt and ivModeDecrypt with the chained bodies cbcWordBody and cbcWordDecBody (truncating each step output to the block width so encryption and decryption are polynomial-time on arbitrary keys, which changes nothing on valid outputs).

Security is many-query left-or-right CPA security (SymmetricINDCPAOn, Attack Game 5.2 and Definition 5.2) on equal-length pairs of whole blocks (blockPairValid), in the standard model, against uniform strict oracle-PPT adversaries. For a BlockCipher E, the distinguisher E.cbcToPrpDistinguisher adversary bit runs ivModeToPrfDistinguisher cbcBodyQueries at block width E.blockLen n on adversary n [], answering each admissible pair by drawing a uniform E.blockLen n-bit initial value and querying its encryption oracle sequentially on c[j] ⊕ m[j].

  1. E.cbcToPrpDistinguisher adversary bit is uniform strict oracle PPT whenever the adversary is (BlockCipher.isOraclePPT_cbcToPrpDistinguisher).
  2. Against E.prpRealGame, it has the exact output law of adversary in the random-IV CBC CPA game for E.cbcEncrypt with challenge bit bit (BlockCipher.eval_prpRealGame_cbcToPrpDistinguisher).
  3. Against a uniform random permutation, for an adversary whose requests have at most L bits, it has the output law of the typed CBC experiment (CBCMode.lean), giving the concrete block-cipher bound BlockCipher.advantage_cbcEncrypt_le (after Theorem 5.4, (5.22)) and the asymptotic CPA security theorem BlockCipher.PRP.indcpa_cbcEncrypt ([BS23], Theorem 5.4, for any E : BlockCipher with E.PRP and super-polynomial block space Negligible fun n => ((2 : ℝ≥0) ^ E.blockLen n)⁻¹).

Deviations from Theorem 5.4 #

Main definitions #

Main results #

References #

The cipher #

def Cslib.Crypto.cbcWordBody (encFamily : List Bool → List Bool → List Bool) (n : ℕ) (k iv msg : List Bool) :

The CBC ciphertext body (after the initial value iv) of the msg.length / n blocks of msg under encFamily k: starting from (iv, []), XOR the current chaining block with the next n-bit message block, apply encFamily k truncated to n bits, and append it to the body so far.

noncomputable def Cslib.Crypto.cbcWordEncrypt (encFamily : List Bool → List Bool → List Bool) :

Random-IV CBC encryption ([BS23], Section 5.4.3, printed pp. 194–195): draw a uniform n-bit initial value iv and output iv followed by cbcWordBody encFamily n k iv msg.

def Cslib.Crypto.cbcWordDecBody (decFamily : List Bool → List Bool → List Bool) (n : ℕ) (k iv body : List Bool) :

The CBC decryption body (from initial value iv and ciphertext body body): recover each n-bit plaintext block as the XOR of the previous ciphertext block with decFamily k of the current ciphertext block (truncated to n bits).

Random-IV CBC decryption ([BS23], Section 5.4.3, printed p. 194): accept an n-bit initial value followed by whole n-bit ciphertext blocks (ivModeDecrypt), and recover the plaintext blocks via cbcWordDecBody. Malformed ciphertexts (shorter than n bits, or whose body is not a multiple of n bits) return none.

theorem Cslib.Crypto.cbcWordDecrypt_cbcWordEncrypt {encFamily decFamily : List Bool → List Bool → List Bool} {n : ℕ} {k : List Bool} (hlen : ∀ (block : List Bool), block.length = n → (encFamily k block).length = n) (hinv : ∀ (block : List Bool), block.length = n → decFamily k (encFamily k block) = block) {msg : List Bool} (hmsg : msg.length % n = 0) {ct : List Bool} (hct : ct ∈ (cbcWordEncrypt encFamily n k msg).eval.support) :
cbcWordDecrypt decFamily n k ct = some msg

Decryption inverts encryption on whole-block messages whenever encFamily k preserves n-bit blocks and decFamily k left-inverts encFamily k on n-bit blocks.

noncomputable def Cslib.Crypto.BlockCipher.cbcEncrypt (E : BlockCipher) (n : ℕ) (k msg : List Bool) :

Random-IV CBC encryption for an arbitrary uniform BlockCipher E ([BS23], Section 5.4.3, printed p. 194): at parameter n, draw a uniform E.blockLen n-bit initial value iv and output iv followed by cbcWordBody (E.encrypt n) (E.blockLen n) k iv msg.

Random-IV CBC decryption for an arbitrary uniform BlockCipher E ([BS23], Section 5.4.3, printed p. 194): accept an E.blockLen n-bit initial value followed by whole E.blockLen n-bit ciphertext blocks (ivModeDecrypt), and recover the plaintext blocks via cbcWordDecBody (E.decrypt n).

theorem Cslib.Crypto.BlockCipher.cbcDecrypt_cbcEncrypt (E : BlockCipher) {n : ℕ} {k : List Bool} (hk : k.length = E.keyLen n) {msg : List Bool} (hmsg : msg.length % E.blockLen n = 0) {ct : List Bool} (hct : ct ∈ (E.cbcEncrypt n k msg).eval.support) :
E.cbcDecrypt n k ct = some msg

For every BlockCipher E, E.cbcDecrypt inverts E.cbcEncrypt on whole-block messages under E.keyLen n-bit keys.

Efficiency of the honest algorithms #

For every BlockCipher E, E.cbcEncrypt is uniformly strict PPT in (n, k, msg).

Certified word-oracle reduction #

One CBC encryption query step: send the XOR of the chaining block prev and the next message block to the function oracle, keep at most n bits of the reply as the next chaining block, and append it to the ciphertext body so far.

The CBC ciphertext body of msg from initial value iv, computed with one query to the function oracle per n-bit block.

theorem Cslib.Crypto.run_cbcBodyQueries {n : ℕ} (g : List Bool → List Bool) (iv msg : List Bool) :
(ProbOracleComp.run (cbcBodyQueries n iv msg) fun (request : Unit × List Bool) => pure (g request.2)) = pure (cbcWordBody (fun (x x_1 : List Bool) => g x_1) n [] iv msg)

Answered by any deterministic oracle g, cbcBodyQueries computes cbcWordBody for g.

Ideal games and concrete CPA bounds #

The block-cipher distinguisher built from a left-or-right CPA adversary against E.cbcEncrypt ([BS23], proof of Theorem 5.4, adversary B): run ivModeToPrfDistinguisher cbcBodyQueries at block width E.blockLen n on adversary n [].

Efficiency of the block-cipher reduction. For every BlockCipher E and every uniform strict oracle-PPT adversary, E.cbcToPrpDistinguisher adversary bit is uniform strict oracle PPT.

Real block-cipher game. Against E.prpRealGame, E.cbcToPrpDistinguisher adversary bit has the exact output law of adversary in the random-IV CBC CPA game for E.cbcEncrypt with challenge bit bit.

theorem Cslib.Crypto.BlockCipher.advantage_cbcEncrypt_le (E : BlockCipher) (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 word-level CPA bound for random-IV CBC mode, after [BS23], Theorem 5.4, (5.22). For any BlockCipher E, an adversary at parameter n making at most Q requests of at most L bits has CPA advantage against E.cbcEncrypt at most the PRP advantages of E.cbcToPrpDistinguisher adversary false and E.cbcToPrpDistinguisher adversary true plus 4 * ((Q * L).choose 2 / 2 ^ E.blockLen n). Requests of L bits ask for at most L blocks, so Q * L bounds the blocks encrypted in total. This is not the bound (5.22), which has one distinguisher with a factor 2 and the collision term 2 Q ^ 2 ℓ ^ 2 / N for ℓ blocks per request; see the module's deviations.

Asymptotic CPA security (Theorem 5.4) #

theorem Cslib.Crypto.BlockCipher.PRP.indcpa_cbcEncrypt {E : BlockCipher} (hprp : E.PRP) (hneg : Negligible fun (n : ℕ) => (2 ^ E.blockLen n)⁻¹) :

Random-IV CBC mode is CPA-secure for a pseudorandom permutation ([BS23], Section 5.4.3, Theorem 5.4, printed pp. 195–199): for any uniform BlockCipher E with E.PRP and super-polynomial block space Negligible fun n => ((2 : ℝ≥0) ^ E.blockLen n)⁻¹, random-IV CBC mode E.cbcEncrypt has negligible many-query left-or-right CPA advantage on equal-length pairs of whole E.blockLen n-bit blocks under uniform E.keyLen n-bit keys, against every uniform strict oracle-PPT adversary.