Documentation

CslibFrontier.Crypto.Computational.SecondPreimageResistant

Asymptotic second-preimage resistance on bit strings #

A function f is second-preimage resistant ([BS23], Section 8.11.1, Definition 8.6, p. 336) when, given a uniformly sampled input x and the unary security parameter n, every efficient adversary has negligible probability of finding x' ≠ x with f x' = f x.

In Boneh–Shoup Definition 8.6 (m' ∈ M), the adversary's answer is restricted to the message space. secondPreimageGameOn f valid and SecondPreimageResistantOn f valid model that restriction via a parameter-indexed validity predicate valid : ℕ → List Bool → Bool (so valid := fun n w => decide (w.length = n) gives Definition 8.6 on M = {0,1}ⁿ), while secondPreimageGame and SecondPreimageResistant (valid := fun _ _ => true) accept an answer x' of any length, matching the any-length preimage convention of Cslib.Crypto.OneWay.

This module defines the valid-domain game secondPreimageGameOn and its any-length specialization secondPreimageGame, SecondPreimageResistantOn, and the any-length abbrev SecondPreimageResistant (valid := fun _ _ => true), along with .of_injective and not_secondPreimageResistantOn_const. The monad-generic finite experiment and distributional bounds of Exercise 8.23(a)–(b) live in CslibFrontier.Crypto.Game.SecondPreimage; the certified bit-string reductions of (8.17), Exercise 8.23(b)–(d), and Theorem 8.12 live in follow-on modules.

Main definitions #

Main results #

References #

@[reducible, inline]

A second-preimage finder receives the unary parameter and the sampled input word.

noncomputable def Cslib.Crypto.secondPreimageGameOn (f : List Bool → List Bool) (valid : ℕ → List Bool → Bool) (adversary : SecondPreimageFinder) (n : ℕ) :

The valid-domain second-preimage game at length n ([BS23], Section 8.11.1, Definition 8.6, p. 336): draw x ← BitString.sampleList n, run x' ← adversary n x, and accept when valid n x', x' ≠ x, and f x' = f x. When valid n w = decide (w.length = n), this is Definition 8.6 on M = {0,1}ⁿ.

noncomputable def Cslib.Crypto.secondPreimageGame (f : List Bool → List Bool) (adversary : SecondPreimageFinder) (n : ℕ) :

The second-preimage game at length n: secondPreimageExperiment for f on a uniform n-bit input, with the finder told n. This specializes secondPreimageGameOn to valid := fun _ _ => true, accepting any x' ≠ x with f x' = f x regardless of length.

theorem Cslib.Crypto.secondPreimageGame_eq_secondPreimageGameOn (f : List Bool → List Bool) (adversary : SecondPreimageFinder) (n : ℕ) :
secondPreimageGame f adversary n = secondPreimageGameOn f (fun (x : ℕ) (x_1 : List Bool) => true) adversary n

The second-preimage experiment is uniformly PPT, independently of the unused auxiliary input.

One plain polynomial-time algorithm evaluates the function, and every uniform strict PPT second-preimage finder has negligible success in secondPreimageGameOn f valid over the uniform n-bit input and its own independent random coins ([BS23], Section 8.11.1, Definition 8.6, p. 336). When valid n w = decide (w.length = n), this states Definition 8.6 on M = {0,1}ⁿ.

Second-preimage resistance on valid yields negligible winning probability in secondPreimageGameOn for every uniform strict PPT finder.

Establish SecondPreimageResistantOn by proving negligible winning probability for every uniform strict PPT finder.

theorem Cslib.Crypto.succProbability_secondPreimageGameOn_le_of_imp {f₁ f₂ : List Bool → List Bool} {valid₁ valid₂ : ℕ → List Bool → Bool} {n : ℕ} (h : ∀ (x x' : List Bool), x.length = n → valid₁ n x' = true → x' ≠ x → f₁ x' = f₁ x → valid₂ n x' = true ∧ f₂ x' = f₂ x) (adversary : SecondPreimageFinder) :
Game.succProbability (secondPreimageGameOn f₁ valid₁ adversary n).eval ≤ Game.succProbability (secondPreimageGameOn f₂ valid₂ adversary n).eval

Compare two secondPreimageGameOn runs when every winning (x, x') pair in the first (x.length = n, valid₁ n x', x' ≠ x, f₁ x' = f₁ x) satisfies valid₂ n x' and f₂ x' = f₂ x.

theorem Cslib.Crypto.SecondPreimageResistantOn.mono {f : List Bool → List Bool} {valid₁ valid₂ : ℕ → List Bool → Bool} (h : SecondPreimageResistantOn f valid₁) (hle : ∀ (n : ℕ) (w : List Bool), valid₂ n w = true → valid₁ n w = true) :

Shrinking the valid answer predicate preserves second-preimage resistance.

A polynomial-time function that has no valid second preimages colliding with n-bit inputs is unconditionally second-preimage resistant on valid.

Winning secondPreimageGameOn eventually with probability bounded away from zero refutes SecondPreimageResistantOn.

theorem Cslib.Crypto.succProbability_secondPreimageGameOn_pure_eq_one {f g : List Bool → List Bool} {valid : ℕ → List Bool → Bool} {n : ℕ} (h : ∀ (x : List Bool), x.length = n → valid n (g x) = true ∧ g x ≠ x ∧ f (g x) = f x) :
Game.succProbability (secondPreimageGameOn f valid (fun (x : ℕ) (x_1 : List Bool) => pure (g x_1)) n).eval = 1

A deterministic function g producing valid distinct colliding answers on every n-bit input wins secondPreimageGameOn f valid at length n with probability 1.

theorem Cslib.Crypto.not_secondPreimageResistantOn_const {valid : ℕ → List Bool → Bool} (c : List Bool) (hvalid : ∀ᶠ (n : ℕ) in Filter.atTop, ∀ (x : List Bool), x.length = n → valid n ((!x.headD false) :: x.tail) = true) :
¬SecondPreimageResistantOn (fun (x : List Bool) => c) valid

Any constant function is not second-preimage resistant on any validity predicate that admits the head-flipped word on n-bit inputs for sufficiently large n (in particular, valid n w := decide (w.length = n) or fun _ _ => true).

@[reducible, inline]

Any-length second-preimage resistance on bit strings (novel to this library: strengthens SecondPreimageResistantOn f (fun n w => decide (w.length = n)), which is [BS23], Section 8.11.1, Definition 8.6, p. 336, by accepting answers x' of any length, matching Cslib.Crypto.OneWay; plausible because CollisionResistantToOneWay.keyDigest H satisfies it for every collision-resistant HashFamily H).