Documentation

CatCryptCore.Crypto.CryptoWord

CryptoWord Typeclass #

Abstract interface for word types used in cryptographic constructions.

Overview #

Currently Word = Bool is hardcoded in PRFPRG.lean. This typeclass provides an abstract interface so new constructions (like CBC mode) can be written generically while existing Bool-specific proofs remain untouched.

Main definitions #

Main results #

Typeclass Hierarchy #

Base class for types that can be uniformly sampled in CatCrypt games. Requires Fintype (for uniform distribution), Nonempty (distribution is well-defined), DecidableEq (for equality checks in games), and Inhabited (for default values in extraction bridges).

Instances

    Abstract word type for cryptographic constructions. Extends SampleableType with an involutive XOR operation, needed for one-time-pad style proofs (symmetric ratchet, PSK injection, etc.).

    Instances

      Bool Instances #

      @[implicit_reducible]
      Equations
      @[implicit_reducible]
      Equations
      • One or more equations did not get rendered due to their size.

      For Bool, wxor is definitionally xor.

      BitVec Instance #

      @[irreducible]
      noncomputable instance CatCrypt.Crypto.instFintypeBitVec (n : ) :

      Fintype instance for BitVec n via the bijection with Fin (2^n). Marked @[irreducible] to prevent kernel reduction of 2^n for large n (e.g., BitVec 256). The instance is still found by typeclass search.

      Equations
      @[irreducible]

      BitVec n is sampleable (finite, nonempty, decidable equality, inhabited).

      Equations
      @[irreducible]
      noncomputable instance CatCrypt.Crypto.instCryptoWordBitVec (n : ) :

      BitVec n forms a CryptoWord with wxor = XOR. This enables all CatCrypt security proofs to work at any bit width, including the concrete BitVec 256 level matching P-256 / SHA-256. Marked @[irreducible] to prevent kernel reduction for large n.

      Equations

      Derived Properties #

      theorem CatCrypt.Crypto.CryptoWord.wxor_left_cancel {W : Type} [CryptoWord W] (a b : W) :
      wxor a (wxor a b) = b

      Left cancellation: wxor a (wxor a b) = b. Follows from wxor_cancel and wxor_comm.

      XOR Equivalence (Bijection) #

      def CatCrypt.Crypto.wxorEquiv {W : Type} [CryptoWord W] (x : W) :
      W W

      wxor with a fixed value is an equivalence (bijection). This is the CryptoWord analogue of boolXorBij from XorBij.lean.

      Equations
      Instances For
        @[simp]

        Coupling Lemma #

        Sampling a key and applying wxor has the same distribution as sampling directly. CryptoWord analogue of rHoare_sample_xor.

        Zero Advantage #

        Zero advantage for wxor-based games. CryptoWord analogue of advantage_zero_of_xor.