Documentation

CslibFrontier.DataStructure.Dictionary.KickTree.SmallUniversePerm

Unbalanced Naor–Reingold Feistel blocks and Arbitman–Naor–Segev sharding #

This module constructs unbalanced 3-round Feistel Naor–Reingold blocks and t-round compositions on Fin (2 ^ a') ([NR99], Sections 3.2, 5.2, 6, and 8), combines them with the Arbitman–Naor–Segev 1-round Feistel shard router (caseBEquiv, [ANS10], Section 5.2 construction for intra-shard injectivity and Section 5.4 Claim 5.7 for bin load bounds), and proves abstract k-tuple statistical-distance contraction and intra-shard suffix bijectivity for CslibFrontier.DataStructure.Dictionary.KickTree.QuotientPerm.

Main definitions #

Main results #

References #

Section 1: Single-block Naor–Reingold Feistel permutations #

Low-half bit-width ⌊a' / 2⌋ of an unbalanced Naor–Reingold block on Fin (2 ^ a').

High-half bit-width a' - ⌊a' / 2⌋ = ⌈a' / 2⌉ of an unbalanced Naor–Reingold block.

Split Fin (2 ^ a') ≃ Fin (2 ^ ⌊a' / 2⌋) × Fin (2 ^ ⌈a' / 2⌉) into low and high halves.

Round-function triple (f₀, f₁, f₂) for one unbalanced 3-round Feistel Naor–Reingold block on Fin (2 ^ a') ([NR99], Definition 3.1, Section 5.2, and Section 6 Definition 6.1).

Reversing f₀ and f₂ in an NRBlockFuncs inverts the 3-round Feistel block.

Pair-domain 3-round Feistel Naor–Reingold permutation.

Flat 3-round Feistel Naor–Reingold permutation on Fin (2 ^ a').

Composition of t Naor–Reingold blocks on Fin (2 ^ a') in index order 0, 1, …, t - 1.

@[simp]
theorem Cslib.DataStructure.Dictionary.KickTree.nrComposedEquiv_succ (a' t : ℕ) (blks : Fin (t + 1) → NRBlockFuncs a') :
nrComposedEquiv a' (t + 1) blks = Equiv.trans (nrComposedEquiv a' t fun (i : Fin t) => blks i.castSucc) (nrBlockEquiv a' (blks (Fin.last t)))
theorem Cslib.DataStructure.Dictionary.KickTree.nrComposedEquiv_succ_left (a' t : ℕ) (blks : Fin (t + 1) → NRBlockFuncs a') :
nrComposedEquiv a' (t + 1) blks = Equiv.trans (nrBlockEquiv a' (blks 0)) (nrComposedEquiv a' t fun (i : Fin t) => blks i.succ)
@[simp]
theorem Cslib.DataStructure.Dictionary.KickTree.nrComposedEquiv_symm (a' t : ℕ) (blks : Fin t → NRBlockFuncs a') :
Equiv.symm (nrComposedEquiv a' t blks) = nrComposedEquiv a' t fun (i : Fin t) => (blks i.rev).rev
structure Cslib.DataStructure.Dictionary.KickTree.NRBlockSeed (ι₀ : Type u_1) (ι₁ : Type u_2) (ι₂ : Type u_3) :
Type (max (max u_1 u_2) u_3)

Seed triple (s₀, s₁, s₂) for one Naor–Reingold block over seed spaces ι₀, ι₁, ι₂.

  • s₀ : ι₀

    Pre-whitening round seed.

  • s₁ : ι₁

    Middle round seed.

  • s₂ : ι₂

    Final round seed.

Instances For
    def Cslib.DataStructure.Dictionary.KickTree.nrBlockSeedEquivProd (ι₀ : Type u_1) (ι₁ : Type u_2) (ι₂ : Type u_3) :
    NRBlockSeed ι₀ ι₁ ι₂ ≃ ι₀ × ι₁ × ι₂

    Equivalence between NRBlockSeed ι₀ ι₁ ι₂ and ι₀ × ι₁ × ι₂.

    @[instance_reducible]
    instance Cslib.DataStructure.Dictionary.KickTree.instFintypeNRBlockSeed {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Fintype ι₀] [Fintype ι₁] [Fintype ι₂] :
    Fintype (NRBlockSeed ι₀ ι₁ ι₂)
    instance Cslib.DataStructure.Dictionary.KickTree.instNonemptyNRBlockSeed {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Nonempty ι₀] [Nonempty ι₁] [Nonempty ι₂] :
    Nonempty (NRBlockSeed ι₀ ι₁ ι₂)
    noncomputable def Cslib.DataStructure.Dictionary.KickTree.nrBlockSeedDist {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Fintype ι₀] [Nonempty ι₀] [Fintype ι₁] [Nonempty ι₁] [Fintype ι₂] [Nonempty ι₂] (a' : ℕ) (h₀ : ι₀ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) (h₁ : ι₁ → Fin (2 ^ nrHalfHigh a') → Fin (2 ^ nrHalfLow a')) (h₂ : ι₂ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) :
    PMF (Equiv.Perm (Fin (2 ^ a')))

    Random Naor–Reingold block on Fin (2 ^ a') induced by uniform independent seeds in NRBlockSeed ι₀ ι₁ ι₂.

    theorem Cslib.DataStructure.Dictionary.KickTree.nrBlockSeedDist_eq {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Fintype ι₀] [Nonempty ι₀] [Fintype ι₁] [Nonempty ι₁] [Fintype ι₂] [Nonempty ι₂] (a' : ℕ) (h₀ : ι₀ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) (h₁ : ι₁ → Fin (2 ^ nrHalfHigh a') → Fin (2 ^ nrHalfLow a')) (h₂ : ι₂ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) :
    nrBlockSeedDist a' h₀ h₁ h₂ = PMF.map (fun (s : NRBlockSeed ι₀ ι₁ ι₂) => nrBlockEquiv a' { f₀ := h₀ s.s₀, f₁ := h₁ s.s₁, f₂ := h₂ s.s₂ }) (Probability.PMF.uniformOfFintype (NRBlockSeed ι₀ ι₁ ι₂))
    theorem Cslib.DataStructure.Dictionary.KickTree.dist_permTupleKernel_nrBlock_le {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} {T : Type u_4} [Fintype ι₀] [Fintype ι₁] [Fintype ι₂] [Fintype T] {a' k : ℕ} {h₀ : ι₀ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')} {h₁ : ι₁ → Fin (2 ^ nrHalfHigh a') → Fin (2 ^ nrHalfLow a')} {h₂ : ι₂ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')} (hh₀ : Probability.IsKWiseIndependentHash 2 h₀) (hh₁ : Probability.IsKWiseIndependentHash k h₁) (hh₂ : Probability.IsKWiseIndependentHash k h₂) (hT : Fintype.card T ≤ k) (x : T ↪ Fin (2 ^ a')) :

    Single-block Naor–Reingold k-tuple statistical-distance bound ([NR99], Section 3.2 Definition 3.1, Section 5.2, Section 6 Definition 6.1, and Section 8 Corollary 8.1, printed pp. 38, 49–50, 52, 60–61 / PDF pp. 10, 21–22, 24, 32–33).

    Per Definition 2.10 item 2 of [NR99], the uniform embedding distribution PMF.uniformOfFintype (T ↪ Fin (2 ^ a')) models the uniform distribution on tuples of distinct elements, and this theorem bounds distinguishing advantage from that ideal distribution.

    Section 2: Composed Naor–Reingold blocks and Case B sharded bijection #

    structure Cslib.DataStructure.Dictionary.KickTree.NRComposedSeed (t : ℕ) (ι₀ : Type u_1) (ι₁ : Type u_2) (ι₂ : Type u_3) :
    Type (max (max u_1 u_2) u_3)

    Seed tuple Fin t → NRBlockSeed ι₀ ι₁ ι₂ for t independent Naor–Reingold blocks.

    • blocks : Fin t → NRBlockSeed ι₀ ι₁ ι₂

      Per-round block seeds.

    Instances For
      def Cslib.DataStructure.Dictionary.KickTree.nrComposedSeedEquivFun (t : ℕ) (ι₀ : Type u_1) (ι₁ : Type u_2) (ι₂ : Type u_3) :
      NRComposedSeed t ι₀ ι₁ ι₂ ≃ (Fin t → NRBlockSeed ι₀ ι₁ ι₂)

      Equivalence between NRComposedSeed t ι₀ ι₁ ι₂ and Fin t → NRBlockSeed ι₀ ι₁ ι₂.

      @[instance_reducible]
      instance Cslib.DataStructure.Dictionary.KickTree.instFintypeNRComposedSeed {t : ℕ} {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Fintype ι₀] [Fintype ι₁] [Fintype ι₂] :
      Fintype (NRComposedSeed t ι₀ ι₁ ι₂)
      instance Cslib.DataStructure.Dictionary.KickTree.instNonemptyNRComposedSeed {t : ℕ} {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Nonempty ι₀] [Nonempty ι₁] [Nonempty ι₂] :
      Nonempty (NRComposedSeed t ι₀ ι₁ ι₂)
      noncomputable def Cslib.DataStructure.Dictionary.KickTree.nrComposedSeedDist {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Fintype ι₀] [Nonempty ι₀] [Fintype ι₁] [Nonempty ι₁] [Fintype ι₂] [Nonempty ι₂] (a' t : ℕ) (h₀ : ι₀ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) (h₁ : ι₁ → Fin (2 ^ nrHalfHigh a') → Fin (2 ^ nrHalfLow a')) (h₂ : ι₂ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) :
      PMF (Equiv.Perm (Fin (2 ^ a')))

      Random t-composed Naor–Reingold permutation on Fin (2 ^ a') under a uniform NRComposedSeed.

      theorem Cslib.DataStructure.Dictionary.KickTree.nrComposedSeedDist_eq {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Fintype ι₀] [Nonempty ι₀] [Fintype ι₁] [Nonempty ι₁] [Fintype ι₂] [Nonempty ι₂] (a' t : ℕ) (h₀ : ι₀ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) (h₁ : ι₁ → Fin (2 ^ nrHalfHigh a') → Fin (2 ^ nrHalfLow a')) (h₂ : ι₂ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) :
      nrComposedSeedDist a' t h₀ h₁ h₂ = PMF.map (fun (s : NRComposedSeed t ι₀ ι₁ ι₂) => nrComposedEquiv a' t fun (r : Fin t) => { f₀ := h₀ (s.blocks r).s₀, f₁ := h₁ (s.blocks r).s₁, f₂ := h₂ (s.blocks r).s₂ }) (Probability.PMF.uniformOfFintype (NRComposedSeed t ι₀ ι₁ ι₂))
      theorem Cslib.DataStructure.Dictionary.KickTree.nrComposedSeedDist_eq_composePermDist {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} [Fintype ι₀] [Nonempty ι₀] [Fintype ι₁] [Nonempty ι₁] [Fintype ι₂] [Nonempty ι₂] (a' : ℕ) (h₀ : ι₀ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) (h₁ : ι₁ → Fin (2 ^ nrHalfHigh a') → Fin (2 ^ nrHalfLow a')) (h₂ : ι₂ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')) (t : ℕ) :
      nrComposedSeedDist a' t h₀ h₁ h₂ = Probability.composePermDist t fun (x : Fin t) => nrBlockSeedDist a' h₀ h₁ h₂
      theorem Cslib.DataStructure.Dictionary.KickTree.dist_permTupleKernel_nrComposed_le {ι₀ : Type u_1} {ι₁ : Type u_2} {ι₂ : Type u_3} {T : Type u_4} [Fintype ι₀] [Fintype ι₁] [Fintype ι₂] [Fintype T] {a' t k : ℕ} (ht : 1 ≤ t) {h₀ : ι₀ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')} {h₁ : ι₁ → Fin (2 ^ nrHalfHigh a') → Fin (2 ^ nrHalfLow a')} {h₂ : ι₂ → Fin (2 ^ nrHalfLow a') → Fin (2 ^ nrHalfHigh a')} (hh₀ : Probability.IsKWiseIndependentHash 2 h₀) (hh₁ : Probability.IsKWiseIndependentHash k h₁) (hh₂ : Probability.IsKWiseIndependentHash k h₂) (hT : Fintype.card T ≤ k) (x : T ↪ Fin (2 ^ a')) :
      dist (Probability.permTupleKernel (nrComposedSeedDist a' t h₀ h₁ h₂) x) (Probability.PMF.uniformOfFintype (T ↪ Fin (2 ^ a'))) ≤ 1 / 2 * (3 * ↑k ^ 2 / 2 ^ nrHalfLow a') ^ t

      t-composed Naor–Reingold k-tuple statistical-distance contraction: composing t ≥ 1 independent 3-round Feistel Naor–Reingold blocks with 2-wise independent h₀ and k-wise independent h₁, h₂ achieves statistical distance at most (1 / 2) * (3 * k ^ 2 / 2 ^ ⌊a' / 2⌋) ^ t from uniform on T ↪ Fin (2 ^ a').

      @[reducible, inline]

      Shard-index bit-width ⌊m / 2⌋ for Arbitman–Naor–Segev 1-round Feistel sharding in Case B.

      @[reducible, inline]

      Intra-shard local bucket bit-width m - shardBits m = ⌈m / 2⌉ in Case B.

      @[reducible, inline]

      Right-coordinate suffix bit-width a' = a - ⌊m / 2⌋ permuted by Naor–Reingold in Case B.

      Round-function bundle for Case B: 1-round Feistel shard router fShard plus t composed 3-round Feistel Naor–Reingold blocks on Fin (2 ^ suffixBits a m).

      Split Fin (2 ^ suffixBits a m) ≃ Fin (2 ^ localBucketBits m) × Fin (2 ^ (a - m)).

      Combine (shard, (localBucket, quot)) into (Fin (2 ^ m)) × (Fin (2 ^ (a - m))).

      def Cslib.DataStructure.Dictionary.KickTree.caseBEquiv {a m t : ℕ} (hma : m ≤ a) (r : CaseBRounds a m t) :
      Fin (2 ^ a) ≃ Fin (2 ^ m) × Fin (2 ^ (a - m))

      Case B bijection (u : Fin (2 ^ a)) ≃ Fin (2 ^ m) × Fin (2 ^ (a - m)): 1-round Feistel shard σ = x_L ^^^ fShard y_R followed by t-round Naor–Reingold permutation z = nrComposedEquiv a' t nrBlocks y_R split into (localBucket, quot).

      Shard index σ : Fin (2 ^ shardBits m) extracted from a Fin (2 ^ m) bucket index.

      Local intra-shard bucket Fin (2 ^ localBucketBits m) extracted from b : Fin (2 ^ m).

      def Cslib.DataStructure.Dictionary.KickTree.keySuffix {a m : ℕ} (hma : m ≤ a) (u : Fin (2 ^ a)) :
      Fin (2 ^ suffixBits a m)

      Right-coordinate suffix y_R : Fin (2 ^ suffixBits a m) of u : Fin (2 ^ a).

      def Cslib.DataStructure.Dictionary.KickTree.caseBShard {a m t : ℕ} (hma : m ≤ a) (r : CaseBRounds a m t) (u : Fin (2 ^ a)) :

      Shard σ(u) = x_L ^^^ fShard y_R assigned to u by caseBEquiv.

      theorem Cslib.DataStructure.Dictionary.KickTree.injOn_yR_of_caseBShard_eq {a m t : ℕ} (hma : m ≤ a) (r : CaseBRounds a m t) (σ : Fin (2 ^ shardBits m)) :
      Set.InjOn (keySuffix hma) {u : Fin (2 ^ a) | caseBShard hma r u = σ}

      Deterministic shard collision-freedom ([ANS10], arXiv:0912.5424v3, Section 5.2 construction, PDF pp. 21–23 / printed pp. 20–22): for every CaseBRounds r and shard σ : Fin (2 ^ shardBits m), the suffix projection keySuffix hma (y_R) is strictly injective on all keys routed into shard σ. (Section 5.4 Claim 5.7 provides bin load bounds for this construction.)

      theorem Cslib.DataStructure.Dictionary.KickTree.dist_caseB_shardTuple_le {Top : Type u_1} {ι_sh : Type u_2} {ι₀ : Type u_3} {ι₁ : Type u_4} {ι₂ : Type u_5} {ι_aux : Type u_6} [Fintype Top] [Nonempty Top] [Fintype ι_sh] [Nonempty ι_sh] [Fintype ι₀] [Nonempty ι₀] [Fintype ι₁] [Nonempty ι₁] [Fintype ι₂] [Nonempty ι₂] [Fintype ι_aux] [Nonempty ι_aux] {a m b_aux t κ : ℕ} (hma : m ≤ a) (ht : 1 ≤ t) (h_sh : Top → ι_sh → Fin (2 ^ suffixBits a m) → Fin (2 ^ shardBits m)) (h_nr₀ : Top → ι₀ → Fin (2 ^ nrHalfLow (suffixBits a m)) → Fin (2 ^ nrHalfHigh (suffixBits a m))) (h_nr₁ : Top → ι₁ → Fin (2 ^ nrHalfHigh (suffixBits a m)) → Fin (2 ^ nrHalfLow (suffixBits a m))) (h_nr₂ : Top → ι₂ → Fin (2 ^ nrHalfLow (suffixBits a m)) → Fin (2 ^ nrHalfHigh (suffixBits a m))) (h_aux : Top → ι_aux → Fin (2 ^ a) → Fin (2 ^ b_aux)) {T : Finset (Fin (2 ^ a))} (hT : T.card ≤ κ) (yEmb : ↥T ↪ Fin (2 ^ suffixBits a m)) (GoodTop : Set Top) {δ_top : ℝ} (hδ_top : ((Probability.PMF.uniformOfFintype Top).toOuterMeasure GoodTopᶜ).toReal ≤ δ_top) (hgood_sh : ∀ τ ∈ GoodTop, Probability.IsKWiseIndependentHash κ (h_sh τ)) (hgood_nr₀ : ∀ τ ∈ GoodTop, Probability.IsKWiseIndependentHash 2 (h_nr₀ τ)) (hgood_nr₁ : ∀ τ ∈ GoodTop, Probability.IsKWiseIndependentHash κ (h_nr₁ τ)) (hgood_nr₂ : ∀ τ ∈ GoodTop, Probability.IsKWiseIndependentHash κ (h_nr₂ τ)) (hgood_aux : ∀ τ ∈ GoodTop, Probability.IsKWiseIndependentHash κ (h_aux τ)) :
      dist ((Probability.PMF.uniformOfFintype Top).bind fun (τ : Top) => (Probability.PMF.uniformOfFintype ι_sh).bind fun (s_sh : ι_sh) => (nrComposedSeedDist (suffixBits a m) t (h_nr₀ τ) (h_nr₁ τ) (h_nr₂ τ)).bind fun (π : Equiv.Perm (Fin (2 ^ suffixBits a m))) => PMF.map (fun (s_aux : ι_aux) => (fun (u : ↥T) => ((FeistelPerm.bitDomainEquiv ⋯) ↑u).1 ^^^ h_sh τ s_sh (yEmb u), ((Equiv.refl ↥T).embeddingCongr π) yEmb, fun (u : ↥T) => h_aux τ s_aux ↑u)) (Probability.PMF.uniformOfFintype ι_aux)) (Probability.PMF.uniformOfFintype ((↥T → Fin (2 ^ shardBits m)) × (↥T ↪ Fin (2 ^ suffixBits a m)) × (↥T → Fin (2 ^ b_aux)))) ≤ δ_top + 1 / 2 * (3 * ↑κ ^ 2 / 2 ^ nrHalfLow (suffixBits a m)) ^ t

      Abstract Case B shard-tuple statistical-distance transfer: on any T : Finset (Fin (2 ^ a)) with #T ≤ κ and yEmb : T ↪ Fin (2 ^ suffixBits a m), under a (1 - δ_top)-good top seed τ ∈ GoodTop, the joint distribution of (shard(u), nrPerm(y_R u), aux(u))_{u ∈ T} is within δ_top + (1 / 2) * (3 * κ ^ 2 / 2 ^ ⌊a' / 2⌋) ^ t of Uniform × UniformInj × Uniform.

      Suffix-space preimage (B.image (bucketLocal m) ×ˢ univ) of an intra-shard bucket set B.

      theorem Cslib.DataStructure.Dictionary.KickTree.mem_intraShardSuffixSet_iff {a m : ℕ} (hma : m ≤ a) (σ : Fin (2 ^ shardBits m)) {B : Finset (Fin (2 ^ m))} (hB : ∀ b ∈ B, bucketShard m b = σ) (sh : Fin (2 ^ shardBits m)) (z : Fin (2 ^ suffixBits a m)) :
      theorem Cslib.DataStructure.Dictionary.KickTree.card_intraShardSuffixSet {a m : ℕ} (hma : m ≤ a) (σ : Fin (2 ^ shardBits m)) {B : Finset (Fin (2 ^ m))} (hB : ∀ b ∈ B, bucketShard m b = σ) :
      (intraShardSuffixSet hma B).card = B.card * 2 ^ (a - m)
      theorem Cslib.DataStructure.Dictionary.KickTree.prob_shardTuple_event_eq {T : Type u_1} [Fintype T] [DecidableEq T] {a m b_aux : ℕ} [Nonempty (T ↪ Fin (2 ^ suffixBits a m))] (σ : Fin (2 ^ shardBits m)) (Q : T → Finset (Fin (2 ^ suffixBits a m))) (A : T → Finset (Fin (2 ^ b_aux))) :
      ((Probability.PMF.uniformOfFintype ((T → Fin (2 ^ shardBits m)) × (T ↪ Fin (2 ^ suffixBits a m)) × (T → Fin (2 ^ b_aux)))).toOuterMeasure {(sh, emb, aux) : (T → Fin (2 ^ shardBits m)) × (T ↪ Fin (2 ^ suffixBits a m)) × (T → Fin (2 ^ b_aux)) | ∀ (i : T), sh i = σ ∧ emb i ∈ Q i ∧ aux i ∈ A i}).toReal = (1 / 2 ^ shardBits m) ^ Fintype.card T * ((Probability.PMF.uniformOfFintype (T ↪ Fin (2 ^ suffixBits a m))).toOuterMeasure {e : T ↪ Fin (2 ^ suffixBits a m) | ∀ (i : T), e i ∈ Q i}).toReal * ∏ i : T, ↑(A i).card / 2 ^ b_aux