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 #
SampleableType— base typeclass:Fintype + Nonempty + DecidableEq + InhabitedCryptoWord— extendsSampleableTypewith involutive XOR (wxor)wxorEquiv— bijection fromwxor_cancelrHoare_sample_wxor— coupling lemma for wxor
Main results #
advantage_zero_of_wxor— zero advantage for wxor-based gamesSampleableType Bool/CryptoWord BoolinstancesSampleableType (BitVec n)/CryptoWord (BitVec n)instances
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).
- fintype : Fintype W
- nonempty : Nonempty W
- deceq : DecidableEq W
- inhabited : Inhabited W
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.).
- deceq : DecidableEq W
- wxor : W → W → W
The XOR-like operation
wxor is involutive:
wxor (wxor a b) b = awxor is commutative
Instances
Bool Instances #
Equations
- CatCrypt.Crypto.instSampleableTypeBool = { fintype := Bool.fintype, nonempty := ⋯, deceq := instDecidableEqBool, inhabited := instInhabitedBool }
Equations
- One or more equations did not get rendered due to their size.
For Bool, wxor is definitionally xor.
BitVec Instance #
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
- CatCrypt.Crypto.instFintypeBitVec n = Fintype.ofEquiv (Fin (2 ^ n)) { toFun := BitVec.ofFin, invFun := BitVec.toFin, left_inv := ⋯, right_inv := ⋯ }
BitVec n is sampleable (finite, nonempty, decidable equality, inhabited).
Equations
- CatCrypt.Crypto.instSampleableTypeBitVec n = { fintype := CatCrypt.Crypto.instFintypeBitVec n, nonempty := ⋯, deceq := instDecidableEqBitVec, inhabited := BitVec.instInhabited }
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
- CatCrypt.Crypto.instCryptoWordBitVec n = { toSampleableType := CatCrypt.Crypto.instSampleableTypeBitVec n, wxor := fun (a b : BitVec n) => a ^^^ b, wxor_cancel := ⋯, wxor_comm := ⋯ }
Derived Properties #
Left cancellation: wxor a (wxor a b) = b.
Follows from wxor_cancel and wxor_comm.
XOR Equivalence (Bijection) #
wxor with a fixed value is an equivalence (bijection).
This is the CryptoWord analogue of boolXorBij from XorBij.lean.
Equations
- CatCrypt.Crypto.wxorEquiv x = { toFun := fun (k : W) => CatCrypt.Crypto.CryptoWord.wxor k x, invFun := fun (r : W) => CatCrypt.Crypto.CryptoWord.wxor r x, left_inv := ⋯, right_inv := ⋯ }
Instances For
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.