Documentation

CslibFrontier.Crypto.Game.Forgery.VerificationQueries

Forgery experiments with verification queries #

In [BS23], Section 6.2 (Attack Game 6.2, p. 221), an adversary against a message authentication code interleaves signing queries m with verification queries (m̂, t̂) and wins as soon as the challenger accepts a verification query not among the previously answered (m_i, t_i) pairs. Unlike Attack Game 6.1 (forgeExperiment), the adversary produces no final candidate; a traditional Attack Game 6.1 forger is the special case making one verification query at the end (forgerToVq).

This module develops the finite query-bounded steps of Theorem 6.1 ([BS23], pp. 221–223) and Exercise 6.2 ([BS23], p. 246), where adversaries carry structural query budgets (IsSigningQueryBounded, IsVerificationQueryBounded) without machine running-time certificates. The full computational theorems with IsOraclePPT reduction certificates on MACScheme live in CslibFrontier.Crypto.Computational.MAC.VerificationQueries.

Design notes #

Main definitions #

Main results #

References #

Oracle interface, budgets, and Attack Game 6.2 #

@[reducible, inline]
abbrev Cslib.Crypto.forgeVqSpec (M Sig : Type) :
OracleSpec (M ⊕ M × Sig)

Combined signing and verification oracle interface for Attack Game 6.2: left queries .inl m request a signature in Sig, and right queries .inr (m, σ) request a Boolean verification verdict.

@[reducible, inline]
abbrev Cslib.Crypto.IsSigningQueryBounded {M Sig α : Type} (program : ProbOracleComp (forgeVqSpec M Sig) α) (Q_s : ℕ) :

Pathwise budget of at most Q_s signing queries (.inl m), leaving private coin flips and verification queries unconstrained.

@[reducible, inline]
abbrev Cslib.Crypto.IsVerificationQueryBounded {M Sig α : Type} (program : ProbOracleComp (forgeVqSpec M Sig) α) (Q_v : ℕ) :

Pathwise budget of at most Q_v verification queries (.inr (m, σ)), leaving private coin flips and signing queries unconstrained.

One signing query costs 1 signing query.

One verification query costs 0 signing queries.

One signing query costs 0 verification queries.

One verification query costs 1 verification query.

theorem Cslib.Crypto.IsSigningQueryBounded.of_isQueryBounded {M Sig α : Type} {program : ProbOracleComp (forgeVqSpec M Sig) α} {Q : ℕ} (h : program.IsQueryBounded Q) :

A total external query budget bounds the number of signing queries.

A total external query budget bounds the number of verification queries.

theorem Cslib.Crypto.IsQueryBounded.of_signing_and_verification {M Sig α : Type} {program : ProbOracleComp (forgeVqSpec M Sig) α} {Q_s Q_v : ℕ} (hs : IsSigningQueryBounded program Q_s) (hv : IsVerificationQueryBounded program Q_v) :
program.IsQueryBounded (Q_s + Q_v)

Separate signing and verification query budgets yield a total external query budget of Q_s + Q_v.

structure Cslib.Crypto.VqOracleState (M Sig : Type) :

Challenger state for Attack Game 6.2: the chronological log of answered signing pairs and whether some fresh verification query has already verified (won).

  • log : List (M × Sig)

    Answered (message, signature) pairs in the order answered by signer.

  • won : Bool

    Latches true as soon as a verification query (m, σ) verifies and satisfies freshPair.

Instances For
    def Cslib.Crypto.instDecidableEqVqOracleState.decEq {M✝ Sig✝ : Type} [DecidableEq M✝] [DecidableEq Sig✝] (x✝ x✝¹ : VqOracleState M✝ Sig✝) :
    Decidable (x✝ = x✝¹)
    @[instance_reducible]
    instance Cslib.Crypto.instDecidableEqVqOracleState {M✝ Sig✝ : Type} [DecidableEq M✝] [DecidableEq Sig✝] :
    def Cslib.Crypto.instReprVqOracleState.repr {M✝ Sig✝ : Type} [Repr M✝] [Repr Sig✝] :
    VqOracleState M✝ Sig✝ → ℕ → Std.Format
    @[instance_reducible]
    instance Cslib.Crypto.instReprVqOracleState {M✝ Sig✝ : Type} [Repr M✝] [Repr Sig✝] :
    Repr (VqOracleState M✝ Sig✝)
    def Cslib.Crypto.vqOracle {PK SK M Sig : Type} [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (pk : PK) (sk : SK) (q : M ⊕ M × Sig) :

    Stateful challenger oracle for Attack Game 6.2 ([BS23], p. 221):

    • .inl m runs signer sk st.log m; if accepted (some reply), appends (m, σ) to st.log and returns σ; if refused (none), returns default without modifying st.
    • .inr (m, σ) evaluates ok := verify pk sk m σ, latches st.won when ok && freshPair m σ st.log holds, and returns ok.
    def Cslib.Crypto.vqForgeExperiment {PK SK M Sig : Type} [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit) :

    Forgery experiment with verification queries ([BS23], Section 6.2, Attack Game 6.2, p. 221): draw (pk, sk) from keyGen, run A pk against vqOracle signer verify pk sk from the empty log with won = false, and accept iff won latched true on some fresh valid verification query.

    Embedding Attack Game 6.1 into Attack Game 6.2 #

    def Cslib.Crypto.forgerToVq {PK M Sig : Type} (A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)) (pk : PK) :

    Embed a standard Attack Game 6.1 forger A into Attack Game 6.2 by forwarding all signing queries to .inl and submitting A's final output (m, σ) as a single .inr (m, σ) verification query.

    theorem Cslib.Crypto.eval_vqForgeExperiment_forgerToVq {PK SK M Sig : Type} [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)) :
    ProbComp.eval (vqForgeExperiment keyGen signer verify (forgerToVq A)) = ProbComp.eval (forgeExperiment keyGen signer verify freshPair A)

    forgerToVq A in vqForgeExperiment has the exact Boolean law of A in forgeExperiment with strong freshness (freshPair).

    theorem Cslib.Crypto.isSigningQueryBounded_forgerToVq {PK M Sig : Type} {A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)} {pk : PK} {Q_s : ℕ} (h : (A pk).IsQueryBounded Q_s) :

    forgerToVq A preserves the signing query bound of A.

    theorem Cslib.Crypto.isVerificationQueryBounded_forgerToVq {PK M Sig : Type} (A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)) (pk : PK) :

    forgerToVq A makes at most 1 verification query.

    Finite Theorem 6.1: planted-query guessing reduction to Attack Game 6.1 #

    theorem Cslib.Crypto.succProbability_vqForgeExperiment_zero {PK SK M Sig : Type} [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) {A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit} (hA : ∀ (pk : PK), IsVerificationQueryBounded (A pk) 0) :
    (vqForgeExperiment keyGen signer verify A).succProbability = 0

    An adversary with verification-query budget 0 has succProbability = 0 in vqForgeExperiment.

    def Cslib.Crypto.vqToForgerHandler {M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (admit : List (M × Sig) → M → Bool) (q : M ⊕ M × Sig) :
    StateT (ProbOracleComp.PlantedOracleState (M × Sig) (List (M × Sig))) (ProbOracleComp fun (x : M) => Sig) (forgeVqSpec M Sig q)

    Stateful handler of the planted-query guessing reduction ([BS23], Theorem 6.1, pp. 221–223):

    • once st.planted.hasCaptured = true, returns (default, st) on .inl and (false, st) on .inr without querying the external signing oracle;
    • while st.planted.hasCaptured = false:
      • on .inl m, if admit st.oracleState m holds, queries m on the external signing oracle and appends (m, σ) to st.oracleState, and otherwise returns (default, st) locally;
      • on .inr p, captures p with reply false when st.planted.rem == 0, and otherwise answers decide (p ∈ st.oracleState) while decrementing st.planted.rem.
    def Cslib.Crypto.vqToForgerOn {PK M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (admit : List (M × Sig) → M → Bool) (index : ProbComp ℕ) (A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit) (pk : PK) :
    ProbOracleComp (fun (x : M) => Sig) (M × Sig)

    Policy-aware planted-query reduction ([BS23], Theorem 6.1, pp. 221–223): draw a target verification-query index j from index, simulate A pk through vqToForgerHandler admit starting at PlantedOracleState.init j default [], and output the captured candidate pair st.planted.candidate.

    @[reducible, inline]
    abbrev Cslib.Crypto.vqToForger {PK M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (index : ProbComp ℕ) (A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit) :
    PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)

    Planted-query reduction for unrestricted signing policies (admit := fun _ _ => true), as in Signer.ofSign.

    theorem Cslib.Crypto.isQueryBounded_vqToForgerOn {PK M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (admit : List (M × Sig) → M → Bool) (index : ProbComp ℕ) {A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit} {pk : PK} {Q_s : ℕ} (h : IsSigningQueryBounded (A pk) Q_s) :
    (vqToForgerOn admit index A pk).IsQueryBounded Q_s

    vqToForgerOn makes at most Q_s signing queries whenever A pk makes at most Q_s signing queries.

    theorem Cslib.Crypto.eval_vqForgeExperiment_le_mul_add_of_index {PK SK M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (admit : List (M × Sig) → M → Bool) (hadmit : ∀ keys ∈ keyGen.eval.support, ∀ (log : List (M × Sig)) (m : M), (signer keys.2 log m).isSome = admit log m) (hsign : ∀ keys ∈ keyGen.eval.support, ∀ (log : List (M × Sig)) (m : M) (program : ProbComp Sig), signer keys.2 log m = some program → ∀ σ ∈ program.eval.support, verify keys.1 keys.2 m σ = true) (Q_v : ℕ) (index : ProbComp ℕ) {c ε : ENNReal} (hindex : ∀ j < Q_v, 1 ≤ c * index.eval j + ε) {A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit} (hA : ∀ (pk : PK), IsVerificationQueryBounded (A pk) Q_v) :
    (ProbComp.eval (vqForgeExperiment keyGen signer verify A)) true ≤ c * (ProbComp.eval (forgeExperiment keyGen signer verify freshPair (vqToForgerOn admit index A))) true + ε

    Finite index-sampler guessing step toward [BS23], Section 6.2, Theorem 6.1 (pp. 221–223), without machine running-time certificates (not the computational result; see Cslib.Crypto.MACScheme.succProbability_sufCmaVqGame_le_mul_add and Cslib.Crypto.MACScheme.sufCmaVq_iff_sufCma): suppose every signature produced by signer verifies (hsign), admit characterizes when signer accepts (hadmit), A pk makes at most Q_v verification queries (hA), and index hits every j < Q_v according to 1 ≤ c * Pr[index = j] + ε (hindex). Then vqForgeExperiment accepts with probability at most c times that of forgeExperiment with freshPair on vqToForgerOn admit index A, plus ε.

    theorem Cslib.Crypto.succProbability_vqForgeExperiment_le_mul {PK SK M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (admit : List (M × Sig) → M → Bool) (hadmit : ∀ keys ∈ keyGen.eval.support, ∀ (log : List (M × Sig)) (m : M), (signer keys.2 log m).isSome = admit log m) (hsign : ∀ keys ∈ keyGen.eval.support, ∀ (log : List (M × Sig)) (m : M) (program : ProbComp Sig), signer keys.2 log m = some program → ∀ σ ∈ program.eval.support, verify keys.1 keys.2 m σ = true) (Q_v : ℕ) {A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit} (hA : ∀ (pk : PK), IsVerificationQueryBounded (A pk) Q_v) :
    (vqForgeExperiment keyGen signer verify A).succProbability ≤ ↑Q_v * (forgeExperiment keyGen signer verify freshPair (vqToForgerOn admit (Fin.val <$> ProbComp.unifFin (Q_v - 1)) A)).succProbability

    Finite query-bounded step toward [BS23], Section 6.2, Theorem 6.1 (pp. 221–223), without machine running-time certificates (not the cited computational result; see Cslib.Crypto.MACScheme.succProbability_sufCmaVqGame_le_mul_add and Cslib.Crypto.MACScheme.sufCmaVq_iff_sufCma): when every signature produced by signer verifies and admit characterizes when signer accepts, an adversary making at most Q_v verification queries wins vqForgeExperiment with probability at most Q_v times the success probability of vqToForgerOn admit (Fin.val <$> ProbComp.unifFin (Q_v - 1)) A in forgeExperiment with freshPair. Holds for every Q_v : ℕ, including Q_v = 0.

    theorem Cslib.Crypto.succProbability_vqForgeExperiment_ofSign_le_mul {PK SK M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (keyGen : ProbComp (PK × SK)) (sign : SK → M → ProbComp Sig) (verify : PK → SK → M → Sig → Bool) (hsign : ∀ keys ∈ keyGen.eval.support, ∀ (m : M), ∀ σ ∈ (sign keys.2 m).eval.support, verify keys.1 keys.2 m σ = true) (Q_v : ℕ) {A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit} (hA : ∀ (pk : PK), IsVerificationQueryBounded (A pk) Q_v) :

    Finite query-bounded step toward [BS23], Section 6.2, Theorem 6.1 (pp. 221–223) for unrestricted signers (Signer.ofSign), without machine running-time certificates (not the cited computational result; see Cslib.Crypto.MACScheme.sufCmaVq_iff_sufCma): when every signature in the support of sign sk m verifies, vqForgeExperiment success probability for any Q_v-verification-query adversary is at most Q_v times the freshPair forgeExperiment success probability of vqToForger (Fin.val <$> ProbComp.unifFin (Q_v - 1)) A.

    theorem Cslib.Crypto.eval_vqForgeExperiment_le_mul_sampleModIndex_add {PK SK M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (admit : List (M × Sig) → M → Bool) (hadmit : ∀ keys ∈ keyGen.eval.support, ∀ (log : List (M × Sig)) (m : M), (signer keys.2 log m).isSome = admit log m) (hsign : ∀ keys ∈ keyGen.eval.support, ∀ (log : List (M × Sig)) (m : M) (program : ProbComp Sig), signer keys.2 log m = some program → ∀ σ ∈ program.eval.support, verify keys.1 keys.2 m σ = true) (width Q_v : ℕ) {A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit} (hA : ∀ (pk : PK), IsVerificationQueryBounded (A pk) Q_v) :
    (ProbComp.eval (vqForgeExperiment keyGen signer verify A)) true ≤ ↑Q_v * (ProbComp.eval (forgeExperiment keyGen signer verify freshPair (vqToForgerOn admit (ProbComp.sampleModIndex width Q_v) A))) true + ↑Q_v / 2 ^ width

    Finite query-bounded fair-coin sampleModIndex step toward [BS23], Section 6.2, Theorem 6.1 (pp. 221–223), without machine running-time certificates (not the cited computational result; see Cslib.Crypto.MACScheme.succProbability_sufCmaVqGame_le_mul_add): drawing the planted verification-query index via ProbComp.sampleModIndex width Q_v from width fair coins gives the factor Q_v plus the dyadic bias Q_v / 2 ^ width, for every width and Q_v (including Q_v = 0).

    theorem Cslib.Crypto.eval_vqForgeExperiment_le_mul_sampleModIndex_of_dvd {PK SK M Sig : Type} [Inhabited M] [Inhabited Sig] [DecidableEq M] [DecidableEq Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (admit : List (M × Sig) → M → Bool) (hadmit : ∀ keys ∈ keyGen.eval.support, ∀ (log : List (M × Sig)) (m : M), (signer keys.2 log m).isSome = admit log m) (hsign : ∀ keys ∈ keyGen.eval.support, ∀ (log : List (M × Sig)) (m : M) (program : ProbComp Sig), signer keys.2 log m = some program → ∀ σ ∈ program.eval.support, verify keys.1 keys.2 m σ = true) (width Q_v : ℕ) (hdvd : Q_v = 0 ∨ Q_v ∣ 2 ^ width) {A : PK → ProbOracleComp (forgeVqSpec M Sig) Unit} (hA : ∀ (pk : PK), IsVerificationQueryBounded (A pk) Q_v) :
    (ProbComp.eval (vqForgeExperiment keyGen signer verify A)) true ≤ ↑Q_v * (ProbComp.eval (forgeExperiment keyGen signer verify freshPair (vqToForgerOn admit (ProbComp.sampleModIndex width Q_v) A))) true

    Finite query-bounded exact dyadic sampleModIndex step toward [BS23], Section 6.2, Theorem 6.1 (pp. 221–223), without machine running-time certificates (not the cited computational result; see Cslib.Crypto.MACScheme.succProbability_sufCmaVqGame_le_mul): proves the exact factor-Q_v bound with no additive error term when Q_v = 0 (where vqForgeExperiment accepts with probability 0 via eval_vqForgeExperiment_zero) or when Q_v divides 2 ^ width (where 0 < Q_v and ProbComp.sampleModIndex width Q_v is uniform below Q_v).

    Finite Exercise 6.2: PRF-based MAC with verification queries #

    def Cslib.Crypto.vqMacToPrfHandler {D R : Type} [DecidableEq D] [DecidableEq R] (q : D ⊕ D × R) :
    StateT (VqOracleState D R) (ProbOracleComp fun (x : D) => R) (forgeVqSpec D R q)

    Stateful handler for vqMacToPrfAdversary:

    • .inl m queries m on the external function oracle, appends (m, σ) to st.log, and returns σ;
    • .inr (m, σ) returns true locally when (m, σ) ∈ st.log (avoiding a redundant oracle call), and otherwise queries m on the external function oracle, sets ok := decide (τ = σ), latches st.won || ok, and returns ok.

    Direct reduction from vqForgeExperiment on a deterministic keyed function F : Key → D → R to PRF.Adversary D R ([BS23], Exercise 6.2, p. 246): simulate A () via vqMacToPrfHandler and output st.won. Unlike vqToForger, this reduction guesses no index and forwards both signing and fresh verification queries directly to the PRF oracle.

    vqMacToPrfAdversary A makes at most Q_s + Q_v function queries when A () makes at most Q_s signing queries and at most Q_v verification queries.

    theorem Cslib.Crypto.eval_realExperiment_vqMacToPrfAdversary {Key D R : Type} [Fintype Key] [Nonempty Key] [Inhabited R] [DecidableEq D] [DecidableEq R] (F : Key → D → R) (A : Unit → ProbOracleComp (forgeVqSpec D R) Unit) :
    (PRF.realExperiment F (vqMacToPrfAdversary A)).eval = ProbComp.eval (vqForgeExperiment ((fun (x : Key) => ((), x)) <$> ProbComp.uniform Key) (Signer.ofSign fun (k : Key) (m : D) => pure (F k m)) (fun (x : Unit) (k : Key) (m : D) (σ : R) => decide (F k m = σ)) A)

    Running vqMacToPrfAdversary A in PRF.realExperiment F has the exact Boolean law of vqForgeExperiment against the deterministic MAC (k, m) ↦ F k m.

    theorem Cslib.Crypto.succProbability_vqForgeExperiment_prf_le {Key D R : Type} [Fintype Key] [Nonempty Key] [Fintype D] [DecidableEq D] [Fintype R] [DecidableEq R] [Nonempty R] (F : Key → D → R) (Q_v : ℕ) {A : Unit → ProbOracleComp (forgeVqSpec D R) Unit} (hA : IsVerificationQueryBounded (A ()) Q_v) :
    have this := Classical.inhabited_of_nonempty inst✝; (vqForgeExperiment ((fun (x : Key) => ((), x)) <$> ProbComp.uniform Key) (Signer.ofSign fun (k : Key) (m : D) => pure (F k m)) (fun (x : Unit) (k : Key) (m : D) (σ : R) => decide (F k m = σ)) A).succProbability ≤ PRF.advantage F (vqMacToPrfAdversary A) + ↑Q_v / ↑(Fintype.card R)

    Finite query-bounded step toward [BS23], Section 6.14, Exercise 6.2 (p. 246), without machine running-time certificates (not the cited computational result; see Cslib.Crypto.succProbability_sufCmaVqGame_prfMAC_le and Cslib.Crypto.PseudorandomFunction.sufCmaVq_prfMAC): for any finite keyed function F : Key → D → R and any adversary A making at most Q_v verification queries, the success probability of A in vqForgeExperiment against the deterministic MAC (k, m) ↦ F k m is at most PRF.advantage F (vqMacToPrfAdversary A) + Q_v / Fintype.card R (without a Q_v factor on the PRF advantage). When A () also makes at most Q_s signing queries, vqMacToPrfAdversary A makes at most Q_s + Q_v PRF queries (isQueryBounded_vqMacToPrfAdversary).