Documentation

CslibFrontier.Crypto.Computational.TargetCollisionResistant

Target collision resistance and universal one-way hash families #

A keyed hash family H with key-length schedule keyLen : ℕ → ℕ is target collision-resistant (equivalently, a universal one-way hash family, UOWHF; [NY89], Section 2; [BS23], Section 8.11.2, Attack Game 8.5 and Definition 8.7; [Gol04], Section 6.4.3) if no uniform strict PPT two-stage adversary A = (choose, find) can win the following game with non-negligible probability:

  1. Given 1^n, A.choose n selects a target input m₀ and saved state st before the hash key is sampled;
  2. A uniform key k ← {0, 1}^{keyLen n} is sampled;
  3. Given (1^n, st, k), A.find n st k outputs a candidate input m₁;
  4. A wins when m₀ and m₁ satisfy the domain predicate valid n, m₀ ≠ m₁, and H n k m₀ = H n k m₁.

Unlike full collision resistance (CollisionResistantOn), where a single key k can be reused across every Merkle–Damgård step, plugging a target collision-resistant compression function with one fixed key directly into Merkle–Damgård can fail to give a target collision-resistant hash ([BS23], Section 8.11.3, p. 340). The tree constructions adapted here use independent keys across stages so that the reduction can compute the target compression input at a guessed stage before receiving the challenge key at that stage ([NY89], March 13, 1995 manuscript revision, Section 2.3; [Gol04], Section 6.4.3.2, June 2003 chapter draft Constructions 6.4.24 and 6.4.26, Propositions 6.4.25 and 6.4.27).

We formalize:

  1. Two-stage target-collision adversaries (TargetCollisionFinder, TargetCollisionFinder.IsPPT), the experiment targetCollisionGame with strict PPT certificates, and security predicates TargetCollisionResistantOn and TargetCollisionResistant, together with the zero-loss implication from full collision resistance (CollisionResistantOn.targetCollisionResistantOn).
  2. Syntactic and plain polynomial-time bundled interfaces KeyedCompressionFamily (2M(n) → M(n) under keyLen n-bit keys with n ≤ M(n)) and KeyedHashFamily (unrestricted bit-string inputs under keyLen n-bit keys with n ≤ digestLen n), allowing polynomial key and digest schedules, plus bridges from CompressionFamily and HashFamily.
  3. Level-keyed binary-tree + length-block domain extension (uowhfTreeHash), stretching any target collision-resistant KeyedCompressionFamily to an unrestricted target collision-resistant KeyedHashFamily on all List Bool using (n + 1) * keyLen n-bit keys (KeyedCompressionFamily.treeHash, KeyedCompressionFamily.targetCollisionResistant_treeHash).

Source mapping and finite-parameter boundary #

Whereas [BS23], Section 8.11.3 (pp. 339–340, Fig. 8.15 and Theorem 8.13) presents a linear chain that reuses one compression key k₁ at every step and XORs one of 1 + log₂ L masks k₂[ν(i)] into the chaining value, so that its key is logarithmic in the message length (and mentions a tree-based alternative with logarithmic-size keys on p. 340), and the Naor–Yung (1995 revision, Section 2.3) and Goldreich (June 2003 draft, Section 6.4.3.2) tree constructions hash fixed-length block sequences before composing with length disambiguation, uowhfTreeHash adapts level-keyed binary-tree hashing into a single total function on List Bool:

At any fixed parameter n, messages with msg.length > 2 ^ n exceed the n-level tree capacity: top has multiple blocks and top.headD [] discards the extra roots (for example, at n = 1, [false, false, false] and [false, false, true] produce identical digests for every h, K, keyLen, and blockLen). The arbitrary-input security theorem KeyedCompressionFamily.targetCollisionResistant_treeHash holds asymptotically because strict-PPT admissibility bounds the output lengths of both adversary.choose and adversary.find by polynomials in n; for all sufficiently large n, every supported m₀ and m₁ satisfies length < 2 ^ n ≤ 2 ^ M, within the injective tree and length-block regime where top is a singleton and lowBits M records msg.length injectively.

Main definitions #

Main results #

References #

Two-stage target collision resistance ([NY89], Section 2) #

A two-stage target-collision adversary ([NY89], Section 2; [BS23], Section 8.11.2, Attack Game 8.5 and Definition 8.7; [Gol04], Section 6.4.3): choose selects a target message and saved state from 1^n before the hash key is sampled, and find produces a second message after receiving the sampled key.

Uniform strict PPT admissibility for both stages of a TargetCollisionFinder, charging the full saved-state word passed from choose to find.

noncomputable def Cslib.Crypto.targetCollisionGame (keyLen : ℕ → ℕ) (H : ℕ → List Bool → List Bool → List Bool) (valid : ℕ → List Bool → Bool) (adversary : TargetCollisionFinder) (n : ℕ) :

The two-stage target-collision experiment ([NY89], Section 2; [BS23], Section 8.11.2, Attack Game 8.5): run adversary.choose n to obtain (m₀, state), sample a uniform keyLen n-bit key k, run adversary.find n state k to obtain m₁, and accept iff isCollision (H n) valid n k choice.1 m₁ holds.

The target-collision experiment is uniformly strict PPT, independently of unused auxiliary input.

def Cslib.Crypto.TargetCollisionResistantOn (keyLen : ℕ → ℕ) (H : ℕ → List Bool → List Bool → List Bool) (valid : ℕ → List Bool → Bool) :

Target collision resistance (universal one-wayness) of H with key-length schedule keyLen on valid against every uniform strict PPT TargetCollisionFinder ([NY89], Section 2; [BS23], Section 8.11.2, Definition 8.7; [Gol04], Section 6.4.3).

@[reducible, inline]
abbrev Cslib.Crypto.TargetCollisionResistant (keyLen : ℕ → ℕ) (H : ℕ → List Bool → List Bool → List Bool) :

Unrestricted target collision resistance on all bit strings List Bool: TargetCollisionResistantOn with every word valid. This is [BS23], Attack Game 8.5 and Definition 8.7 (pp. 337–338) for the keyed hash H n with uniform keyLen n-bit keys, against uniform strict PPT two-stage adversaries.

theorem Cslib.Crypto.TargetCollisionResistantOn.negligible {keyLen : ℕ → ℕ} {H : ℕ → List Bool → List Bool → List Bool} {valid : ℕ → List Bool → Bool} (h : TargetCollisionResistantOn keyLen H valid) (adversary : TargetCollisionFinder) (hPPT : adversary.IsPPT) :
Negligible fun (n : ℕ) => Game.succProbability (targetCollisionGame keyLen H valid adversary n).eval

Target collision resistance gives negligible success probability in targetCollisionGame for every strict PPT TargetCollisionFinder.

theorem Cslib.Crypto.TargetCollisionResistantOn.of_negligible {keyLen : ℕ → ℕ} {H : ℕ → List Bool → List Bool → List Bool} {valid : ℕ → List Bool → Bool} (h : ∀ (adversary : TargetCollisionFinder), adversary.IsPPT → Negligible fun (n : ℕ) => Game.succProbability (targetCollisionGame keyLen H valid adversary n).eval) :

Establish TargetCollisionResistantOn by bounding every strict PPT adversary's success probability.

theorem Cslib.Crypto.TargetCollisionResistantOn.mono {keyLen : ℕ → ℕ} {H : ℕ → List Bool → List Bool → List Bool} {valid₁ valid₂ : ℕ → List Bool → Bool} (hTCR : TargetCollisionResistantOn keyLen H valid₂) (hsub : ∀ᶠ (n : ℕ) in Filter.atTop, ∀ (m : List Bool), valid₁ n m = true → valid₂ n m = true) :
TargetCollisionResistantOn keyLen H valid₁

Restricting the valid input domain preserves target collision resistance.

theorem Cslib.Crypto.not_targetCollisionResistantOn_of_le_succProbability {keyLen : ℕ → ℕ} {H : ℕ → List Bool → List Bool → List Bool} {valid : ℕ → List Bool → Bool} {c : NNReal} (hc : c ≠ 0) (adversary : TargetCollisionFinder) (hPPT : adversary.IsPPT) (h : ∀ (n : ℕ), c ≤ Game.succProbability (targetCollisionGame keyLen H valid adversary n).eval) :

Finding target collisions with probability bounded away from zero refutes TargetCollisionResistantOn: a strict PPT adversary whose success probability is at least a fixed c > 0 at every security parameter.

theorem Cslib.Crypto.CollisionResistantOn.targetCollisionResistantOn {H : List Bool → List Bool → List Bool} {valid : ℕ → List Bool → Bool} (hCR : CollisionResistantOn H valid) :
TargetCollisionResistantOn id (fun (x : ℕ) (k msg : List Bool) => H k msg) valid

Full collision resistance implies target collision resistance: running both stages of a TargetCollisionFinder inside a single-stage CollisionFinder produces the exact same game distribution, since adversary.choose n is independent of BitString.sampleList n.

Bundled keyed compression and hash families #

A uniform keyed 2 * blockLen n → blockLen n compression family with plain polynomial-time key length, block length, and evaluation, satisfying n ≤ blockLen n so n-bit lengths embed injectively into blockLen n-bit blocks.

Valid 2 * C.blockLen n-bit compression inputs for C at security parameter n.

Target collision resistance (UOWHF compression security) of C on 2 * C.blockLen n-bit inputs: [BS23], Attack Game 8.5 and Definition 8.7 (pp. 337–338) for C.eval n with uniform C.keyLen n-bit keys and message space the 2 * C.blockLen n-bit words, against uniform strict PPT two-stage adversaries.

A uniform keyed hash family on arbitrary-length bit strings List Bool, with plain polynomial-time key length, digest length, and evaluation, satisfying n ≤ digestLen n.

Unrestricted target collision resistance (universal one-wayness) of H on all List Bool: [BS23], Attack Game 8.5 and Definition 8.7 (pp. 337–338) for H.eval n with uniform H.keyLen n-bit keys and every word a message, against uniform strict PPT two-stage adversaries.

View a 2n → n collision-resistant CompressionFamily as a KeyedCompressionFamily with keyLen = id and blockLen = id.

View an unrestricted HashFamily as a KeyedHashFamily with keyLen = id and digestLen = id.

Every HashFamily is unrestrictedly target collision-resistant on List Bool.

Level-keyed binary-tree + length-block domain extension #

Encode msg into a nonempty list of M-bit leaf blocks: [0^M] when msg is empty, and one M-bit block padOrTake M [b] (b :: 0^{M-1} for M ≥ 1) per bit b of msg otherwise.

theorem Cslib.Crypto.length_mem_uowhfLeaves {M : ℕ} {msg w : List Bool} (hw : w ∈ uowhfLeaves M msg) :
w.length = M
theorem Cslib.Crypto.uowhfLeaves_injective_of_length_eq {M : ℕ} (hM : 1 ≤ M) {m₀ m₁ : List Bool} (hlen : m₀.length = m₁.length) (heq : uowhfLeaves M m₀ = uowhfLeaves M m₁) :
m₀ = m₁
def Cslib.Crypto.uowhfPairInput (M : ℕ) (level : List (List Bool)) (j : ℕ) :

Concatenate the 2 * j-th and (2 * j + 1)-st blocks of level, normalizing each to exact width M via padOrTake M (defaulting missing odd-tail blocks to 0^M).

@[simp]
theorem Cslib.Crypto.length_uowhfPairInput (M : ℕ) (level : List (List Bool)) (j : ℕ) :
(uowhfPairInput M level j).length = 2 * M
def Cslib.Crypto.uowhfTreeStep (h : ℕ → List Bool → List Bool → List Bool) (n κ M : ℕ) (k : List Bool) (level : List (List Bool)) :

Compress one level of the binary hash tree under subkey k: keep level unchanged if it has at most one block, and otherwise compress each adjacent pair into an M-bit block.

theorem Cslib.Crypto.length_uowhfTreeStep (h : ℕ → List Bool → List Bool → List Bool) (n κ M : ℕ) (k : List Bool) (level : List (List Bool)) :
(uowhfTreeStep h n κ M k level).length = if level.length ≤ 1 then level.length else (level.length + 1) / 2
def Cslib.Crypto.uowhfTreeLevels (h : ℕ → List Bool → List Bool → List Bool) (n κ M : ℕ) (keys init : List (List Bool)) :

Fold uowhfTreeStep across a list of level subkeys keys.

@[simp]
theorem Cslib.Crypto.uowhfTreeLevels_nil (h : ℕ → List Bool → List Bool → List Bool) (n κ M : ℕ) (init : List (List Bool)) :
uowhfTreeLevels h n κ M [] init = init
theorem Cslib.Crypto.uowhfTreeLevels_append (h : ℕ → List Bool → List Bool → List Bool) (n κ M : ℕ) (ks₁ ks₂ init : List (List Bool)) :
uowhfTreeLevels h n κ M (ks₁ ++ ks₂) init = uowhfTreeLevels h n κ M ks₂ (uowhfTreeLevels h n κ M ks₁ init)
theorem Cslib.Crypto.length_uowhfTreeLevels_eq_one (h : ℕ → List Bool → List Bool → List Bool) (n κ M : ℕ) (keys : List (List Bool)) {init : List (List Bool)} (hne : init ≠ []) (hle : init.length ≤ 2 ^ keys.length) :
(uowhfTreeLevels h n κ M keys init).length = 1

After keys.length tree-compression levels, any nonempty leaf list of length at most 2 ^ keys.length collapses to a single root block.

def Cslib.Crypto.uowhfTreeHash (h : ℕ → List Bool → List Bool → List Bool) (keyLen blockLen : ℕ → ℕ) (n : ℕ) (K msg : List Bool) :

Level-keyed binary-tree + length-block hash: total fixed-depth adaptation of level-keyed tree hashing ([NY89], 1995 revision, Section 2.3; [Gol04], Section 6.4.3.2, June 2003 draft Constructions 6.4.24 and 6.4.26; cf. [BS23], Section 8.11.3, p. 340). Split K into n level subkeys k_0, ..., k_{n-1} plus one final subkey k_n of width keyLen n, fold uowhfTreeStep across k_0, ..., k_{n-1} starting from the one-bit-per-leaf encoding uowhfLeaves (blockLen n) msg, take root := padOrTake (blockLen n) (top.headD []), and compress root ++ BitString.lowBits (blockLen n) msg.length (msg.length mod 2^{blockLen n}) under k_n.

At fixed n, messages with msg.length > 2 ^ n leave multiple blocks in top and top.headD [] discards the extra roots; for msg.length < 2 ^ n ≤ 2 ^ blockLen n, top is a singleton and lowBits records msg.length injectively.

@[simp]
theorem Cslib.Crypto.length_uowhfTreeHash (h : ℕ → List Bool → List Bool → List Bool) (keyLen blockLen : ℕ → ℕ) (n : ℕ) (K msg : List Bool) :
(uowhfTreeHash h keyLen blockLen n K msg).length = blockLen n
def Cslib.Crypto.uowhfCandidateInput (h : ℕ → List Bool → List Bool → List Bool) (n κ M i j : ℕ) (front msg : List Bool) :

Candidate 2 * M-bit compression input fed to subkey i (0 ≤ i ≤ n) at pair index j during evaluation of uowhfTreeHash on msg, using only the prefix front containing subkeys < i.

@[simp]
theorem Cslib.Crypto.length_uowhfCandidateInput (h : ℕ → List Bool → List Bool → List Bool) (n κ M i j : ℕ) (front msg : List Bool) :
(uowhfCandidateInput h n κ M i j front msg).length = 2 * M

Deterministic tree collision witness #

theorem Cslib.Crypto.exists_uowhfCandidateInput_collision {h : ℕ → List Bool → List Bool → List Bool} {keyLen blockLen : ℕ → ℕ} {n B : ℕ} {K m₀ m₁ : List Bool} (hn : 1 ≤ n) (hM_ge : n ≤ blockLen n) (hB : 1 ≤ B) (hm₀_B : m₀.length ≤ B) (hm₀_pow : m₀.length < 2 ^ n) (hm₁_pow : m₁.length < 2 ^ n) (hlen_h : ∀ (k x : List Bool), k.length = keyLen n → x.length = 2 * blockLen n → (h n k x).length = blockLen n) (hne : m₀ ≠ m₁) (hcol : uowhfTreeHash h keyLen blockLen n K m₀ = uowhfTreeHash h keyLen blockLen n K m₁) :
∃ i ≤ n, ∃ j < B, have x₀ := uowhfCandidateInput h n (keyLen n) (blockLen n) i j K m₀; have x₁ := uowhfCandidateInput h n (keyLen n) (blockLen n) i j K m₁; x₀ ≠ x₁ ∧ h n (BitString.listRow (keyLen n) i K) x₀ = h n (BitString.listRow (keyLen n) i K) x₁

Deterministic node-collision extraction for uowhfTreeHash: whenever two distinct messages m₀ ≠ m₁ of length < 2 ^ n (with m₀.length ≤ B, 1 ≤ B, 1 ≤ n, and n ≤ blockLen n) produce the same digest under uowhfTreeHash, there exist a subkey index i ≤ n and a pair index j < B whose 2 * blockLen n-bit candidate inputs collide under BitString.listRow (keyLen n) i K.

Two-stage planted-subkey reduction for uowhfTreeHash #

noncomputable def Cslib.Crypto.uowhfTreeAdversary (h : ℕ → List Bool → List Bool → List Bool) (keyLen blockLen maxBlocks : ℕ → ℕ) (adversary : TargetCollisionFinder) :

Two-stage target-collision reduction from uowhfTreeHash to the underlying compression family h: Stage 1 samples a dyadic slot slot < (n + 1) * maxBlocks n encoding (i, j) (i ≤ n, j < maxBlocks n), runs adversary.choose n, samples i prefix subkeys front before seeing the challenge subkey, and outputs the (i, j) target compression input x₀; Stage 2 receives the challenge subkey kStar, samples the remaining n - i suffix subkeys back, runs adversary.find on front ++ kStar ++ back, and extracts the (i, j) candidate input x₁.

uowhfTreeAdversary is a uniform strict PPT TargetCollisionFinder whenever h, keyLen, blockLen, maxBlocks are plain polynomial-time and adversary is strict PPT.

theorem Cslib.Crypto.succProbability_targetCollisionGame_uowhfTreeHash_le {h : ℕ → List Bool → List Bool → List Bool} {keyLen blockLen maxBlocks : ℕ → ℕ} (adversary : TargetCollisionFinder) (n : ℕ) (hn : 1 ≤ n) (hM_ge : n ≤ blockLen n) (hB : 1 ≤ maxBlocks n) (hlen_h : ∀ (k x : List Bool), k.length = keyLen n → x.length = 2 * blockLen n → (h n k x).length = blockLen n) (hm₀_bound : ∀ choice ∈ (adversary.choose n).eval.support, choice.1.length ≤ maxBlocks n ∧ choice.1.length < 2 ^ n) (hm₁_bound : ∀ choice ∈ (adversary.choose n).eval.support, ∀ K ∈ (BitString.uniformList ((n + 1) * keyLen n)).support, ∀ m₁ ∈ (adversary.find n choice.2 K).eval.support, m₁.length < 2 ^ n) :
Game.succProbability (targetCollisionGame (fun (m : ℕ) => (m + 1) * keyLen m) (uowhfTreeHash h keyLen blockLen) (fun (x : ℕ) (x_1 : List Bool) => true) adversary n).eval ≤ ↑(Probability.dyadicSize ((n + 1) * maxBlocks n)) * Game.succProbability (targetCollisionGame keyLen h (fun (m : ℕ) (x : List Bool) => x.length == 2 * blockLen m) (uowhfTreeAdversary h keyLen blockLen maxBlocks adversary) n).eval

Concrete security bound for uowhfTreeHash: at any security parameter n ≥ 1 with n ≤ blockLen n, 1 ≤ maxBlocks n, and every supported message pair (m₀, m₁) of adversary satisfying m₀.length ≤ maxBlocks n, m₀.length < 2 ^ n, and m₁.length < 2 ^ n, the target-collision success probability of adversary against uowhfTreeHash is at most dyadicSize ((n + 1) * maxBlocks n) times that of uowhfTreeAdversary against h.

Extend any KeyedCompressionFamily C (2 * C.blockLen n → C.blockLen n under C.keyLen n-bit keys) to an unrestricted KeyedHashFamily on List Bool with (n + 1) * C.keyLen n-bit keys and C.blockLen n-bit digests via uowhfTreeHash. Note that at fixed n, uowhfTreeHash has injective tree capacity < 2 ^ n bits and discards extra roots beyond 2 ^ n via List.headD; asymptotic security on all List Bool relies on strict-PPT adversary output-length bounds.

Domain extension for target collision resistance (adapting [NY89], 1995 revision, Section 2.3 and [Gol04], Section 6.4.3.2, June 2003 draft Constructions 6.4.24 and 6.4.26, Propositions 6.4.25 and 6.4.27; cf. [BS23], Section 8.11.3, pp. 339–340): if C is target collision-resistant on 2 * C.blockLen n-bit inputs, then C.treeHash is unrestrictedly target collision-resistant on all List Bool. Strict-PPT admissibility bounds the output lengths of both adversary.choose and adversary.find by polynomials in n, placing every supported m₀ and m₁ strictly below 2 ^ n ≤ 2 ^ C.blockLen n for all sufficiently large n.