Documentation

CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle

Guessing advantage and key derivation in the random-oracle model #

Formalizes the guessing games of [BS23], Section 8.10.1 (Attack Game 8.3 and its first and third motivating examples, pp. 325–326, together with the independent uniform-component case matching Attack Game 11.3 in Section 11.5.2, pp. 448–449) and the list-guessing game and list-to-singleton reduction of Section 8.10.2, built on top of Cslib.Crypto.KeyDerivation.realOutput and idealOutput. Its random-oracle bounds are steps toward Theorem 8.10 (pp. 331–332), not the cited result: the reductions roToListGuess and roToGuess sample the whole oracle table uniformOfFintype (S → T) eagerly, so they are not the theorem's elementary wrappers, and the asymptotic transfer assumes guessing hardness against unbounded guessers. See CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational for the elementary lazy-simulation wrappers lazyROToListGuess and lazyROToGuess and computational Theorem 8.10 over general encoded finite secret and digest families.

Relation to CslibFrontier/Probability/Entropy/Guessing.lean #

CslibFrontier.Probability.Entropy.Guessing defines the deterministic maximum a posteriori estimator Cslib.Probability.PMF.maxPosteriorGuess for a joint distribution joint : PMF (β × α) whose observation comes first, and proves errorProb_maxPosteriorGuess_le among deterministic estimators g : β → α when β and α are finite. Here guessAdvantage sample info A measures the success probability of an arbitrary randomized adversary A : X → ProbComp S trying to guess s ← sample from info s. Taking joint := sample.map fun s => (info s, s), guessAdvantage_le_pure_maxPosteriorGuess and guessAdvantage_le_one_sub_errorProb_maxPosteriorGuess show that maxPosteriorGuess joint also achieves the maximum guessAdvantage among all randomized adversaries whenever S is finite and nonempty (with no finiteness assumption on X).

Differences from the printed book #

  1. General sample : PMF S and info : S → X. Attack Game 8.3 (p. 326) takes a probability distribution P on a finite set S and a function I on S. guessOutput, listGuessOutput, and the reductions work for arbitrary S and X where finiteness is not needed (for example, guessOutput_apply_true and listGuessAdvantage_le_mul_guessAdvantage).
  2. Eager finite random oracle uniformOfFintype (S → T). Following CslibFrontier/Crypto/Primitives/PRF/RandomOracleModel.lean, roRealOutput and roIdealOutput sample the entire oracle table : S → T eagerly for finite nonempty S and T, and RODistinguisher X S T := X → T → ProbOracleComp (fun _ : S => T) Bool uses ProbOracleComp with D.IsOracleQueryBounded Q counting oracle queries on every execution path. The proof of roAdvantage_le_listGuessAdvantage rewrites roRealOutput with PMF.bind_uniformOfFintype_update and applies ProbOracleComp.IdenticalUntilBad instead of the book's lazy associative array.
  3. Random-index tie-breaking with List.getD. listGuessToGuess Q B hardcodes a uniform index draw below Q (Fin.val <$> ProbComp.unifFin (Q - 1)) and defaults to Classical.arbitrary S past the end of B's list, holding for every Q : ℕ including Q = 0 (unlike ListCDH.listCDHToCDH, which takes the index sampler as an argument so listCDHToCDHAdversary can carry an efficiency certificate; the certified wrapper in CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational uses ProbComp.sampleModIndex).
  4. Information-theoretic asymptotic bound over query budgets; computational companion. The book's Theorem 8.10 states that B and B' are elementary wrappers around D. Here roToListGuess and roToGuess sample the whole oracle table S → T eagerly in ProbComp, which is not polynomial time when S is exponential, so they are not the elementary wrappers of Theorem 8.10. Accordingly, negligible_roAdvantage_of_statisticalGuessHard takes PolynomiallyBounded Q, (D n).IsOracleQueryBounded (Q n), and a guessing assumption ∀ A, Negligible … ranging over all guessers with no efficiency bound, covering information-theoretically unpredictable sources but not computationally unpredictable ones such as the fourth example of §8.10.1 (pp. 325–326). Attack Game 11.3 in §11.5.2 (pp. 448–449) is such a source only when (Fintype.card Y)⁻¹ is negligible: the hidden uniform component in Y is guessed with probability (Fintype.card Y)⁻¹ (guessAdvantage_bind_uniformOfFintype_fst_le), which is 1 when Y is a singleton. The certified elementary lazy-simulation wrappers lazyROToListGuess and lazyROToGuess over general encoded finite secret and digest families against computational unpredictability (§8.10.1, fourth example, p. 326) are in CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational.

Main definitions #

Main results #

References #

1. Attack Game 8.3: Guessing advantage and the examples of §8.10.1 #

@[reducible, inline]

A guessing adversary in Attack Game 8.3 ([BS23], §8.10.1, p. 326): given the leaked side information info s : X, it outputs a candidate secret in S.

noncomputable def Cslib.Crypto.KeyDerivation.guessOutput {S X : Type} [DecidableEq S] (sample : PMF S) (info : S → X) (A : GuessAdversary X S) :

Attack Game 8.3 ([BS23], §8.10.1, p. 326): the challenger draws s ← sample, sends info s to A, and A wins when its output equals s.

noncomputable def Cslib.Crypto.KeyDerivation.guessAdvantage {S X : Type} [DecidableEq S] (sample : PMF S) (info : S → X) (A : GuessAdversary X S) :

Guessadv[A, sample, info] ([BS23], Attack Game 8.3, p. 326): the probability that A guesses s given info s.

theorem Cslib.Crypto.KeyDerivation.guessOutput_apply_true {S X : Type} [DecidableEq S] (sample : PMF S) (info : S → X) (A : GuessAdversary X S) :
(guessOutput sample info A) true = ∑' (s : S), sample s * (A (info s)).eval s

The winning probability in guessOutput is ∑' s, sample s * (ProbComp.eval (A (info s))) s.

theorem Cslib.Crypto.KeyDerivation.guessOutput_pure_apply_true {S X : Type} [DecidableEq S] (sample : PMF S) (info : S → X) (g : X → S) :
(guessOutput sample info fun (x : X) => pure (g x)) true = (PMF.map (fun (s : S) => (info s, s)) sample).toOuterMeasure {z : X × S | g z.1 = z.2}

For any deterministic guessing function g : X → S, its success probability in guessOutput equals the probability of {z | g z.1 = z.2} under the joint law of (info s, s).

theorem Cslib.Crypto.KeyDerivation.guessAdvantage_le_pure_maxPosteriorGuess {S X : Type} [Fintype S] [DecidableEq S] [Nonempty S] (sample : PMF S) (info : S → X) (A : GuessAdversary X S) :
guessAdvantage sample info A ≤ guessAdvantage sample info fun (x : X) => pure (Probability.PMF.maxPosteriorGuess (PMF.map (fun (s : S) => (info s, s)) sample) x)

The maximum a posteriori estimator Cslib.Probability.PMF.maxPosteriorGuess of the joint distribution of (info s, s) maximizes guessAdvantage among all randomized guessing adversaries.

theorem Cslib.Crypto.KeyDerivation.guessAdvantage_le_one_sub_errorProb_maxPosteriorGuess {S X : Type} [Fintype S] [DecidableEq S] [Nonempty S] (sample : PMF S) (info : S → X) (A : GuessAdversary X S) :
↑(guessAdvantage sample info A) ≤ 1 - ((PMF.map (fun (s : S) => (info s, s)) sample).toOuterMeasure {z : X × S | Probability.PMF.maxPosteriorGuess (PMF.map (fun (s : S) => (info s, s)) sample) z.1 ≠ z.2}).toReal

Every randomized guessing adversary in Attack Game 8.3 has advantage at most one minus the error probability of Cslib.Probability.PMF.maxPosteriorGuess on (info s, s).

theorem Cslib.Crypto.KeyDerivation.guessAdvantage_le_card_mul_of_mass_le {S X : Type} [DecidableEq S] [Fintype X] (sample : PMF S) (info : S → X) {mass : NNReal} (hmass : ∀ (s : S), sample s ≤ ↑mass) (A : GuessAdversary X S) :
guessAdvantage sample info A ≤ ↑(Fintype.card X) * mass

If every secret has probability at most mass and info takes values in a finite type X, every guessing adversary has advantage at most |X| * mass.

§8.10.1, first example ([BS23], pp. 325–326): when the secret is uniformly distributed over a nonempty finite dictionary S and info is constant (no side information), every adversary has guessing advantage (Fintype.card S)⁻¹.

When the secret is a pair (x, y) whose second component is drawn uniformly from Y independently of the leaked first component x ([BS23], Attack Game 11.3 in §11.5.2, pp. 448–449), every adversary has guessing advantage at most (Fintype.card Y)⁻¹.

§8.10.1, third example ([BS23], pp. 325–326): when the secret is a uniformly distributed BitString (k + m) and info leaks the first k bits (Fin.take k (Nat.le_add_right k m)), every adversary has guessing advantage at most 1 / 2 ^ m (for k = 64, m = 64, at most 1 / 2 ^ 64).

2. List guessing game and list-to-singleton reduction (§8.10.2, p. 331) #

@[reducible, inline]

A list-guessing adversary ([BS23], §8.10.2, p. 331): given info s : X, it outputs a list of candidate secrets in S.

noncomputable def Cslib.Crypto.KeyDerivation.listGuessOutput {S X : Type} [DecidableEq S] (sample : PMF S) (info : S → X) (B : ListGuessAdversary X S) :

The list-guessing game ([BS23], §8.10.2, p. 331): the challenger draws s ← sample, sends info s to B, and B wins when s is a member of its output list.

noncomputable def Cslib.Crypto.KeyDerivation.listGuessAdvantage {S X : Type} [DecidableEq S] (sample : PMF S) (info : S → X) (B : ListGuessAdversary X S) :

ListGuessadv[B, sample, info] ([BS23], §8.10.2, p. 331): the probability that the secret s lies in the list output by B (info s).

noncomputable def Cslib.Crypto.KeyDerivation.listGuessToGuess {S X : Type} [Nonempty S] (Q : ℕ) (B : ListGuessAdversary X S) (x : X) :

Convert a list-guessing adversary into a singleton-guessing adversary ([BS23], §8.10.2, p. 331): run B x to obtain a list of candidates, draw an index uniformly below Q (Fin.val <$> ProbComp.unifFin (Q - 1)), and output the entry at that position (or an arbitrary element of S when the index falls past the end of the list).

theorem Cslib.Crypto.KeyDerivation.listGuessAdvantage_le_mul_guessAdvantage {S X : Type} [DecidableEq S] [Nonempty S] (sample : PMF S) (info : S → X) {Q : ℕ} {B : ListGuessAdversary X S} (hB : ∀ (x : X), ∀ l ∈ (B x).eval.support, l.length ≤ Q) :
listGuessAdvantage sample info B ≤ ↑Q * guessAdvantage sample info (listGuessToGuess Q B)

List-to-singleton guessing reduction ([BS23], §8.10.2, p. 331): if every list output by B has length at most Q, then listGuessAdvantage sample info B ≤ Q * guessAdvantage sample info (listGuessToGuess Q B).

3. Key derivation in the random-oracle model and Theorem 8.10 (§8.10.2, pp. 331–332) #

@[reducible, inline]

A key-derivation distinguisher in the random-oracle model ([BS23], §8.10.2, p. 331): given the side information x : X and a candidate key t : T, it runs an adaptive test with private coins and oracle access to S → T.

@[reducible, inline]

D makes at most Q random-oracle queries on every path for every input (x, t), whatever its private samples and the oracle replies.

noncomputable def Cslib.Crypto.KeyDerivation.roRealOutput {S X T : Type} [Fintype S] [DecidableEq S] [Fintype T] [Nonempty T] (sample : PMF S) (info : S → X) (D : RODistinguisher X S T) :

Experiment 0 of key derivation in the random-oracle model ([BS23], §8.10.2, p. 331): sample a random oracle table : S → T, then play KeyDerivation.realOutput with derive = table and D answering oracle queries from table.

noncomputable def Cslib.Crypto.KeyDerivation.roIdealOutput {S X T : Type} [Fintype S] [DecidableEq S] [Fintype T] [Nonempty T] (sample : PMF S) (info : S → X) (D : RODistinguisher X S T) :

Experiment 1 of key derivation in the random-oracle model ([BS23], §8.10.2, p. 331): sample a random oracle table : S → T, then play KeyDerivation.idealOutput with a uniform key on T and D answering oracle queries from table.

noncomputable def Cslib.Crypto.KeyDerivation.roAdvantage {S X T : Type} [Fintype S] [DecidableEq S] [Fintype T] [Nonempty T] (sample : PMF S) (info : S → X) (D : RODistinguisher X S T) :

Dist^{ro}adv[D, sample, info] ([BS23], §8.10.2, p. 331): the distinguishing advantage of D between (info s, O(s)) and (info s, t) when O : S → T is a random oracle.

noncomputable def Cslib.Crypto.KeyDerivation.roToListGuess {S X T : Type} [Fintype S] [DecidableEq S] [Fintype T] [Nonempty T] (D : RODistinguisher X S T) (x : X) :

Eager-table (uniformOfFintype (S → T)) list-guessing wrapper B for Theorem 8.10 ([BS23], §8.10.2, pp. 331–332): given x = info s, sample a random oracle table : S → T and an independent key t : T, run D x t against table, and output the list of points at which D x t queried table. Because it samples the whole oracle table S → T eagerly in ProbComp, this is not the elementary wrapper of Theorem 8.10; lazyROToListGuess (and lazyROToGuess) in CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational are the elementary lazy-simulation wrappers over general encoded finite domains.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.KeyDerivation.roToGuess {S X T : Type} [Fintype S] [DecidableEq S] [Nonempty S] [Fintype T] [Nonempty T] (Q : ℕ) (D : RODistinguisher X S T) :

Eager-table (uniformOfFintype (S → T)) singleton-guessing wrapper B' for Theorem 8.10 ([BS23], §8.10.2, p. 331): run roToListGuess D x and select one of its first Q queried points uniformly at random. Because roToListGuess D samples the whole oracle table S → T eagerly in ProbComp, this is not the elementary wrapper of Theorem 8.10; lazyROToGuess (built on lazyROToListGuess) in CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational is the elementary lazy-simulation wrapper over general encoded finite domains.

Eager-table step toward the output-size bound of [BS23], Theorem 8.10 (§8.10.2, p. 331), not the cited result: if D makes at most Q random-oracle queries on every path, then the eager-table list guesser roToListGuess D outputs a list of length at most Q on every supported run. For the elementary lazy-simulation wrapper lazyROToListGuess, see length_le_of_mem_support_lazyROToListGuess in CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational.

theorem Cslib.Crypto.KeyDerivation.roAdvantage_le_listGuessAdvantage {S X T : Type} [Fintype S] [DecidableEq S] [Fintype T] [Nonempty T] (sample : PMF S) (info : S → X) (D : RODistinguisher X S T) :
roAdvantage sample info D ≤ listGuessAdvantage sample info (roToListGuess D)

Eager-table step toward the list-guessing inequality of [BS23], Theorem 8.10 (§8.10.2, pp. 331–332), not the cited result: in the random-oracle model, a KDF distinguisher's advantage is at most the list-guessing advantage of roToListGuess D. The theorem asks for a list guesser that is an elementary wrapper around D; roToListGuess D samples the whole oracle table uniformOfFintype (S → T) eagerly in ProbComp, so it is not one. The elementary lazy-simulation wrapper lazyROToListGuess in CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational satisfies this inequality (roAdvantage_toRODistinguisher_le_listGuessAdvantage for exact uniform digest samplers and roAdvantage_toRODistinguisher_le_listGuessAdvantage_add for approximate ones).

theorem Cslib.Crypto.KeyDerivation.roAdvantage_le_mul_guessAdvantage {S X T : Type} [Fintype S] [DecidableEq S] [Nonempty S] [Fintype T] [Nonempty T] (sample : PMF S) (info : S → X) {D : RODistinguisher X S T} {Q : ℕ} (hQ : D.IsOracleQueryBounded Q) :
roAdvantage sample info D ≤ ↑Q * guessAdvantage sample info (roToGuess Q D)

Eager-table step toward the singleton-guessing inequality of [BS23], Theorem 8.10 (§8.10.2, p. 331), not the cited result: if D makes at most Q random-oracle queries on every path, its KDF distinguishing advantage in the random-oracle model is at most Q * guessAdvantage sample info (roToGuess Q D). The theorem asks for a guesser that is an elementary wrapper around D; roToGuess Q D samples the whole oracle table uniformOfFintype (S → T) eagerly in ProbComp, so it is not one. roAdvantage_toRODistinguisher_le_mul_guessAdvantage_add in CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational is the concrete variant with the elementary lazy-simulation wrapper lazyROToGuess: its fair-coin index and digest sampling add Q / 2 ^ width + (Q + 1) * εT to the bound, which the asymptotic corollary SecretGuessHard.negligible_roAdvantage absorbs.

theorem Cslib.Crypto.KeyDerivation.negligible_roAdvantage_of_statisticalGuessHard {S X T : ℕ → Type} [(n : ℕ) → Fintype (S n)] [(n : ℕ) → DecidableEq (S n)] [∀ (n : ℕ), Nonempty (S n)] [(n : ℕ) → Fintype (T n)] [∀ (n : ℕ), Nonempty (T n)] (sample : (n : ℕ) → PMF (S n)) (info : (n : ℕ) → S n → X n) {D : (n : ℕ) → RODistinguisher (X n) (S n) (T n)} {Q : ℕ → ℕ} (hQ : PolynomiallyBounded Q) (hD : ∀ (n : ℕ), (D n).IsOracleQueryBounded (Q n)) (hguess : ∀ (A : (n : ℕ) → GuessAdversary (X n) (S n)), Negligible fun (n : ℕ) => guessAdvantage (sample n) (info n) (A n)) :
Negligible fun (n : ℕ) => roAdvantage (sample n) (info n) (D n)

Statistical-guessing step toward the asymptotic reading of [BS23], Theorem 8.10 (§8.10.2, p. 331), not the cited result: if a family of random-oracle KDF distinguishers makes polynomially many random-oracle queries and every family of guessing adversaries, with no efficiency bound, has negligible guessing advantage against the source, then the KDF distinguishing advantage is negligible. Theorem 8.10 needs guessing hardness only against its elementary wrappers, which also covers computationally unpredictable sources (§8.10.1, fourth example, pp. 325–326); this premise holds only for information-theoretically unpredictable ones, such as Attack Game 11.3 in §11.5.2 (pp. 448–449) when its hidden uniform component ranges over a set Y with (Fintype.card Y)⁻¹ negligible, since that component is guessed with probability (Fintype.card Y)⁻¹ (guessAdvantage_bind_uniformOfFintype_fst_le), which is 1 when Y is a singleton. SecretGuessHard.negligible_roAdvantage in CslibFrontier.Crypto.Computational.KeyDerivation.RandomOracle.Computational is the computational form over general encoded finite secret and digest families.