Documentation

CslibFrontier.Crypto.Game

Security of Boolean experiments #

A Game is the distribution of the Boolean output of a security experiment, independent of the language used to write the experiment. A game has a success probability, and two games have a distinguishing advantage: the absolute difference of their success probabilities, as in [BS23], Section 3.1. The convention where the advantage of a single game is its success probability is comparison with certain failure, and the convention measuring bias away from a fair coin is guessingAdvantage.

Families of games indexed by a natural-number security parameter are indistinguishable for a class of adversaries when every admissible adversary has negligible advantage. Adversaries are whole objects, which may themselves be families of tests, and the game at each parameter is obtained from the adversary. Finite cryptographic primitives instantiate these definitions directly, and computational definitions over infinite sample spaces can reuse them.

Main definitions #

Main results #

References #

Copied from cslib PR #1069 at 1d14c55a10cfe3fe4463cffa61a7f02f0d56f502.

@[reducible, inline]

The distribution of the Boolean output of a security experiment.

@[reducible, inline]

The probability that an experiment succeeds, that is, outputs true.

@[reducible, inline]

The probability that an experiment fails, that is, outputs false.

Success probability is at most one.

An experiment either succeeds or fails.

Failure probability is the complement of success probability.

@[simp]

Complementing a game's answer exchanges success and failure.

@[reducible, inline]
abbrev Cslib.Crypto.Game.advantage (game1 game2 : Game) :

The distinguishing advantage between two games is the absolute difference of their success probabilities.

theorem Cslib.Crypto.Game.coe_advantage (game1 game2 : Game) :
↑(game1.advantage game2) = |↑game1.succProbability - ↑game2.succProbability|

As a real number, the advantage is the absolute difference of the success probabilities.

theorem Cslib.Crypto.Game.advantage_le_one (game1 game2 : Game) :
game1.advantage game2 ≤ 1

Distinguishing advantage is at most one.

theorem Cslib.Crypto.Game.advantage_self (game : Game) :
game.advantage game = 0

Equal games have zero advantage.

theorem Cslib.Crypto.Game.advantage_comm (game1 game2 : Game) :
game1.advantage game2 = game2.advantage game1

Swapping the games preserves advantage.

@[simp]
theorem Cslib.Crypto.Game.advantage_not (game1 game2 : Game) :
advantage (PMF.map not game1) (PMF.map not game2) = game1.advantage game2

Complementing both answers preserves advantage.

theorem Cslib.Crypto.Game.advantage_triangle (first middle last : Game) :
first.advantage last ≤ first.advantage middle + middle.advantage last

The elementary game-hopping inequality.

@[simp]

Comparing with certain failure measures the probability of success.

@[reducible, inline]
noncomputable abbrev Cslib.Crypto.Game.guessingAdvantage (game : Game) :

The advantage of a game over a fair coin, measuring its prediction bias.

As a real number, the guessing advantage is the distance of the success probability from one half.

def Cslib.Crypto.Game.Indistinguishable {Adversary : Type u_1} (game1 game2 : Adversary → ℕ → Game) (Admissible : Adversary → Prop) :

Two families of games are indistinguishable for a class of adversaries when each admissible adversary has negligible advantage. The admissibility predicate applies to the whole adversary before the security parameter is supplied, so it can constrain the adversary across all parameters at once.

def Cslib.Crypto.Game.IndistinguishableWithError {Adversary : Type u_1} (game1 game2 : Adversary → ℕ → Game) (Admissible : Adversary → Prop) (ε : ℕ → NNReal) :

A common concrete bound on the advantage of all admissible adversaries at each parameter.

theorem Cslib.Crypto.Game.IndistinguishableWithError.of_admissible {Adversary : Type u_1} {game1 game2 : Adversary → ℕ → Game} {Admissible Restricted : Adversary → Prop} {ε : ℕ → NNReal} (h : IndistinguishableWithError game1 game2 Admissible ε) (hsub : ∀ (adversary : Adversary), Restricted adversary → Admissible adversary) :
IndistinguishableWithError game1 game2 Restricted ε

Restricting admissibility preserves a concrete bound.

theorem Cslib.Crypto.Game.Indistinguishable.of_admissible {Adversary : Type u_1} {game1 game2 : Adversary → ℕ → Game} {Admissible Restricted : Adversary → Prop} (h : Indistinguishable game1 game2 Admissible) (hsub : ∀ (adversary : Adversary), Restricted adversary → Admissible adversary) :
Indistinguishable game1 game2 Restricted

Restricting admissibility preserves indistinguishability.

theorem Cslib.Crypto.Game.IndistinguishableWithError.mono {Adversary : Type u_1} {game1 game2 : Adversary → ℕ → Game} {Admissible : Adversary → Prop} {ε δ : ℕ → NNReal} (h : IndistinguishableWithError game1 game2 Admissible ε) (hle : ∀ (n : ℕ), ε n ≤ δ n) :
IndistinguishableWithError game1 game2 Admissible δ

Enlarging an error budget preserves its guarantee.

theorem Cslib.Crypto.Game.Indistinguishable.refl {Adversary : Type u_1} (game : Adversary → ℕ → Game) (Admissible : Adversary → Prop) :
Indistinguishable game game Admissible

A family of games is indistinguishable from itself.

theorem Cslib.Crypto.Game.IndistinguishableWithError.symm {Adversary : Type u_1} {game1 game2 : Adversary → ℕ → Game} {Admissible : Adversary → Prop} {ε : ℕ → NNReal} (h : IndistinguishableWithError game1 game2 Admissible ε) :
IndistinguishableWithError game2 game1 Admissible ε

Swapping the games preserves a concrete bound.

theorem Cslib.Crypto.Game.Indistinguishable.symm {Adversary : Type u_1} {game1 game2 : Adversary → ℕ → Game} {Admissible : Adversary → Prop} (h : Indistinguishable game1 game2 Admissible) :
Indistinguishable game2 game1 Admissible

Swapping the games preserves indistinguishability.

theorem Cslib.Crypto.Game.IndistinguishableWithError.trans {Adversary : Type u_1} {first middle last : Adversary → ℕ → Game} {Admissible : Adversary → Prop} {ε δ : ℕ → NNReal} (hfirst : IndistinguishableWithError first middle Admissible ε) (hlast : IndistinguishableWithError middle last Admissible δ) :
IndistinguishableWithError first last Admissible fun (n : ℕ) => ε n + δ n

Concrete bounds add across a game hop.

theorem Cslib.Crypto.Game.Indistinguishable.trans {Adversary : Type u_1} {first middle last : Adversary → ℕ → Game} {Admissible : Adversary → Prop} (hfirst : Indistinguishable first middle Admissible) (hlast : Indistinguishable middle last Admissible) :
Indistinguishable first last Admissible

Indistinguishability composes through an intermediate family of games.

theorem Cslib.Crypto.Game.IndistinguishableWithError.indistinguishable {Adversary : Type u_1} {game1 game2 : Adversary → ℕ → Game} {Admissible : Adversary → Prop} {ε : ℕ → NNReal} (h : IndistinguishableWithError game1 game2 Admissible ε) (hε : Negligible ε) :
Indistinguishable game1 game2 Admissible

A negligible common error bound implies indistinguishability.

theorem Cslib.Crypto.Game.Indistinguishable.of_reduction {SourceAdversary : Type u_1} {TargetAdversary : Type u_2} {source1 source2 : SourceAdversary → ℕ → Game} {target1 target2 : TargetAdversary → ℕ → Game} {SourceAdmissible : SourceAdversary → Prop} {TargetAdmissible : TargetAdversary → Prop} (h : Indistinguishable source1 source2 SourceAdmissible) (reduce : TargetAdversary → SourceAdversary) (hadmissible : ∀ (adversary : TargetAdversary), TargetAdmissible adversary → SourceAdmissible (reduce adversary)) (hbound : ∀ (adversary : TargetAdversary), TargetAdmissible adversary → ∃ (loss : ℕ → ℕ) (error : ℕ → NNReal), PolynomiallyBounded loss ∧ Negligible error ∧ ∀ (n : ℕ), (target1 adversary n).advantage (target2 adversary n) ≤ ↑(loss n) * (source1 (reduce adversary) n).advantage (source2 (reduce adversary) n) + error n) :
Indistinguishable target1 target2 TargetAdmissible

A reduction turns each target adversary into a source adversary. It transfers indistinguishability from the source games to the target games when it preserves admissibility and bounds the target advantage by the source advantage up to a polynomial loss and a negligible error. The loss and the error may depend on the target adversary, while the reduction maps whole adversaries and does not depend on the security parameter.

@[simp]

Comparing certain failure on the left with a game measures the game's success probability.

theorem Cslib.Crypto.Game.indistinguishable_pure_false_iff {Adversary : Type u_1} (game : Adversary → ℕ → Game) (Admissible : Adversary → Prop) :
Indistinguishable game (fun (x : Adversary) (x_1 : ℕ) => PMF.pure false) Admissible ↔ ∀ (adversary : Adversary), Admissible adversary → Negligible fun (n : ℕ) => (game adversary n).succProbability

A family of games is indistinguishable from PMF.pure false if and only if every admissible adversary has negligible success probability.

theorem Cslib.Crypto.Game.pure_false_indistinguishable_iff {Adversary : Type u_1} (game : Adversary → ℕ → Game) (Admissible : Adversary → Prop) :
Indistinguishable (fun (x : Adversary) (x_1 : ℕ) => PMF.pure false) game Admissible ↔ ∀ (adversary : Adversary), Admissible adversary → Negligible fun (n : ℕ) => (game adversary n).succProbability

PMF.pure false is indistinguishable from a family of games if and only if every admissible adversary has negligible success probability.

theorem Cslib.Crypto.Game.Indistinguishable.negligible_succProbability {Adversary : Type u_1} {game : Adversary → ℕ → Game} {Admissible : Adversary → Prop} (h : Indistinguishable game (fun (x : Adversary) (x_1 : ℕ) => PMF.pure false) Admissible) (adversary : Adversary) (ha : Admissible adversary) :
Negligible fun (n : ℕ) => (game adversary n).succProbability

Indistinguishability from PMF.pure false gives negligible success probability for every admissible adversary.

theorem Cslib.Crypto.Game.Indistinguishable.of_negligible_succProbability {Adversary : Type u_1} {game : Adversary → ℕ → Game} {Admissible : Adversary → Prop} (h : ∀ (adversary : Adversary), Admissible adversary → Negligible fun (n : ℕ) => (game adversary n).succProbability) :
Indistinguishable game (fun (x : Adversary) (x_1 : ℕ) => PMF.pure false) Admissible

Establish indistinguishability from PMF.pure false by showing that every admissible adversary has negligible success probability.

theorem Cslib.Crypto.Game.Indistinguishable.of_eventually_succProbability_le {Adversary : Type u_1} {game1 game2 : Adversary → ℕ → Game} {Admissible : Adversary → Prop} (h : Indistinguishable game2 (fun (x : Adversary) (x_1 : ℕ) => PMF.pure false) Admissible) (hle : ∀ (adversary : Adversary), Admissible adversary → ∀ᶠ (n : ℕ) in Filter.atTop, (game1 adversary n).succProbability ≤ (game2 adversary n).succProbability) :
Indistinguishable game1 (fun (x : Adversary) (x_1 : ℕ) => PMF.pure false) Admissible

If game2 is indistinguishable from PMF.pure false and every admissible adversary eventually has success probability in game1 at most its success probability in game2, then game1 is also indistinguishable from PMF.pure false.

theorem Cslib.Crypto.Game.Indistinguishable.of_succProbability_le {Adversary : Type u_1} {game1 game2 : Adversary → ℕ → Game} {Admissible : Adversary → Prop} (h : Indistinguishable game2 (fun (x : Adversary) (x_1 : ℕ) => PMF.pure false) Admissible) (hle : ∀ (adversary : Adversary), Admissible adversary → ∀ (n : ℕ), (game1 adversary n).succProbability ≤ (game2 adversary n).succProbability) :
Indistinguishable game1 (fun (x : Adversary) (x_1 : ℕ) => PMF.pure false) Admissible

If game2 is indistinguishable from PMF.pure false and every admissible adversary has success probability in game1 at most its success probability in game2 at every parameter, then game1 is also indistinguishable from PMF.pure false.

theorem Cslib.Crypto.Game.Indistinguishable.of_eventually_succProbability_reduction {SourceAdversary : Type u_1} {TargetAdversary : Type u_2} {source : SourceAdversary → ℕ → Game} {target : TargetAdversary → ℕ → Game} {SourceAdmissible : SourceAdversary → Prop} {TargetAdmissible : TargetAdversary → Prop} (h : Indistinguishable source (fun (x : SourceAdversary) (x_1 : ℕ) => PMF.pure false) SourceAdmissible) (reduce : TargetAdversary → SourceAdversary) (hadmissible : ∀ (adversary : TargetAdversary), TargetAdmissible adversary → SourceAdmissible (reduce adversary)) (hle : ∀ (adversary : TargetAdversary), TargetAdmissible adversary → ∀ᶠ (n : ℕ) in Filter.atTop, (target adversary n).succProbability ≤ (source (reduce adversary) n).succProbability) :
Indistinguishable target (fun (x : TargetAdversary) (x_1 : ℕ) => PMF.pure false) TargetAdmissible

One-sided reduction from source to target: if source is indistinguishable from PMF.pure false and reduce maps every admissible target adversary to an admissible source adversary that eventually upper-bounds its success probability, then target is indistinguishable from PMF.pure false.

theorem Cslib.Crypto.Game.Indistinguishable.of_succProbability_reduction {SourceAdversary : Type u_1} {TargetAdversary : Type u_2} {source : SourceAdversary → ℕ → Game} {target : TargetAdversary → ℕ → Game} {SourceAdmissible : SourceAdversary → Prop} {TargetAdmissible : TargetAdversary → Prop} (h : Indistinguishable source (fun (x : SourceAdversary) (x_1 : ℕ) => PMF.pure false) SourceAdmissible) (reduce : TargetAdversary → SourceAdversary) (hadmissible : ∀ (adversary : TargetAdversary), TargetAdmissible adversary → SourceAdmissible (reduce adversary)) (hle : ∀ (adversary : TargetAdversary), TargetAdmissible adversary → ∀ (n : ℕ), (target adversary n).succProbability ≤ (source (reduce adversary) n).succProbability) :
Indistinguishable target (fun (x : TargetAdversary) (x_1 : ℕ) => PMF.pure false) TargetAdmissible

Pointwise one-sided reduction from source to target: if source is indistinguishable from PMF.pure false and reduce maps every admissible target adversary to an admissible source adversary that upper-bounds its success probability at every parameter, then target is indistinguishable from PMF.pure false.

@[simp]

As a real number, the success probability is the real-valued probability of true.

@[simp]

As a real number, the failure probability is the real-valued probability of false.

Comparing a game with certain success measures the game's failure probability.

Comparing certain success on the left with a game measures the game's failure probability.

As a real number, the advantage of certain success over game is one minus the probability that game outputs true.

theorem Cslib.Crypto.Game.advantage_le_of_apply_le {game1 game2 : Game} {B : ENNReal} (hB : B ≠ ⊤) (h1 : game1 true ≤ game2 true + B) (h2 : game2 true ≤ game1 true + B) :
↑(game1.advantage game2) ≤ B.toReal

Mutual upper bounds on the two acceptance probabilities bound the real-valued advantage.

theorem Cslib.Crypto.Game.advantage_bind_le {α : Type u_1} (d : PMF α) (game1 game2 : α → Game) {ε : ℝ} (h : ∀ (a : α), ↑((game1 a).advantage (game2 a)) ≤ ε) :
↑(advantage (d.bind game1) (d.bind game2)) ≤ ε

Averaging two families of games over a common first stage preserves any uniform real-valued advantage bound.

theorem Cslib.Crypto.Game.advantage_bind_uniformOfFintype_of_ne_le {α : Type u_1} [Fintype α] [Nonempty α] (a₀ : α) (g : α → Game) (p : Game) (hne : ∀ (a : α), a ≠ a₀ → g a = p) :

If a family of games g : α → Game agrees with p : Game on every a ≠ a₀, then averaging g over PMF.uniformOfFintype α is within (Fintype.card α)⁻¹ of p.

theorem Cslib.Crypto.Game.advantage_bind_le_nnreal {α : Type u_1} (d : PMF α) (game1 game2 : α → Game) {ε : NNReal} (h : ∀ (a : α), (game1 a).advantage (game2 a) ≤ ε) :
advantage (d.bind game1) (d.bind game2) ≤ ε

ℝ≥0 version of Game.advantage_bind_le.

theorem Cslib.Crypto.Game.bind_apply_le_add_bind_apply {β : Type u_1} (μ : PMF β) (game1 game2 err : β → Game) (b : Bool) (h : ∀ (x : β), (game1 x) b ≤ (game2 x) b + (err x) b ∧ (game2 x) b ≤ (game1 x) b + (err x) b) :
(μ.bind game1) b ≤ (μ.bind game2) b + (μ.bind err) b ∧ (μ.bind game2) b ≤ (μ.bind game1) b + (μ.bind err) b

Averaging pointwise acceptance-probability bounds game1 x b ≤ game2 x b + err x b and game2 x b ≤ game1 x b + err x b over μ : PMF β preserves the bounds for μ.bind.

theorem Cslib.Crypto.Game.advantage_bind_le_succProbability_bind {β : Type u_1} (μ : PMF β) (game1 game2 err : β → Game) (h : ∀ (x : β), (game1 x) true ≤ (game2 x) true + (err x) true ∧ (game2 x) true ≤ (game1 x) true + (err x) true) :
advantage (μ.bind game1) (μ.bind game2) ≤ succProbability (μ.bind err)

Averaging pointwise acceptance-probability bounds game1 x true ≤ game2 x true + err x true and game2 x true ≤ game1 x true + err x true over μ : PMF β bounds the Game.advantage of the mixtures by Game.succProbability (μ.bind err).

theorem Cslib.Crypto.Game.advantage_bind_le_of_support {α : Type u_1} (μ : PMF α) (game1 game2 : α → Game) {ε : NNReal} (h : ∀ a ∈ μ.support, (game1 a).advantage (game2 a) ≤ ε) :
advantage (μ.bind game1) (μ.bind game2) ≤ ε

Support-restricted version of Game.advantage_bind_le_nnreal: a uniform advantage bound on μ.support extends to μ.bind.

theorem Cslib.Crypto.Game.advantage_bind_comm {α : Type u_1} {β : Type u_2} (p : PMF α) (q : PMF β) (f g : α → β → Game) :
advantage (p.bind fun (a : α) => q.bind fun (b : β) => f a b) (p.bind fun (a : α) => q.bind fun (b : β) => g a b) = advantage (q.bind fun (b : β) => p.bind fun (a : α) => f a b) (q.bind fun (b : β) => p.bind fun (a : α) => g a b)

Swapping two independent first-stage distributions via PMF.bind_comm preserves Game.advantage.

theorem Cslib.Crypto.Game.succProbability_uniform_bool_xor (g : Bool → Game) :
↑(succProbability ((Probability.PMF.uniformOfFintype Bool).bind fun (bit : Bool) => PMF.map (fun (guess : Bool) => guess ^^ bit) (g bit))) = (1 + ↑(g false).succProbability - ↑(g true).succProbability) / 2

For any Boolean-indexed family of games g : Bool → Game, sampling a uniform hidden bit bit ← PMF.uniformOfFintype Bool and outputting guess ^^ bit for guess ← g bit succeeds with probability (1 + succProbability (g false) - succProbability (g true)) / 2.

theorem Cslib.Crypto.Game.advantage_le_two_mul_uniform_bool_xor (g₀ g₁ : Bool → Game) :
(g₀ false).advantage (g₀ true) ≤ 2 * advantage ((Probability.PMF.uniformOfFintype Bool).bind fun (bit : Bool) => PMF.map (fun (guess : Bool) => guess ^^ bit) (g₀ bit)) ((Probability.PMF.uniformOfFintype Bool).bind fun (bit : Bool) => PMF.map (fun (guess : Bool) => guess ^^ bit) (g₁ bit)) + (g₁ false).advantage (g₁ true)

For any two Boolean-indexed game families g₀, g₁ : Bool → Game, the advantage advantage (g₀ false) (g₀ true) is bounded by twice the distinguishing advantage between their uniform hidden-bit XOR mixtures plus advantage (g₁ false) (g₁ true).