Documentation

CatCryptCore.Examples.CTRMode

Counter (CTR) Mode: the Perfect Single-Block Instantiation #

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

A single message block m is encrypted as (nonce, E(k, nonce) ⊕ m) for a fresh uniform nonce (the initial counter value): the keystream block E(k, nonce) acts as a one-time pad. Decryption recomputes E(k, nonce) from the transmitted nonce and un-pads. This single-block CTR construction is exactly the CPA-from-PRF construction (CatCrypt.Examples.CPAFromPRF) with the PRF input specialized to the counter/nonce, so we obtain its security for free.

The perfect instantiation #

Model the block cipher in CTR mode as a bijection family: for each counter value ctr, the keystream map keystream ctr : KeyBlock, k ↦ E(k, ctr), is a bijection from keys to blocks (the ideal-cipher / perfect-PRF model). Over a uniform key the keystream block E(k, nonce) is then uniform on Block, independent of the message, so the pad E(k, nonce) ⊕ m is uniform regardless of m. The two IND-CPA games (encrypting m₀ vs. m₁) are perfectly indistinguishable: the IND-CPA advantage of every adversary is exactly 0.

Scope #

This file proves the single-block statement, which is the clean core-provable case (it coincides with CPA-from-PRF). Genuine multi-block CTR — encrypting (m₁, …, mₙ) as (nonce, E(k, nonce+0) ⊕ m₁, …, E(k, nonce+n-1) ⊕ mₙ) — needs a product-of-bijections (independent-keystream-block) argument not developed in core, and is deliberately out of scope here.

Main definitions #

Main results #

References #

The Single-Block CTR Scheme #

Data for single-block CTR-mode encryption Enc(k, m) = (nonce, E(k, nonce) ⊕ m).

keystream ctr : KeyBlock is the counter-indexed keystream map k ↦ E(k, ctr), required to be a bijection for each counter value (the ideal-cipher / perfect-PRF model), and xorBlock is an involutive XOR on blocks. For a uniform key the keystream block keystream nonce k is uniform, which is the source of perfect security.

Instances For

    Single-block CTR is CPA-from-PRF with the PRF input taken to be the nonce: Input = Output = Block, bij = keystream, xorOut = xorBlock.

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

      The core EncScheme induced by a single-block CTR scheme: encrypt k m = do nonce ← sample Block; pure (nonce, (keystream nonce k) ⊕ m).

      Equations
      Instances For

        Correctness #

        The scheme is correct: decrypting (nonce, (keystream nonce k) ⊕ m) recovers m.

        Perfect IND-CPA Security #

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

        Over a uniform key the keystream block keystream nonce k is uniform on Block (bijection family), so the pad keystream nonce k ⊕ m is uniform regardless of m; the two IND-CPA games are therefore perfectly indistinguishable.

        Example: single-block CTR over Bool #

        Block cipher E(k, n) = k ⊕ n (keystream n = boolXorBij n), giving Enc(k, m) = (n, (k ⊕ n) ⊕ m) for a fresh bit n.

        Single-block CTR over Bool with block cipher E(k, n) = k ⊕ n.

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

          The Computational IND-CPA Bound from the Block Cipher's PRF Security #

          The perfect result above models the block cipher in CTR mode as an ideal cipher (a bijection family), giving IND-CPA advantage exactly 0. The standard computational reduction that a real block cipher would use bounds the CTR IND-CPA advantage by the block cipher's PRF advantage ε_prf, via the two-hop game walk

          HopTransitionBound
          PRF-swapreal challenge game → ctrIdealGame (keystream E(k,·) → random function)ε_prf (PRFAssumption)
          perfectctrIdealGame → other challenge world (random pad is message-independent)0

          The perfect hop is an SPComp game equality proved by bind_vcgen; the PRF-swap hop is the reduction's soundness, taken as a hypothesis and discharged by the PRFAssumption. Composition is the advantage triangle inequality.

          The message-independent ideal CTR game: output a fresh nonce and a fresh uniform pad (nonce, pad). This is CTR encryption with the keystream E(k,·) replaced by a random function; being independent of the message, both IND-CPA challenge worlds collapse onto it.

          Equations
          Instances For

            At a fixed nonce r, the keystream-then-XOR map k ↦ E(k, r) ⊕ msg is a bijection KeyBlock: compose the keystream bijection keystream r with the involutive XOR by msg. This is the change of variables that turns the (uniform key) pad into a uniform block, i.e. the coupling behind the perfect hop.

            Equations
            Instances For

              Perfect hop. Each concrete IND-CPA challenge game equals the message-independent ctrIdealGame: sampling the nonce first (via bijCPA_game_eq) and then changing variables k ↦ E(k, r) ⊕ msg through padEquiv collapses the keyed pad to a fresh uniform block. Proved by bind_vcgen using the coupling bijection.

              Single-block CTR mode: the computational IND-CPA bound.

              The IND-CPA advantage of single-block CTR is at most the block cipher's PRF advantage H.ε. The proof is the advantage triangle inequality over the two hops:

              • the PRF-swap hop AdvantageA (challenge true) (ctrIdealGame) A is the reduction's soundness (hswap): an IND-CPA distinguisher here is a PRF distinguisher Ared on input x, so the hop is bounded by PRF_Adv F x Ared, which PRFAssumption H caps at H.ε;
              • the perfect hop AdvantageA (ctrIdealGame) (challenge false) A is 0, because ctr_game_eq_ideal identifies ctrIdealGame with the false challenge world.

              Because CTRBlockScheme is the ideal-cipher (bijection-family) model, the PRF-swap hop is itself 0 here (see ctr_perfect_indcpa); the theorem states the reduction in the general form a real PRF instantiation uses.