Documentation

CslibFrontier.Crypto.Protocols.Signature.RandomOracle

Signatures in the random-oracle model #

A signature scheme in the random-oracle model ([BS23], Section 8.10.2) signs and verifies with oracle access to a function H : Query → Digest, which the security experiment draws uniformly at random. Signing draws its coins and then runs an OracleComp program against H; verification is a deterministic OracleComp program. The oracle is sampled lazily: each new point gets a uniform answer, remembered in an association list (oracle), so the query and digest types need not be finite beyond the digests.

The existential-unforgeability experiment (eufCmaGame, [BS23], Attack Game 13.1 in its random-oracle version) gives a forger the public key and oracle access to the signer and to H; the forger wins with a valid signature on a message it never asked to have signed. A Forger has explicit coins, drawn first, and is otherwise a deterministic OracleComp program; this is the form in which a forger can be rerun on the same coins, as forking needs. Its signing and hash calls are counted separately (Forger.CallBounded), as security bounds depend on them differently.

The shared interactive execution core (world, logSigning, runLoggedForger, liftVerify, liftOracleForger, worldRealize, worldGame) realizes the forger's signing/hash interface and the verifier's hash interface inside a single Cslib.Interactive.World whose state is the shared random-oracle cache List (Query × Digest), with local signing-pair logging List (M × Sig). Projecting the pair log recovers handler (runWith_world_runLoggedForger_liftOracleForger), and specializing the post-verification acceptance predicate yields:

A standard-model scheme Cslib.Crypto.Signature.Scheme is a scheme here with Query := Empty (Signature.Scheme.toROM in CslibFrontier.Crypto.Computational.Signature.RandomOracle), and its forgery experiments are instances of worldGame.

Main definitions #

Main results #

References #

@[reducible, inline]
abbrev Cslib.Crypto.Protocols.ROMSignature.ForgerSpec (M Query Sig Digest : Type) :
OracleSpec (M ⊕ Query)

The calls of a forger: a signing call names a message and returns a signature, and a hash call names a point and returns its digest.

structure Cslib.Crypto.Protocols.ROMSignature.Scheme (PK SK M Sig Query Digest : Type) :

A signature scheme in the random-oracle model, with public keys PK, secret keys SK, messages M, signatures Sig, and oracle H : Query → Digest. Signing first draws coins.

  • keyGen : PMF (PK × SK)

    Draw a public key and a secret key.

  • SignCoins : Type

    The signer's coins.

  • signCoins : SK → M → PMF self.SignCoins

    Draw the signer's coins for a message.

  • sign : SK → M → self.SignCoins → OracleComp (fun (x : Query) => Digest) Sig

    Sign, querying the oracle.

  • verify : PK → M → Sig → OracleComp (fun (x : Query) => Digest) Bool

    Verify, querying the oracle.

structure Cslib.Crypto.Protocols.ROMSignature.Forger (PK M Sig Query Digest : Type) :

A forger with explicit coins: it draws its coins, then, given the public key, calls the signer and the oracle and outputs a message and a signature.

  • Coins : Type

    The forger's coins.

  • coins : PMF self.Coins

    Draw the forger's coins.

  • forge : PK → self.Coins → OracleComp (ForgerSpec M Query Sig Digest) (M × Sig)

    Forge, calling the signer and the oracle.

A forger's call costs one when it is a signing call.

A forger's call costs one when it is a hash call.

def Cslib.Crypto.Protocols.ROMSignature.Forger.CallBounded {PK M Sig Query Digest : Type} (A : Forger PK M Sig Query Digest) (signs hashes : ℕ) :

The forger makes at most signs signing calls and at most hashes hash calls on every path, for every public key and every choice of its coins.

theorem Cslib.Crypto.Protocols.ROMSignature.Forger.CallBounded.isQueryBounded {PK M Sig Query Digest : Type} {A : Forger PK M Sig Query Digest} {signs hashes : ℕ} (h : A.CallBounded signs hashes) (pk : PK) (coins : A.Coins) :
(A.forge pk coins).IsQueryBounded (signs + hashes)

A forger making at most signs signing and hashes hash calls makes at most signs + hashes calls.

Every message in the signing query log and final candidate forgery is distinct.

Instances For
    @[instance_reducible]

    The final forged message msg was never queried to the signing oracle (msg ∉ queried), allowing earlier signing queries or internal random-oracle queries to repeat.

    Instances For

      Distinctness of all outputs (FreshOutputs) implies freshness of the final forged message (FreshOutputsOnFinalMessage).

      noncomputable def Cslib.Crypto.Protocols.ROMSignature.oracle {Query : Type} (Digest : Type) [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (q : Query) :
      StateT (List (Query × Digest)) PMF Digest

      The random oracle: a uniform digest for each new point, remembered thereafter.

      theorem Cslib.Crypto.Protocols.ROMSignature.run_oracle_of_lookup_eq_none {Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] {q : Query} {cache : List (Query × Digest)} (h : List.lookup q cache = none) :
      (oracle Digest q).run cache = (Probability.PMF.uniformOfFintype Digest).bind fun (c : Digest) => PMF.pure (c, (q, c) :: cache)

      A query at a point absent from the cache draws a uniform digest and records it.

      theorem Cslib.Crypto.Protocols.ROMSignature.run_oracle_of_lookup_eq_some {Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] {q : Query} {cache : List (Query × Digest)} {c : Digest} (h : List.lookup q cache = some c) :
      (oracle Digest q).run cache = PMF.pure (c, cache)

      A query at a cached point returns the cached digest and leaves the cache unchanged.

      theorem Cslib.Crypto.Protocols.ROMSignature.lookup_of_mem_support_oracle {Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] {q : Query} {cache : List (Query × Digest)} {result : Digest × List (Query × Digest)} (h : result ∈ (oracle Digest q cache).support) :
      List.lookup q result.2 = some result.1

      A table entry produced by a call of oracle is found at its queried point.

      theorem Cslib.Crypto.Protocols.ROMSignature.length_le_of_mem_support_oracle {Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] {q : Query} {cache : List (Query × Digest)} {result : Digest × List (Query × Digest)} (h : result ∈ (oracle Digest q cache).support) :
      result.2.length ≤ cache.length + 1

      A call of oracle adds at most one entry to the cache.

      theorem Cslib.Crypto.Protocols.ROMSignature.lookup_mono_of_mem_support_oracle {Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] {q : Query} {c c₁ : List (Query × Digest)} {d : Digest} (h : (d, c₁) ∈ ((oracle Digest q).run c).support) :
      (∀ (q' : Query) (d' : Digest), List.lookup q' c = some d' → List.lookup q' c₁ = some d') ∧ List.lookup q c₁ = some d

      Every cache transition of oracle preserves existing bindings and stores d at q.

      theorem Cslib.Crypto.Protocols.ROMSignature.interpret_oracle_mono_and_replay {Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] {α : Type} (prog : OracleComp (fun (x : Query) => Digest) α) {c c' : List (Query × Digest)} {a : α} (hrun : (a, c') ∈ ((OracleComp.interpret (oracle Digest) prog).run c).support) :
      (∀ (q : Query) (d : Digest), List.lookup q c = some d → List.lookup q c' = some d) ∧ ∀ (cFinal : List (Query × Digest)), (∀ (q : Query) (d : Digest), List.lookup q c' = some d → List.lookup q cFinal = some d) → (OracleComp.interpret (oracle Digest) prog).run cFinal = PMF.pure (a, cFinal)

      Running an OracleComp against oracle Digest preserves existing cache entries, and the same program deterministically replays (a, cFinal) on any extending cache cFinal.

      noncomputable def Cslib.Crypto.Protocols.ROMSignature.handler {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (sk : SK) (q : M ⊕ Query) :
      StateT (List (Query × Digest) × List M) PMF (ForgerSpec M Query Sig Digest q)

      Answer a forger's calls: sign with the secret key, recording the message, or query the oracle. Signing and the forger share the oracle.

      Shared Interactive.World execution core #

      noncomputable def Cslib.Crypto.Protocols.ROMSignature.forgerWorldImpl {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (sk : SK) (q : M ⊕ Query) :
      StateT (List (Query × Digest)) PMF (ForgerSpec M Query Sig Digest q)

      Implementation of the forger's signing and hash calls against the shared random-oracle cache List (Query × Digest) without recording a signing log.

      @[reducible]
      noncomputable def Cslib.Crypto.Protocols.ROMSignature.world {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (sk : SK) :
      Interactive.World (ForgerSpec M Query Sig Digest) fun (x : Query) => Digest

      The interactive oracle world of a random-oracle signature experiment under secret key sk: the forger's signing and hash calls (ForgerSpec M Query Sig Digest) and the verifier's hash calls (fun _ : Query => Digest) share the same lazily sampled random-oracle cache List (Query × Digest).

      def Cslib.Crypto.Protocols.ROMSignature.logSigning {M Sig Query Digest : Type} (q : M ⊕ Query) :
      StateT (List (M × Sig)) (ProbOracleComp (ForgerSpec M Query Sig Digest)) (ForgerSpec M Query Sig Digest q)

      Forger call handler that forwards signing and hash queries to the external ForgerSpec oracle while logging each (message, signature) pair returned by the signing oracle.

      def Cslib.Crypto.Protocols.ROMSignature.runLoggedForger {M Sig Query Digest : Type} (forger : ProbOracleComp (ForgerSpec M Query Sig Digest) (M × Sig)) :
      ProbOracleComp (ForgerSpec M Query Sig Digest) ((M × Sig) × List (M × Sig))

      Run an adaptive ProbOracleComp forger while recording the list of (message, signature) pairs returned by the signing oracle.

      def Cslib.Crypto.Protocols.ROMSignature.liftVerify {M Sig Query Digest α : Type} (prog : OracleComp (fun (x : Query) => Digest) α) :
      ProbOracleComp ((ForgerSpec M Query Sig Digest).sum fun (x : Query) => Digest) α

      Lift a verifier OracleComp over the hash oracle into the joint prover/verifier oracle interface of world.

      def Cslib.Crypto.Protocols.ROMSignature.liftOracleForger {M Sig Query Digest α : Type} (prog : OracleComp (ForgerSpec M Query Sig Digest) α) :
      ProbOracleComp (ForgerSpec M Query Sig Digest) α

      Embed a deterministic OracleComp forger program into ProbOracleComp.

      def Cslib.Crypto.Protocols.ROMSignature.worldRealize {PK SK M Sig Query Digest : Type} (scheme : Scheme PK SK M Sig Query Digest) (pk : PK) (forger : ProbOracleComp (ForgerSpec M Query Sig Digest) (M × Sig)) (accept : Bool → M × Sig → List (M × Sig) → Bool) :
      ProbOracleComp ((ForgerSpec M Query Sig Digest).sum fun (x : Query) => Digest) Bool

      Shared interactive execution core in world scheme sk: run a ProbOracleComp forger with signing-pair logging, then run scheme.verify pk on the candidate forgery in the same random-oracle world, and judge the outcome with accept verified msig pairs.

      noncomputable def Cslib.Crypto.Protocols.ROMSignature.worldGame {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (forger : PK → ProbOracleComp (ForgerSpec M Query Sig Digest) (M × Sig)) (accept : Bool → M × Sig → List (M × Sig) → Bool) :

      Evaluate a signature security game through Interactive.World.eval on world scheme sk: draw (pk, sk) ← scheme.keyGen, run worldRealize scheme pk (forger pk) accept in world scheme sk, and return the acceptance distribution.

      theorem Cslib.Crypto.Protocols.ROMSignature.runWith_world_liftProver {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (sk : SK) {α : Type} (prog : ProbOracleComp (ForgerSpec M Query Sig Digest) α) (cache : List (Query × Digest)) :

      Running a lifted prover computation in world scheme sk reduces to running it against forgerWorldImpl scheme sk.

      theorem Cslib.Crypto.Protocols.ROMSignature.runWith_world_liftVerify {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (sk : SK) {α : Type} (prog : OracleComp (fun (x : Query) => Digest) α) (cache : List (Query × Digest)) :
      ProbOracleComp.runWith (world scheme sk).impl (liftVerify prog) cache = (OracleComp.interpret (oracle Digest) prog).run cache

      Running a lifted verifier computation in world scheme sk reduces to interpreting it against oracle Digest.

      theorem Cslib.Crypto.Protocols.ROMSignature.runWith_world_runLoggedForger_liftOracleForger {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (sk : SK) (prog : OracleComp (ForgerSpec M Query Sig Digest) (M × Sig)) (cache : List (Query × Digest)) :
      PMF.map (fun (x : ((M × Sig) × List (M × Sig)) × List (Query × Digest)) => match x with | ((msig, pairs), cache') => (msig, cache', List.map Prod.fst pairs)) (ProbOracleComp.runWith (forgerWorldImpl scheme sk) (runLoggedForger (liftOracleForger prog)) cache) = (OracleComp.interpret (handler scheme sk) prog).run (cache, [])

      Running runLoggedForger (liftOracleForger prog) against forgerWorldImpl scheme sk and projecting the logged (message, signature) pairs to their first components reproduces handler scheme sk.

      theorem Cslib.Crypto.Protocols.ROMSignature.eval_world_worldRealize {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (pk : PK) (sk : SK) (forger : ProbOracleComp (ForgerSpec M Query Sig Digest) (M × Sig)) (accept : Bool → M × Sig → List (M × Sig) → Bool) :
      (world scheme sk).eval (worldRealize scheme pk forger accept) = do let __x ← ProbOracleComp.runWith (forgerWorldImpl scheme sk) (runLoggedForger forger) [] match __x with | ((msig, pairs), cache) => do let verified ← (OracleComp.interpret (oracle Digest) (scheme.verify pk msig.1 msig.2)).run cache pure (accept verified.1 msig pairs)

      Evaluating worldRealize on any ProbOracleComp forger in world scheme sk matches running runLoggedForger forger against forgerWorldImpl scheme sk and then running scheme.verify on the resulting cache.

      theorem Cslib.Crypto.Protocols.ROMSignature.eval_world_worldRealize_liftOracleForger {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (pk : PK) (sk : SK) (prog : OracleComp (ForgerSpec M Query Sig Digest) (M × Sig)) (accept : Bool → M × Sig → List (M × Sig) → Bool) :
      (world scheme sk).eval (worldRealize scheme pk (liftOracleForger prog) accept) = do let __x ← ProbOracleComp.runWith (forgerWorldImpl scheme sk) (runLoggedForger (liftOracleForger prog)) [] match __x with | ((msig, pairs), cache) => do let verified ← (OracleComp.interpret (oracle Digest) (scheme.verify pk msig.1 msig.2)).run cache pure (accept verified.1 msig pairs)

      Evaluating worldRealize on a lifted deterministic OracleComp forger in world scheme sk matches running logSigning + forgerWorldImpl and then scheme.verify on the resulting cache.

      Security games (eufCmaGame, ufCma0Game, sufCmaGame) #

      noncomputable def Cslib.Crypto.Protocols.ROMSignature.eufCmaGame {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] [DecidableEq M] (scheme : Scheme PK SK M Sig Query Digest) (forger : Forger PK M Sig Query Digest) :

      The random-oracle EUF-CMA experiment ([BS23], Attack Game 13.1): the forger wins with a valid signature, under the same oracle, on a message it never had signed.

      theorem Cslib.Crypto.Protocols.ROMSignature.eufCmaGame_eq_worldGame {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] [DecidableEq M] (scheme : Scheme PK SK M Sig Query Digest) (forger : Forger PK M Sig Query Digest) :
      eufCmaGame scheme forger = do let keys ← scheme.keyGen let s ← forger.coins (world scheme keys.2).eval (worldRealize scheme keys.1 (liftOracleForger (forger.forge keys.1 s)) fun (verified : Bool) (x : M × Sig) (pairs : List (M × Sig)) => match x with | (msg, snd) => verified && !(List.map Prod.fst pairs).contains msg)

      eufCmaGame is equivalent to evaluating worldRealize in world scheme sk with the final-message freshness predicate !(pairs.map Prod.fst).contains msg.

      noncomputable def Cslib.Crypto.Protocols.ROMSignature.ufCma0Game {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (forger : Forger PK M Sig Query Digest) :

      Key-only existential unforgeability (ufCma0Game): the forger wins when its candidate forgery verifies and it made zero signing queries (pairs.isEmpty).

      noncomputable def Cslib.Crypto.Protocols.ROMSignature.sufCmaGame {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] [DecidableEq M] [DecidableEq Sig] (scheme : Scheme PK SK M Sig Query Digest) (forger : Forger PK M Sig Query Digest) :

      Strong (fresh-pair) existential unforgeability under chosen-message attack (sufCmaGame): the forger wins when its candidate (msg, sig) verifies and (msg, sig) was never returned by the signing oracle (!pairs.contains (msg, sig)).

      noncomputable def Cslib.Crypto.Protocols.ROMSignature.sufCma0Game {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] [DecidableEq M] [DecidableEq Sig] (scheme : Scheme PK SK M Sig Query Digest) (forger : Forger PK M Sig Query Digest) :

      Key-only strong existential unforgeability (sufCma0Game): the forger wins when its candidate (msg, sig) verifies, (msg, sig) was never returned by the signing oracle, and the signing log is empty (pairs.isEmpty).

      @[simp]
      theorem Cslib.Crypto.Protocols.ROMSignature.sufCma0Game_eq_ufCma0Game {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] [DecidableEq M] [DecidableEq Sig] (scheme : Scheme PK SK M Sig Query Digest) (forger : Forger PK M Sig Query Digest) :
      sufCma0Game scheme forger = ufCma0Game scheme forger

      Key-only strong unforgeability sufCma0Game coincides with ufCma0Game because an empty signing log contains no pairs.

      Completeness (Scheme.Correct and Scheme.CorrectOn) #

      def Cslib.Crypto.Protocols.ROMSignature.Scheme.Correct {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) :

      A scheme is correct when every honest signature verifies under the same oracle, from every state of the oracle.

      def Cslib.Crypto.Protocols.ROMSignature.Scheme.CorrectOn {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) (admissible : M → Prop) :

      A scheme is correct on messages satisfying admissible when every honest signature on an admissible message verifies under the same oracle, from every state of the oracle.

      theorem Cslib.Crypto.Protocols.ROMSignature.Scheme.Correct.correctOn {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] {scheme : Scheme PK SK M Sig Query Digest} (h : scheme.Correct) (admissible : M → Prop) :
      scheme.CorrectOn admissible

      All-message correctness implies correctness on any admissible message predicate.

      @[simp]
      theorem Cslib.Crypto.Protocols.ROMSignature.Scheme.correctOn_true_iff {PK SK M Sig Query Digest : Type} [DecidableEq Query] [Fintype Digest] [Nonempty Digest] (scheme : Scheme PK SK M Sig Query Digest) :
      (scheme.CorrectOn fun (x : M) => True) ↔ scheme.Correct

      Correctness on fun _ => True is equivalent to unrestricted Scheme.Correct.