Documentation

CslibFrontier.Crypto.Primitives.UHF.Finite

Universal hash games with a finite key space #

These experiments express the collision and difference-prediction advantages of [BS23], Attack Games 7.1–7.3, as probabilities of returning true. The challenger keeps the uniform key private. An adversary is a closed probabilistic program with no key input.

Main definitions #

Main results #

The results here concern one key distribution and one hash function at a time. The computational collision games and asymptotic implication are in Crypto.Primitives.UHF.Computational.

References #

The two messages submitted to the collision game.

  • first : M

    The first message.

  • second : M

    The second message.

theorem Cslib.Crypto.UHF.encCollisionGuess_first_budget {M : Type} (encM : M ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → CollisionGuess M} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encCollisionGuess encM) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).first) encIn✝ encM S✝

Frame the first collision message and then write the encoding of the second message.

theorem Cslib.Crypto.UHF.encCollisionGuess_mk_budget {M : Type} (encM : M ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 x1 : γ → M} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encM budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn encM budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { first := x0 x, second := x1 x }) encIn (encCollisionGuess encM) budget
@[reducible, inline]

The tuple of the fields of encCollisionGuess.

theorem Cslib.Crypto.UHF.encCollisionGuess_mk_polyTime {M : Type} (encM : M ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {x0 x1 : γ → M} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn encM) (h1 : Turing.MultiTapeTM.ComputableInPolyTime x1 encIn encM) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { first := x0 x, second := x1 x }) encIn (encCollisionGuess encM)
theorem Cslib.Crypto.UHF.encCollisionGuess_second_polyTime {M : Type} (encM : M ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → CollisionGuess M} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encCollisionGuess encM) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (g✝ c).second) encIn✝ encM
theorem Cslib.Crypto.UHF.encCollisionGuess_mk_inO {M : Type} (encM : M ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → M} {T0 S0 : γ → ℕ} {x1 : γ → M} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encM T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn encM T1 S1) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { first := x0 x, second := x1 x }) encIn (encCollisionGuess encM) (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
theorem Cslib.Crypto.UHF.encCollisionGuess_mk_deg {M : Type} (encM : M ↪ List Bool) :
Turing.MultiTapeTM.ComputableInDegree (fun (p : M × M) => { first := p.1, second := p.2 }) (encCollisionGuessFields encM) (encCollisionGuess encM) 1 1
theorem Cslib.Crypto.UHF.encCollisionGuess_first_polyTime {M : Type} (encM : M ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → CollisionGuess M} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encCollisionGuess encM) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (g✝ c).first) encIn✝ encM
theorem Cslib.Crypto.UHF.encCollisionGuess_second_budget {M : Type} (encM : M ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → CollisionGuess M} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encCollisionGuess encM) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).second) encIn✝ encM S✝

The messages and the predicted difference of their hashes.

  • first : M
  • second : M
  • difference : Y

    The predicted hash of the second message minus the hash of the first.

noncomputable def Cslib.Crypto.UHF.collisionExperiment {K M Y : Type} [Fintype K] [Nonempty K] [DecidableEq M] [DecidableEq Y] (H : K → M → Y) (A : ProbComp (CollisionGuess M)) :

Attack Game 7.1 ([BS23], v0.6, §7.1, p. 253). A guess wins when its two distinct messages hash to the same value under an independently sampled uniform key. The experiment rejects equal messages, which the source forbids submitting.

noncomputable def Cslib.Crypto.UHF.differenceExperiment {K M Y : Type} [Fintype K] [Nonempty K] [DecidableEq M] [AddGroup Y] [DecidableEq Y] (H : K → M → Y) (A : ProbComp (DifferenceGuess M Y)) :

Attack Game 7.3 ([BS23], v0.6, §7.4, p. 268). A guess wins when its prediction equals the hash of the second message minus the hash of the first under a uniform key. Equal messages are rejected. The digest space may be any additive group, encompassing the source's cyclic group and the XOR example in Remark 7.3.

The pairwise collision bound (7.1) is equivalent to the game bound of Definition 7.2 ([BS23], v0.6, p. 254), for one uniform-key instance and any ε.

The pairwise difference bound is equivalent to the game bound of Definition 7.5 ([BS23], v0.6, pp. 268–269), for one uniform-key instance and any ε.

def Cslib.Crypto.UHF.bestCollisionGuess {K M Y : Type} [Fintype K] [DecidableEq M] [DecidableEq Y] (H : K → M → Y) (messages : List M) :

Exhaustively score the distinct pairs from an enumerated message space by the number of keys giving a collision. Choose the first maximizer, or return none if there is no pair.

theorem Cslib.Crypto.UHF.bestCollisionGuess_wins {K M Y : Type} [Fintype K] [Nonempty K] [DecidableEq M] [DecidableEq Y] (H : K → M → Y) (messages : List M) (complete : ∀ (m : M), m ∈ messages) {ε : ENNReal} {m m' : M} (hne : m ≠ m') (h : ε < (Probability.PMF.uniformOfFintype K).toOuterMeasure {k : K | H k m = H k m'}) :
∃ (guess : CollisionGuess M), bestCollisionGuess H messages = some guess ∧ ε < (collisionExperiment H (pure guess)).eval true

Exercise 7.3 ([BS23], v0.6, p. 277). Given a complete enumeration of a finite message space, exhaustive search produces a deterministic guess that exceeds ε whenever some distinct pair does. The search takes only the hash and the enumeration as inputs. The witness pair and the sampled challenge key are absent from its inputs.

noncomputable def Cslib.Crypto.UHF.multiQueryExperiment {K M Y : Type} [Fintype K] [Nonempty K] [DecidableEq M] [DecidableEq Y] (H : K → M → Y) (B : ProbComp (List M)) :

Attack Game 7.2 (multi-query UHF, [BS23], Version 0.6, Section 7.1.1, p. 254): the adversary B outputs a list of messages, the challenger samples a uniform hash key independently, and B wins when two distinct messages of the list have the same digest (MUHFadv[B, H] is the probability of true). The book asks B to output distinct messages; Lean accepts any List M and rewards only pairs with m ≠ m' and H k m = H k m', so duplicate messages earn nothing.

noncomputable def Cslib.Crypto.UHF.collisionPairReduction {M : Type} (fallback : M) (A : ProbComp (List M)) :

Run the multi-query adversary and sample an ordered pair of distinct positions with bounded fair-bit rejection sampling. A list of length s allows s attempts. If the attempts fail or there are fewer than two positions, return a repeated dummy message.

theorem Cslib.Crypto.UHF.isPPTOn_collisionPairReduction {M I : Type} {encI : I ↪ List Bool} {encM : M ↪ List Bool} {A : I → ProbComp (List M)} (hA : Probability.IsPPTOn encI (Turing.MultiTapeTM.encList encM) A) (fallback : M) :
Probability.IsPPTOn encI (encCollisionGuess encM) fun (x : I) => collisionPairReduction fallback (A x)

Bounded sampling and unary list access preserve strict PPT for a multi-query adversary. The certificate charges the framed input list and uses at most its length in attempts.

theorem Cslib.Crypto.UHF.eval_multiQueryExperiment_le_collisionPairReduction {K M Y : Type} [Fintype K] [Nonempty K] [DecidableEq M] [DecidableEq Y] (H : K → M → Y) (fallback : M) (A : ProbComp (List M)) {Q : ℕ} (hA : ∀ ms ∈ A.eval.support, ms.length ≤ Q) :

A finite-game step toward Lemma 7.1 ([BS23], v0.6, printed pp. 254–255). If the multi-query adversary outputs at most Q messages, its collision probability is at most Q ^ 2 / 2 times that of the explicit single-pair wrapper. Whenever the list contains a collision, both orders of a colliding pair have enough sampling mass to give the bound. The wrapper has a strict PPT certificate. Crypto.Primitives.UHF.Computational lifts this bound to public setup and proves the asymptotic implication.

theorem Cslib.Crypto.UHF.eval_multiQueryExperiment_le {K M Y : Type} [Fintype K] [Nonempty K] [DecidableEq M] [DecidableEq Y] {H : K → M → Y} {ε : ENNReal} (hH : Probability.IsUniversalHash (Probability.PMF.uniformOfFintype K) H ε) {B : ProbComp (List M)} {Q : ℕ} (hB : ∀ ms ∈ B.eval.support, ms.length ≤ Q) :

The ε-bounded case of [BS23], Lemma 7.1, a step toward the lemma, not the cited result: against an ε-bounded UHF (IsUniversalHash for the uniform key, the ε-UHF of Definition 7.2), an adversary whose supported output lists have length at most Q wins Attack Game 7.2 with probability at most Q.choose 2 * ε. Only the key type has to be finite. Lemma 7.1 assumes only a computational UHF and bounds the multi-query advantage by Q ^ 2 / 2 times the advantage of an efficient wrapper in Attack Game 7.1; here the hash is ε-bounded against every adversary, efficient or not, for one fixed instance, with any ε (Definition 7.2 calls it statistical only when ε is negligible), and the proof uses a union bound (#5790).