Documentation

CslibFrontier.Crypto.Primitives.PRG.Nisan

Nisan's generator for read-once branching programs #

Nisan's generator [Nis92] stretches a seed consisting of a block x : X and k seeds h₁, …, h_k of a pairwise independent family h i : X → X into 2 ^ k blocks (Cslib.Crypto.PRG.Nisan.blocks):

G₀(x) = x, G_{k+1}(x; h₁, …, h_{k+1}) = G_k(x; h₂, …, h_{k+1}) ++ G_k(h₁ x; h₂, …, h_{k+1}).

So block b = (b₁ … b_k) in binary is h_k^{b_k} (⋯ (h₂^{b₂} (h₁^{b₁} x))), the first seed choosing the most significant bit and acting first. The recursion peels off the first hash seed; presentations that peel off the last one, G_k(x; h₁, …, h_k) = G_{k-1}(x; h₁, …, h_{k-1}) ++ G_{k-1}(h_k x; h₁, …, h_{k-1}), define the same generator on the reversed tuple of hash seeds (h_k, …, h₁), which is uniform exactly when (h₁, …, h_k) is. For every read-once branching program of width w and length 2 ^ k over the alphabet X, its acceptance probabilities on the output of the generator, for a uniform seed, and on uniform words differ by at most (2 ^ k - 1) w / (2 √|X|) (Cslib.Crypto.PRG.Nisan.abs_dens_eval_blocks_sub_le), and the same holds for every time-dependent transition function δ with w states, run as the indexed fold List.foldlIdx δ (Cslib.Crypto.PRG.Nisan.abs_dens_foldlIdx_blocks_sub_le). As a generator (Cslib.Crypto.PRG.Nisan.generator), it is secure against the tests computed by read-once branching programs of width w (Cslib.Crypto.PRG.IsReadOnceTest) with that error (Cslib.Crypto.PRG.Nisan.secure_generator). With X the bit strings of length n and the Toeplitz hash family, seeds of O(n k) bits fool programs on 2 ^ k n bits (CslibFrontier.Crypto.Primitives.PRG.Nisan.Bits): for width w, length R and error ε this is the seed length O(log (w R / ε) log R) of Nisan's theorem Arora and Barak, Theorem 16.48, Vadhan, Section 8.2.1; in this parametrized form it is the seed length of Hatami and Hoza, Theorem 3.8, which the remark after that theorem attributes to Nisan as well.

Proof #

For a fixed sequence of hash seeds, the run of the program from time t on the 2 ^ k blocks generated from a uniform x is a random walk on the states; let G_t be its transition matrix and U_t the transition matrix of the run on 2 ^ k uniform letters. For every probability vector π on the states, the expected ℓ¹ error 𝔼 ‖π (G_t - U_t)‖₁ over the hash seeds is at most (2 ^ k - 1) w / √|X|, by induction on k. For k + 1, the run splits into two halves of 2 ^ k blocks, generated from x and from h₁ x with the same seeds h₂, …, h_{k+1}. With these fixed, the event that the first half moves u to m and the event that the second half moves m to v are sets A and B of blocks, and the hash mixing lemma (Cslib.Probability.IsPairwiseIndependentHash.expect_abs_dens_filter_apply_mem_sub_le) shows that h₁ correlates the two halves of the run by at most √(μ(A) μ(B) / |X|) on average. By Cauchy–Schwarz these terms sum to at most w / √|X| over the pairs (m, v). The errors of the two halves are bounded by induction: the second with the start distribution π U_t, since the first half then has distribution exactly π U_t. Acceptance probabilities differ by at most half the ℓ¹ distance of the final-state distributions. This is Nisan's hashing argument [Nis92], in expectation form. Unlike Hatami and Hoza, Section 3.2, which iterates a derandomized product through the Impagliazzo–Nisan–Wigderson generator, the two halves here reuse the same hash seeds, so the induction runs over all start distributions with the lower seeds fixed.

Main definitions #

Main results #

References #

def Cslib.Crypto.PRG.IsReadOnceTest {L : ℕ} {X : Type u_1} (w : ℕ) (adversary : Adversary (Fin L → X)) :

The tests on words of length L over X computed by read-once branching programs of width w, that is with the states Fin w. As admissible adversaries of Cslib.Crypto.PRG.Generator.Secure, they express security against computations of length L with log w bits of memory reading their input once, in order.

The generator #

def Cslib.Crypto.PRG.Nisan.blocks {ι : Type u_1} {X : Type u_2} (h : ι → X → X) (k : ℕ) :
X → (Fin k → ι) → Fin (2 ^ k) → X

The 2 ^ k blocks of Nisan's generator with the hash family h, on the block x and the hash seeds hs: one block x for k = 0, and for k + 1 the blocks for x followed by the blocks for h (hs 0) x, both with the seeds hs 1, …, hs k.

@[simp]
theorem Cslib.Crypto.PRG.Nisan.blocks_zero {ι : Type u_1} {X : Type u_2} (h : ι → X → X) (x : X) (hs : Fin 0 → ι) (j : Fin (2 ^ 0)) :
blocks h 0 x hs j = x
theorem Cslib.Crypto.PRG.Nisan.ofFn_blocks_succ {ι : Type u_1} {X : Type u_2} (h : ι → X → X) (k : ℕ) (x : X) (hs : Fin (k + 1) → ι) :
List.ofFn (blocks h (k + 1) x hs) = List.ofFn (blocks h k x (Fin.tail hs)) ++ List.ofFn (blocks h k (h (hs 0) x) (Fin.tail hs))

The blocks for k + 1 hash seeds are the blocks for x followed by those for h (hs 0) x, with the remaining seeds.

theorem Cslib.Crypto.PRG.Nisan.blocks_apply_eq_foldl {ι : Type u_1} {X : Type u_2} (h : ι → X → X) (k : ℕ) (x : X) (hs : Fin k → ι) (j : Fin (2 ^ k)) :
blocks h k x hs j = List.foldl (fun (y : X) (ℓ : Fin k) => if (↑j).testBit (k - 1 - ↑ℓ) = true then h (hs ℓ) y else y) x (List.finRange k)

A block of Nisan's generator on its own: block j applies, in order of the hash seeds, the hash h (hs ℓ) exactly at the levels ℓ for which bit k - 1 - ℓ of j is set, the first seed choosing the most significant bit. So one block costs k hash evaluations, not 2 ^ k.

def Cslib.Crypto.PRG.Nisan.generator {ι : Type u_1} {X : Type u_2} (h : ι → X → X) (k : ℕ) :
Generator (X × (Fin k → ι)) (Fin (2 ^ k) → X)

Nisan's generator with the hash family h and k hash seeds: the seed is a block and k hash seeds, the output is 2 ^ k blocks.

@[simp]
theorem Cslib.Crypto.PRG.Nisan.generator_apply {ι : Type u_1} {X : Type u_2} (h : ι → X → X) (k : ℕ) (z : X × (Fin k → ι)) :
(generator h k) z = blocks h k z.1 z.2

Transition probabilities #

The junction bound #

The induction #

Fooling read-once branching programs #

theorem Cslib.Crypto.PRG.Nisan.abs_dens_foldlIdx_blocks_sub_le {ι : Type u_1} {X : Type u_2} {S : Type u_3} [Fintype ι] [Fintype X] [DecidableEq X] [Fintype S] {h : ι → X → X} (hh : Probability.IsPairwiseIndependentHash h) (δ : ℕ → S → X → S) (s₀ : S) (F : S → Bool) (k : ℕ) :
|↑{z : X × (Fin k → ι) | F (List.foldlIdx δ s₀ (List.ofFn (blocks h k z.1 z.2))) = true}.dens - ↑{u : Fin (2 ^ k) → X | F (List.foldlIdx δ s₀ (List.ofFn u)) = true}.dens| ≤ (2 ^ k - 1) * ↑(Fintype.card S) / (2 * √↑(Fintype.card X))

Nisan's generator fools time-dependent transition functions [Nis92]: for a pairwise independent family h i : X → X, every transition function δ with states S, start state s₀ and accepting states F, the probability that the run on the 2 ^ k blocks of Nisan's generator with a uniform seed accepts differs from the probability that the run on 2 ^ k uniform letters accepts by at most (2 ^ k - 1) |S| / (2 √|X|).

theorem Cslib.Crypto.PRG.Nisan.dens_hashSeeds_far_le {ι : Type u_1} {X : Type u_2} {S : Type u_3} [Fintype ι] [Fintype X] [DecidableEq X] [Fintype S] [DecidableEq S] {h : ι → X → X} (hh : Probability.IsPairwiseIndependentHash h) (δ : ℕ → S → X → S) (k : ℕ) {ε : ℝ} (hε : 0 < ε) :
↑{hs : Fin k → ι | ∃ (s : S), ε < ∑ s' : S, |↑{x : X | List.foldlIdx δ s (List.ofFn (blocks h k x hs)) = s'}.dens - ↑{u : Fin (2 ^ k) → X | List.foldlIdx δ s (List.ofFn u) = s'}.dens|}.dens ≤ ↑(Fintype.card S) * ((2 ^ k - 1) * ↑(Fintype.card S) / √↑(Fintype.card X)) / ε

Most hash seeds of Nisan's generator are good: for a pairwise independent family h i : X → X and every transition function δ with states S, the fraction of the hash seeds hs for which, from some start state s, the distribution of the end state of the run on the generated blocks (for a uniform block x, with the hash seeds hs fixed) is ε-far in ℓ¹ from the distribution of the end state of the run on 2 ^ k uniform letters is at most |S| ((2 ^ k - 1) |S| / √|X|) / ε. This is Markov's inequality and a union bound over the start states, applied to the expectation bound of the proof of Cslib.Crypto.PRG.Nisan.abs_dens_foldlIdx_blocks_sub_le. It is the form of the generator that the Saks–Zhou iteration consumes, with the hash seeds fixed and the block averaged (Cslib.Probability.SaksZhou.dens_entryFarSet_nisanPow_le).

theorem Cslib.Crypto.PRG.Nisan.abs_dens_eval_blocks_sub_le {ι : Type u_1} {X : Type u_2} {S : Type u_3} [Fintype ι] [Fintype X] [DecidableEq X] [Fintype S] {h : ι → X → X} (hh : Probability.IsPairwiseIndependentHash h) (k : ℕ) (P : BranchingPrograms.ReadOnceProgram (2 ^ k) S X) :
|↑{z : X × (Fin k → ι) | P.eval (blocks h k z.1 z.2) = true}.dens - ↑{u : Fin (2 ^ k) → X | P.eval u = true}.dens| ≤ (2 ^ k - 1) * ↑(Fintype.card S) / (2 * √↑(Fintype.card X))

Nisan's generator fools read-once branching programs [Nis92]: for a pairwise independent family h i : X → X and every read-once branching program P of length 2 ^ k over X with states S, the probability that P accepts the output of Nisan's generator on a uniform seed differs from the probability that it accepts a uniform word by at most (2 ^ k - 1) |S| / (2 √|X|).

theorem Cslib.Crypto.PRG.Nisan.secure_generator {ι : Type u_1} {X : Type u_2} [Fintype ι] [Nonempty ι] [Fintype X] [Nonempty X] [DecidableEq X] {h : ι → X → X} (hh : Probability.IsPairwiseIndependentHash h) (k w : ℕ) :
(generator h k).Secure (IsReadOnceTest w) ((2 ^ k - 1) * ↑w / (2 * NNReal.sqrt ↑(Fintype.card X)))

Nisan's generator is secure against read-once branching programs [Nis92]: for a pairwise independent family h i : X → X, no read-once branching program of width w and length 2 ^ k distinguishes the output of Nisan's generator with k hash seeds from a uniform word with advantage more than (2 ^ k - 1) w / (2 √|X|).