Documentation

CslibFrontier.Crypto.Computational.MerkleDamgard.Multicollision

Joux multicollisions of Merkle–Damgård chains, with their cost #

Joux's attack ([BS23], §8.4.1, printed pp. 298–299) finds many messages with one digest for an iterated hash at little more than the cost of one collision. If b pairs of different blocks (m_i, m_i') satisfy h(t_i, m_i) = h(t_i, m_i'), where t_{i+1} = h(t_i, m_i), then each of the 2 ^ b messages that take one block from each pair reaches the same chaining value.

This module proves that structural fact for any iterated function (IsCollisionChain, IsCollisionChain.isMulticollision), and builds and analyses oracle programs that find such chains with the birthday finder of CslibFrontier.Crypto.Computational.CollisionResistant.Birthday. Each program has a bound on its oracle calls that holds on every path, and a lower bound on its success probability that holds for every compression function meeting a length condition.

These are steps toward §8.4.1, not the cited result: the book finds a 2 ^ b-collision "in time O(b 2 ^ (n/2))" and uses it to find a collision of H₁(M) ‖ H₂(M) in time O(n 2 ^ (n/2)), whereas the certificates here count compression evaluations, not running time, and the concatenated-hash attack is not formalized (#5293).

The cost measure. The certificates are ProbOracleComp.IsQueryBounded, with the compression function as the oracle. They count evaluations of the compression function on every path, whatever the samples and the replies; that is the cost measure of §8.3. They are not running-time bounds: sampling, the search for a colliding pair and the bookkeeping are not counted, and no machine model is involved. They are worst-case counts, not expected costs. The programs reach the compression function only through the oracle, and the success theorems run them against fun x => pure (h k x), so each certificate and its success theorem are about the same program.

Differences from [BS23] #

Main definitions #

Main results #

References #

Collision chains of an iterated function #

def Cslib.Crypto.IsCollisionChain {T M : Type} (step : T → M → T) :
T → List (M × M) → Prop

pairs is a chain of collisions of step from t: the two messages of the first pair differ and collide at t, and the rest is a chain from their common next value.

def Cslib.Crypto.jouxMessage {M : Type} (pairs : List (M × M)) (σ : BitString pairs.length) :

The message that takes the second message of pair i exactly when σ i is set.

theorem Cslib.Crypto.IsCollisionChain.fst_ne_snd {T M : Type} {step : T → M → T} {t : T} {pairs : List (M × M)} :
IsCollisionChain step t pairs → ∀ p ∈ pairs, p.1 ≠ p.2

The two messages of each pair of a collision chain differ.

theorem Cslib.Crypto.IsCollisionChain.foldl_jouxMessage {T M : Type} {step : T → M → T} {t : T} {pairs : List (M × M)} :
IsCollisionChain step t pairs → ∀ (σ : BitString pairs.length), List.foldl step t (jouxMessage pairs σ) = List.foldl step t (List.map Prod.fst pairs)

Joux's observation ([BS23], §8.4.1, printed p. 299): every choice of one message from each pair of a collision chain reaches the same value as the first messages.

theorem Cslib.Crypto.IsCollisionChain.jouxMessage_injective {T M : Type} {step : T → M → T} {t : T} {pairs : List (M × M)} (hc : IsCollisionChain step t pairs) :

Different selections from a collision chain are different messages.

def Cslib.Crypto.IsMulticollision {α : Type u_1} {β : Type u_2} (f : α → β) (s : ℕ) (S : Finset α) :

S is an s-collision of f: s distinct points with one common value (the sense of [BS23], §8.4.1 and Exercise 8.7).

theorem Cslib.Crypto.IsCollisionChain.isMulticollision {T M : Type} [DecidableEq M] {step : T → M → T} {t : T} {pairs : List (M × M)} (hc : IsCollisionChain step t pairs) (tail : List M) :
IsMulticollision (fun (ms : List M) => List.foldl step t (ms ++ tail)) (2 ^ pairs.length) (Finset.image (jouxMessage pairs) Finset.univ)

Joux multicollisions ([BS23], §8.4.1, printed p. 299): a collision chain of length b gives a 2 ^ b-collision of the iterated function, also after any common suffix.

theorem Cslib.Crypto.isCollision_of_isMulticollision {H : List Bool → List Bool → List Bool} {valid : ℕ → List Bool → Bool} {n s : ℕ} {key : List Bool} {S : Finset (List Bool)} (hS : IsMulticollision (H key) s S) {m₁ m₂ : List Bool} (h₁ : m₁ ∈ S) (h₂ : m₂ ∈ S) (hne : m₁ ≠ m₂) (hv₁ : valid n m₁ = true) (hv₂ : valid n m₂ = true) :
isCollision H valid n key m₁ m₂ = true

Two different valid members of a multicollision of H key are a collision in the sense of the collision-resistance game (isCollision).

The Joux finder for any step program #

def Cslib.Crypto.jouxFinder {Query M T : Type} {spec : Query → Type} [DecidableEq M] [DecidableEq T] (stage : T → M → ProbOracleComp spec T) (sampler : ProbComp M) (s : ℕ) :
ℕ → ℕ → T → ProbOracleComp spec (Option (List (M × M)))

Joux's finder with a budget of f birthday attempts for b stages, from the chaining value t. Each attempt runs birthdayFinder with the step program stage t from the current value. A collision is recorded and the search goes on from the value it reaches; an attempt that finds no collision is repeated from the same value. Returns the b pairs, or none when the budget runs out first.

theorem Cslib.Crypto.isQueryBounded_jouxFinder {Query M T : Type} {spec : Query → Type} [DecidableEq M] [DecidableEq T] {stage : T → M → ProbOracleComp spec T} {c : ℕ} (hstage : ∀ (t : T) (m : M), (stage t m).IsQueryBounded c) (sampler : ProbComp M) (s f b : ℕ) (t : T) :
(jouxFinder stage sampler s f b t).IsQueryBounded (f * (s * c))

Cost of the Joux finder. f attempts of s steps of at most c oracle calls each make at most f * (s * c) oracle calls on every path, whatever the number of stages. This counts oracle calls only; it is not a running time.

def Cslib.Crypto.jouxSuccess {M T : Type} (step : T → M → T) (b : ℕ) (t : T) :
Set (Option (List (M × M)))

The successful outputs of the Joux finder: b pairs forming a collision chain of step from t.

theorem Cslib.Crypto.jouxFinder_success {Query M T : Type} {spec : Query → Type} [DecidableEq M] [DecidableEq T] [Fintype M] [Nonempty M] {stage : T → M → ProbOracleComp spec T} (O : (q : Query) → spec q) (step : T → M → T) (hstage : ∀ (t : T) (m : M), ((stage t m).run fun (x : Query) => pure (O x)) = pure (step t m)) (D : Finset T) (hD : ∀ t ∈ D, ∀ (m : M), step t m ∈ D) (s : ℕ) {ε : ℝ} (hε : Real.exp (-(↑s * (↑s - 1) / (2 * ↑D.card))) + ↑(s.choose 2) * (↑(Fintype.card M))⁻¹ ≤ ε) (f b : ℕ) {t : T} (ht : t ∈ D) :
1 - 2 ^ b * ((1 + ε) / 2) ^ f / 2 ≤ (((jouxFinder stage (ProbComp.uniform M) s f b t).run fun (x : Query) => pure (O x)).eval.toOuterMeasure (jouxSuccess step b t)).toReal

Success probability of the Joux finder. Run against a deterministic oracle O under which the step program stage t m returns step t m, from a value t in a finite set D closed under step: if one birthday attempt with s uniform messages finds no collision with probability at most ε (in the form that birthdayFinder_success proves, with |D| values), then f attempts complete the b stages, returning a collision chain of length b, except with probability at most 2 ^ b * ((1 + ε) / 2) ^ f / 2.

Merkle–Damgård chains with ℓ-bit blocks #

noncomputable def Cslib.Crypto.merkleDamgardJouxFinder (ℓ s f b : ℕ) (iv : List Bool) :

Joux's finder for a Merkle–Damgård chain with ℓ-bit blocks from iv, against the compression function as an oracle: at most f attempts of s uniform blocks for b stages, one compression call per block.

Cost of Joux's attack on a chain. merkleDamgardJouxFinder ℓ s f b iv makes at most f * s evaluations of the compression function on every path. This counts oracle calls only; it is not a running time.

theorem Cslib.Crypto.isMulticollision_merkleDamgardChain {h : List Bool → List Bool → List Bool} {k : List Bool} {ℓ : ℕ} {iv : List Bool} {pairs : List (BitString ℓ × BitString ℓ)} (hc : IsCollisionChain (fun (t : List Bool) (m : BitString ℓ) => h k (t ++ List.ofFn m)) iv pairs) (tail : List (List Bool)) :

A collision chain of ℓ-bit blocks gives a 2 ^ b-collision of the chain from iv, after any common suffix of blocks ([BS23], §8.4.1, printed p. 299).

The outputs of merkleDamgardJouxFinder that are b pairs whose 2 ^ b selections, each followed by any common list of blocks tail, are a 2 ^ b-collision of the chain from iv. One output serves every tail. mem_multicollisionOutputs unfolds membership.

theorem Cslib.Crypto.mem_multicollisionOutputs {h : List Bool → List Bool → List Bool} {k : List Bool} {ℓ b : ℕ} {iv : List Bool} {o : Option (List (BitString ℓ × BitString ℓ))} :
o ∈ multicollisionOutputs h k ℓ b iv ↔ ∃ (pairs : List (BitString ℓ × BitString ℓ)), o = some pairs ∧ pairs.length = b ∧ ∀ (tail : List (List Bool)), IsMulticollision (fun (bs : List (List Bool)) => merkleDamgardChain h k iv (bs ++ tail)) (2 ^ b) (Finset.image (List.map List.ofFn) (Finset.image (jouxMessage pairs) Finset.univ))

Membership in multicollisionOutputs: b pairs whose selections, each followed by any common list of blocks, are a 2 ^ b-collision of the chain from iv.

theorem Cslib.Crypto.merkleDamgardJouxFinder_success {h : List Bool → List Bool → List Bool} {k : List Bool} {n ℓ : ℕ} (hlen : ∀ (x : List Bool), x.length = n + ℓ → (h k x).length = n) {iv : List Bool} (hiv : iv.length = n) (s : ℕ) {ε : ℝ} (hε : Real.exp (-(↑s * (↑s - 1) / (2 * 2 ^ n))) + ↑(s.choose 2) * (2 ^ ℓ)⁻¹ ≤ ε) (f b : ℕ) :
1 - 2 ^ b * ((1 + ε) / 2) ^ f / 2 ≤ (((merkleDamgardJouxFinder ℓ s f b iv).run fun (x : List Bool) => pure (h k x)).eval.toOuterMeasure (multicollisionOutputs h k ℓ b iv)).toReal

Joux's attack on a chain, with its cost. Let h k map n + ℓ-bit inputs to n-bit outputs and let iv have n bits. With at most f * s compression evaluations (isQueryBounded_merkleDamgardJouxFinder), merkleDamgardJouxFinder outputs b pairs such that, for every common list of blocks tail, their 2 ^ b selections, each followed by tail, are a 2 ^ b-collision of the chain, except with probability at most 2 ^ b * ((1 + ε) / 2) ^ f / 2, where ε bounds exp (-s (s - 1) / 2 ^ (n + 1)) + C(s, 2) / 2 ^ ℓ, the bound of Lemma 8.2 on the probability that one attempt finds no collision.

theorem Cslib.Crypto.merkleDamgardJouxFinder_success_half {h : List Bool → List Bool → List Bool} {k : List Bool} {n ℓ : ℕ} (hlen : ∀ (x : List Bool), x.length = n + ℓ → (h k x).length = n) {iv : List Bool} (hiv : iv.length = n) (hℓ : n + 7 ≤ ℓ) (b : ℕ) :
1 / 2 ≤ (((merkleDamgardJouxFinder ℓ (⌈2 * √↑(2 ^ n)⌉₊ + 1) (3 * b) b iv).run fun (x : List Bool) => pure (h k x)).eval.toOuterMeasure (multicollisionOutputs h k ℓ b iv)).toReal

Joux's attack on a chain with O(b 2 ^ (n/2)) compression evaluations, a step toward [BS23], §8.4.1 (printed p. 299), not the cited result: the book finds a 2 ^ b-collision "in time O(b 2 ^ (n/2))", whereas the count here is of compression evaluations only, not a running time (#5293). Let h k map n + ℓ-bit inputs to n-bit outputs, let iv have n bits, and let blocks be at least seven bits longer than chaining values (n + 7 ≤ ℓ). With the sample count s = ⌈2 √(2 ^ n)⌉ + 1 of Lemma 8.2 per attempt and a budget of 3 b attempts, merkleDamgardJouxFinder makes at most 3 b s compression evaluations (isQueryBounded_merkleDamgardJouxFinder), and with probability at least 1/2 it outputs b pairs such that, for every common list of blocks tail, their 2 ^ b selections, each followed by tail, are a 2 ^ b-collision. The book states no success probability.

The library's one-bit-per-block merkleDamgard #

Absorb the bits of m from the chaining value t as merkleDamgard does, one data block and one compression call per bit.

theorem Cslib.Crypto.run_absorbBits {h : List Bool → List Bool → List Bool} {k : List Bool} (n : ℕ) (t m : List Bool) :
((absorbBits n t m).run fun (x : List Bool) => pure (h k x)) = pure (merkleDamgardChain h k t (List.map (mdDataBlock n) m))

Against h k, absorbBits n t m continues the chain from t over the data blocks of m.

absorbBits n t m makes at most m.length compression calls.

A collision chain of g-bit groups, from the value after the marker block, gives a 2 ^ b-collision of merkleDamgard h k among messages of b * g bits.

noncomputable def Cslib.Crypto.merkleDamgardBitJouxFinder (n g s f b : ℕ) :

Joux's finder for the library's merkleDamgard with n-bit digests: one compression call for the marker block, then at most f attempts of s uniform g-bit groups for b stages, g compression calls per group.

Cost of Joux's attack on merkleDamgard. merkleDamgardBitJouxFinder n g s f b makes at most 1 + f * (s * g) evaluations of the compression function on every path. This counts oracle calls only; it is not a running time.

The outputs of merkleDamgardBitJouxFinder that are b pairs whose 2 ^ b selections are a 2 ^ b-collision of merkleDamgard h k. mem_bitMulticollisionOutputs unfolds membership.

Membership in bitMulticollisionOutputs: b pairs of g-bit groups whose selections are a 2 ^ b-collision of merkleDamgard h k.

theorem Cslib.Crypto.merkleDamgardBitJouxFinder_success {h : List Bool → List Bool → List Bool} {k : List Bool} (hlen : ∀ (x : List Bool), x.length = 2 * k.length → (h k x).length = k.length) (g s : ℕ) {ε : ℝ} (hε : Real.exp (-(↑s * (↑s - 1) / (2 * 2 ^ k.length))) + ↑(s.choose 2) * (2 ^ g)⁻¹ ≤ ε) (f b : ℕ) :
1 - 2 ^ b * ((1 + ε) / 2) ^ f / 2 ≤ (((merkleDamgardBitJouxFinder k.length g s f b).run fun (x : List Bool) => pure (h k x)).eval.toOuterMeasure (bitMulticollisionOutputs h k g b)).toReal

Joux's attack on merkleDamgard, with its cost. Let h k map 2 n-bit inputs to n-bit outputs, where n = k.length. With at most 1 + f * (s * g) compression evaluations (isQueryBounded_merkleDamgardBitJouxFinder), merkleDamgardBitJouxFinder outputs b pairs of g-bit groups whose 2 ^ b selections are a 2 ^ b-collision of merkleDamgard h k except with probability at most 2 ^ b * ((1 + ε) / 2) ^ f / 2, where ε bounds exp (-s (s - 1) / 2 ^ (n + 1)) + C(s, 2) / 2 ^ g.

theorem Cslib.Crypto.merkleDamgardBitJouxFinder_success_half {h : List Bool → List Bool → List Bool} {k : List Bool} (hlen : ∀ (x : List Bool), x.length = 2 * k.length → (h k x).length = k.length) {g : ℕ} (hg : k.length + 7 ≤ g) (b : ℕ) :
1 / 2 ≤ (((merkleDamgardBitJouxFinder k.length g (⌈2 * √↑(2 ^ k.length)⌉₊ + 1) (3 * b) b).run fun (x : List Bool) => pure (h k x)).eval.toOuterMeasure (bitMulticollisionOutputs h k g b)).toReal

Joux's attack on merkleDamgard with the sample count of Lemma 8.2, a step after [BS23], §8.4.1 (printed p. 299), not the cited result: it attacks the library's one-bit-per-block merkleDamgard rather than the book's chain, and it counts compression evaluations, not running time (#5293). Let h k map 2 n-bit inputs to n-bit outputs, where n = k.length, and let groups have g bits, at least seven more than a digest (n + 7 ≤ g). With s = ⌈2 √(2 ^ n)⌉ + 1 samples per attempt and a budget of 3 b attempts, merkleDamgardBitJouxFinder makes at most 1 + 3 b s g compression evaluations (isQueryBounded_merkleDamgardBitJouxFinder) and outputs a 2 ^ b-collision of merkleDamgard h k with probability at least 1/2. The factor g ≥ n + 7 is the price of one compression call per message bit, so this count is not the book's O(b 2 ^ (n/2)).