Feistel networks, oracle distinguishers and PRP/PRF advantages
DefinitionLubyRackoffcryptographyfeistelpseudorandom-permutation
Model for the Luby–Rackoff theorems. is a finite abelian group with , and blocks are pairs .
- is the probability of under the uniform distribution on a finite type.
- An oracle algorithm with oracle is an adaptive query tree: it either returns a value or queries and continues depending on the answer.
eval Oruns it against ,transcript Olists its (query, answer) pairs, andQueryBounded qmeans every run against every oracle makes at most queries. A distinguisher returns a bit. - , with uniform.
- The Feistel round is , a permutation with inverse . The network applies first and last.
prpAdv k D: makes forward queries to with independent uniform , versus a uniform permutation of .sprpAdv k D: the same, but queries and .prfAdv F B: for a uniform key , versus a uniform function .prpAdvF F k DandsprpAdvF F k D: as above, with round functions for independent uniform keys.
Definition code
import Mathlib
/-!
# Feistel networks and pseudorandom permutations
Information-theoretic model for the Luby–Rackoff theorems. Blocks are pairs `(L, R)`
of elements of a finite abelian group `G` (for `n`-bit halves take
`G = Fin n → ZMod 2`, so `|G| = 2ⁿ` and `+` is XOR). All randomness is uniform over
finite types, and distinguishers are deterministic adaptive oracle algorithms with
unbounded computation.
-/
namespace LubyRackoff
/-- Probability of an event when the outcome is uniform on a finite type. -/
noncomputable def prob {Ω : Type*} [Fintype Ω] (P : Ω → Prop) : ℝ := by
classical
exact ((Finset.univ.filter P).card : ℝ) / (Fintype.card Ω : ℝ)
/-- A deterministic oracle algorithm with oracle `X → Y` and output in `α`,
as an adaptive query tree. -/
inductive OComp (X Y α : Type) where
| ret : α → OComp X Y α
| query : X → (Y → OComp X Y α) → OComp X Y α
namespace OComp
variable {X Y α : Type}
/-- The output of `c` when run with oracle `O`. -/
def eval (O : X → Y) : OComp X Y α → α
| ret a => a
| query x k => eval O (k (O x))
/-- The transcript of `c` run with oracle `O`: its queries and the answers, in order. -/
def transcript (O : X → Y) : OComp X Y α → List (X × Y)
| ret _ => []
| query x k => (x, O x) :: transcript O (k (O x))
/-- `c` makes at most `q` oracle queries, whatever the oracle. -/
def QueryBounded (c : OComp X Y α) (q : ℕ) : Prop :=
∀ O : X → Y, (c.transcript O).length ≤ q
end OComp
/-- A distinguisher: a deterministic oracle algorithm outputting a bit. -/
abbrev Dist (X Y : Type) := OComp X Y Bool
/-- The distinguishing advantage of `D` between the oracles `O₁ ω₁` (`ω₁` uniform on
`Ω₁`) and `O₂ ω₂` (`ω₂` uniform on `Ω₂`). -/
noncomputable def adv {X Y Ω₁ Ω₂ : Type} [Fintype Ω₁] [Fintype Ω₂] (D : Dist X Y)
(O₁ : Ω₁ → X → Y) (O₂ : Ω₂ → X → Y) : ℝ :=
|prob (fun ω => (D.eval (O₁ ω)) = true) - prob (fun ω => (D.eval (O₂ ω)) = true)|
/-- Forward access to a permutation. -/
def fwd {β : Type} (π : Equiv.Perm β) : β → β := π
/-- Two-sided access to a permutation: `inl x ↦ π x` and `inr y ↦ π⁻¹ y`. -/
def both {β : Type} (π : Equiv.Perm β) : β ⊕ β → β := Sum.elim π π.symm
variable {G : Type} [AddCommGroup G]
/-- One Feistel round with round function `f`: `(L, R) ↦ (R, L + f R)`. -/
def round (f : G → G) : Equiv.Perm (G × G) where
toFun x := (x.2, x.1 + f x.2)
invFun y := (y.2 - f y.1, y.1)
left_inv x := by simp
right_inv y := by simp
/-- The `k`-round Feistel network `Ψ(f₀, …, f_{k-1})`: round `f₀` first. -/
def feistel {k : ℕ} (f : Fin k → G → G) : Equiv.Perm (G × G) :=
(List.ofFn fun i => round (f i)).foldl (fun acc r => acc.trans r) (Equiv.refl _)
/-- Advantage of `D` (forward queries only) in telling the `k`-round Feistel network with
independent uniform round functions from a uniform permutation of `G × G`. -/
noncomputable def prpAdv [Fintype G] [DecidableEq G] (k : ℕ) (D : Dist (G × G) (G × G)) : ℝ :=
adv D (fun f : Fin k → G → G => fwd (feistel f)) (fun π : Equiv.Perm (G × G) => fwd π)
/-- As `prpAdv`, but `D` may also query the inverse permutation. -/
noncomputable def sprpAdv [Fintype G] [DecidableEq G] (k : ℕ)
(D : Dist ((G × G) ⊕ (G × G)) (G × G)) : ℝ :=
adv D (fun f : Fin k → G → G => both (feistel f)) (fun π : Equiv.Perm (G × G) => both π)
/-- PRF advantage of `B` against the keyed family `F`: `F κ` for a uniform key `κ`
versus a uniform function `G → G`. -/
noncomputable def prfAdv [Fintype G] [DecidableEq G] {K : Type} [Fintype K] (F : K → G → G)
(B : Dist G G) : ℝ :=
adv B F (fun f : G → G => f)
/-- PRP advantage of `D` against the `k`-round Feistel network keyed by `k` independent
uniform keys of `F`. -/
noncomputable def prpAdvF [Fintype G] [DecidableEq G] {K : Type} [Fintype K]
(F : K → G → G) (k : ℕ) (D : Dist (G × G) (G × G)) : ℝ :=
adv D (fun κ : Fin k → K => fwd (feistel fun i => F (κ i)))
(fun π : Equiv.Perm (G × G) => fwd π)
/-- Strong-PRP (forward and inverse queries) version of `prpAdvF`. -/
noncomputable def sprpAdvF [Fintype G] [DecidableEq G] {K : Type} [Fintype K]
(F : K → G → G) (k : ℕ) (D : Dist ((G × G) ⊕ (G × G)) (G × G)) : ℝ :=
adv D (fun κ : Fin k → K => both (feistel fun i => F (κ i)))
(fun π : Equiv.Perm (G × G) => both π)
end LubyRackoff
Source
Luby–Rackoff, SIAM J. Comput. 17(2) 1988, https://doi.org/10.1137/0217022