Documentation

CslibFrontier.Crypto.Primitives.PRP.Finite

Finite pseudorandom permutations #

A block cipher with keys in Key and blocks in D is a keyed permutation E : Key → Equiv.Perm D. In the chosen-plaintext game ([BS23], Section 4.1.2, Attack Game 4.1) an adaptive oracle adversary with private coins queries either E key for one uniform key or one uniform permutation π of D. In the chosen-ciphertext game (strong PRP, Section 4.1.3) it may also query the inverse, through the bidirectional interface RandomPermutation.PermOracleSpec D.

The ideal-experiment switching lemma ([BS23], Attack Game 4.3 and Theorem 4.6) bounds the advantage of a Q-query adversary between a uniform permutation and a uniform function of D by Q.choose 2 / |D| (advantage_idealExperiment_prfIdealExperiment_le). Hence PRP and PRF advantages differ by at most Q.choose 2 / |D| (abs_advantage_sub_prfAdvantage_le, Theorem 4.4), and in particular PRP security implies PRF security up to that term (prfAdvantage_le_advantage_add). A forward adversary runs unchanged against the bidirectional interface (StrongAdversary.ofForward), so strong PRP security implies PRP security (strongAdvantage_ofForward).

The word-level asymptotic notions Cslib.Crypto.BlockCipher.PRP and Cslib.Crypto.BlockCipher.StrongPRP derive their switching lemma from this one.

Main definitions #

Main results #

References #

Chosen-plaintext security #

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.PRP.realExperiment {Key D : Type} [Fintype Key] [Nonempty Key] (E : Key → Equiv.Perm D) (A : PRF.Adversary D D) :

The real chosen-plaintext experiment: sample one uniform key and answer every query x with E key x. It is the real PRF experiment for the keyed function E.

The ideal chosen-plaintext experiment: sample one uniform permutation π of D and answer every query x with π x.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.PRP.advantage {Key D : Type} [Fintype D] [DecidableEq D] [Fintype Key] [Nonempty Key] (E : Key → Equiv.Perm D) (A : PRF.Adversary D D) :

The PRP distinguishing advantage of A against E.

The law of idealExperiment: a uniform permutation π, then the adversary interpreted at the PMF level against π.

Ideal-experiment PRP/PRF switching lemma ([BS23], Attack Game 4.3 and Theorem 4.6): an adversary making at most Q queries distinguishes a uniform permutation of D from a uniform function D → D with advantage at most Q.choose 2 / |D|.

theorem Cslib.Crypto.PRP.abs_advantage_sub_prfAdvantage_le {Key D : Type} [Fintype D] [DecidableEq D] [Nonempty D] [Fintype Key] [Nonempty Key] (E : Key → Equiv.Perm D) {A : PRF.Adversary D D} {Q : ℕ} (hQ : ProbOracleComp.IsQueryBounded A Q) :
|↑(advantage E A) - ↑(PRF.advantage (fun (key : Key) => ⇑(E key)) A)| ≤ ↑(Q.choose 2) / ↑(Fintype.card D)

PRF switching lemma ([BS23], Theorem 4.4): for any keyed permutation E and any adversary A making at most Q queries, the block-cipher (PRP) and PRF distinguishing advantages differ by at most Q.choose 2 / |D|.

theorem Cslib.Crypto.PRP.prfAdvantage_le_advantage_add {Key D : Type} [Fintype D] [DecidableEq D] [Nonempty D] [Fintype Key] [Nonempty Key] (E : Key → Equiv.Perm D) {A : PRF.Adversary D D} {Q : ℕ} (hQ : ProbOracleComp.IsQueryBounded A Q) :
↑(PRF.advantage (fun (key : Key) => ⇑(E key)) A) ≤ ↑(advantage E A) + ↑(Q.choose 2) / ↑(Fintype.card D)

A PRP is a PRF ([BS23], half of Theorem 4.4): against an adversary making at most Q queries, the PRF advantage of a block cipher is at most its PRP advantage plus Q.choose 2 / |D|.

Strong pseudorandom permutations #

@[reducible, inline]

An adaptive test with private coins and oracle access to a permutation of D and its inverse: .forward x asks for π x and .inverse y asks for π.symm y.

Run a forward adversary against the bidirectional interface, sending every query to the forward direction. Private samples are unchanged.

@[simp]

Running ofForward A against any bidirectional oracle runs A against its forward direction.

noncomputable def Cslib.Crypto.PRP.strongRealExperiment {Key D : Type} [Fintype Key] [Nonempty Key] (E : Key → Equiv.Perm D) (A : StrongAdversary D) :

The real chosen-ciphertext experiment: sample one uniform key and answer .forward x with E key x and .inverse y with (E key).symm y.

@[simp]

A forward adversary plays the real chosen-ciphertext experiment as the chosen-plaintext one.

The ideal chosen-ciphertext experiment: sample one uniform permutation π of D and answer .forward x with π x and .inverse y with π.symm y.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.PRP.strongAdvantage {Key D : Type} [Fintype D] [DecidableEq D] [Fintype Key] [Nonempty Key] (E : Key → Equiv.Perm D) (A : StrongAdversary D) :

The strong PRP distinguishing advantage of A against E.

@[simp]

A forward adversary plays the ideal chosen-ciphertext experiment as the chosen-plaintext one.

Strong PRP security implies PRP security ([BS23], Section 4.1.3): the forward adversary ofForward A has the PRP advantage of A.