Documentation

CslibFrontier.Crypto.Primitives.Hash.BlockCipherCompression

Compression functions from block ciphers #

[KL20], Section 7.3.1, builds a compression function from a block cipher F : K × B → B, where each F k is a permutation of the block space B whose inverse is also efficiently computable. The Davies–Meyer construction (Figure 7.11) is h(k, x) = F_k(x) ⊕ x; Theorem 7.5 shows it is collision resistant when F is an ideal cipher.

Here we record the explicit attacks that rule out other natural choices, using only that each F k is a permutation with an inverse:

The block space is any additive group (for bits, BitString n, where + is exclusive or); the attacks of Exercise 7.23 and Exercise 8.11 hold over every additive group, while the fixed-point attack uses x + x = 0 on bit strings. The ideal-cipher bound of Theorem 7.5 and Exercise 7.23(b), h(k, x) = F_k(x) ⊕ k ⊕ x, are not formalized here; for the 2-query ideal-cipher collision finders on keyMasked and keyMaskedInput, see CslibFrontier.Crypto.Primitives.IdealCipher.CompressionVariants.

Main definitions #

Main results #

References #

The compression functions #

def Cslib.Crypto.BlockCipherCompression.daviesMeyer {K : Type u_1} {B : Type u_2} [Add B] (F : K → Equiv.Perm B) (p : K × B) :
B

The Davies–Meyer compression function h(k, x) = F_k(x) + x ([KL20], Section 7.3.1, Figure 7.11).

def Cslib.Crypto.BlockCipherCompression.cipherOutput {K : Type u_1} {B : Type u_2} (F : K → Equiv.Perm B) (p : K × B) :
B

The compression function h(k, x) = F_k(x) of [KL20], Exercise 7.23(a).

def Cslib.Crypto.BlockCipherCompression.keyMasked {B : Type u_2} [Add B] (F : B → Equiv.Perm B) (p : B × B) :
B

The compression function h(k, x) = F_k(x) + k of [KL20], Exercise 7.23(c); keys and blocks have the same type. Up to swapping its two arguments, this is h₄ of [BS23], Section 8.5.2, p. 301.

def Cslib.Crypto.BlockCipherCompression.keyMaskedInput {B : Type u_2} [Add B] (F : B → Equiv.Perm B) (p : B × B) :
B

The compression function h₅(k, x) = F_k(k + x) + k ([BS23], Section 8.5.2, p. 301); keys and blocks have the same type. Over bit strings (BitString n), + is exclusive or, so this matches h₅(x, y) := E(x, x ⊕ y) ⊕ x.

Inverse-query attacks on Exercise 7.23(a), (c) and Exercise 8.11 #

@[simp]
theorem Cslib.Crypto.BlockCipherCompression.cipherOutput_symm {K : Type u_1} {B : Type u_2} (F : K → Equiv.Perm B) (k : K) (y : B) :
cipherOutput F (k, (Equiv.symm (F k)) y) = y

One inverse query finds a preimage of y under h(k, x) = F_k(x), for any key k.

theorem Cslib.Crypto.BlockCipherCompression.cipherOutput_collision {K : Type u_1} {B : Type u_2} (F : K → Equiv.Perm B) {k k' : K} (hk : k ≠ k') (y : B) :
(k, (Equiv.symm (F k)) y) ≠ (k', (Equiv.symm (F k')) y) ∧ cipherOutput F (k, (Equiv.symm (F k)) y) = cipherOutput F (k', (Equiv.symm (F k')) y)

Exercise 7.23(a) ([KL20], Section 7.3.1): for distinct keys k ≠ k' and any target y, the inputs (k, F_k⁻¹(y)) and (k', F_{k'}⁻¹(y)) are distinct and collide under h(k, x) = F_k(x).

@[simp]
theorem Cslib.Crypto.BlockCipherCompression.keyMasked_symm {B : Type u_2} [AddGroup B] (F : B → Equiv.Perm B) (k y : B) :
keyMasked F (k, (Equiv.symm (F k)) (y - k)) = y

One inverse query finds a preimage of y under h(k, x) = F_k(x) + k: take x = F_k⁻¹(y - k).

theorem Cslib.Crypto.BlockCipherCompression.keyMasked_collision {B : Type u_2} [AddGroup B] (F : B → Equiv.Perm B) {k k' : B} (hk : k ≠ k') (y : B) :
(k, (Equiv.symm (F k)) (y - k)) ≠ (k', (Equiv.symm (F k')) (y - k')) ∧ keyMasked F (k, (Equiv.symm (F k)) (y - k)) = keyMasked F (k', (Equiv.symm (F k')) (y - k'))

Exercise 7.23(c) ([KL20], Section 7.3.1; also the h₄ part of [BS23], Exercise 8.11, p. 349): for distinct keys k ≠ k' and any target y, the inputs (k, F_k⁻¹(y - k)) and (k', F_{k'}⁻¹(y - k')) are distinct and collide under h(k, x) = F_k(x) + k.

keyMaskedInput is keyMasked composed with the map (k, x) ↦ (k, k + x).

@[simp]
theorem Cslib.Crypto.BlockCipherCompression.keyMaskedInput_symm {B : Type u_2} [AddGroup B] (F : B → Equiv.Perm B) (k y : B) :
keyMaskedInput F (k, -k + (Equiv.symm (F k)) (y - k)) = y

One inverse query finds a preimage of y under h₅(k, x) = F_k(k + x) + k: take x = -k + F_k⁻¹(y - k).

theorem Cslib.Crypto.BlockCipherCompression.keyMaskedInput_collision {B : Type u_2} [AddGroup B] (F : B → Equiv.Perm B) {k k' : B} (hk : k ≠ k') (y : B) :
(k, -k + (Equiv.symm (F k)) (y - k)) ≠ (k', -k' + (Equiv.symm (F k')) (y - k')) ∧ keyMaskedInput F (k, -k + (Equiv.symm (F k)) (y - k)) = keyMaskedInput F (k', -k' + (Equiv.symm (F k')) (y - k'))

Exercise 8.11 ([BS23], Exercise 8.11, p. 349; h₅ is defined in Section 8.5.2, p. 301): for distinct keys k ≠ k' and any target y, the inputs (k, -k + F_k⁻¹(y - k)) and (k', -k' + F_{k'}⁻¹(y - k')) are distinct and collide under keyMaskedInput (h₅).

Fixed points and Davies–Meyer (Exercise 7.24) #

theorem Cslib.Crypto.BlockCipherCompression.daviesMeyer_eq_zero_iff {K : Type u_1} {B : Type u_2} [AddGroup B] (F : K → Equiv.Perm B) (k : K) (x : B) :
daviesMeyer F (k, x) = 0 ↔ (F k) x = -x

Over any additive group, Davies–Meyer outputs 0 exactly on the inputs with F_k(x) = -x.

theorem Cslib.Crypto.BlockCipherCompression.daviesMeyer_eq_zero_iff_fixed {K : Type u_1} {n : ℕ} (F : K → Equiv.Perm (BitString n)) (k : K) (x : BitString n) :
daviesMeyer F (k, x) = 0 ↔ (F k) x = x

On bit strings, Davies–Meyer outputs 0 exactly on the fixed points F_k(x) = x.

theorem Cslib.Crypto.BlockCipherCompression.daviesMeyer_collision_of_fixedPoints {K : Type u_1} {n : ℕ} (F : K → Equiv.Perm (BitString n)) {k k' : K} {x x' : BitString n} (hx : (F k) x = x) (hx' : (F k') x' = x') :

Exercise 7.24 ([KL20], Section 7.3.1): two distinct fixed points F_k(x) = x and F_{k'}(x') = x' (possibly for the same key) collide under Davies–Meyer, both hashing to 0.