Documentation

CslibFrontier.Languages.Probabilistic.IdealCipher

Ideal Cipher Model #

This module formalizes the Ideal Cipher Model, consisting of independent random permutations for each key, and defines its exact and forgetful lazy samplers.

Main definitions #

Main results #

References #

@[reducible, inline]
abbrev Cslib.IdealCipher.Query (Key Block : Type) :

A query to the ideal cipher, consisting of a key and a block query.

@[reducible, inline]
abbrev Cslib.IdealCipher.Spec (Key Block : Type) :
OracleSpec (Query Key Block)

The oracle specification for an ideal cipher.

noncomputable def Cslib.IdealCipher.lazyEvalPerm {Key Block : Type} (q : Query Key Block) :
StateT (Key → Equiv.Perm Block) PMF Block

Evaluate an ideal cipher directly with a full permutation state.

noncomputable def Cslib.IdealCipher.answer {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) :
StateT (Key → RandomPermutation.Cache Block) PMF Block

Evaluate an ideal cipher with a lazy cache.

noncomputable def Cslib.IdealCipher.forgetfulAnswer {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) :
StateT (Key → RandomPermutation.Cache Block) PMF Block

Evaluate an ideal cipher with a forgetful cache that doesn't check consistency.

noncomputable def Cslib.IdealCipher.complete {Key Block : Type} [Fintype Key] [DecidableEq Block] [Fintype Block] (st : Key → RandomPermutation.Cache Block) :
PMF (Key → Equiv.Perm Block)

Generates a complete tuple of independent random permutations extending the given cache function.

theorem Cslib.IdealCipher.complete_nil {Key Block : Type} [Fintype Key] [DecidableEq Block] [Fintype Block] :
(complete fun (x : Key) => []) = Probability.PMF.pi fun (x : Key) => Probability.PMF.uniformOfFintype (Equiv.Perm Block)

Completing the empty cache samples an independent uniformly random permutation for every key.

noncomputable def Cslib.IdealCipher.exactWithBad {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) :
StateT ((Key → RandomPermutation.Cache Block) × Bool) PMF Block

An exact evaluation step for the ideal cipher model, with a bad flag that triggers when a duplicate output is sampled.

noncomputable def Cslib.IdealCipher.forgetfulWithBad {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) :
StateT ((Key → RandomPermutation.Cache Block) × Bool) PMF Block

A forgetful evaluation step for the ideal cipher model, updating the cache and the bad flag.

theorem Cslib.IdealCipher.answer_preserve_isPartialBijection {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) (st : Key → RandomPermutation.Cache Block) (hst : ∀ (k : Key), RandomPermutation.IsPartialBijection (st k)) (a : Block) (st' : Key → RandomPermutation.Cache Block) (hmem : (a, st') ∈ (answer q st).support) (k : Key) :

A query step of answer preserves the invariant that every key's cache is a partial bijection.

theorem Cslib.IdealCipher.answer_complete {Key Block : Type} [DecidableEq Key] [Fintype Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) (st : Key → RandomPermutation.Cache Block) (hst : ∀ (k : Key), RandomPermutation.IsPartialBijection (st k)) :
((answer q st).bind fun (x : Block × (Key → RandomPermutation.Cache Block)) => match x with | (a, st') => PMF.map (fun (x : Key → Equiv.Perm Block) => (a, x)) (complete st')) = (complete st).bind fun (P : Key → Equiv.Perm Block) => (fun (x : Block) => (x, P)) <$> PMF.pure (RandomPermutation.evalPerm (P q.1) q.2)

Single-step simulation law for answer against complete: when every key's cache in st is a partial bijection, answering q lazily and completing the updated caches yields the same joint distribution of (answer, permutations) as completing st first and evaluating q under the resulting permutation family.

theorem Cslib.IdealCipher.uniform_interpret_eq_lazy {Key Block : Type} [DecidableEq Key] [Fintype Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] {α : Type} (program : OracleComp (Spec Key Block) α) :
(do let P ← Probability.PMF.pi fun (x : Key) => Probability.PMF.uniformOfFintype (Equiv.Perm Block) OracleComp.interpret (fun (q : Query Key Block) => PMF.pure (RandomPermutation.evalPerm (P q.1) q.2)) program) = PMF.map Prod.fst ((OracleComp.interpret answer program).run fun (x : Key) => [])

Running program against independent uniformly random permutations P : Key → Equiv.Perm Block yields the same output distribution as running program lazily under answer from empty caches and projecting out the return value.

theorem Cslib.IdealCipher.toOuterMeasure_bad_forgetfulWithBad_le {Key Block : Type} [DecidableEq Key] [Fintype Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] {β : Type} {program : OracleComp (Spec Key Block) β} {n : ℕ} (hn : program.IsQueryBounded n) (cache : Key → RandomPermutation.Cache Block) :
((OracleComp.interpret forgetfulWithBad program).run (cache, false)).toOuterMeasure {(fst, fst_1, bad) : β × (Key → RandomPermutation.Cache Block) × Bool | bad = true} ≤ ↑(n * ∑ k : Key, List.length (cache k) + n.choose 2) * (↑(Fintype.card Block))⁻¹

Quadratic birthday bound on the bad-flag probability of forgetfulWithBad: starting from initial key caches cache with bad = false, an n-query-bounded program sets bad = true with probability at most (n * ∑ k, (cache k).length + n.choose 2) * (Fintype.card Block)⁻¹.

theorem Cslib.IdealCipher.exactWithBad_preserve_isPartialBijection {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) (st : (Key → RandomPermutation.Cache Block) × Bool) (hst : ∀ (k : Key), RandomPermutation.IsPartialBijection (st.1 k)) (a : Block) (st' : (Key → RandomPermutation.Cache Block) × Bool) (hmem : (a, st') ∈ (exactWithBad q st).support) (k : Key) :

A query step of exactWithBad preserves the invariant that every key's cache is a partial bijection.

theorem Cslib.IdealCipher.exactWithBad_map_fst {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) (st : (Key → RandomPermutation.Cache Block) × Bool) (hcache : ∀ (k : Key), RandomPermutation.IsPartialBijection (st.1 k)) :
PMF.map (fun (x : Block × (Key → RandomPermutation.Cache Block) × Bool) => match x with | (a, st') => (a, st'.1)) (exactWithBad q st) = answer q st.1

Dropping the bad flag after a step of exactWithBad recovers the law of answer, provided every key's cache in st.1 is a partial bijection.

theorem Cslib.IdealCipher.forgetfulWithBad_map_fst {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] (q : Query Key Block) (st : (Key → RandomPermutation.Cache Block) × Bool) :
PMF.map (fun (x : Block × (Key → RandomPermutation.Cache Block) × Bool) => match x with | (a, st') => (a, st'.1)) (forgetfulWithBad q st) = forgetfulAnswer q st.1

Dropping the bad flag after a step of forgetfulWithBad recovers the law of forgetfulAnswer.

theorem Cslib.IdealCipher.run_interpret_exactWithBad_map_fst {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] {β : Type} (program : OracleComp (Spec Key Block) β) (cache : Key → RandomPermutation.Cache Block) (bad : Bool) (hcache : ∀ (k : Key), RandomPermutation.IsPartialBijection (cache k)) :
PMF.map (fun (x : β × (Key → RandomPermutation.Cache Block) × Bool) => match x with | (a, st') => (a, st'.1)) ((OracleComp.interpret exactWithBad program).run (cache, bad)) = (OracleComp.interpret answer program).run cache

Dropping the final bad flag after running program under exactWithBad recovers the run under answer, provided every key's initial cache is a partial bijection.

theorem Cslib.IdealCipher.run_interpret_forgetfulWithBad_map_fst {Key Block : Type} [DecidableEq Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] {β : Type} (program : OracleComp (Spec Key Block) β) (cache : Key → RandomPermutation.Cache Block) (bad : Bool) :
PMF.map (fun (x : β × (Key → RandomPermutation.Cache Block) × Bool) => match x with | (a, st') => (a, st'.1)) ((OracleComp.interpret forgetfulWithBad program).run (cache, bad)) = (OracleComp.interpret forgetfulAnswer program).run cache

Dropping the final bad flag after running program under forgetfulWithBad recovers the run under forgetfulAnswer.

theorem Cslib.IdealCipher.abs_sub_uniformPerm_forgetful_le {Key Block : Type} [DecidableEq Key] [Fintype Key] [DecidableEq Block] [Fintype Block] [Nonempty Block] {β γ : Type} {program : OracleComp (Spec Key Block) β} {Q : ℕ} (hQ : program.IsQueryBounded Q) (next : β → PMF γ) (c : γ) :
|((do let a ← do let P ← Probability.PMF.pi fun (x : Key) => Probability.PMF.uniformOfFintype (Equiv.Perm Block) OracleComp.interpret (fun (q : Query Key Block) => PMF.pure (RandomPermutation.evalPerm (P q.1) q.2)) program next a) c).toReal - ((do let a ← PMF.map Prod.fst ((OracleComp.interpret forgetfulAnswer program).run fun (x : Key) => []) next a) c).toReal| ≤ ↑(Q.choose 2) * (↑(Fintype.card Block))⁻¹

Ideal-cipher switching bound (ℝ, two-sided): for any Q-query-bounded program program, postprocessing kernel next : β → PMF γ, and outcome c : γ, the probabilities of outputting c under independent uniformly random permutations P : Key → Equiv.Perm Block and under the forgetful lazy sampler forgetfulAnswer (starting from empty caches) differ by at most Q.choose 2 * (Fintype.card Block)⁻¹.