Documentation

CatCryptCore.Examples.CBCMode

CBC Mode: Perfect IND-CPA Security for a Single Block #

Cipher-block-chaining (CBC) mode turns a block cipher into an IND-CPA-secure symmetric encryption scheme. Following Rosulek, The Joy of Cryptography, §8 (block cipher modes).

A block cipher is a keyed family of permutations F(k, ·) : BlockBlock. CBC encryption of a message m₁ … mₙ draws a uniform initialization vector IV and sets

c₀ = IV        cᵢ = F(k, cᵢ₋₁ ⊕ mᵢ)

transmitting (c₀, c₁, …, cₙ). Each block is masked by the previous ciphertext block before the cipher is applied, and the random IV seeds the chain.

The single-block, perfect instantiation #

This file proves the single-block case, where the ciphertext is (IV, F(k, IV ⊕ m)), and instantiates the block cipher by a family that is bijective in both arguments:

This second property is exactly the perfect-PRF condition of CatCrypt.Examples.PRF (BijPRFFamily); a block cipher meeting it behaves like a truly random permutation evaluated at a single point. Under it, the two IND-CPA games (encrypting m₀ vs m₁) are perfectly indistinguishable: the IND-CPA advantage of every adversary is exactly 0.

Overview #

The security argument is the bijection-coupling technique, structured exactly as CatCrypt.Examples.CPAFromPRF. The IV is sampled first (SPComp.swap_sample_sample) and synchronized across the two games (rHoare_same_step); then at each fixed IV the key is coupled by the bijection keyEquiv IV m₀ m₁ : KeyKey chosen so that F(k, IV ⊕ m₀) = F(keyEquiv IV m₀ m₁ k, IV ⊕ m₁), forcing the two ciphertexts to coincide (rHoare_bij_step).

Multi-block CBC (n > 1) is not perfectly secure — its security reduces to the pseudorandomness of the block cipher — and is deliberately out of scope.

Main definitions #

Main results #

References #

The CBC Block Cipher #

A block cipher for single-block CBC mode: a keyed permutation of Block that is bijective in both arguments, together with a block masking operation.

  • perm k : BlockBlock is the keyed permutation F(k, ·) (invertible per key, so decryption works);
  • keyBij x : KeyBlock witnesses that k ↦ F(k, x) is a bijection for each cipher input x (so over a uniform key the output is uniform — the source of perfect security), and coh says these two views agree: keyBij x k = perm k x;
  • xorB is the block masking operation chaining IV into the message, with xorB_cancel making it self-inverse.
Instances For

    The core EncScheme induced by single-block CBC.

    • Key, Plaintext = Block, Ciphertext = Block × Block (the pair (IV, c₁))
    • keyGen samples a uniform key
    • encrypt k m = do IV ← sample Block; pure (IV, F(k, IV ⊕ m))
    • decrypt k (IV, c) = pure (some (F(k, ·)⁻¹(c) ⊕ IV))
    Equations
    • One or more equations did not get rendered due to their size.
    Instances For

      Correctness #

      Single-block CBC is correct: decrypting (IV, F(k, IV ⊕ m)) recovers m.

      Decryption inverts the cipher — F(k, ·)⁻¹(F(k, IV ⊕ m)) = IV ⊕ m — and then un-masks with IV, and (IV ⊕ m) ⊕ IV = m.

      Perfect IND-CPA Security #

      The key-space bijection coupling the two IND-CPA games at a fixed IV: it maps k to the unique key k' with F(k', IV ⊕ m₁) = F(k, IV ⊕ m₀), so the two ciphertexts agree.

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For
        theorem CatCrypt.Examples.CBCMode.cbc_game_eq (C : CBCBlockCipher) (m₀ m₁ : C.Block) (b : Bool) :
        Crypto.SecurityDefs.INDCPA_Game C.toEncScheme m₀ m₁ b = (Core.SPComp.sample C.Block).bind fun (iv : C.Block) => (Core.SPComp.sample C.Key).bind fun (k : C.Key) => Core.SPComp.pure (iv, (C.perm k) (C.xorB iv (if b = true then m₀ else m₁)))

        Reordered form of the IND-CPA game: sample the IV first, then the key, then output (IV, F(k, IV ⊕ (if b then m₀ else m₁))).

        Coupling: the two IND-CPA games for single-block CBC are equidistributed.

        At each fixed IV, over a uniform key k the block F(k, IV ⊕ m) is uniform, so the m₀- and m₁-ciphertexts have the same distribution; keyEquiv IV m₀ m₁ couples the two keys so the ciphertexts agree pointwise.

        Single-block CBC has perfect IND-CPA security: every adversary has IND-CPA advantage exactly 0.

        The computational reduction: CBC IND-CPA ≤ block-cipher PRP advantage #

        cbc_perfect_indcpa above is perfect (ε = 0) because the block cipher there is idealized — bijective in the key, so over a uniform key the cipher output is exactly uniform. A real block cipher is only a pseudorandom permutation: it merely looks uniform to a bounded distinguisher, with some advantage ε.

        The computational bound follows. Single-block CBC over a real block cipher eval has IND-CPA advantage at most 2·ε, where ε is the block cipher's PRP/PRF advantage (PRFAssumption). The reduction is the standard real-or-random ladder over four games

        `real_true  —swap→  ideal_true  —perfect→  ideal_false  —swap→  real_false`,
        

        composed by the advantage triangle inequality:

        HopTransitionBound
        real_true → ideal_truereplace eval by the ideal (bijective) cipherε (PRP/PRF assumption)
        ideal_true → ideal_falseuniform-IV masking makes the ideal challenge message-independent0 (perfect)
        ideal_false → real_falsereplace the ideal cipher back by evalε (PRP/PRF assumption)

        The two swap hops are the reduction to the block cipher's security (each bounded by the PRF advantage of a reduction adversary, then by the PRFAssumption); the middle hop is the perfect step, proved here via bind_vcgen.

        The real single-block CBC scheme over an arbitrary keyed block function eval : KeyBlockBlock (the computational block cipher, not assumed bijective). Its ciphertext type Block × Block matches toEncScheme's, so the same adversary distinguishes both. Decryption is irrelevant to IND-CPA and is left as a stub.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          The ideal single-block cipher call is a fresh uniform block: over a uniform key k, F(k, x) is uniform on Block and independent of x. Proved by bind_vcgen using (C.keyBij x) — the change of variables through the key→block bijection turns the keyed evaluation into a plain uniform sample.

          The ideal CBC challenge is message-independent: for the bijective block cipher, (IV, F(k, IV ⊕ m)) over uniform IV, k is distributed as a uniform pair (IV, c), regardless of the message or the challenge bit b. This is the uniform-IV masking that makes the ideal game perfectly secure.

          Single-block CBC IND-CPA advantage is bounded by the block cipher's PRP/PRF advantage.

          For a real block cipher eval, the IND-CPA advantage of single-block CBC is at most 2·H.ε, where H : PRFAssumption F is the block cipher's pseudorandomness assumption. The two swap hops hswap0/hswap1 express the reduction: each is bounded by the PRF advantage of a reduction adversary (PRF_Adv F xᵢ Aᵢ), which the assumption bounds by H.ε. The middle (perfect) hop is cbc_ideal_game_uniform: the two ideal games coincide, so their advantage is 0. The three are composed by the advantage triangle inequality.

          Example: single-block CBC over Bool #

          The trivial perfect block cipher F(k, x) = k ⊕ x — the same bijection family underlying the one-time pad and boolXorPRF — is bijective in both arguments, so single-block CBC over Bool is perfectly IND-CPA. The ciphertext is (IV, (IV ⊕ m) ⊕ k).

          Single-block CBC over Bool with block cipher F(k, x) = k ⊕ x.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For

            Single-block CBC over Bool has perfect IND-CPA security.