Documentation

CslibFrontier.Crypto.Game.Forgery

Forgery experiments #

A forgery experiment draws a key pair, runs a forger with access to a signing oracle and accepts when the forger's candidate (m, σ) verifies and is fresh. Signatures and MACs differ only in the parameters: a MAC has no public key (PK = Unit) and verifies with the secret key.

The signing oracle is a policy over the history of answered queries (Signer). Each policy either signs the next query or refuses it; a refused query is answered with default and is not recorded, as in ProbOracleComp.runLogWith. Full, one-time, indexed and counter signing oracles are policies, so the experiment is written once (forgeExperiment). Signer.restrict refuses the queries outside a message space, which is how a word-level game keeps signing queries in the source's message space. Freshness is a parameter too: freshMessage asks for a message that was never signed (existential unforgeability) and freshPair for a pair that was never answered (strong unforgeability). The evaluation law eval_forgeExperiment_eq writes the experiment's law as an event of the logged run.

Main definitions #

Main results #

References #

@[reducible, inline]
abbrev Cslib.Crypto.Signer (SK M Sig : Type) :

A signing policy: given the secret key, the log of answered queries (in the order answered) and the next query, either the program that signs it or none to refuse it.

def Cslib.Crypto.Signer.ofSign {SK M Sig : Type} (sign : SK → M → ProbComp Sig) :
Signer SK M Sig

The policy that signs every query with sign.

def Cslib.Crypto.Signer.restrict {SK M Sig : Type} (s : Signer SK M Sig) (adm : M → Bool) :
Signer SK M Sig

The restriction of s to the queries accepted by adm: answer an admissible query as s does and refuse every other one. A refused query is answered with default and is not logged, so under oneTime or counter it uses up no answer and no counter value.

def Cslib.Crypto.Signer.oneTime {SK M Sig : Type} (s : Signer SK M Sig) :
Signer SK M Sig

The one-time restriction of s: answer the first query as s does, refuse every later one.

def Cslib.Crypto.Signer.indexed {SK M Sig : Type} (cap : ℕ) (sign : SK → ℕ → M → ProbComp Sig) :
Signer SK (ℕ × M) Sig

The indexed policy with capacity cap: a query (u, m) is signed with sign sk u m when u < cap and the index u has not been used.

def Cslib.Crypto.Signer.counter {SK M Sig : Type} (cap : ℕ) (sign : SK → ℕ → M → ProbComp Sig) :
Signer SK M (ℕ × Sig)

The counter policy with capacity cap: the i-th answered query is signed with index i and the signature carries i; queries after the first cap are refused.

@[simp]
theorem Cslib.Crypto.Signer.ofSign_apply {SK M Sig : Type} (sign : SK → M → ProbComp Sig) (sk : SK) (log : List (M × Sig)) (m : M) :
ofSign sign sk log m = some (sign sk m)
@[simp]
theorem Cslib.Crypto.Signer.restrict_apply {SK M Sig : Type} (s : Signer SK M Sig) (adm : M → Bool) (sk : SK) (log : List (M × Sig)) (m : M) :
s.restrict adm sk log m = if adm m = true then s sk log m else none
@[simp]
theorem Cslib.Crypto.Signer.oneTime_nil {SK M Sig : Type} (s : Signer SK M Sig) (sk : SK) (m : M) :
s.oneTime sk [] m = s sk [] m
@[simp]
theorem Cslib.Crypto.Signer.oneTime_cons {SK M Sig : Type} (s : Signer SK M Sig) (sk : SK) (p : M × Sig) (log : List (M × Sig)) (m : M) :
s.oneTime sk (p :: log) m = none
def Cslib.Crypto.forgeExperiment {PK SK M Sig : Type} [Inhabited Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (fresh : M → Sig → List (M × Sig) → Bool) (A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)) :

The forgery experiment ([BS23], Attack Games 6.1 and 13.1): draw (pk, sk) from keyGen, run the forger on pk against the signing oracle of the policy signer at sk, and accept its candidate (m, σ) when verify pk sk m σ holds and fresh m σ log holds for the log of answered queries.

def Cslib.Crypto.freshMessage {M Sig : Type} [DecidableEq M] (m : M) :
Sig → (log : List (M × Sig)) → Bool

Existential freshness: the message m was never signed.

def Cslib.Crypto.freshPair {M Sig : Type} [DecidableEq M] [DecidableEq Sig] (m : M) (σ : Sig) (log : List (M × Sig)) :

Strong freshness: the pair (m, σ) was never an answer of the signing oracle.

def Cslib.Crypto.oneTimeForgeExperiment {SK M Sig : Type} {P : Type → Type} [Monad P] [DecidableEq M] [DecidableEq Sig] {σ : Type} (keyGen : P SK) (sign : SK → M → P Sig) (verify : SK → M → Sig → Bool) (choose : P (M × σ)) (guess : σ → Sig → P (M × Sig)) :

The fresh-pair MAC experiment with one signing response ([BS23], Attack Game 6.1 restricted as in Section 7.6). The forger chooses its query and saves private state, then receives the tag before producing its candidate. This works for probabilistic programs and their distribution semantics.

theorem Cslib.Crypto.freshPair_of_freshMessage {M Sig : Type} [DecidableEq M] [DecidableEq Sig] {m : M} {σ : Sig} {log : List (M × Sig)} (h : freshMessage m σ log = true) :
freshPair m σ log = true

A message that was never signed is not part of any answered pair.

theorem Cslib.Crypto.eval_forgeExperiment_eq {PK SK M Sig : Type} [Inhabited Sig] (keyGen : ProbComp (PK × SK)) (signer : Signer SK M Sig) (verify : PK → SK → M → Sig → Bool) (fresh : M → Sig → List (M × Sig) → Bool) (A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)) :
ProbComp.eval (forgeExperiment keyGen signer verify fresh A) = keyGen.eval.bind fun (x : PK × SK) => match x with | (pk, sk) => PMF.map (fun (x : (M × Sig) × List (M × Sig)) => match x with | ((m, σ), log) => verify pk sk m σ && fresh m σ log) ((A pk).runLogWith (signer sk)).eval

The law of the forgery experiment, as an event of the logged run.

theorem Cslib.Crypto.succProbability_forgeExperiment_mono {PK SK M Sig : Type} [Inhabited Sig] {keyGen : ProbComp (PK × SK)} {signer : Signer SK M Sig} {verify : PK → SK → M → Sig → Bool} {fresh fresh' : M → Sig → List (M × Sig) → Bool} (h : ∀ (m : M) (σ : Sig) (log : List (M × Sig)), fresh m σ log = true → fresh' m σ log = true) (A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)) :
(forgeExperiment keyGen signer verify fresh A).succProbability ≤ (forgeExperiment keyGen signer verify fresh' A).succProbability

Freshness is monotone: replacing the freshness test by a weaker one does not decrease the success probability of any forger.

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

Strong unforgeability implies existential unforgeability: a forger succeeds at least as often in the strong experiment as in the existential one.

theorem Cslib.Crypto.forgeExperiment_freshPair_eq_freshMessage_of_unique {PK SK M Sig : Type} [Inhabited Sig] {keyGen : ProbComp (PK × SK)} {signer : Signer SK M Sig} {verify : PK → SK → M → Sig → Bool} [DecidableEq M] [DecidableEq Sig] (hunique : ∀ keys ∈ keyGen.eval.support, ∀ (m : M) (σ : Sig), verify keys.1 keys.2 m σ = true → ∀ (log : List (M × Sig)) (program : ProbComp Sig), signer keys.2 log m = some program → ∀ σ' ∈ program.eval.support, σ' = σ) (A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)) :
ProbComp.eval (forgeExperiment keyGen signer verify freshPair A) = ProbComp.eval (forgeExperiment keyGen signer verify freshMessage A)

Unique oracle answers on valid messages: when every valid pair (m, σ) under a supported key pair agrees with every answer σ' that signer can produce on m, strong and existential forgery are the same experiment (even when signer also answers queries outside the domain of verify).

theorem Cslib.Crypto.forgeExperiment_freshPair_eq_freshMessage {PK SK M Sig : Type} [Inhabited Sig] {keyGen : ProbComp (PK × SK)} {signer : Signer SK M Sig} {verify : PK → SK → M → Sig → Bool} [DecidableEq M] [DecidableEq Sig] (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) (hunique : ∀ keys ∈ keyGen.eval.support, ∀ (m : M) (σ σ' : Sig), verify keys.1 keys.2 m σ = true → verify keys.1 keys.2 m σ' = true → σ = σ') (A : PK → ProbOracleComp (fun (x : M) => Sig) (M × Sig)) :
ProbComp.eval (forgeExperiment keyGen signer verify freshPair A) = ProbComp.eval (forgeExperiment keyGen signer verify freshMessage A)

Unique signatures: when every signature that the policy produces verifies and each message has at most one valid signature, a strong forgery is an existential one, so the two experiments coincide.