Documentation

CslibFrontier.Crypto.Primitives.PRF.HashThenPRF

Composition of a pseudorandom function with a universal hash function #

Applying a pseudorandom function F to the digest of a keyed hash function H gives F'((k₁, k₂), m) = F(k₂, H(k₁, m)) (Cslib.Crypto.PRF.hashThenPRF; [BS23], Section 7.3, equation (7.18), p. 262). For finite key, message, digest and output types, Cslib.Crypto.PRF.advantage_hashThenPRF_le_add_multiQuery (equation (7.20), p. 263) bounds the PRF advantage of any adaptive adversary A against hashThenPRF H F by the PRF advantage of Cslib.Crypto.PRF.hashReduction H A (B_F) against F plus the winning probability of Cslib.Crypto.PRF.idealQueries A (B'_H) in the multi-query universal-hash game Cslib.Crypto.UHF.multiQueryExperiment H. When H is ε-universal against every adversary (Cslib.Probability.IsUniversalHash) and A makes at most Q queries on every path, Cslib.Crypto.PRF.advantage_hashThenPRF_le bounds that second term by Q.choose 2 * ε.

These finite-type bounds give query-count and output-length guarantees through Cslib.Crypto.PRF.isQueryBounded_hashReduction and Cslib.Crypto.PRF.length_le_of_mem_support_idealQueries. IsUniversalHash supplies a collision bound at one instance. The computational form of Theorem 7.7, with strict PPT certificates and negligible advantage, is Cslib.Crypto.PRF.hashThenPRFWord_indistinguishable in CslibFrontier/Crypto/Computational/PseudorandomFunction/HashThenPRF.lean.

Conversely, Cslib.Crypto.PRF.toOuterMeasure_collision_le_advantage_collisionDistinguisher formalizes the observation of Section 7.3 (p. 263) that two distinct messages colliding with probability δ give a two-query distinguisher (Cslib.Crypto.PRF.collisionDistinguisher) of advantage at least δ - 1 / |Z| against hashThenPRF H F.

Main definitions #

Main results #

Steps toward Theorem 7.7 #

Implementation notes #

collisionDistinguisher is not exposed. For module callers, Cslib.Crypto.PRF.eval_realExperiment_collisionDistinguisher and Cslib.Crypto.PRF.eval_idealExperiment_collisionDistinguisher give its output laws in the two experiments.

References #

def Cslib.Crypto.PRF.hashThenPRF {K₁ K₂ M Y Z : Type} (H : K₁ → M → Y) (F : K₂ → Y → Z) (k : K₁ × K₂) (m : M) :
Z

Equation (7.18) ([BS23], Version 0.6, Section 7.3, p. 262): F'((k₁, k₂), m) = F(k₂, H(k₁, m)).

noncomputable def Cslib.Crypto.PRF.hashReduction {K₁ M Y Z : Type} [Fintype K₁] [Nonempty K₁] (H : K₁ → M → Y) (A : Adversary M Z) :
ProbOracleComp (fun (x : Y) => Z) Bool

The adversary B_F of Theorem 7.7 ([BS23], Version 0.6, Section 7.3, p. 263): sample a hash key, run A, and forward each query through H k.

theorem Cslib.Crypto.PRF.isQueryBounded_hashReduction {K₁ M Y Z : Type} [Fintype K₁] [Nonempty K₁] (H : K₁ → M → Y) {A : Adversary M Z} {Q : ℕ} (hQ : ProbOracleComp.IsQueryBounded A Q) :

B_F makes one query per query of A.

noncomputable def Cslib.Crypto.PRF.idealQueries {M Z : Type} [DecidableEq M] [Fintype Z] [Nonempty Z] (A : Adversary M Z) :

The adversary B'_H named in (7.20) (p. 263) and constructed in Game 2 (p. 264) of [BS23] (Version 0.6, Section 7.3): run A against a lazily sampled random function on M and output the list of distinct queries it cached.

B'_H outputs at most as many messages as A makes queries.

theorem Cslib.Crypto.PRF.eval_realExperiment_hashThenPRF {K₁ K₂ M Y Z : Type} [Fintype K₁] [Nonempty K₁] [Fintype K₂] [Nonempty K₂] (H : K₁ → M → Y) (F : K₂ → Y → Z) (A : Adversary M Z) :

Game 0 of the proof of Theorem 7.7 ([BS23], Version 0.6, Section 7.3, pp. 263–264), a step toward equation (7.21): the real experiment of A against hashThenPRF H F has the same distribution as the real experiment of hashReduction H A (B_F) against F.

Equation (7.22) ([BS23], Version 0.6, Section 7.3, p. 264), Games 1 and 2: against a uniform function, hashing the queries first changes the adversary's output only when two distinct queries collide under the hash key.

theorem Cslib.Crypto.PRF.advantage_hashThenPRF_le_add_multiQuery {K₁ K₂ M Y Z : Type} [Fintype K₁] [Nonempty K₁] [Fintype K₂] [Nonempty K₂] [Fintype M] [DecidableEq M] [Fintype Y] [DecidableEq Y] [Fintype Z] [Nonempty Z] (H : K₁ → M → Y) (F : K₂ → Y → Z) (A : Adversary M Z) :

Concrete bound (7.20) for finite types, a step toward [BS23], Theorem 7.7 (Version 0.6, Section 7.3, pp. 262–263), not the cited result: for every H, F, and adversary A, the distinguishing advantage against hashThenPRF H F is bounded by the advantage of hashReduction H A against F plus the probability that idealQueries A wins the multi-query UHF game against H. This finite result counts oracle queries. The computational form is Cslib.Crypto.PRF.hashThenPRFWord_indistinguishable.

theorem Cslib.Crypto.PRF.advantage_hashThenPRF_le {K₁ K₂ M Y Z : Type} [Fintype K₁] [Nonempty K₁] [Fintype K₂] [Nonempty K₂] [Fintype M] [DecidableEq M] [Fintype Y] [DecidableEq Y] [Fintype Z] [Nonempty Z] {H : K₁ → M → Y} {ε : ENNReal} (hH : Probability.IsUniversalHash (Probability.PMF.uniformOfFintype K₁) H ε) (F : K₂ → Y → Z) {A : Adversary M Z} {Q : ℕ} (hQ : ProbOracleComp.IsQueryBounded A Q) :
↑(advantage (hashThenPRF H F) A) ≤ ↑(advantage F (hashReduction H A)) + ↑(Q.choose 2) * ε

Concrete bound for finite types and an ε-bounded UHF, a step toward [BS23], Theorem 7.7 (Version 0.6, Section 7.3, p. 262), not the cited result: for an adversary making at most Q queries, advantage (hashThenPRF H F) A ≤ advantage F (hashReduction H A) + C(Q, 2) · ε. This finite result assumes an ε collision bound at one instance and counts oracle queries. The computational form is Cslib.Crypto.PRF.hashThenPRFWord_indistinguishable.

def Cslib.Crypto.PRF.collisionDistinguisher {M Z : Type} [DecidableEq Z] (m₀ m₁ : M) :
ProbOracleComp (fun (x : M) => Z) Bool

The two-query collision distinguisher of [BS23] (Version 0.6, Section 7.3, p. 263): query m₀ and m₁ and accept when their replies agree.

collisionDistinguisher m₀ m₁ makes at most two external queries.

theorem Cslib.Crypto.PRF.eval_realExperiment_collisionDistinguisher {K₁ K₂ M Y Z : Type} [Fintype K₁] [Nonempty K₁] [Fintype K₂] [Nonempty K₂] [DecidableEq Z] (H : K₁ → M → Y) (F : K₂ → Y → Z) (m₀ m₁ : M) :
(realExperiment (hashThenPRF H F) (collisionDistinguisher m₀ m₁)).eval = (Probability.PMF.uniformOfFintype (K₁ × K₂)).bind fun (k : K₁ × K₂) => PMF.pure (decide (F k.2 (H k.1 m₀) = F k.2 (H k.1 m₁)))

Output distribution of collisionDistinguisher m₀ m₁ in the real experiment against hashThenPRF H F.

Output distribution of collisionDistinguisher m₀ m₁ in the ideal PRF experiment.

theorem Cslib.Crypto.PRF.toOuterMeasure_collision_le_advantage_collisionDistinguisher {K₁ K₂ M Y Z : Type} [Fintype K₁] [Nonempty K₁] [Fintype K₂] [Nonempty K₂] [Fintype M] [DecidableEq M] [Fintype Z] [Nonempty Z] [DecidableEq Z] (H : K₁ → M → Y) (F : K₂ → Y → Z) {m₀ m₁ : M} (hm : m₀ ≠ m₁) :

If m₀ ≠ m₁ collide under H with probability δ over the uniform hash key, the two-query distinguisher collisionDistinguisher m₀ m₁ achieves advantage at least δ - 1 / |Z| against hashThenPRF H F, for every F ([BS23], Version 0.6, Section 7.3, p. 263).