Documentation

CslibFrontier.Crypto.Computational.EvenMansour

Word-level Even–Mansour block cipher and ideal-permutation PRP security #

The Even–Mansour block cipher ([EM97]; [BS23], Section 4.7; [KL20]) constructs a block cipher on n-bit blocks from a public permutation P by XORing pre-whitening and post-whitening keys before and after P: $$E_{k_1, k_2}(x) = P(x \oplus k_1) \oplus k_2, \qquad D_{k_1, k_2}(y) = P^{-1}(y \oplus k_2) \oplus k_1,$$ together with the single-key variant $E_k(x) = P(x \oplus k) \oplus k$ ([DKS12]).

This module provides the computational word-level counterpart to CslibFrontier.Crypto.Protocols.Cipher.EvenMansour, mirroring how CslibFrontier.Crypto.Computational.LubyRackoff pairs with CslibFrontier.Crypto.Protocols.Cipher.LubyRackoff:

  1. Word-level Even–Mansour operations and ComputableInPolyTime certificates: evenMansourPreKeyWord, evenMansourPostKeyWord, splitTwoKeys, evenMansourEncryptWord, evenMansourDecryptWord, singleKeyEvenMansourEncryptWord, and singleKeyEvenMansourDecryptWord act on List Bool words, satisfy exact length, involution, inversion, and BitString n representation laws, and carry ComputableInPolyTime certificates. Given polynomial-time word-level forward and inverse permutations P, P_inv : ℕ → List Bool → List Bool, evenMansourCipher and singleKeyEvenMansourCipher bundle the two-key (2 * n-bit key, n-bit block) and single-key (n-bit key, n-bit block) constructions as uniform BlockCipher instances whose induced permutations BlockCipher.permEquiv agree with EvenMansour.evenMansourEquiv and EvenMansour.singleKeyEvenMansourEquiv.
  2. Asymptotic Negligible security for polynomially query-bounded randomized (ProbOracleComp) distinguishers: building on the finite-group coin-fixing bounds EvenMansour.advantage_evenMansourProbRealGame_bitString_le and EvenMansour.advantage_singleKeyEvenMansourProbRealGame_bitString_le from CslibFrontier.Crypto.Protocols.Cipher.EvenMansour, any family of randomized distinguishers whose cipher and primitive query budgets Q_C, Q_P : ℕ → ℕ are polynomially bounded has Negligible distinguishing advantage (negligible_advantage_evenMansourProbRealGame, negligible_advantage_singleKeyEvenMansourProbRealGame).
  3. Word-oracle (WordOracleComp) ideal-permutation games and IsOraclePPT security: evenMansourWordRealGame, singleKeyEvenMansourWordRealGame, and evenMansourWordIdealGame expose the bidirectional cipher and primitive permutation channels as word oracles (rejecting malformed queries with []), satisfy the 2 * Q_C * Q_P / 2 ^ n security bound, and are Game.Indistinguishable against all IsOraclePPT encBool distinguishers (indistinguishable_evenMansourWordRealGame_evenMansourWordIdealGame, indistinguishable_singleKeyEvenMansourWordRealGame_evenMansourWordIdealGame).

All security results here are information-theoretic in the ideal-permutation model: P is a uniformly random permutation, the bounds hold for every distinguisher with the stated query counts whatever its running time, and the IsOraclePPT theorems use that class only for its polynomial query bound. No computational assumption is involved.

Main definitions #

Main results #

References #

Word-level Even–Mansour operations and ComputableInPolyTime certificates #

Pre-whitening XOR mask on bit words: x ⊕ k₁ (List.zipWith Bool.xor x k₁).

Post-whitening XOR mask on bit words: y ⊕ k₂ (List.zipWith Bool.xor y k₂).

Split a 2 * n-bit key word k₁ ++ k₂ into its two n-bit subkeys (keyBlock n 0 key, keyBlock n 1 key).

Word-level two-key Even–Mansour encryption E_{k₁, k₂}(x) = P(x ⊕ k₁) ⊕ k₂ ([EM97]; [BS23], Section 4.7).

Word-level two-key Even–Mansour decryption D_{k₁, k₂}(y) = P⁻¹(y ⊕ k₂) ⊕ k₁ ([EM97]; [BS23], Section 4.7).

Word-level single-key Even–Mansour encryption E_k(x) = P(x ⊕ k) ⊕ k ([DKS12]).

Word-level single-key Even–Mansour decryption D_k(y) = P⁻¹(y ⊕ k) ⊕ k ([DKS12]).

def Cslib.Crypto.evenMansourEncrypt (P : ℕ → List Bool → List Bool) (n : ℕ) (key block : List Bool) :

Parameterized two-key Even–Mansour encryption on a 2 * n-bit key k₁ ++ k₂ and n-bit block.

def Cslib.Crypto.evenMansourDecrypt (P_inv : ℕ → List Bool → List Bool) (n : ℕ) (key block : List Bool) :

Parameterized two-key Even–Mansour decryption on a 2 * n-bit key k₁ ++ k₂ and n-bit ciphertext.

Parameterized single-key Even–Mansour encryption on an n-bit key and n-bit block.

def Cslib.Crypto.singleKeyEvenMansourDecrypt (P_inv : ℕ → List Bool → List Bool) (n : ℕ) (key block : List Bool) :

Parameterized single-key Even–Mansour decryption on an n-bit key and n-bit ciphertext.

Length, involution, and representation lemmas #

@[simp]

Applying evenMansourPreKeyWord k₁ twice cancels on equal-length words.

@[simp]

Applying evenMansourPostKeyWord k₂ twice cancels on equal-length words.

On BitString n, evenMansourPreKeyWord computes x + k₁.

On BitString n, evenMansourPostKeyWord computes y + k₂.

theorem Cslib.Crypto.length_splitTwoKeys_fst {n : ℕ} {key : List Bool} (hkey : key.length = 2 * n) :
(splitTwoKeys n key).1.length = n

The first subkey returned by splitTwoKeys n key has length n when key.length = 2 * n.

theorem Cslib.Crypto.length_splitTwoKeys_snd {n : ℕ} {key : List Bool} (hkey : key.length = 2 * n) :
(splitTwoKeys n key).2.length = n

The second subkey returned by splitTwoKeys n key has length n when key.length = 2 * n.

theorem Cslib.Crypto.length_evenMansourEncryptWord {n : ℕ} {P : List Bool → List Bool} (hP : ∀ (u : List Bool), u.length = n → (P u).length = n) {k₁ k₂ x : List Bool} (hk₁ : k₁.length = n) (hk₂ : k₂.length = n) (hx : x.length = n) :
(evenMansourEncryptWord P k₁ k₂ x).length = n

Word-level Even–Mansour encryption preserves n-bit block length when P preserves n-bit words and the subkeys have length n.

theorem Cslib.Crypto.length_evenMansourDecryptWord {n : ℕ} {P_inv : List Bool → List Bool} (hP_inv : ∀ (v : List Bool), v.length = n → (P_inv v).length = n) {k₁ k₂ y : List Bool} (hk₁ : k₁.length = n) (hk₂ : k₂.length = n) (hy : y.length = n) :
(evenMansourDecryptWord P_inv k₁ k₂ y).length = n

Word-level Even–Mansour decryption preserves n-bit block length when P_inv preserves n-bit words and the subkeys have length n.

theorem Cslib.Crypto.evenMansourDecryptWord_evenMansourEncryptWord {n : ℕ} {P P_inv : List Bool → List Bool} (hP : ∀ (u : List Bool), u.length = n → (P u).length = n) (hleft : ∀ (u : List Bool), u.length = n → P_inv (P u) = u) {k₁ k₂ x : List Bool} (hk₁ : k₁.length = n) (hk₂ : k₂.length = n) (hx : x.length = n) :
evenMansourDecryptWord P_inv k₁ k₂ (evenMansourEncryptWord P k₁ k₂ x) = x

Word-level Even–Mansour decryption inverts encryption on n-bit words whenever P_inv left-inverts P on n-bit words and P preserves n-bit length.

theorem Cslib.Crypto.evenMansourEncryptWord_evenMansourDecryptWord {n : ℕ} {P P_inv : List Bool → List Bool} (hP_inv : ∀ (v : List Bool), v.length = n → (P_inv v).length = n) (hright : ∀ (v : List Bool), v.length = n → P (P_inv v) = v) {k₁ k₂ y : List Bool} (hk₁ : k₁.length = n) (hk₂ : k₂.length = n) (hy : y.length = n) :
evenMansourEncryptWord P k₁ k₂ (evenMansourDecryptWord P_inv k₁ k₂ y) = y

Word-level Even–Mansour encryption inverts decryption on n-bit words whenever P_inv right-inverts P on n-bit words and P_inv preserves n-bit length.

theorem Cslib.Crypto.singleKeyEvenMansourDecryptWord_singleKeyEvenMansourEncryptWord {n : ℕ} {P P_inv : List Bool → List Bool} (hP : ∀ (u : List Bool), u.length = n → (P u).length = n) (hleft : ∀ (u : List Bool), u.length = n → P_inv (P u) = u) {k x : List Bool} (hk : k.length = n) (hx : x.length = n) :

Single-key word-level decryption inverts encryption on n-bit words.

theorem Cslib.Crypto.singleKeyEvenMansourEncryptWord_singleKeyEvenMansourDecryptWord {n : ℕ} {P P_inv : List Bool → List Bool} (hP_inv : ∀ (v : List Bool), v.length = n → (P_inv v).length = n) (hright : ∀ (v : List Bool), v.length = n → P (P_inv v) = v) {k y : List Bool} (hk : k.length = n) (hy : y.length = n) :

Single-key word-level encryption inverts decryption on n-bit words.

theorem Cslib.Crypto.evenMansourEncryptWord_ofFn {n : ℕ} {P : List Bool → List Bool} {π : Equiv.Perm (BitString n)} (hP : ∀ (u : BitString n), P (List.ofFn u) = List.ofFn (π u)) (k₁ k₂ x : BitString n) :

When P represents π : Equiv.Perm (BitString n) on n-bit words, evenMansourEncryptWord computes EvenMansour.evenMansourEquiv π k₁ k₂.

theorem Cslib.Crypto.evenMansourDecryptWord_ofFn {n : ℕ} {P_inv : List Bool → List Bool} {π : Equiv.Perm (BitString n)} (hP_inv : ∀ (v : BitString n), P_inv (List.ofFn v) = List.ofFn ((Equiv.symm π) v)) (k₁ k₂ y : BitString n) :

When P_inv represents π.symm on n-bit words, evenMansourDecryptWord computes (EvenMansour.evenMansourEquiv π k₁ k₂).symm.

ComputableInPolyTime certificates #

Uniform BlockCipher bundles #

def Cslib.Crypto.permOfWordFamily (P P_inv : ℕ → List Bool → List Bool) (hP_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P n block).length = n) (hP_inv_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P_inv n block).length = n) (hleft : ∀ (n : ℕ) (block : List Bool), block.length = n → P_inv n (P n block) = block) (hright : ∀ (n : ℕ) (block : List Bool), block.length = n → P n (P_inv n block) = block) (n : ℕ) :

The permutation on BitString n induced by a pair of length-preserving inverse word functions (P n, P_inv n).

def Cslib.Crypto.evenMansourCipher (P P_inv : ℕ → List Bool → List Bool) (hP_poly : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool) => P p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hP_inv_poly : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool) => P_inv p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hP_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P n block).length = n) (hP_inv_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P_inv n block).length = n) (hleft : ∀ (n : ℕ) (block : List Bool), block.length = n → P_inv n (P n block) = block) (hright : ∀ (n : ℕ) (block : List Bool), block.length = n → P n (P_inv n block) = block) :

The uniform two-key Even–Mansour BlockCipher with 2 * n-bit keys and n-bit blocks, built from polynomial-time inverse word permutations P and P_inv ([EM97]; [BS23], Section 4.7).

def Cslib.Crypto.singleKeyEvenMansourCipher (P P_inv : ℕ → List Bool → List Bool) (hP_poly : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool) => P p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hP_inv_poly : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool) => P_inv p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hP_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P n block).length = n) (hP_inv_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P_inv n block).length = n) (hleft : ∀ (n : ℕ) (block : List Bool), block.length = n → P_inv n (P n block) = block) (hright : ∀ (n : ℕ) (block : List Bool), block.length = n → P n (P_inv n block) = block) :

The uniform single-key Even–Mansour BlockCipher with n-bit keys and n-bit blocks, built from polynomial-time inverse word permutations P and P_inv ([DKS12]).

theorem Cslib.Crypto.permEquiv_evenMansourCipher (P P_inv : ℕ → List Bool → List Bool) (hP_poly : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool) => P p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hP_inv_poly : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool) => P_inv p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hP_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P n block).length = n) (hP_inv_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P_inv n block).length = n) (hleft : ∀ (n : ℕ) (block : List Bool), block.length = n → P_inv n (P n block) = block) (hright : ∀ (n : ℕ) (block : List Bool), block.length = n → P n (P_inv n block) = block) (n : ℕ) (key : List Bool) (hkey : key.length = 2 * n) :
(evenMansourCipher P P_inv hP_poly hP_inv_poly hP_len hP_inv_len hleft hright).permEquiv n key hkey = EvenMansour.evenMansourEquiv (permOfWordFamily P P_inv hP_len hP_inv_len hleft hright n) (BitString.ofList n (splitTwoKeys n key).1) (BitString.ofList n (splitTwoKeys n key).2)

The permutation induced by evenMansourCipher on a 2 * n-bit key key equals EvenMansour.evenMansourEquiv with the split n-bit subkeys.

theorem Cslib.Crypto.permEquiv_singleKeyEvenMansourCipher (P P_inv : ℕ → List Bool → List Bool) (hP_poly : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool) => P p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hP_inv_poly : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × List Bool) => P_inv p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encBits) Turing.MultiTapeTM.encBits) (hP_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P n block).length = n) (hP_inv_len : ∀ (n : ℕ) (block : List Bool), block.length = n → (P_inv n block).length = n) (hleft : ∀ (n : ℕ) (block : List Bool), block.length = n → P_inv n (P n block) = block) (hright : ∀ (n : ℕ) (block : List Bool), block.length = n → P n (P_inv n block) = block) (n : ℕ) (key : List Bool) (hkey : key.length = n) :
(singleKeyEvenMansourCipher P P_inv hP_poly hP_inv_poly hP_len hP_inv_len hleft hright).permEquiv n key hkey = EvenMansour.singleKeyEvenMansourEquiv (permOfWordFamily P P_inv hP_len hP_inv_len hleft hright n) (BitString.ofList n key)

The permutation induced by singleKeyEvenMansourCipher on an n-bit key key equals EvenMansour.singleKeyEvenMansourEquiv.

Asymptotic Negligible security for polynomially query-bounded ProbOracleComp #

distinguishers

theorem Cslib.Crypto.negligible_advantage_evenMansourProbRealGame {program : (n : ℕ) → ProbOracleComp (EvenMansour.EvenMansourSpec (BitString n)) Bool} {Q_e Q_π : ℕ → ℕ} (hQ_e : PolynomiallyBounded Q_e) (hQ_π : PolynomiallyBounded Q_π) (hcall : ∀ (n : ℕ), EvenMansour.IsProbCallBounded (program n) (Q_e n) (Q_π n)) :

Asymptotic two-key Even–Mansour security for polynomially query-bounded randomized distinguishers ([EM97]; [BS23], Theorem 4.14): for any family of randomized distinguishers program : (n : ℕ) → ProbOracleComp (EvenMansourSpec (BitString n)) Bool whose cipher and primitive query budgets Q_e, Q_π : ℕ → ℕ are polynomially bounded, the distinguishing advantage is Negligible.

Asymptotic single-key Even–Mansour security for polynomially query-bounded randomized distinguishers ([DKS12]; [BS23], Section 4.7): for any family of randomized distinguishers program : (n : ℕ) → ProbOracleComp (EvenMansourSpec (BitString n)) Bool whose cipher and primitive query budgets Q_e, Q_π : ℕ → ℕ are polynomially bounded, the distinguishing advantage is Negligible.

Word-oracle (WordOracleComp) ideal-permutation games and IsOraclePPT security #

@[reducible, inline]

A parameterized adaptive word-oracle distinguisher in the Even–Mansour ideal-permutation model: operation (false, false) queries cipher encryption, (false, true) queries cipher decryption, (true, false) queries the forward public permutation, and (true, true) queries the inverse public permutation.

Cost function counting word-oracle cipher queries (1 when isPerm = false, 0 when isPerm = true).

Cost function counting word-oracle primitive permutation queries (0 when isPerm = false, 1 when isPerm = true).

Separate cipher and primitive query budgets for a WordOracleComp (Bool × Bool) distinguisher.

Any word-oracle distinguisher making at most Q total queries satisfies IsWordCallBounded program Q Q.

The real word-oracle two-key Even–Mansour experiment: sample a uniform permutation π of BitString n and a uniform 2 * n-bit key key, and run adversary n [] against the two-key Even–Mansour cipher and primitive permutation word channels (answering malformed queries of length ≠ n with []).

The real word-oracle single-key Even–Mansour experiment: sample a uniform permutation π of BitString n and a uniform n-bit key key, and run adversary n [] against the single-key Even–Mansour cipher and primitive permutation word channels (answering malformed queries of length ≠ n with []).

The ideal word-oracle Even–Mansour experiment: sample two independent uniform permutations E, π of BitString n and run adversary n [] against the bidirectional word channels of E and π (answering malformed queries of length ≠ n with []).

theorem Cslib.Crypto.advantage_evenMansourWordRealGame_evenMansourWordIdealGame_le (adversary : EvenMansourDistinguisher) (n Q_e Q_π : ℕ) (hcall : IsWordCallBounded (adversary n []) Q_e Q_π) :
↑(Game.advantage (evenMansourWordRealGame adversary n).eval (evenMansourWordIdealGame adversary n).eval) ≤ 2 * ↑Q_e * ↑Q_π / 2 ^ n

Word-oracle two-key Even–Mansour security bound ([EM97]; [BS23], Theorem 4.14): any word-oracle distinguisher making at most Q_e cipher queries and at most Q_π primitive permutation queries at security parameter n has distinguishing advantage at most 2 * Q_e * Q_π / 2 ^ n.

Word-oracle single-key Even–Mansour security bound ([DKS12]; [BS23], Section 4.7): any word-oracle distinguisher making at most Q_e cipher queries and at most Q_π primitive permutation queries at security parameter n has distinguishing advantage at most 2 * Q_e * Q_π / 2 ^ n.

theorem Cslib.Crypto.negligible_advantage_evenMansourWordRealGame (adversary : EvenMansourDistinguisher) {Q_e Q_π : ℕ → ℕ} (hQ_e : PolynomiallyBounded Q_e) (hQ_π : PolynomiallyBounded Q_π) (hcall : ∀ (n : ℕ), IsWordCallBounded (adversary n []) (Q_e n) (Q_π n)) :

Asymptotic word-oracle two-key Even–Mansour security for any distinguisher with polynomially bounded cipher and primitive query schedules Q_e, Q_π : ℕ → ℕ.

theorem Cslib.Crypto.negligible_advantage_singleKeyEvenMansourWordRealGame (adversary : EvenMansourDistinguisher) {Q_e Q_π : ℕ → ℕ} (hQ_e : PolynomiallyBounded Q_e) (hQ_π : PolynomiallyBounded Q_π) (hcall : ∀ (n : ℕ), IsWordCallBounded (adversary n []) (Q_e n) (Q_π n)) :

Asymptotic word-oracle single-key Even–Mansour security for any distinguisher with polynomially bounded cipher and primitive query schedules Q_e, Q_π : ℕ → ℕ.

Two-key Even–Mansour security in the ideal-permutation model, against IsOraclePPT distinguishers ([EM97]; [BS23], Theorem 4.14; [KL20]): no uniform IsOraclePPT encBool distinguisher can distinguish evenMansourWordRealGame from evenMansourWordIdealGame with non-negligible advantage. The security is information-theoretic: the permutation is ideal, and the proof uses IsOraclePPT only for its polynomial query bound, so the conclusion holds for every distinguisher with polynomially many queries (negligible_advantage_evenMansourWordRealGame).

Single-key Even–Mansour security in the ideal-permutation model, against IsOraclePPT distinguishers ([DKS12]; [BS23], Section 4.7): no uniform IsOraclePPT encBool distinguisher can distinguish singleKeyEvenMansourWordRealGame from evenMansourWordIdealGame with non-negligible advantage. The security is information-theoretic: the permutation is ideal, and the proof uses IsOraclePPT only for its polynomial query bound, so the conclusion holds for every distinguisher with polynomially many queries (negligible_advantage_singleKeyEvenMansourWordRealGame).