Documentation

CslibFrontier.Crypto.Protocols.Cipher.FeistelNetworks

Block cipher networks: SPNs, unbalanced Feistel networks, periodicity, and Feistel distinguishers #

This module complements CslibFrontier.Crypto.Protocols.Cipher.LubyRackoff with structural and concrete-security results on block cipher networks from [KL20] and original extensions:

  1. Substitution–permutation networks (SPNs) ([KL20], Section 7.2.1, Proposition 7.3): in Cslib.Crypto.SPN, key mixing (spnKeyMixEquiv), S-box substitution (spnSubstituteEquiv), sub-block and wire permutations (spnPermuteEquiv, spnBitPermuteEquiv), single rounds (spnRoundEquiv), and multi-round SPNs (spnNetworkEquiv) are permutations with an explicit round-by-round inverse (spnRoundEquiv_symm, spnNetworkEquiv_symm_cons, bijective_spnNetworkEquiv).
  2. Unbalanced Feistel networks (original construction generalizing the balanced Feistel network of [KL20], Section 7.2.2, Proposition 7.4): alternating rounds on A × B (unbalancedFeistelLeftEquiv, unbalancedFeistelRightEquiv), 2- and 4-round networks (unbalancedFeistel2, unbalancedFeistel4), agreement with balanced Feistel (feistel4), and lifting to Equiv.Perm (BitString n) for any block length n (unbalancedFeistel4BitString, through the split BitString.halfSplitEquiv).
  3. Degenerate round-function periodicity ([KL20], Exercise 7.10(a),(b)): general periodicity reduction (feistelNetwork_replicate_mod), period-2 law for 0 : G → G (feistelNetwork_replicate_zero), and period-3 law for id : G → G when ∀ a : G, -a = a (feistelNetwork_replicate_id).
  4. Explicit 1- and 2-round CPA, 3-round repeated-key CPA, and 3-round CCA distinguishers (attacks from [KL20], Section 8.6 and Exercises 8.16–8.18; concrete bounds are original):

Implementation notes #

In [KL20], Section 8.6 and Exercises 8.16–8.18 state the distinguishers against Feistel networks instantiated with keyed PRFs F_{k_i}. Proving acceptance with probability 1 for every fixed tuple of round functions f₁, f₂, f₃ : G → G immediately implies acceptance with probability 1 under any key distribution (such as the keys of feistel3Cipher in LubyRackoff).

References #

Substitution–permutation networks (SPNs) #

@[reducible, inline]
abbrev Cslib.Crypto.SPN.SPNState (boxes : ℕ) (G : Type u_2) :
Type u_2

The state of a substitution–permutation network with boxes sub-blocks in G: a tuple Fin boxes → G.

def Cslib.Crypto.SPN.spnSubstituteEquiv {boxes : ℕ} {G : Type u_1} (sboxes : Fin boxes → Equiv.Perm G) :

Parallel S-box substitution layer of an SPN: apply a family of bijective S-boxes sboxes : Fin boxes → Equiv.Perm G independently to each sub-block (i ↦ sboxes i (state i)).

@[simp]
theorem Cslib.Crypto.SPN.spnSubstituteEquiv_apply {boxes : ℕ} {G : Type u_1} (sboxes : Fin boxes → Equiv.Perm G) (state : SPNState boxes G) (i : Fin boxes) :
(spnSubstituteEquiv sboxes) state i = (sboxes i) (state i)
@[simp]
theorem Cslib.Crypto.SPN.spnSubstituteEquiv_symm {boxes : ℕ} {G : Type u_1} (sboxes : Fin boxes → Equiv.Perm G) :
Equiv.symm (spnSubstituteEquiv sboxes) = spnSubstituteEquiv fun (i : Fin boxes) => Equiv.symm (sboxes i)
def Cslib.Crypto.SPN.spnPermuteEquiv {boxes : ℕ} {G : Type u_1} (σ : Equiv.Perm (Fin boxes)) :

Sub-block permutation layer across Fin boxes: reindex sub-blocks along σ : Equiv.Perm (Fin boxes).

@[simp]
theorem Cslib.Crypto.SPN.spnPermuteEquiv_apply {boxes : ℕ} {G : Type u_1} (σ : Equiv.Perm (Fin boxes)) (state : SPNState boxes G) (i : Fin boxes) :
(spnPermuteEquiv σ) state i = state ((Equiv.symm σ) i)
def Cslib.Crypto.SPN.spnBitPermuteEquiv {boxes width : ℕ} (mix : Equiv.Perm (Fin boxes × Fin width)) :
Equiv.Perm (SPNState boxes (BitString width))

Wire-level bit-permutation (mixing) layer on SPNState boxes (BitString width): permute the boxes × width individual bit coordinates according to mix : Equiv.Perm (Fin boxes × Fin width).

@[simp]
theorem Cslib.Crypto.SPN.spnBitPermuteEquiv_apply {boxes width : ℕ} (mix : Equiv.Perm (Fin boxes × Fin width)) (state : SPNState boxes (BitString width)) (i : Fin boxes) (j : Fin width) :
(spnBitPermuteEquiv mix) state i j = state ((Equiv.symm mix) (i, j)).1 ((Equiv.symm mix) (i, j)).2
def Cslib.Crypto.SPN.spnKeyMixEquiv {boxes : ℕ} {G : Type u_1} [AddGroup G] (subkey : SPNState boxes G) :

Subkey mixing layer of an SPN: add subkey : SPNState boxes G coordinatewise on the right (state ↦ state + subkey), with inverse state ↦ state - subkey.

@[simp]
theorem Cslib.Crypto.SPN.spnKeyMixEquiv_apply {boxes : ℕ} {G : Type u_1} [AddGroup G] (subkey state : SPNState boxes G) :
(spnKeyMixEquiv subkey) state = state + subkey
@[simp]
theorem Cslib.Crypto.SPN.spnKeyMixEquiv_symm_apply {boxes : ℕ} {G : Type u_1} [AddGroup G] (subkey state : SPNState boxes G) :
(Equiv.symm (spnKeyMixEquiv subkey)) state = state - subkey
def Cslib.Crypto.SPN.spnRoundEquiv {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (subkey : SPNState boxes G) :

A single round of a substitution–permutation network ([KL20], Section 7.2.1): mix in subkey, apply parallel S-boxes sboxes, and apply mixLayer.

@[simp]
theorem Cslib.Crypto.SPN.spnRoundEquiv_apply {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (subkey state : SPNState boxes G) :
(spnRoundEquiv sboxes mixLayer subkey) state = mixLayer ((spnSubstituteEquiv sboxes) (state + subkey))
theorem Cslib.Crypto.SPN.spnRoundEquiv_symm {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (subkey : SPNState boxes G) :
Equiv.symm (spnRoundEquiv sboxes mixLayer subkey) = (Equiv.symm mixLayer).trans (Equiv.trans (spnSubstituteEquiv fun (i : Fin boxes) => Equiv.symm (sboxes i)) (Equiv.symm (spnKeyMixEquiv subkey)))

Explicit inverse of a single SPN round: invert mixLayer, apply inverse S-boxes (sboxes i).symm, and subtract subkey.

@[simp]
theorem Cslib.Crypto.SPN.spnRoundEquiv_symm_apply {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (subkey state : SPNState boxes G) :
(Equiv.symm (spnRoundEquiv sboxes mixLayer subkey)) state = (spnSubstituteEquiv fun (i : Fin boxes) => Equiv.symm (sboxes i)) ((Equiv.symm mixLayer) state) - subkey
def Cslib.Crypto.SPN.spnRoundsEquiv {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (roundKeys : List (SPNState boxes G)) :

Multi-round substitution–permutation network without final post-whitening: fold spnRoundEquiv sboxes mixLayer k left-to-right across roundKeys.

@[simp]
theorem Cslib.Crypto.SPN.spnRoundsEquiv_nil {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) :
spnRoundsEquiv sboxes mixLayer [] = Equiv.refl (SPNState boxes G)
@[simp]
theorem Cslib.Crypto.SPN.spnRoundsEquiv_cons {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (k : SPNState boxes G) (ks : List (SPNState boxes G)) :
spnRoundsEquiv sboxes mixLayer (k :: ks) = Equiv.trans (spnRoundEquiv sboxes mixLayer k) (spnRoundsEquiv sboxes mixLayer ks)
@[simp]
theorem Cslib.Crypto.SPN.spnRoundsEquiv_append {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (ks₁ ks₂ : List (SPNState boxes G)) :
spnRoundsEquiv sboxes mixLayer (ks₁ ++ ks₂) = Equiv.trans (spnRoundsEquiv sboxes mixLayer ks₁) (spnRoundsEquiv sboxes mixLayer ks₂)
def Cslib.Crypto.SPN.spnNetworkEquiv {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (roundKeys : List (SPNState boxes G)) (finalKey : SPNState boxes G) :

Full substitution–permutation network ([KL20], Section 7.2.1, Proposition 7.3): execute spnRoundsEquiv sboxes mixLayer roundKeys followed by a final post-whitening key-mixing step spnKeyMixEquiv finalKey.

@[simp]
theorem Cslib.Crypto.SPN.spnNetworkEquiv_apply {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (roundKeys : List (SPNState boxes G)) (finalKey state : SPNState boxes G) :
(spnNetworkEquiv sboxes mixLayer roundKeys finalKey) state = (spnRoundsEquiv sboxes mixLayer roundKeys) state + finalKey
@[simp]
theorem Cslib.Crypto.SPN.spnNetworkEquiv_symm_nil {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (finalKey : SPNState boxes G) :
Equiv.symm (spnNetworkEquiv sboxes mixLayer [] finalKey) = Equiv.symm (spnKeyMixEquiv finalKey)
theorem Cslib.Crypto.SPN.spnNetworkEquiv_symm_cons {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (k : SPNState boxes G) (ks : List (SPNState boxes G)) (finalKey : SPNState boxes G) :
Equiv.symm (spnNetworkEquiv sboxes mixLayer (k :: ks) finalKey) = (Equiv.symm (spnNetworkEquiv sboxes mixLayer ks finalKey)).trans (Equiv.symm (spnRoundEquiv sboxes mixLayer k))

Decrypting a non-empty SPN (k :: ks) undoes the remaining network (ks, finalKey) first and then applies the single-round inverse (spnRoundEquiv sboxes mixLayer k).symm.

theorem Cslib.Crypto.SPN.bijective_spnNetworkEquiv {boxes : ℕ} {G : Type u_1} [AddGroup G] (sboxes : Fin boxes → Equiv.Perm G) (mixLayer : Equiv.Perm (SPNState boxes G)) (roundKeys : List (SPNState boxes G)) (finalKey : SPNState boxes G) :
Function.Bijective ⇑(spnNetworkEquiv sboxes mixLayer roundKeys finalKey)

Proposition 7.3 of [KL20]: for any bijective S-boxes sboxes, any bijective mixing layer mixLayer, and any subkey schedule (roundKeys, finalKey), the resulting substitution–permutation network spnNetworkEquiv sboxes mixLayer roundKeys finalKey is a bijection on SPNState boxes G.

Unbalanced Feistel networks and arbitrary block-length splitting #

def Cslib.Crypto.LubyRackoff.unbalancedFeistelLeft {A : Type u_1} {B : Type u_2} [AddGroup A] (f : B → A) (p : A × B) :
A × B

Left-updating unbalanced Feistel round on A × B (original): (a, b) ↦ (a + f b, b) for f : B → A.

def Cslib.Crypto.LubyRackoff.unbalancedFeistelLeftInv {A : Type u_1} {B : Type u_2} [AddGroup A] (f : B → A) (p : A × B) :
A × B

Explicit inverse of a left-updating unbalanced Feistel round: (a, b) ↦ (a - f b, b).

def Cslib.Crypto.LubyRackoff.unbalancedFeistelLeftEquiv {A : Type u_1} {B : Type u_2} [AddGroup A] (f : B → A) :

Left-updating unbalanced Feistel round bundled as a permutation Equiv.Perm (A × B).

@[simp]
theorem Cslib.Crypto.LubyRackoff.unbalancedFeistelLeftEquiv_apply {A : Type u_1} {B : Type u_2} [AddGroup A] (f : B → A) (p : A × B) :
(unbalancedFeistelLeftEquiv f) p = (p.1 + f p.2, p.2)
@[simp]
theorem Cslib.Crypto.LubyRackoff.unbalancedFeistelLeftEquiv_symm_apply {A : Type u_1} {B : Type u_2} [AddGroup A] (f : B → A) (p : A × B) :
def Cslib.Crypto.LubyRackoff.unbalancedFeistelRight {A : Type u_1} {B : Type u_2} [AddGroup B] (g : A → B) (p : A × B) :
A × B

Right-updating unbalanced Feistel round on A × B (original): (a, b) ↦ (a, b + g a) for g : A → B.

def Cslib.Crypto.LubyRackoff.unbalancedFeistelRightInv {A : Type u_1} {B : Type u_2} [AddGroup B] (g : A → B) (p : A × B) :
A × B

Explicit inverse of a right-updating unbalanced Feistel round: (a, b) ↦ (a, b - g a).

def Cslib.Crypto.LubyRackoff.unbalancedFeistelRightEquiv {A : Type u_1} {B : Type u_2} [AddGroup B] (g : A → B) :

Right-updating unbalanced Feistel round bundled as a permutation Equiv.Perm (A × B).

@[simp]
theorem Cslib.Crypto.LubyRackoff.unbalancedFeistelRightEquiv_apply {A : Type u_1} {B : Type u_2} [AddGroup B] (g : A → B) (p : A × B) :
(unbalancedFeistelRightEquiv g) p = (p.1, p.2 + g p.1)
@[simp]
theorem Cslib.Crypto.LubyRackoff.unbalancedFeistelRightEquiv_symm_apply {A : Type u_1} {B : Type u_2} [AddGroup B] (g : A → B) (p : A × B) :

Swapping the two halves (Equiv.prodComm) conjugates a left-updating unbalanced Feistel round into a right-updating unbalanced Feistel round.

A balanced Feistel round feistelRoundEquiv f ([KL20], Section 7.2.2, Proposition 7.4) is a left-updating unbalanced round followed by swapping halves Equiv.prodComm G G.

def Cslib.Crypto.LubyRackoff.unbalancedFeistel2 {A : Type u_1} {B : Type u_2} [AddGroup A] [AddGroup B] (f₁ : B → A) (f₂ : A → B) :

Two-round alternating unbalanced Feistel network on A × B (original): update A using f₁ : B → A, then update B using f₂ : A → B.

@[simp]
theorem Cslib.Crypto.LubyRackoff.unbalancedFeistel2_apply {A : Type u_1} {B : Type u_2} [AddGroup A] [AddGroup B] (f₁ : B → A) (f₂ : A → B) (p : A × B) :
(unbalancedFeistel2 f₁ f₂) p = (p.1 + f₁ p.2, p.2 + f₂ (p.1 + f₁ p.2))
@[simp]
theorem Cslib.Crypto.LubyRackoff.unbalancedFeistel2_symm_apply {A : Type u_1} {B : Type u_2} [AddGroup A] [AddGroup B] (f₁ : B → A) (f₂ : A → B) (p : A × B) :
(Equiv.symm (unbalancedFeistel2 f₁ f₂)) p = (p.1 - f₁ (p.2 - f₂ p.1), p.2 - f₂ p.1)

When A = B = G, the 2-round alternating unbalanced Feistel network unbalancedFeistel2 f₁ f₂ coincides with the 2-round balanced Feistel network feistelNetwork [f₁, f₂].

def Cslib.Crypto.LubyRackoff.unbalancedFeistel4 {A : Type u_1} {B : Type u_2} [AddGroup A] [AddGroup B] (f₁ : B → A) (f₂ : A → B) (f₃ : B → A) (f₄ : A → B) :

Four-round alternating unbalanced Feistel network on A × B (original): alternate f₁ : B → A, f₂ : A → B, f₃ : B → A, and f₄ : A → B.

theorem Cslib.Crypto.LubyRackoff.unbalancedFeistel4_apply {A : Type u_1} {B : Type u_2} [AddGroup A] [AddGroup B] (f₁ : B → A) (f₂ : A → B) (f₃ : B → A) (f₄ : A → B) (p : A × B) :
(unbalancedFeistel4 f₁ f₂ f₃ f₄) p = have u := p.1 + f₁ p.2; have v := p.2 + f₂ u; have w := u + f₃ v; (w, v + f₄ w)
theorem Cslib.Crypto.LubyRackoff.unbalancedFeistel4_symm_apply {A : Type u_1} {B : Type u_2} [AddGroup A] [AddGroup B] (f₁ : B → A) (f₂ : A → B) (f₃ : B → A) (f₄ : A → B) (wz : A × B) :
(Equiv.symm (unbalancedFeistel4 f₁ f₂ f₃ f₄)) wz = have v := wz.2 - f₄ wz.1; have u := wz.1 - f₃ v; (u - f₁ (v - f₂ u), v - f₂ u)
theorem Cslib.Crypto.LubyRackoff.unbalancedFeistel4_eq_feistel4 {G : Type u_3} [AddGroup G] (f₁ f₂ f₃ f₄ : G → G) :
unbalancedFeistel4 f₁ f₂ f₃ f₄ = feistel4 f₁ f₂ f₃ f₄

When A = B = G, the 4-round alternating unbalanced Feistel network unbalancedFeistel4 f₁ f₂ f₃ f₄ coincides with the 4-round balanced Feistel network feistel4 f₁ f₂ f₃ f₄.

def Cslib.Crypto.LubyRackoff.unbalancedFeistel4BitString (n : ℕ) (f₁ : BitString (n - n / 2) → BitString (n / 2)) (f₂ : BitString (n / 2) → BitString (n - n / 2)) (f₃ : BitString (n - n / 2) → BitString (n / 2)) (f₄ : BitString (n / 2) → BitString (n - n / 2)) :

Four-round unbalanced Feistel permutation on BitString n for any (even or odd) block size n, constructed from half-block round functions f₁, f₃ : BitString (n - n / 2) → BitString (n / 2) and f₂, f₄ : BitString (n / 2) → BitString (n - n / 2) (original).

Degenerate round-function periodicity in Feistel networks #

Replicating a + b copies of a single round function f composes the a-round and b-round Feistel networks.

If k identical Feistel rounds of f compose to the identity permutation on G × G, then for every r : ℕ, r rounds of f equal r % k rounds of f.

@[simp]

A single Feistel round with the identically zero function 0 : G → G is Equiv.prodComm G G.

@[simp]

Two Feistel rounds with the zero round function 0 : G → G compose to the identity.

Period-2 law for zero Feistel rounds ([KL20], Exercise 7.10(a)): running r Feistel rounds with the identically zero round function 0 : G → G acts as the identity when r is even and swaps the two halves (l, r) ↦ (r, l) when r is odd.

Over any group of exponent two (∀ a : G, -a = a), three Feistel rounds with the identity round function id : G → G compose to the identity permutation on G × G ([KL20], Exercise 7.10(b)).

theorem Cslib.Crypto.LubyRackoff.feistelNetwork_replicate_id {G : Type u_1} [AddGroup G] (hneg : ∀ (a : G), -a = a) (r : ℕ) (p : G × G) :
(feistelNetwork (List.replicate r id)) p = if r % 3 = 0 then p else if r % 3 = 1 then (p.2, p.1 + p.2) else (p.1 + p.2, p.1)

Period-3 law for identity Feistel rounds ([KL20], Exercise 7.10(b)): over any group of exponent two (∀ a : G, -a = a, such as BitString n), running r Feistel rounds with the identity round function id : G → G has period 3:

  • r % 3 = 0: (l, r') ↦ (l, r'),
  • r % 3 = 1: (l, r') ↦ (r', l + r'),
  • r % 3 = 2: (l, r') ↦ (l + r', l).

Extension-cache fiber bounds and explicit Feistel distinguishers #

1-round Feistel CPA distinguisher #

def Cslib.Crypto.LubyRackoff.feistel1CPAAttack {G : Type} [DecidableEq G] (l₀ r₀ : G) :
OracleComp (fun (x : G × G) => G × G) Bool

The 1-query chosen-plaintext distinguisher against 1-round Feistel ([KL20], Section 8.6): query (l₀, r₀) to obtain (v, w) and accept iff v = r₀.

Every 1-round Feistel network feistelRoundEquiv f is accepted with probability 1 by feistel1CPAAttack l₀ r₀ ([KL20], Section 8.6), for any round function f : G → G.

Against randomFunctionGame, feistel1CPAAttack l₀ r₀ accepts with probability |G|⁻¹ (original bound).

feistel1CPAAttack l₀ r₀ distinguishes any 1-round Feistel network feistelRoundEquiv f from randomFunctionGame with exact advantage 1 - |G|⁻¹ (original bound).

Against idealPermGame, feistel1CPAAttack l₀ r₀ accepts with probability at most |G|⁻¹ (original bound).

feistel1CPAAttack l₀ r₀ distinguishes any 1-round Feistel network feistelRoundEquiv f from idealPermGame with advantage at least 1 - |G|⁻¹ (original bound).

2-round Feistel CPA distinguisher #

def Cslib.Crypto.LubyRackoff.feistel2CPAAttack {G : Type} [AddGroup G] [DecidableEq G] (l₀ l₁ r₀ : G) :
OracleComp (fun (x : G × G) => G × G) Bool

The 2-query chosen-plaintext distinguisher against 2-round Feistel ([KL20], Exercise 8.16): query (l₀, r₀) to obtain (v₀, w₀), query (l₁, r₀) to obtain (v₁, w₁), and accept iff v₀ - v₁ = l₀ - l₁.

feistel2CPAAttack makes at most 2 oracle queries.

theorem Cslib.Crypto.LubyRackoff.eval_feistel2_feistel2CPAAttack {G : Type} [AddGroup G] [DecidableEq G] (f₁ f₂ : G → G) (l₀ l₁ r₀ : G) :
OracleComp.interpret (fun (p : G × G) => PMF.pure ((feistelNetwork [f₁, f₂]) p)) (feistel2CPAAttack l₀ l₁ r₀) = PMF.pure true

Every 2-round Feistel network feistelNetwork [f₁, f₂] is accepted with probability 1 by feistel2CPAAttack l₀ l₁ r₀ ([KL20], Exercise 8.16), for any round functions f₁, f₂ : G → G and any l₀, l₁, r₀ : G.

theorem Cslib.Crypto.LubyRackoff.idealPermGame_feistel2CPAAttack_true_le {G : Type} [AddGroup G] [Fintype G] [DecidableEq G] [Nonempty G] {l₀ l₁ : G} (r₀ : G) (h01 : l₀ ≠ l₁) (hG : 2 ≤ Fintype.card G) :
((idealPermGame (feistel2CPAAttack l₀ l₁ r₀)) true).toReal ≤ ↑(Fintype.card G) / (↑(Fintype.card G) ^ 2 - 1)

Against idealPermGame, when l₀ ≠ l₁ and 2 ≤ Fintype.card G, feistel2CPAAttack l₀ l₁ r₀ accepts with probability at most |G| / (|G| ^ 2 - 1) (original bound).

theorem Cslib.Crypto.LubyRackoff.le_advantage_feistel2CPAAttack_idealPermGame {G : Type} [AddGroup G] [Fintype G] [DecidableEq G] [Nonempty G] (f₁ f₂ : G → G) {l₀ l₁ : G} (r₀ : G) (h01 : l₀ ≠ l₁) (hG : 2 ≤ Fintype.card G) :
1 - ↑(Fintype.card G) / (↑(Fintype.card G) ^ 2 - 1) ≤ ↑(Game.advantage (OracleComp.interpret (fun (p : G × G) => PMF.pure ((feistelNetwork [f₁, f₂]) p)) (feistel2CPAAttack l₀ l₁ r₀)) (idealPermGame (feistel2CPAAttack l₀ l₁ r₀)))

When l₀ ≠ l₁ and 2 ≤ Fintype.card G, feistel2CPAAttack l₀ l₁ r₀ distinguishes any 2-round Feistel network feistelNetwork [f₁, f₂] from idealPermGame with advantage at least 1 - |G| / (|G| ^ 2 - 1) (≥ 1 / 3; attack from [KL20], Exercise 8.16, original bound).

3-round repeated-key ([f, f, f]) Feistel CPA distinguisher #

The 2-query chosen-plaintext distinguisher against 3-round Feistel with a repeated round function [f, f, f] ([KL20], Exercise 8.18): query (x, x) to obtain vw, query vw.swap = (vw.2, vw.1) to obtain lr, and accept iff lr = (x, x).

Over any group of exponent two (∀ a : G, -a = a), every repeated-key 3-round Feistel network feistel3 f f f is accepted with probability 1 by feistel3RepeatedKeyCPAAttack x ([KL20], Exercise 8.18).

Against idealPermGame, when 2 ≤ Fintype.card G, feistel3RepeatedKeyCPAAttack x accepts with probability at most 2 / |G| ^ 2 (≤ 1 / 2; original bound).

Over any group of exponent two (∀ a : G, -a = a) with 2 ≤ Fintype.card G, feistel3RepeatedKeyCPAAttack x distinguishes any repeated-key 3-round Feistel network feistel3 f f f from idealPermGame with advantage at least 1 - 2 / |G| ^ 2 (≥ 1 / 2; attack from [KL20], Exercise 8.18, original bound).

Sharper permutation-fiber bound for the 3-round CCA distinguisher #

Sharper permutation-fiber bound for feistel3CCAAttack (attack from [KL20], Exercise 8.17; original bound): when l₀ ≠ l₁ and 2 ≤ Fintype.card G, the true bidirectional random-permutation game idealStrongGame accepts feistel3CCAAttack l₀ l₁ r₀ with probability at most (|G| + 1) / (|G| ^ 2 - 1) = (|G| - 1)⁻¹ (≤ 1 / 2 for |G| ≥ 3).

theorem Cslib.Crypto.LubyRackoff.le_advantage_feistel3CCAAttack_idealStrongGame_of_two_le_card {G : Type} [AddGroup G] [Fintype G] [DecidableEq G] [Nonempty G] (f₁ f₂ f₃ : G → G) {l₀ l₁ : G} (r₀ : G) (h01 : l₀ ≠ l₁) (hG : 2 ≤ Fintype.card G) :

Sharper chosen-ciphertext advantage lower bound for feistel3CCAAttack (attack from [KL20], Exercise 8.17; original bound): when l₀ ≠ l₁ and 2 ≤ Fintype.card G, feistel3CCAAttack l₀ l₁ r₀ distinguishes any 3-round Feistel network feistel3 f₁ f₂ f₃ from idealStrongGame with advantage at least 1 - (|G| - 1)⁻¹ (≥ 1 / 2 for |G| ≥ 3).