Documentation

CatCryptCore.Examples.DeepHybrid

Hybrid Argument for XOR Encryption #

This file carries out the hybrid argument for two and three instances of one-bit XOR encryption, after ProofFrog's Hybrid protocol. The games are shallow SPComp computations.

Overview #

Hybrid Arguments: A standard technique for proving security reductions. If a single instance of a primitive is secure, then n instances are secure with advantage at most n times the single-instance advantage.

Core Idea: We construct a sequence of hybrid games:

Each adjacent pair of hybrids differs in exactly one position, enabling a reduction to single-instance security.

Main Results #

ProofFrog Comparison #

ProofFrog's Hybrid protocol (for PubEnc):

This file:

References #

Type Definitions #

@[reducible, inline]

Message/key/ciphertext type (simplified to Bool)

Equations
Instances For

    Single-Instance Oracles #

    The hybrid argument is based on two oracles:

    Single-Instance Security #

    The key property: XOR encryption is perfectly secure (zero advantage)

    XOR encryption produces indistinguishable outputs for any two messages.

    The proof uses bijection coupling: for uniform k, xor k m is uniformly distributed, so realOracle m and idealOracle m produce the same distribution.

    XOR encryption has zero distinguishing advantage

    Hybrid Game Structure #

    For n oracle calls, we define:

    Select oracle based on position relative to hybrid index

    Equations
    Instances For

      Two-Instance Hybrid Games #

      For concrete demonstration, we define hybrid games for two encryption instances.

      Real game: both encryptions use real oracle

      Equations
      Instances For

        Hybrid 1: first encryption ideal, second real

        Equations
        Instances For

          Ideal game: both encryptions use ideal oracle

          Equations
          Instances For

            Hybrid Step Couplings #

            theorem CatCrypt.Examples.DeepHybrid.step_0_1_coupling (m₀ m₁ : Word) :
            Relational.rHoare Relational.eqPre (twoReal m₀ m₁) (twoHybrid m₀ m₁) fun (p₁ : Word × Word) (h₁ : Core.Heap) (p₂ : Word × Word) (h₂ : Core.Heap) => p₁.2 = p₂.2 ∧ Relational.eqPre h₁ h₂

            Coupling between twoReal and twoHybrid (differ in position 0)

            The key insight: both games use the same second oracle call (realOracle m₁), so the second components will match. The first components differ but we don't need them to match for this postcondition.

            theorem CatCrypt.Examples.DeepHybrid.step_1_2_coupling (m₀ m₁ : Word) :
            Relational.rHoare Relational.eqPre (twoHybrid m₀ m₁) (twoIdeal m₀ m₁) fun (p₁ : Word × Word) (h₁ : Core.Heap) (p₂ : Word × Word) (h₂ : Core.Heap) => p₁.1 = p₂.1 ∧ Relational.eqPre h₁ h₂

            Coupling between twoHybrid and twoIdeal (differ in position 1)

            The key insight: both games use the same first oracle call (idealOracle m₀), so the first components will match.

            Triangle Inequality for Advantage #

            The total advantage is bounded by the sum of step advantages.

            theorem CatCrypt.Examples.DeepHybrid.two_instance_advantage_bound (m₀ m₁ : Word) (A : Word × Word → Core.SPComp Bool) :
            Crypto.AdvantageA (twoReal m₀ m₁) (twoIdeal m₀ m₁) A ≤ Crypto.AdvantageA (twoReal m₀ m₁) (twoHybrid m₀ m₁) A + Crypto.AdvantageA (twoHybrid m₀ m₁) (twoIdeal m₀ m₁) A

            Advantage bound: Real to Ideal via Hybrid

            N-Instance Generalization #

            For the general case with n instances, we use a simpler fixed-size structure.

            noncomputable def CatCrypt.Examples.DeepHybrid.threeHybrid (i : ℕ) (m₀ m₁ m₂ : Word) :

            Hybrid games for 3 instances

            Equations
            • One or more equations did not get rendered due to their size.
            Instances For
              theorem CatCrypt.Examples.DeepHybrid.threeHybrid_0_is_real (m₀ m₁ m₂ : Word) :
              threeHybrid 0 m₀ m₁ m₂ = do let c₀ ← realOracle m₀ let c₁ ← realOracle m₁ let c₂ ← realOracle m₂ Core.SPComp.pure (c₀, c₁, c₂)

              Hybrid 0 = all real

              theorem CatCrypt.Examples.DeepHybrid.threeHybrid_3_is_ideal (m₀ m₁ m₂ : Word) :
              threeHybrid 3 m₀ m₁ m₂ = do let c₀ ← idealOracle m₀ let c₁ ← idealOracle m₁ let c₂ ← idealOracle m₂ Core.SPComp.pure (c₀, c₁, c₂)

              Hybrid 3 = all ideal

              theorem CatCrypt.Examples.DeepHybrid.three_instance_triangle (m₀ m₁ m₂ : Word) (A : ThreeOutput → Core.SPComp Bool) :
              Crypto.AdvantageA (threeHybrid 0 m₀ m₁ m₂) (threeHybrid 3 m₀ m₁ m₂) A ≤ Crypto.AdvantageA (threeHybrid 0 m₀ m₁ m₂) (threeHybrid 1 m₀ m₁ m₂) A + Crypto.AdvantageA (threeHybrid 1 m₀ m₁ m₂) (threeHybrid 2 m₀ m₁ m₂) A + Crypto.AdvantageA (threeHybrid 2 m₀ m₁ m₂) (threeHybrid 3 m₀ m₁ m₂) A

              Triangle bound for 3-instance case

              Perfect Security for XOR Encryption #

              For XOR encryption, each single step has zero advantage, so the total advantage is also zero.

              Key lemma: realOracle and idealOracle produce identical distributions.

              Since XOR with a uniform random key produces a uniform distribution, both oracles sample from the same distribution. This means all hybrid games are actually identical!

              theorem CatCrypt.Examples.DeepHybrid.threeHybrid_simpl (i : ℕ) (m₀ m₁ m₂ : Word) :
              threeHybrid i m₀ m₁ m₂ = do let c₀ ← idealOracle m₀ let c₁ ← idealOracle m₁ let c₂ ← idealOracle m₂ Core.SPComp.pure (c₀, c₁, c₂)

              All threeHybrid games simplify to the same computation.

              Since realOracle = idealOracle for XOR encryption, all branches of the hybrid game produce the same result.

              theorem CatCrypt.Examples.DeepHybrid.hybrid_step_zero_advantage (i : ℕ) (m₀ m₁ m₂ : Word) (A : ThreeOutput → Core.SPComp Bool) (_hi : i < 3) :
              Crypto.AdvantageA (threeHybrid i m₀ m₁ m₂) (threeHybrid (i + 1) m₀ m₁ m₂) A ≤ 0

              Key observation: Each step in a hybrid ladder for XOR has zero advantage.

              This is because realOracle and idealOracle produce identical distributions (both sample uniformly). Therefore consecutive hybrids are actually the same game, giving advantage = 0.

              Summary #

              This file demonstrates the generic hybrid argument pattern:

              Structure #

              1. Single-Instance Security: Prove real and ideal oracles are indistinguishable

              2. Hybrid Ladder: Define intermediate games

              3. Step Bounds: Each adjacent step bounded by single-instance advantage

              4. Triangle Inequality: Total advantage bounded by sum of steps

              ProofFrog Comparison #

              ProofFrogThis file
              Auto hybrid generationExplicit selectOracle
              Z3 for equivalencerHoare + coupling
              ~50 lines~350 lines
              Fast iterationMachine-checked

              Key Insight #

              For XOR encryption (or any perfectly secure primitive):

              For computationally secure primitives, the bound would be:

              This is the standard "n-factor security loss" of hybrid arguments.

              Proved results #