Documentation

CslibFrontier.Crypto.Computational.TwoStage

Two-stage adversaries and the left-or-right experiment #

Many attack games run the adversary twice. It first receives the challenger's public input and chooses a challenge request, then receives the challenge and answers. Between the two calls it keeps a saved state. TwoStage I₁ O₁ I₂ O σ is such an adversary: choose maps the first input to a request and a state of type σ, and guess maps the state and the challenge to the answer. The state type is a parameter, so a saved state can be a typed record.

TwoStage.IsPPT states that a family of two-stage adversaries, one for each security parameter, is uniform strict PPT: one finite machine for each stage, reading the unary security parameter and the encoded stage input, including the full encoded saved state. Security definitions over two-stage adversaries quantify over every state type and state encoding. The word-level adversaries with state List Bool are the instance σ := List Bool, encσ := encBits, so a typed definition quantifying over every σ implies the word-level one. The converse is not free: it needs a word-level adversary that simulates the second stage on the encσ codewords.

lrExperiment is the left-or-right experiment. The adversary chooses two messages from the drawn public input; the challenger checks the pair with an admissibility predicate, encrypts the message selected by the bit and gives the challenge to the adversary, whose guess is the output. An inadmissible pair outputs false on both sides. This is the challenge phase of single-challenge IND-CPA ([BS23], Section 11.2, Attack Game 11.1, p. 436); key generation belongs to the scheme's own experiment, which draws the public input and then runs lrExperiment.

Main definitions #

Main results #

References #

structure Cslib.Crypto.TwoStage (I₁ O₁ I₂ O σ : Type) :

A two-stage adversary. choose receives the first input, of type I₁, and returns a request of type O₁ together with a saved state of type σ; guess receives the saved state and the second input, of type I₂, and returns its answer, of type O. The state is all that the adversary retains between the stages.

  • choose : I₁ → ProbComp (O₁ × σ)

    Receive the first input and return a request and a saved state.

  • guess : σ → I₂ → ProbComp O

    Receive the saved state and the second input and return the answer.

structure Cslib.Crypto.TwoStage.IsPPT {I₁ O₁ I₂ O σ : Type} (encI₁ : I₁ ↪ List Bool) (encO₁ : O₁ ↪ List Bool) (encI₂ : I₂ ↪ List Bool) (encO : O ↪ List Bool) (encσ : σ ↪ List Bool) (A : ℕ → TwoStage I₁ O₁ I₂ O σ) :

A family of two-stage adversaries, one for each security parameter, is uniform strict PPT: one finite machine runs each stage at every parameter. The choice stage reads the unary security parameter and the encoded first input; the guessing stage reads the unary security parameter, the encoded saved state and the encoded second input. Each clock charges the complete encoded input, including the saved state.

A pair of challenge messages.

  • msg₀ : M

    The message encrypted when the challenge bit is false.

  • msg₁ : M

    The message encrypted when the challenge bit is true.

The message selected by the challenge bit b: msg₀ for false and msg₁ for true.

A message pair is the ordered pair (msg₀, msg₁).

The encoding of a message pair: the encoding encPair encM encM of (msg₀, msg₁), that is msg₀ framed, then msg₁. The encoded words are those of the former tuple encoding.

@[simp]
theorem Cslib.Crypto.encMessagePair_apply {M : Type} {encM : M ↪ List Bool} (pair : MessagePair M) :
(encMessagePair encM) pair = (Turing.MultiTapeTM.encPair encM encM) (pair.msg₀, pair.msg₁)
theorem Cslib.Crypto.encMessagePair_msg₀_polyTime {M γ : Type} {encM : M ↪ List Bool} {encIn : γ ↪ List Bool} {g : γ → MessagePair M} (h : Turing.MultiTapeTM.ComputableInPolyTime g encIn (encMessagePair encM)) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (a : γ) => (g a).msg₀) encIn encM

The first message of a computed message pair is computed in polynomial time.

theorem Cslib.Crypto.encMessagePair_msg₁_polyTime {M γ : Type} {encM : M ↪ List Bool} {encIn : γ ↪ List Bool} {g : γ → MessagePair M} (h : Turing.MultiTapeTM.ComputableInPolyTime g encIn (encMessagePair encM)) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (a : γ) => (g a).msg₁) encIn encM

The second message of a computed message pair is computed in polynomial time.

theorem Cslib.Crypto.encMessagePair_mk_polyTime {M γ : Type} {encM : M ↪ List Bool} {encIn : γ ↪ List Bool} {x₀ x₁ : γ → M} (h₀ : Turing.MultiTapeTM.ComputableInPolyTime x₀ encIn encM) (h₁ : Turing.MultiTapeTM.ComputableInPolyTime x₁ encIn encM) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (a : γ) => { msg₀ := x₀ a, msg₁ := x₁ a }) encIn (encMessagePair encM)

A message pair of two computed messages is computed in polynomial time.

def Cslib.Crypto.lrExperiment {I₁ M C σ : Type} (valid : I₁ → M → M → Bool) (enc : I₁ → M → ProbComp C) (A : TwoStage I₁ (MessagePair M) C Bool σ) (b : Bool) (x : I₁) :

The left-or-right experiment ([BS23], Attack Game 11.1, challenge phase) on the drawn public input x. The adversary chooses a message pair and a state from x. If valid x msg₀ msg₁ holds, the challenger encrypts the message selected by b under x and returns the adversary's guess on the state and the challenge; otherwise it returns false, on both sides.

@[simp]
theorem Cslib.Crypto.eval_lrExperiment {I₁ M C σ : Type} (valid : I₁ → M → M → Bool) (enc : I₁ → M → ProbComp C) (A : TwoStage I₁ (MessagePair M) C Bool σ) (b : Bool) (x : I₁) :
ProbComp.eval (lrExperiment valid enc A b x) = (A.choose x).eval.bind fun (p : MessagePair M × σ) => if valid x p.1.msg₀ p.1.msg₁ = true then (enc x (p.1.select b)).eval.bind fun (c : C) => (A.guess p.2 c).eval else PMF.pure false

The output distribution of the left-or-right experiment: the adversary chooses a message pair and a state; on an admissible pair the challenge encrypts the message selected by b and the output is the adversary's guess, and on an inadmissible pair the output is false.