MD strengthening is collision resistant
ProvedCityMD.mainFor there is a fixed black-box reduction such that for every keyed compression family on -bit blocks and collision finder on messages shorter than bits, Merkle–Damgård with SHA-2 style padding satisfies , with making at most calls.
Preamble
import Mathlib import Definitions.Def_CityMD open Cryptography.MerkleDamgard CityMD
Formal statement
/-- Merkle–Damgård with MD-strengthening padding (`w`-bit blocks, `ℓ`-bit length
field) is collision resistant if the compression family is. -/
theorem CityMD.main {K S : Type} [Fintype K] [DecidableEq S] [Inhabited S]
(w ℓ : ℕ) (hw : 0 < w) (iv : S) :
∃ E : List (Fin w → Bool) → List (Fin w → Bool) →
OComp (S × (Fin w → Bool)) S ((S × (Fin w → Bool)) × (S × (Fin w → Bool))),
∀ (f : K → S → (Fin w → Bool) → S) (A : K → {m : List Bool // m.length < 2 ^ ℓ} ×
{m : List Bool // m.length < 2 ^ ℓ}),
(∀ k, (E (shaPad w ℓ (A k).1.1) (shaPad w ℓ (A k).2.1)).queries (uncurried (f k)) ≤
(shaPad w ℓ (A k).1.1).length + (shaPad w ℓ (A k).2.1).length) ∧
advCR (fun k => mdHash (f k) iv fun m : {m : List Bool // m.length < 2 ^ ℓ} =>
shaPad w ℓ m.1) A ≤
advCR (fun k => uncurried (f k))
(fun k => (E (shaPad w ℓ (A k).1.1) (shaPad w ℓ (A k).2.1)).run
(uncurried (f k))) := by sorryRead-back
What the Lean code literally says, in plain math · claude-opus-5-5
CityMD.main
Read-back
Fix a finite K, a type S (decidable equality, inhabited), and w, ℓ with w > 0, and an iv. Messages are bit strings m with |m| < 2^ℓ, and blocks are w-bit strings Fin w → Bool. There is a fixed oracle program E(L, L′), with oracle (S × {0,1}^w) → S, returning a pair of points. For every compression family f : K → S → {0,1}^w → S and every collision finder A : K → (message × message), both of the following hold:
- For every k, E(shaPad m₁, shaPad m₂) makes at most |shaPad m₁| + |shaPad m₂| oracle calls against f_k.
- Pr_k[m₁ ≠ m₂ ∧ hash_{f_k}(iv, shaPad m₁) = hash_{f_k}(iv, shaPad m₂)] ≤ Pr_k[E's output (p,q) has p ≠ q ∧ f_k(p) = f_k(q)].
Audit notes
- True. This is
crinstantiated withshaPad_suffixFree. - (Revised after audit: blocks are now exactly w bits, so f is a compression function on S × {0,1}^w as in the textbook statement.)
- ℓ = 0: there is only one message, so the left side is 0 and the claim is trivial but consistent.
- The docstring ("is collision resistant if the compression family is") matches the code. It is stated as a tight reduction.