Documentation

CslibFrontier.Crypto.Computational.PseudorandomGenerator.NextBit

Yao's next-bit theorem for uniform pseudorandom generators #

CslibFrontier/Crypto/Primitives/PRG/NextBit.lean relates prediction to distinguishing for arbitrary tests and predictors on finite output types, without bounding the cost of the tests and predictors that its reductions build. This module lifts that argument to uniform strict-PPT PseudorandomGenerators over arbitrary bit strings: the reductions are explicit programs with strict-PPT certificates, and no closure hypothesis or non-uniform advice is used.

Two standard uniform next-bit formulations are covered and proved equivalent to PseudorandomGenerator:

  1. Random-index prediction (NextBitUnpredictableRandomIndex): a single-stage Distinguisher receives the security parameter 1ⁿ and a prefix (G s).take i for a uniformly sampled bit index i < length n, and attempts to guess (G s)[i]. Note that (G s).take i has length i, so the predictor observes the index from the prefix itself.
  2. Adversary-chosen index (NextBitUnpredictable, Boneh–Shoup Attack Game 3.2): a two-stage adversary TwoStage Unit ℕ (List Bool) Bool σ first chooses an index i (with saved state σ) and then, given a prefix (G s).take i of the generated word, attempts to guess (G s)[i]; if length n ≤ i, the challenger outputs a fair coin so out-of-range guesses yield zero advantage.

Both reductions (wordNextBitPredictor / wordNextBitTwoStage and nextBitDistinguisher / twoStageNextBitDistinguisher) are certified strict PPT for a unary polynomial-time length, which PRG.polyTime_length supplies for a polynomial-time length-regular generator. They reuse ProbComp.sampleDyadicIndex (isPPTOn_sampleDyadicIndex) for padded uniform index sampling, and the finite hybrid/predictor theorem PRG.Generator.toReal_predictionExperiment_nextBitPredictor from CslibFrontier/Crypto/Primitives/PRG/NextBit.lean.

Main definitions #

Main results #

References #

Uniformity, binary-splitting, and padded-average helpers #

theorem Cslib.Crypto.uniformList_bind_take_getD {α : Type u_1} (m i : ℕ) (hi : i < m) (k : List Bool → Bool → PMF α) :
((BitString.uniformList m).bind fun (word : List Bool) => k (List.take i word) (word.getD i false)) = (BitString.uniformList i).bind fun (front : List Bool) => (Probability.PMF.uniformOfFintype Bool).bind fun (bit : Bool) => k front bit

For i < m, reading the prefix word.take i and the bit word.getD i false of a uniform m-bit word is the same as sampling a uniform i-bit prefix and an independent fair bit.

theorem Cslib.Crypto.uniformList_bind_take_getD_eq_uniform_bool {m i : ℕ} (hi : i < m) (f : List Bool → PMF Bool) :
((BitString.uniformList m).bind fun (word : List Bool) => PMF.map (fun (guess : Bool) => decide (guess = word.getD i false)) (f (List.take i word))) = Probability.PMF.uniformOfFintype Bool

For any predictor f that sees only the first i < m bits of a uniform m-bit word, the indicator that its guess equals bit i is a fair coin.

Polynomial-time and PPT helper certificates #

Section 1: Random-Index Next-Bit Prediction #

noncomputable def Cslib.Crypto.nextBitPredictionGame (generator : List Bool → List Bool) (length : ℕ → ℕ) (predictor : Distinguisher) (n : ℕ) :

Random-index next-bit prediction game: draw a uniform n-bit seed s, set word := generator s, draw a uniform bit position i < length n, run predictor n (word.take i), and accept when the guess matches bit i of word. If length n = 0, output a fair coin.

Uniform strict-PPT next-bit unpredictability at a random bit position. This is the random-position form of [BS23], Attack Game 3.2 and Definition 3.3 (printed p. 64), not Definition 3.3 as printed: the challenger draws the position uniformly, and the single-stage predictor does not choose it. Every uniform strict PPT predictor Distinguisher has negligible guessing advantage in nextBitPredictionGame.

noncomputable def Cslib.Crypto.wordNextBitPredictor (length : ℕ → ℕ) (adversary : Distinguisher) :

The uniform strict-PPT next-bit predictor constructed from a PRG distinguisher adversary: given (n, prefixBits) with prefixBits.length < length n, sample a candidate bit candidate and uniform suffix suffix ← BitString.sampleList (length n - (prefixBits.length + 1)), run adversary n (prefixBits ++ candidate :: suffix), and output candidate if it accepts or !candidate if it rejects.

wordNextBitPredictor length adversary is uniformly strict PPT whenever length is unary polynomial-time computable and adversary is uniformly strict PPT.

theorem Cslib.Crypto.guessingAdvantage_nextBitPredictionGame_wordNextBitPredictor {generator : List Bool → List Bool} {length : ℕ → ℕ} (hlen : ∀ (word : List Bool), (generator word).length = length word.length) (adversary : Distinguisher) {n : ℕ} (hpos : 0 < length n) :
(nextBitPredictionGame generator length (wordNextBitPredictor length adversary) n).guessingAdvantage = Game.advantage (prgRealGame generator adversary n).eval (prgIdealGame length adversary n).eval / ↑(length n)

Exact quantitative advantage of wordNextBitPredictor: when 0 < length n, the random-index prediction advantage is 1 / length n times the distinguisher's PRG advantage.

noncomputable def Cslib.Crypto.nextBitDistinguisher (length : ℕ → ℕ) (predictor : Distinguisher) :

Uniform strict-PPT random-index next-bit distinguisher built from a single-stage predictor: when 0 < length n, draw a padded uniform index i ← ProbComp.sampleDyadicIndex (length n - 1); if i < length n, output decide ((← predictor n (word.take i)) = word.getD i false), else output a fair coin.

nextBitDistinguisher length predictor is uniformly strict PPT whenever length is unary polynomial-time computable and predictor is uniformly strict PPT.

On uniform ideal inputs, nextBitDistinguisher length predictor accepts with probability exactly 1 / 2.

theorem Cslib.Crypto.advantage_nextBitDistinguisher_eq (generator : List Bool → List Bool) (length : ℕ → ℕ) (predictor : Distinguisher) {n : ℕ} (hpos : 0 < length n) :
Game.advantage (prgRealGame generator (nextBitDistinguisher length predictor) n).eval (prgIdealGame length (nextBitDistinguisher length predictor) n).eval = ↑(length n) / ↑(Probability.dyadicSize (length n - 1)) * (nextBitPredictionGame generator length predictor n).guessingAdvantage

Exact quantitative advantage of nextBitDistinguisher: when 0 < length n, its PRG advantage equals (length n / dyadicSize (length n - 1)) times predictor's random-index guessing advantage.

theorem Cslib.Crypto.guessingAdvantage_nextBitPredictionGame_le (generator : List Bool → List Bool) (length : ℕ → ℕ) (predictor : Distinguisher) {n : ℕ} (hpos : 0 < length n) :
(nextBitPredictionGame generator length predictor n).guessingAdvantage ≤ 2 * Game.advantage (prgRealGame generator (nextBitDistinguisher length predictor) n).eval (prgIdealGame length (nextBitDistinguisher length predictor) n).eval

Consequently nextBitDistinguisher loses at most a factor of 2 in advantage relative to nextBitPredictionGame.

Every PseudorandomGenerator is random-index next-bit unpredictable.

theorem Cslib.Crypto.PseudorandomGenerator.of_nextBitUnpredictableRandomIndex {generator : List Bool → List Bool} {length : ℕ → ℕ} (hg : Turing.MultiTapeTM.ComputableInPolyTime generator Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) (hlen : ∀ (word : List Bool), (generator word).length = length word.length) (hstretch : ∀ (n : ℕ), n < length n) (hunpred : NextBitUnpredictableRandomIndex generator length) :
PseudorandomGenerator generator length

A polynomial-time length-stretching generator that is random-index next-bit unpredictable is a PseudorandomGenerator.

Yao's next-bit theorem for a challenger-chosen uniform position. For a deterministic polynomial-time generator that maps every n-bit seed to exactly length n bits with n < length n, security against uniform strict PPT distinguishers is equivalent to random-index next-bit unpredictability. This variant of [BS23], Section 3.5, Theorems 3.4 and 3.6 (pp. 64 and 67), samples the position uniformly from the whole output. The predictor built from a distinguisher loses exactly a factor of length n.

Section 2: Two-Stage Next-Bit Prediction (Boneh–Shoup Attack Game 3.2) #

noncomputable def Cslib.Crypto.nextBitExperiment {σ : Type} (generator : List Bool → List Bool) (length : ℕ → ℕ) (adversary : TwoStage Unit ℕ (List Bool) Bool σ) (n : ℕ) :

Boneh–Shoup Attack Game 3.2 next-bit prediction experiment for a two-stage predictor: stage 1 chooses a bit position i and state state; stage 2 receives state and the generated prefix word.take i and guesses bit i of word. Out-of-range positions (length n ≤ i) return a fair coin so they yield zero advantage.

def Cslib.Crypto.NextBitUnpredictable (generator : List Bool → List Bool) (length : ℕ → ℕ) :

Uniform strict-PPT next-bit unpredictability ([BS23], Attack Game 3.2 and Definition 3.3, printed p. 64): every uniform strict PPT two-stage predictor choosing a position i : ℕ (binary encoded) has negligible guessing advantage in nextBitExperiment.

noncomputable def Cslib.Crypto.wordNextBitTwoStage (length : ℕ → ℕ) (adversary : Distinguisher) (n : ℕ) :

The uniform strict-PPT two-stage next-bit predictor built from a PRG distinguisher adversary: stage 1 draws a padded uniform bit index i ← ProbComp.sampleDyadicIndex (length n - 1); stage 2 forwards prefix queries to wordNextBitPredictor length adversary.

theorem Cslib.Crypto.guessingAdvantage_nextBitExperiment_wordNextBitTwoStage {generator : List Bool → List Bool} {length : ℕ → ℕ} (hlen : ∀ (word : List Bool), (generator word).length = length word.length) (adversary : Distinguisher) {n : ℕ} (hpos : 0 < length n) :
Game.guessingAdvantage (ProbComp.eval (nextBitExperiment generator length (wordNextBitTwoStage length adversary n) n)) = Game.advantage (prgRealGame generator adversary n).eval (prgIdealGame length adversary n).eval / ↑(Probability.dyadicSize (length n - 1))

Exact quantitative advantage of wordNextBitTwoStage: when 0 < length n, its two-stage next-bit guessing advantage is 1 / dyadicSize (length n - 1) times adversary's PRG advantage.

noncomputable def Cslib.Crypto.twoStageNextBitDistinguisher {σ : Type} (length : ℕ → ℕ) (adversary : ℕ → TwoStage Unit ℕ (List Bool) Bool σ) :

The uniform strict-PPT PRG distinguisher constructed from a two-stage next-bit predictor adversary: run stage 1 (i, state) ← (adversary n).choose (), cap idx := min (length n) i to a unary bound in polynomial time, and if idx < length n run stage 2 on word.take idx and compare with bit idx; otherwise flip a fair coin.

twoStageNextBitDistinguisher length adversary is uniformly strict PPT whenever length is unary polynomial-time computable and adversary is uniformly strict PPT.

On uniform ideal inputs, twoStageNextBitDistinguisher accepts with probability 1 / 2.

theorem Cslib.Crypto.eval_prgRealGame_twoStageNextBitDistinguisher {σ : Type} (generator : List Bool → List Bool) (length : ℕ → ℕ) (adversary : ℕ → TwoStage Unit ℕ (List Bool) Bool σ) (n : ℕ) :
(prgRealGame generator (twoStageNextBitDistinguisher length adversary) n).eval = ProbComp.eval (nextBitExperiment generator length (adversary n) n)

On generated inputs, twoStageNextBitDistinguisher agrees identically with nextBitExperiment.

theorem Cslib.Crypto.guessingAdvantage_nextBitExperiment_eq {σ : Type} (generator : List Bool → List Bool) (length : ℕ → ℕ) (adversary : ℕ → TwoStage Unit ℕ (List Bool) Bool σ) (n : ℕ) :
Game.guessingAdvantage (ProbComp.eval (nextBitExperiment generator length (adversary n) n)) = Game.advantage (prgRealGame generator (twoStageNextBitDistinguisher length adversary) n).eval (prgIdealGame length (twoStageNextBitDistinguisher length adversary) n).eval

Exact zero-loss quantitative identity between Attack Game 3.2 and PRG distinguishing for twoStageNextBitDistinguisher.

theorem Cslib.Crypto.PseudorandomGenerator.nextBitUnpredictable {generator : List Bool → List Bool} {length : ℕ → ℕ} (hG : PseudorandomGenerator generator length) :
NextBitUnpredictable generator length

Every PseudorandomGenerator is two-stage next-bit unpredictable (NextBitUnpredictable, Boneh–Shoup Attack Game 3.2).

theorem Cslib.Crypto.PseudorandomGenerator.of_nextBitUnpredictable {generator : List Bool → List Bool} {length : ℕ → ℕ} (hg : Turing.MultiTapeTM.ComputableInPolyTime generator Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits) (hlen : ∀ (word : List Bool), (generator word).length = length word.length) (hstretch : ∀ (n : ℕ), n < length n) (hunpred : NextBitUnpredictable generator length) :
PseudorandomGenerator generator length

A polynomial-time length-stretching generator that is two-stage next-bit unpredictable is a PseudorandomGenerator.

theorem Cslib.Crypto.pseudorandomGenerator_iff_nextBitUnpredictable (generator : List Bool → List Bool) (length : ℕ → ℕ) :
PseudorandomGenerator generator length ↔ Turing.MultiTapeTM.ComputableInPolyTime generator Turing.MultiTapeTM.encBits Turing.MultiTapeTM.encBits ∧ (∀ (word : List Bool), (generator word).length = length word.length) ∧ (∀ (n : ℕ), n < length n) ∧ NextBitUnpredictable generator length

Yao's next-bit theorem for an adversary-chosen position. For a deterministic polynomial-time generator that maps every n-bit seed to exactly length n bits with n < length n, security against uniform strict PPT distinguishers is equivalent to two-stage next-bit unpredictability. This is the stretching case of [BS23], Section 3.5, Attack Game 3.2, Definition 3.3 and Theorems 3.4 and 3.6 (pp. 64 and 67). The predictor built from a distinguisher samples a padded dyadic range to keep a strict clock and loses a factor of dyadicSize (length n - 1).