Documentation

CslibFrontier.Crypto.Computational.KeyExchange

Key exchange secure against eavesdroppers #

A two-party key-exchange protocol is described here by the law of its honest execution: the transcript of messages that an eavesdropper sees, the key output by Alice and the key output by Bob. Keys may live in a set named by the transcript, such as the group chosen in Diffie–Hellman, so the key type is a family K : T → Type. The protocol is correct when the two keys agree on every execution.

Security against a passive eavesdropper ([KL20], Section 11.3, Definition 11.1, p. 392; compare the session-key indistinguishability remark in [BS23], Section 10.1, p. 400) compares a real experiment, in which the adversary receives the view made of the transcript and Alice's key, with an ideal experiment, in which the view pairs the transcript with an independently drawn ideal key. Saying that an adversary guesses a hidden uniform bit with probability at most 1 / 2 + negl(n) is the same as requiring negligible advantage between the real and the ideal experiment. Both experiments are "draw a view, then run the eavesdropper on it" (Game.withSetup), for the view laws realView and idealView of an execution law. The ideal key may depend on the transcript through idealKey : ℕ → (t : T) → PMF (K t); Definition 11.1 draws a uniform n-bit word (EavSecureBits), while [KL20], Theorem 11.3 (p. 394, locator not verified) uses a uniform element of the group named in the transcript (dhIdealKey).

Eavesdroppers are typed: an Eavesdropper T K receives the security parameter and a View T K. Encodings appear only in its efficiency predicate Eavesdropper.IsPPT, which reads the view through encView, and in encOutcome for certifying honest execution programs.

We formalize:

Honest-party efficiency is unbundled from KeyExchange; for dhExecutionProb, uniform strict PPT efficiency on (1ⁿ, d) (or on 1ⁿ along a polynomial-time group schedule) is proved separately in isPPTOn_dhExecutionProb.

Main definitions #

Main results #

Ideal-sampling steps #

References #

structure Cslib.Crypto.KeyExchange.Outcome (T : Type) (K : T → Type) :

The result of one honest execution of a two-party key-exchange protocol: the transcript seen by an eavesdropper and the keys output by Alice and by Bob, which lie in the key set K transcript named by the transcript.

  • transcript : T

    All messages sent between the parties.

  • aliceKey : K self.transcript

    The key output by Alice.

  • bobKey : K self.transcript

    The key output by Bob.

structure Cslib.Crypto.KeyExchange (T : Type) (K : T → Type) :

A two-party key-exchange protocol with transcripts in T and keys in K transcript, described by the law of its honest execution at each security parameter.

  • execute : ℕ → PMF (Outcome T K)

    The law of the transcript and both keys when Alice and Bob run the protocol honestly.

def Cslib.Crypto.KeyExchange.Correct {T : Type} {K : T → Type} (protocol : KeyExchange T K) :

A key-exchange protocol is correct when Alice and Bob output the same key on every honest execution ([KL20], Section 11.3, p. 391).

theorem Cslib.Crypto.KeyExchange.encOutcome_aliceKey_budget {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → Outcome T K} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encOutcome encT encK) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (encK (g✝ c).transcript) (g✝ c).aliceKey) encIn✝ Turing.MultiTapeTM.encBits S✝
theorem Cslib.Crypto.KeyExchange.encOutcome_transcript_budget {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → Outcome T K} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encOutcome encT encK) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).transcript) encIn✝ encT S✝
theorem Cslib.Crypto.KeyExchange.encOutcome_fields_deg {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInDegree (fun (a : Outcome T K) => (a.transcript, (encK a.transcript) a.aliceKey, (encK a.transcript) a.bobKey)) (encOutcome encT encK) (encOutcomeFields encT encK) 1 1
theorem Cslib.Crypto.KeyExchange.encOutcome_bobKey_polyTime {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → Outcome T K} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encOutcome encT encK) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (encK (g✝ c).transcript) (g✝ c).bobKey) encIn✝ Turing.MultiTapeTM.encBits
theorem Cslib.Crypto.KeyExchange.encOutcome_mk_polyTime {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → T} {x1 x2 : (c : γ) → K (x0 c)} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn encT) (h1 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => (encK (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits) (h2 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => (encK (x0 c)) (x2 c)) encIn Turing.MultiTapeTM.encBits) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { transcript := x0 x, aliceKey := x1 x, bobKey := x2 x }) encIn (encOutcome encT encK)
@[simp]
theorem Cslib.Crypto.KeyExchange.encOutcome_apply {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (a : Outcome T K) :
(encOutcome encT encK) a = (encOutcomeFields encT encK) (a.transcript, (encK a.transcript) a.aliceKey, (encK a.transcript) a.bobKey)
theorem Cslib.Crypto.KeyExchange.encOutcome_aliceKey_polyTime {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → Outcome T K} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encOutcome encT encK) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (encK (g✝ c).transcript) (g✝ c).aliceKey) encIn✝ Turing.MultiTapeTM.encBits
theorem Cslib.Crypto.KeyExchange.encOutcome_mk_inO {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → T} {T0 S0 : γ → ℕ} {x1 : (c : γ) → K (x0 c)} {T1 S1 : γ → ℕ} {x2 : (c : γ) → K (x0 c)} {T2 S2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encT T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => (encK (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => (encK (x0 c)) (x2 c)) encIn Turing.MultiTapeTM.encBits T2 S2) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { transcript := x0 x, aliceKey := x1 x, bobKey := x2 x }) encIn (encOutcome encT encK) (fun (x : γ) => T0 x + (T1 x + T2 x)) fun (x : γ) => S0 x + (S1 x + S2 x)
theorem Cslib.Crypto.KeyExchange.encOutcome_bobKey_length_le {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (a : Outcome T K) :
(Turing.MultiTapeTM.encBits ((fun (a : Outcome T K) => (encK a.transcript) a.bobKey) a)).length ≤ ((encOutcome encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encOutcome_bobKey_deg {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
theorem Cslib.Crypto.KeyExchange.encOutcome_aliceKey_length_le {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (a : Outcome T K) :
(Turing.MultiTapeTM.encBits ((fun (a : Outcome T K) => (encK a.transcript) a.aliceKey) a)).length ≤ ((encOutcome encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encOutcome_aliceKey_deg {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
theorem Cslib.Crypto.KeyExchange.encOutcome_transcript_deg {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInDegree (fun (a : Outcome T K) => a.transcript) (encOutcome encT encK) encT 1 1
theorem Cslib.Crypto.KeyExchange.encOutcome_aliceKey_inO {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInO (fun (a : Outcome T K) => (encK a.transcript) a.aliceKey) (encOutcome encT encK) Turing.MultiTapeTM.encBits (fun (a : Outcome T K) => ((encOutcome encT encK) a).length) fun (a : Outcome T K) => ((encOutcome encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encOutcome_bobKey_budget {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → Outcome T K} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encOutcome encT encK) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (encK (g✝ c).transcript) (g✝ c).bobKey) encIn✝ Turing.MultiTapeTM.encBits S✝
def Cslib.Crypto.KeyExchange.encOutcome {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :

The encoding of an honest-execution outcome: the transcript encoded by encT, Alice's key encoded by encK transcript, and Bob's key encoded by encK transcript, each framed except the last (encOutcome_apply).

theorem Cslib.Crypto.KeyExchange.encOutcome_bobKey_inO {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInO (fun (a : Outcome T K) => (encK a.transcript) a.bobKey) (encOutcome encT encK) Turing.MultiTapeTM.encBits (fun (a : Outcome T K) => ((encOutcome encT encK) a).length) fun (a : Outcome T K) => ((encOutcome encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encOutcome_transcript_length_le {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (a : Outcome T K) :
(encT ((fun (a : Outcome T K) => a.transcript) a)).length ≤ ((encOutcome encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encOutcome_transcript_inO {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInO (fun (a : Outcome T K) => a.transcript) (encOutcome encT encK) encT (fun (a : Outcome T K) => ((encOutcome encT encK) a).length) fun (a : Outcome T K) => ((encOutcome encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encOutcome_mk_budget {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → T} {x1 x2 : (c : γ) → K (x0 c)} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encT budget) (h1 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => (encK (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits budget) (h2 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => (encK (x0 c)) (x2 c)) encIn Turing.MultiTapeTM.encBits budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { transcript := x0 x, aliceKey := x1 x, bobKey := x2 x }) encIn (encOutcome encT encK) budget
@[reducible, inline]
abbrev Cslib.Crypto.KeyExchange.encOutcomeFields {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :

The tuple of the fields of encOutcome.

theorem Cslib.Crypto.KeyExchange.encOutcome_transcript_polyTime {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → Outcome T K} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encOutcome encT encK) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (g✝ c).transcript) encIn✝ encT
structure Cslib.Crypto.KeyExchange.View (T : Type) (K : T → Type) :

What an eavesdropper is given: a transcript and a candidate key for it.

  • transcript : T

    All messages sent between the parties.

  • key : K self.transcript

    The candidate key: Alice's key in the real experiment, an ideal key in the ideal one.

def Cslib.Crypto.KeyExchange.encView {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :

The encoding of a view: the transcript encoded by encT, framed, then the key encoded by encK transcript (encView_apply).

theorem Cslib.Crypto.KeyExchange.encView_key_budget {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → View T K} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encView encT encK) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (encK (g✝ c).transcript) (g✝ c).key) encIn✝ Turing.MultiTapeTM.encBits S✝
theorem Cslib.Crypto.KeyExchange.encView_transcript_inO {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInO (fun (a : View T K) => a.transcript) (encView encT encK) encT (fun (a : View T K) => ((encView encT encK) a).length) fun (a : View T K) => ((encView encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encView_key_deg {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
@[reducible, inline]
abbrev Cslib.Crypto.KeyExchange.encViewFields {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :

The tuple of the fields of encView.

theorem Cslib.Crypto.KeyExchange.encView_mk_polyTime {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → T} {x1 : (c : γ) → K (x0 c)} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn encT) (h1 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => (encK (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { transcript := x0 x, key := x1 x }) encIn (encView encT encK)
theorem Cslib.Crypto.KeyExchange.encView_transcript_length_le {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (a : View T K) :
(encT ((fun (a : View T K) => a.transcript) a)).length ≤ ((encView encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encView_fields_deg {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInDegree (fun (a : View T K) => (a.transcript, (encK a.transcript) a.key)) (encView encT encK) (encViewFields encT encK) 1 1
theorem Cslib.Crypto.KeyExchange.encView_mk_inO {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → T} {T0 S0 : γ → ℕ} {x1 : (c : γ) → K (x0 c)} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encT T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => (encK (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits T1 S1) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { transcript := x0 x, key := x1 x }) encIn (encView encT encK) (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
theorem Cslib.Crypto.KeyExchange.encView_transcript_polyTime {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → View T K} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encView encT encK) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (g✝ c).transcript) encIn✝ encT
theorem Cslib.Crypto.KeyExchange.encView_key_length_le {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (a : View T K) :
(Turing.MultiTapeTM.encBits ((fun (a : View T K) => (encK a.transcript) a.key) a)).length ≤ ((encView encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encView_key_polyTime {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → View T K} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encView encT encK) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (encK (g✝ c).transcript) (g✝ c).key) encIn✝ Turing.MultiTapeTM.encBits
@[simp]
theorem Cslib.Crypto.KeyExchange.encView_apply {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (a : View T K) :
(encView encT encK) a = (encViewFields encT encK) (a.transcript, (encK a.transcript) a.key)
theorem Cslib.Crypto.KeyExchange.encView_key_inO {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInO (fun (a : View T K) => (encK a.transcript) a.key) (encView encT encK) Turing.MultiTapeTM.encBits (fun (a : View T K) => ((encView encT encK) a).length) fun (a : View T K) => ((encView encT encK) a).length
theorem Cslib.Crypto.KeyExchange.encView_mk_budget {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → T} {x1 : (c : γ) → K (x0 c)} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encT budget) (h1 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => (encK (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { transcript := x0 x, key := x1 x }) encIn (encView encT encK) budget
theorem Cslib.Crypto.KeyExchange.encView_transcript_deg {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :
Turing.MultiTapeTM.ComputableInDegree (fun (a : View T K) => a.transcript) (encView encT encK) encT 1 1
theorem Cslib.Crypto.KeyExchange.encView_transcript_budget {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → View T K} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encView encT encK) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).transcript) encIn✝ encT S✝
noncomputable def Cslib.Crypto.KeyExchange.realView {T : Type} {K : T → Type} (execution : PMF (Outcome T K)) :
PMF (View T K)

The real view: run the protocol honestly and pair the transcript with Alice's key. This is what the adversary sees in KE^eav with hidden bit 0 ([KL20], p. 391).

noncomputable def Cslib.Crypto.KeyExchange.idealView {T : Type} {K : T → Type} (idealKey : (t : T) → PMF (K t)) (execution : PMF (Outcome T K)) :
PMF (View T K)

The ideal view: run the protocol honestly and pair the transcript with a fresh key drawn from idealKey transcript. This is what the adversary sees in KE^eav with hidden bit 1 ([KL20], p. 391).

@[reducible, inline]

An eavesdropper: given the security parameter and a view, it outputs a bit. Eavesdropper.IsPPT states its efficiency on encodings.

@[reducible, inline]
abbrev Cslib.Crypto.KeyExchange.encEavInput {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) :

Eavesdropper input (1ⁿ, view): the security parameter in unary, then the view encoded by encView encT encK. For a constant key encoding these are the words of encPair encUnary (encPair encT encK) on (n, (transcript, key)).

def Cslib.Crypto.KeyExchange.Eavesdropper.IsPPT {T : Type} {K : T → Type} (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (adversary : Eavesdropper T K) :

An eavesdropper is PPT when one uniform strict PPT machine reads encEavInput encT encK and writes the adversary's bit.

noncomputable def Cslib.Crypto.KeyExchange.realGame {T : Type} {K : T → Type} (protocol : KeyExchange T K) (adversary : Eavesdropper T K) (n : ℕ) :

The real eavesdropping experiment KE^eav with hidden bit 0: draw the real view, then run the eavesdropper on it.

noncomputable def Cslib.Crypto.KeyExchange.idealGame {T : Type} {K : T → Type} (protocol : KeyExchange T K) (idealKey : ℕ → (t : T) → PMF (K t)) (adversary : Eavesdropper T K) (n : ℕ) :

The ideal eavesdropping experiment KE^eav with hidden bit 1: draw the ideal view with key law idealKey n, then run the eavesdropper on it.

def Cslib.Crypto.KeyExchange.EavSecure {T : Type} {K : T → Type} (protocol : KeyExchange T K) (encT : T ↪ List Bool) (encK : (t : T) → K t ↪ List Bool) (idealKey : ℕ → (t : T) → PMF (K t)) :

Security against eavesdroppers with ideal-key law idealKey: every uniform strict PPT eavesdropper has negligible advantage between realGame and idealGame.

@[reducible, inline]
abbrev Cslib.Crypto.KeyExchange.EavSecureBits {T : Type} (protocol : KeyExchange T fun (x : T) => List Bool) (encT : T ↪ List Bool) :

Security against eavesdroppers for bit-word keys ([KL20], Definition 11.1, p. 392): the ideal key is a uniform n-bit word, independent of the transcript.

theorem Cslib.Crypto.KeyExchange.withSetup_realView_bind {T : Type} {K : T → Type} {P : Type} (setup : PMF P) (execution : P → PMF (Outcome T K)) (exp : View T K → Experiment) :
Game.withSetup (realView (setup.bind execution)) exp = setup.bind fun (p : P) => Game.withSetup (realView (execution p)) exp

For a protocol that first draws public parameters p from setup, then runs the execution execution p, the real experiment draws p and then runs the fixed real experiment of execution p.

theorem Cslib.Crypto.KeyExchange.withSetup_idealView_bind {T : Type} {K : T → Type} {P : Type} (setup : PMF P) (execution : P → PMF (Outcome T K)) (idealKey : (t : T) → PMF (K t)) (exp : View T K → Experiment) :
Game.withSetup (idealView idealKey (setup.bind execution)) exp = setup.bind fun (p : P) => Game.withSetup (idealView idealKey (execution p)) exp

For a protocol that first draws public parameters p from setup, then runs the execution execution p, the ideal experiment draws p and then runs the fixed ideal experiment of execution p.

The Diffie–Hellman protocol #

A Diffie–Hellman transcript: the group parameters chosen by Alice and the public shares hA = x • g of Alice and hB = y • g of Bob in that group.

theorem Cslib.Crypto.PrimeOrderGroupFamily.encDHTranscript_mk_inO (F : PrimeOrderGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → F.Desc} {T0 S0 : γ → ℕ} {x1 : (c : γ) → F.Carrier (x0 c)} {T1 S1 : γ → ℕ} {x2 : (c : γ) → F.Carrier (x0 c)} {T2 S2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn F.encDesc T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => F.encode (x0 c) (x1 c)) encIn Turing.MultiTapeTM.encBits T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => F.encode (x0 c) (x2 c)) encIn Turing.MultiTapeTM.encBits T2 S2) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { groupParameters := x0 x, aliceShare := x1 x, bobShare := x2 x }) encIn F.encDHTranscript (fun (x : γ) => T0 x + (T1 x + T2 x)) fun (x : γ) => S0 x + (S1 x + S2 x)
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDHTranscript_groupParameters_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DHTranscript} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ F.encDHTranscript S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).groupParameters) encIn✝ F.encDesc S✝
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDHTranscript_mk_budget (F : PrimeOrderGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → F.Desc} {x1 x2 : (c : γ) → F.Carrier (x0 c)} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn F.encDesc budget) (h1 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => F.encode (x0 c) (x1 c)) encIn Turing.MultiTapeTM.encBits budget) (h2 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => F.encode (x0 c) (x2 c)) encIn Turing.MultiTapeTM.encBits budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { groupParameters := x0 x, aliceShare := x1 x, bobShare := x2 x }) encIn F.encDHTranscript budget

The encoding of a Diffie–Hellman transcript: the group parameters and the words F.encode d hA, F.encode d hB of the shares, each framed except the last (encDHTranscript_apply).

theorem Cslib.Crypto.PrimeOrderGroupFamily.encDHTranscript_bobShare_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DHTranscript} :
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDHTranscript_mk_polyTime (F : PrimeOrderGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → F.Desc} {x1 x2 : (c : γ) → F.Carrier (x0 c)} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn F.encDesc) (h1 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => F.encode (x0 c) (x1 c)) encIn Turing.MultiTapeTM.encBits) (h2 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => F.encode (x0 c) (x2 c)) encIn Turing.MultiTapeTM.encBits) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { groupParameters := x0 x, aliceShare := x1 x, bobShare := x2 x }) encIn F.encDHTranscript
@[reducible, inline]

A Diffie–Hellman key is an element of the group named in the transcript.

A Diffie–Hellman key is encoded as an element of the group named in the transcript.

@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDHKey_apply (F : PrimeOrderGroupFamily) (transcript : F.DHTranscript) (key : F.DHKey transcript) :
(F.encDHKey transcript) key = F.encode transcript.groupParameters key

A computed Diffie–Hellman key is encoded by the word of the computed group element.

The honest Diffie–Hellman execution in the group d ([KL20], Construction 11.2, pp. 392–393). Alice draws a uniform exponent x and sends d and hA = x • g; Bob draws a uniform exponent y and sends hB = y • g. Alice outputs x • hB and Bob outputs y • hA. Both exponents are drawn exactly uniformly on ZMod q at the PMF level, an ideal sampler that no fair-coin machine with a strict polynomial time bound realizes exactly when q is not a power of two (#5293).

The Diffie–Hellman key-exchange protocol ([KL20], Construction 11.2): Alice draws the group parameters d from setup n, then the parties run dhExecution d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.mem_support_dhExecution (F : PrimeOrderGroupFamily) {d : F.Desc} {outcome : KeyExchange.Outcome F.DHTranscript F.DHKey} (h : outcome ∈ (F.dhExecution d).support) :
∃ (x : ZMod (F.order d)) (y : ZMod (F.order d)), outcome = { transcript := { groupParameters := d, aliceShare := x • F.generator d, bobShare := y • F.generator d }, aliceKey := (x * y) • F.generator d, bobKey := (x * y) • F.generator d }

Every honest Diffie–Hellman execution in the group d is (d, x • g, y • g) with both keys equal to (x * y) • g.

Alice and Bob output the same key, (x * y) • g ([KL20], p. 393).

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.dhIdealKey (F : PrimeOrderGroupFamily) (transcript : F.DHTranscript) :
PMF (F.DHKey transcript)

The ideal key of [KL20], Theorem 11.3 (p. 394): a uniform element of the group named in the transcript.

Run an eavesdropper on Diffie–Hellman views as a DDH distinguisher: the elements (u, v, w) of the group d are passed on as the transcript (d, u, v) with key w.

At a fixed group, the real eavesdropping experiment on Diffie–Hellman is the real DDH experiment.

At a fixed group and with the uniform group element as ideal key, the ideal eavesdropping experiment on Diffie–Hellman is the random DDH experiment.

The real eavesdropping experiment on Diffie–Hellman is the real DDH experiment.

theorem Cslib.Crypto.PrimeOrderGroupFamily.idealGame_dhKeyExchange (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (adversary : KeyExchange.Eavesdropper F.DHTranscript F.DHKey) (n : ℕ) :
(F.dhKeyExchange setup).idealGame (fun (x : ℕ) => F.dhIdealKey) adversary n = F.ddhRandomGame setup (F.dhEavToDDH adversary) n

With the uniform group element as ideal key, the ideal eavesdropping experiment on Diffie–Hellman is the random DDH experiment.

The distinguisher dhEavToDDH is uniform strict PPT when the eavesdropper is.

Ideal-sampling step toward [KL20], Theorem 11.3, p. 394 (locator not verified), not the cited result: if the Decisional Diffie–Hellman assumption holds for setup, then no uniform strict PPT eavesdropper distinguishes the transcript and Alice's key of dhKeyExchange setup, whose parties draw their exponents exactly uniformly on ZMod q at the PMF level, from the transcript and a uniform element of the same group. Consumed by DDH.dhKeyExchangeProb_eavSecure, which replaces exact uniform exponent draws with the fair-coin sampler sampleExp.

Fair-coin Diffie–Hellman execution #

The honest fair-coin Diffie–Hellman execution in the group d at security parameter n ([BS23], Section 10.4.1, Figure 10.2, pp. 407–408). Alice and Bob each sample an exponent with F.sampleExp n d (within statistical distance 1 / 2 ^ n of uniform on ZMod (F.order d)); Alice sends hA = x • g and Bob sends hB = y • g, and Alice outputs x • hB while Bob outputs y • hA.

The fair-coin Diffie–Hellman key-exchange protocol ([BS23], Section 10.4.1, Figure 10.2, pp. 407–408): public group parameters d are drawn from setup n, then Alice and Bob run dhExecutionProb n d using sampleExp.

dhExecutionProb is uniform strict PPT whenever n and d are computable in polynomial time.

In every honest fair-coin Diffie–Hellman execution, Alice and Bob output the same key ((x : ZMod q) * y) • g.

Replacing dhKeyExchangeProb by the exact-uniform dhKeyExchange before any Boolean game continuation k changes Game.advantage by at most 2 / 2 ^ n (1 / 2 ^ n for each party's sampleExp draw).

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_eavGame_dhKeyExchangeProb_le (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (adversary : KeyExchange.Eavesdropper F.DHTranscript F.DHKey) (n : ℕ) :
((F.dhKeyExchangeProb setup).realGame adversary n).advantage ((F.dhKeyExchangeProb setup).idealGame (fun (x : ℕ) => F.dhIdealKey) adversary n) ≤ (F.ddhRealGame setup (F.dhEavToDDH adversary) n).advantage (F.ddhRandomGame setup (F.dhEavToDDH adversary) n) + 4 / 2 ^ n

Against dhKeyExchangeProb, any eavesdropper's advantage between the real key and the uniform group-element ideal key dhIdealKey is at most its DDH advantage via dhEavToDDH plus the 4 / 2 ^ n fair-coin sampling loss (2 / 2 ^ n in each of the real and ideal games).

Under DDH, Diffie–Hellman key exchange is secure against passive eavesdroppers ([KL20], Section 11.3, Theorem 11.3, p. 394, locator not verified; registration pending a source check against [KL20] Chapter 11, #5657; compare the session-key indistinguishability remark of [BS23], Section 10.1, p. 400): if F.DDH setup holds, then the fair-coin protocol dhKeyExchangeProb setup satisfies KeyExchange.EavSecure against uniform strict PPT eavesdroppers when the ideal key is the uniform group element dhIdealKey. Derived from DDH.dhKeyExchange_eavSecure_ideal and advantage_bind_dhKeyExchangeProb_le with fair-coin sampling loss at most 4 / 2 ^ n.

The man-in-the-middle attack #

The outcome of the man-in-the-middle attack of [KL20], Exercise 11.3 (p. 399): the view of Alice and of Bob, each made of the transcript that party sees and the key it outputs, and the keys the adversary computes for its sessions with each of them.

The man-in-the-middle attack on Diffie–Hellman in the group d ([KL20], Exercise 11.3, p. 399). Alice and Bob run Construction 11.2 honestly with exponents x and y. The adversary draws its own exponents x' and y', delivers hB' = y' • g to Alice in place of hB and hA' = x' • g to Bob in place of hA, and computes y' • hA and x' • hB. Over a setup law, the attack draws d first.

In the man-in-the-middle attack the adversary knows the key Alice outputs and the key Bob outputs.

Alice cannot detect the attack: her view has exactly the law of the eavesdropper's view of an honest Diffie–Hellman execution.

Bob cannot detect the attack: his view has exactly the law of the eavesdropper's view of an honest Diffie–Hellman execution.

A protocol built from XOR masks #

A transcript of the protocol of [KL20], Exercise 11.4: three bit words.

  • aliceFirst : List Bool

    Alice's first message s = k ⊕ r.

  • bobReply : List Bool

    Bob's reply u = s ⊕ t.

  • aliceSecond : List Bool

    Alice's second message w = u ⊕ r.

theorem Cslib.Crypto.KeyExchange.encXorTranscript_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List Bool} {T0 S0 : γ → ℕ} {x1 : γ → List Bool} {T1 S1 : γ → ℕ} {x2 : γ → List Bool} {T2 S2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encBits T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encBits T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO x2 encIn Turing.MultiTapeTM.encBits T2 S2) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { aliceFirst := x0 x, bobReply := x1 x, aliceSecond := x2 x }) encIn encXorTranscript (fun (x : γ) => T0 x + (T1 x + T2 x)) fun (x : γ) => S0 x + (S1 x + S2 x)
theorem Cslib.Crypto.KeyExchange.encXorTranscript_bobReply_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → XorTranscript} :
theorem Cslib.Crypto.KeyExchange.encXorTranscript_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 x1 x2 : γ → List Bool} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn Turing.MultiTapeTM.encBits budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encBits budget) (h2 : Turing.MultiTapeTM.ComputableInSpace x2 encIn Turing.MultiTapeTM.encBits budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { aliceFirst := x0 x, bobReply := x1 x, aliceSecond := x2 x }) encIn encXorTranscript budget
theorem Cslib.Crypto.KeyExchange.encXorTranscript_aliceFirst_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → XorTranscript} :

The encoding of an XOR transcript: its three words, each framed except the last (encXorTranscript_apply).

theorem Cslib.Crypto.KeyExchange.encXorTranscript_aliceSecond_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → XorTranscript} :

The XOR w ⊕ (s ⊕ u) of the three words of an XOR transcript.

The protocol of [KL20], Exercise 11.4 (p. 400). Alice draws uniform n-bit words k and r and sends s = k ⊕ r; Bob draws a uniform n-bit word t and sends u = s ⊕ t; Alice sends w = u ⊕ r. Alice outputs k and Bob outputs w ⊕ t.

theorem Cslib.Crypto.KeyExchange.mem_support_xorKeyExchange {n : ℕ} {outcome : Outcome XorTranscript fun (x : XorTranscript) => List Bool} (h : outcome ∈ (xorKeyExchange.execute n).support) :
∃ (k : List Bool) (r : List Bool) (t : List Bool), k.length = n ∧ r.length = n ∧ t.length = n ∧ outcome = { transcript := { aliceFirst := List.zipWith xor k r, bobReply := List.zipWith xor (List.zipWith xor k r) t, aliceSecond := List.zipWith xor (List.zipWith xor (List.zipWith xor k r) t) r }, aliceKey := k, bobKey := List.zipWith xor (List.zipWith xor (List.zipWith xor (List.zipWith xor k r) t) r) t }

Every honest execution of the XOR protocol comes from n-bit words k, r and t.

Alice and Bob output the same key ([KL20], Exercise 11.4, p. 400).

The eavesdropper that accepts exactly when the candidate key is the XOR w ⊕ (s ⊕ u) of the three transcript words.

On the real key the eavesdropper always accepts.

On a uniform n-bit key the eavesdropper accepts with probability at most 1 / 2 ^ n.

From n = 1 on, the eavesdropper's advantage is at least 1 / 2.

The XOR protocol is not secure against eavesdroppers ([KL20], Exercise 11.4, p. 400): the XOR of the three transcript words is the key, so the eavesdropper xorEavesdropper has advantage at least 1 / 2 at every parameter n ≥ 1.