Documentation

CslibFrontier.Crypto.Game.SecondPreimage

Second-preimage experiments and finite bounds #

The second-preimage experiment for a function and an input distribution, with the finite-domain counting and inversion bounds of [BS23], Exercise 8.23(a)–(b), pp. 352–353. Below, OWadv[A, H] and SPRadv[B, H] are the success probabilities of inversionExperiment and secondPreimageExperiment, and B := fun m => A (H m) is the finder that runs the inverter A on the digest.

The asymptotic bit-string notion SecondPreimageResistant lives in CslibFrontier.Crypto.Computational.SecondPreimageResistant.

Main definitions #

Main results #

References #

def Cslib.Crypto.secondPreimageExperiment {m : Type → Type u_1} [Monad m] {α : Type} {β : Type u_2} [BEq α] [BEq β] (sample : m α) (f : α → β) (finder : α → m α) :

The second-preimage experiment for f on inputs drawn from sample: the challenger draws x and gives finder the input x; finder wins when it returns x' ≠ x with f x' = f x.

theorem Cslib.Crypto.secondPreimageExperiment_eq_bind_map {α : Type} {β : Type u_2} [BEq α] [BEq β] (sample : PMF α) (f : α → β) (finder : α → PMF α) :
secondPreimageExperiment sample f finder = sample.bind fun (x : α) => PMF.map (fun (x' : α) => x' != x && f x' == f x) (finder x)

On distributions, the second-preimage experiment maps the finder's output distribution through the distinctness and collision test.

theorem Cslib.Crypto.secondPreimageExperiment_eq_pure_false_of_injective {α : Type} {β : Type u_2} [BEq α] [LawfulBEq α] [BEq β] [LawfulBEq β] (sample : PMF α) {f : α → β} (hf : Function.Injective f) (finder : α → PMF α) :

An injective function has no second preimages, so every second-preimage finder fails with probability 1.

theorem Cslib.Crypto.succProbability_secondPreimageExperiment_le_of_eq_imp {α : Type} {β : Type u_3} {γ : Type u_4} [BEq α] [LawfulBEq α] [BEq β] [LawfulBEq β] [BEq γ] [LawfulBEq γ] (sample : PMF α) {f : α → β} {g : α → γ} (himp : ∀ (x x' : α), x' ≠ x → g x' = g x → f x' = f x) (finder : α → PMF α) :

If every collision under g is a collision under f, then every second-preimage finder succeeds at least as often against f as against g.

Finite-domain counting and (8.22) (Exercise 8.23(a)–(b)) #

def Cslib.Crypto.HasSecondPreimage {M : Type u_3} {T : Type u_4} (H : M → T) (m : M) :

m has a second preimage under H when some distinct m' ≠ m maps to the same digest.

Instances For
    theorem Cslib.Crypto.eq_of_apply_eq_of_not_hasSecondPreimage {M : Type u_3} {T : Type u_4} {H : M → T} {m₁ m₂ : M} (hm₁ : ¬HasSecondPreimage H m₁) (heq : H m₁ = H m₂) :
    m₁ = m₂

    An input lacking a second preimage is uniquely determined by its digest.

    theorem Cslib.Crypto.card_not_hasSecondPreimage_le {M : Type u_3} {T : Type u_4} [Fintype M] [Fintype T] (H : M → T) [DecidablePred fun (m : M) => ¬HasSecondPreimage H m] :

    Exercise 8.23(a), count form ([BS23], p. 352): at most |T| inputs in M lack a second preimage under H : M → T.

    theorem Cslib.Crypto.card_not_hasSecondPreimage_div_le {M : Type u_3} {T : Type u_4} [Fintype M] [Fintype T] (H : M → T) [DecidablePred fun (m : M) => ¬HasSecondPreimage H m] {s : ℝ} (hs : 0 < s) (hM : s * ↑(Fintype.card T) ≤ ↑(Fintype.card M)) :
    ↑{m : M | ¬HasSecondPreimage H m}.card / ↑(Fintype.card M) ≤ 1 / s

    Exercise 8.23(a), fraction form ([BS23], p. 352): if |M| ≥ s · |T| with 0 < s (the book assumes s > 1, and 0 < s suffices), then at most a 1 / s fraction of inputs in M lack a second preimage.

    theorem Cslib.Crypto.inversionExperiment_le_secondPreimageExperiment_add {α : Type} {β : Type u_3} [BEq α] [LawfulBEq α] [BEq β] [LawfulBEq β] (sample : PMF α) (f : α → β) (A : β → PMF α) :
    (inversionExperiment sample f A) true ≤ (secondPreimageExperiment sample f fun (x : α) => A (f x)) true + ∑' (x : α), sample x * (A (f x)) x

    Distributional split behind (8.22): for any input law sample, an inverter A either finds a second preimage when invoked as x ↦ A (f x) or hits the challenge x itself.

    Factor-one uniform inversion bound: the second-preimage finder B := fun m => A (H m) built from an inverter A satisfies OWadv[A, H] ≤ SPRadv[B, H] + |T| / |M|, without the factor 2 of (8.22).

    Exercise 8.23(b), equation (8.22) ([BS23], p. 353): when |M| ≥ s · |T| with 0 < s, the second-preimage finder B := fun m => A (H m) built from an inverter A satisfies OWadv[A, H] ≤ 2 · SPRadv[B, H] + 1 / s. This weakens succProbability_inversionExperiment_uniform_le_add_card_div, which shows that the factor 2 is not needed.

    @[simp]
    theorem Cslib.ProbComp.eval_secondPreimageExperiment {α β : Type} [BEq α] [BEq β] (sample : ProbComp α) (f : α → β) (finder : α → ProbComp α) :
    (Crypto.secondPreimageExperiment sample f finder).eval = Crypto.secondPreimageExperiment sample.eval f fun (x : α) => (finder x).eval

    Evaluating the second-preimage experiment of programs gives the second-preimage experiment of their distributions.