Lazy sampling of random permutations and the PRP/PRF switching lemma #
A bidirectional permutation oracle (PermOracleSpec α) answers forward queries (.forward x) and
inverse queries (.inverse y) on a finite type α. We provide two lazy stateful samplers over an
association-list cache Cache α = List (α × α):
- Exact without-replacement lazy permutation (
RandomPermutation.answer): on a cache hit, return the recorded image or preimage; on a cache miss, sample uniformly from the remaining unused range elements (unusedRange cache) for a forward query or from the remaining unused domain elements (unusedDomain cache) for an inverse query. UsingOracleComp.run_interpret_simulation_of_invariantand uniform completioncompleteover the setextPerms cacheof permutations extending the partial bijection, we prove that adaptive execution againstanswerfollowed bycompletehas the exact same joint distribution as samplingπ ← PMF.uniformOfFintype (Equiv.Perm α)eagerly (run_interpret_answer_complete,uniform_interpret_eq_lazy). - Forgetful with-replacement lazy permutation (
RandomPermutation.forgetfulAnswer, [BS23], Section 4.7): on a cache miss, sample uniformly from all ofαwithout domain or range exclusion. By couplinganswerandforgetfulAnswervia resampling andOracleComp.IdenticalUntilBad, anyQ-query adaptive distinguisher has distinguishing advantage at mostQ.choose 2 / |α|between a uniformly random permutationπ ← PMF.uniformOfFintype (Equiv.Perm α)andforgetfulAnswer(abs_sub_uniformPerm_forgetful_le). On forward-only programs (liftForward),forgetfulAnswercoincides withmemoize (fun _ => PMF.uniformOfFintype α)and therefore with a uniformly random functionf ← PMF.uniformOfFintype (α → α), yielding the classical PRP/PRF switching lemma (abs_sub_uniformPerm_uniformFunc_le, [BS23], Section 4.4, Theorem 4.4).
Main definitions #
Cslib.RandomPermutation.PermQuery,PermQuery.ofBoolProd,PermOracleSpec,evalPerm,liftForward,liftBoolProd: bidirectional permutation queries, oracle specification, deterministic evaluation, and query liftings.Cslib.RandomPermutation.Cache,invLookup,AgreesWith,IsPartialBijection,extPerms,unusedDomain,unusedRange: partial bijection caches and extension sets.Cslib.RandomPermutation.answer,complete,forgetfulAnswer: exact and forgetful lazy bidirectional permutation samplers and uniform completion.
Main results #
Cslib.RandomPermutation.answer_complete,Cslib.RandomPermutation.run_interpret_answer_complete,Cslib.RandomPermutation.uniform_interpret_eq_lazy: exact eager/lazy equivalence for bidirectional random permutations.Cslib.RandomPermutation.toOuterMeasure_bad_choose_two_le: quadratic union bound(n * size s + n.choose 2) * δfor bad events with linearly growing step probability.Cslib.RandomPermutation.uniformPerm_bind_apply_le_forgetful,Cslib.RandomPermutation.forgetfulAnswer_bind_apply_le_uniformPerm,Cslib.RandomPermutation.toOuterMeasure_forgetfulAnswer_le_pairwise_and_length_le_add,Cslib.RandomPermutation.abs_sub_uniformPerm_forgetful_le: bidirectional random-permutation switching bounds (Q.choose 2 / |α|).Cslib.RandomPermutation.abs_sub_uniformPerm_uniformFunc_le: the PRP/PRF switching lemma ([BS23], Section 4.4, Theorem 4.4).
References #
- D. Boneh, V. Shoup, A Graduate Course in Applied Cryptography, Version 0.6, Sections 4.4 and 4.7 (Theorems 4.4 and 4.7).
Bidirectional permutation query interface #
Instances For
The oracle specification of a bidirectional permutation on α.
Instances For
Deterministically answer a bidirectional permutation query using π : Equiv.Perm α.
Instances For
Evaluating evalPerm π on a forward query .forward x applies π to x.
Evaluating evalPerm π on an inverse query .inverse y applies π.symm to y.
Lift a forward-only oracle program into a bidirectional permutation oracle program.
Instances For
Interpreting liftForward program against evalPerm π is interpreting program against
π.
Lifting a forward-only program preserves query bounds.
Lift a Bool × α bidirectional oracle program into a PermOracleSpec α program.
Instances For
Lifting a Bool × α program preserves query bounds.
Partial bijection cache and lookup lemmas #
A partial permutation table stored as a list of input-output pairs (x, y).
Instances For
Lookup the preimage x of y in cache by searching (y, x) in cache.map Prod.swap.
Instances For
Inverse lookup in the empty cache returns none.
If cache.lookup x = some y, then the pair (x, y) belongs to cache.
Forward lookup of x in cache returns none iff no entry in cache has first component
x.
Inverse lookup of y in cache returns none iff no entry in cache has second component
y.
A permutation π : Equiv.Perm α agrees with cache if π e.1 = e.2 for all e ∈ cache.
Instances For
Decidability of AgreesWith cache π.
Every permutation agrees with the empty cache.
A permutation π agrees with e :: cache iff π e.1 = e.2 and π agrees with cache.
If π agrees with cache and cache.lookup x = some y, then π x = y.
If π agrees with cache and invLookup cache y = some x, then π.symm y = x.
If π agrees with cache and x is not in the domain of cache, then π x is not in the
range of cache.
If π agrees with cache and y is not in the range of cache, then π.symm y is not in
the domain of cache.
Post-composing a permutation agreeing with cache by Equiv.swap (π x) y extends agreement
to (x, y) :: cache when x and y are fresh.
Pre-composing a permutation agreeing with cache by Equiv.swap (π.symm y) x extends
agreement to (x, y) :: cache when x and y are fresh.
A cache is a partial bijection when at least one permutation on α extends it.
Instances For
The empty cache is a partial bijection, witnessed by the identity permutation.
Extending a partial bijection cache with a fresh domain element x and fresh range element
y yields a partial bijection.
Finite domain/range complements and extension finsets #
Elements of α not yet present in the domain of cache.
Instances For
Elements of α not yet present in the range of cache.
Instances For
Permutations π : Equiv.Perm α that agree with every entry in cache.
Instances For
An element x belongs to unusedDomain cache iff cache.lookup x = none.
An element y belongs to unusedRange cache iff invLookup cache y = none.
A permutation π belongs to extPerms cache iff AgreesWith cache π.
Every permutation extends the empty cache.
The extension finset extPerms cache is nonempty iff cache is a partial bijection.
When cache is a partial bijection and x is outside its domain, unusedRange cache is
nonempty.
When cache is a partial bijection and y is outside its range, unusedDomain cache is
nonempty.
Partitioning extPerms cache by the image π x of a fresh input x shows that all fibers over
unusedRange cache have equal size.
Partitioning extPerms cache by the preimage π.symm y of a fresh output y shows that all
fibers over unusedDomain cache have equal size.
Exact lazy bidirectional permutation sampler and eager/lazy equivalence #
Exact without-replacement lazy bidirectional permutation oracle: return cached answers on hits,
and sample uniformly from unusedRange cache (for .forward) or unusedDomain cache (for
.inverse) on misses.
Instances For
Uniformly sample a full permutation π : Equiv.Perm α extending cache.
Instances For
Completing the empty cache samples a uniformly random permutation on α.
answer preserves IsPartialBijection on every supported transition.
Answering one bidirectional query lazily and then completing the partial bijection has the exact
same joint distribution on (answer, π) as completing first and evaluating evalPerm π q.
Eager/lazy equivalence for bidirectional permutations: running an adaptive program against
answer from any partial bijection cache and then completing cache' to a full permutation gives
the same joint distribution on (result, π) as completing cache first and answering queries via
evalPerm π.
Uniform random permutation equals lazy bidirectional sampling: sampling a uniform
permutation π ← PMF.uniformOfFintype (Equiv.Perm α) and answering bidirectional queries via
evalPerm π has the exact same output distribution as running answer from the empty cache
[].
Forgetful lazy permutation sampler and bidirectional switching bound #
Forgetful lazy bidirectional permutation oracle ([BS23], Section 4.7): return the
cached image/preimage on a hit, and sample uniformly from all of α (with replacement) on a
miss.
Instances For
On forward-only programs (liftForward), forgetfulAnswer never queries invLookup, so its
joint result and cache distribution is identical to memoize (fun _ => PMF.uniformOfFintype α).
Quadratic union bound for linearly growing collision sets #
If each oracle call from a good state s turns bad with probability at most size s * δ and
increases size by at most 1, then an adaptive program making at most n queries reaches a bad
state from s with probability at most (n * size s + n.choose 2) * δ.
Bidirectional random-permutation switching inequality (ℝ≥0∞, one-sided): for any
Q-query adaptive program, evaluating against a uniform permutation accepts within
Q.choose 2 * |α|⁻¹ of evaluating against forgetfulAnswer.
Reverse bidirectional random-permutation switching inequality (ℝ≥0∞, one-sided): for any
Q-query adaptive program, evaluating against forgetfulAnswer accepts within
Q.choose 2 * |α|⁻¹ of evaluating against a uniform permutation.
Any final-cache event P under forgetfulAnswer on a Q-query-bounded program has
probability at most that of (c.Pairwise (fun a b => a.1 ≠ b.1) ∧ c.Pairwise (fun a b => a.2 ≠ b.2) ∧ c.length ≤ Q) ∧ P c plus the Q.choose 2 * |α|⁻¹ collision probability of
forgetfulWithBad.
Bidirectional random-permutation switching bound (ℝ, two-sided, [BS23],
Section 4.7): for any Q-query adaptive program, the output distributions under a uniform
permutation π ← PMF.uniformOfFintype (Equiv.Perm α) and under the forgetful lazy sampler
forgetfulAnswer differ in probability on every event by at most Q.choose 2 / |α|.
The PRP/PRF switching lemma (ℝ, two-sided, [BS23], Section 4.4, Theorem 4.4):
for any Q-query forward-only adaptive program program : OracleComp (fun _ : α => α) β, the
acceptance probabilities under a uniformly random permutation
π ← PMF.uniformOfFintype (Equiv.Perm α) and under a uniformly random function
f ← PMF.uniformOfFintype (α → α) differ by at most Q.choose 2 / |α|.