Documentation

CslibFrontier.Crypto.Computational.TrapdoorFunction

Trapdoor function schemes and anonymous key exchange #

[BS23], Section 10.2 (Definition 10.2, pp. 400–401), defines a trapdoor function scheme (G, F, I) with key generation G, public evaluation F(pk, ·) and secret-key inversion I(sk, ·) satisfying I(sk, F(pk, x)) = x, together with its one-wayness game and security notion (Attack Game 10.2 and Definition 10.3, p. 401; asymptotic form in Definition 10.4, pp. 402–403). Section 10.2.1 and Figure 10.1 (pp. 401–402) construct an anonymous two-party key-exchange protocol from any trapdoor function scheme: Alice samples (pk, sk) ← G() and sends pk; Bob samples x ← X uniformly, sends y ← F(pk, x) and outputs x; Alice outputs I(sk, y). Section 10.2.1 (p. 402) shows that for a correct scheme, one-wayness (TrapdoorFunction.OneWay) implies key-guessing security (KeyExchange.AnonKESecure), since any key-guessing adversary directly breaks one-wayness with the exact same advantage; we also prove the converse direction, which is original here and immediate because the two adversary conversions are mutually inverse, giving the equivalence keyExchange_anonKESecure_iff_oneWay. The RSA instantiation (§10.3 and §10.3.1) is in CslibFrontier/Crypto/Computational/TrapdoorFunction/RSA.lean.

Main definitions #

Main results #

Implementation notes #

References #

structure Cslib.Crypto.TrapdoorFunction (PK SK : Type) (X Y : PK → Type) :

A trapdoor function scheme (G, F, I) ([BS23], Section 10.2, Definition 10.2, pp. 400–401) with public keys PK, secret keys SK, and key-dependent domain X pk and range Y pk (Section 10.3, pp. 404–405).

  • keyGen : PMF SK

    Key-generation distribution G over secret keys.

  • publicKey : SK → PK

    The public key determined by a secret key.

  • eval (pk : PK) : X pk → Y pk

    Evaluation F(pk, ·) on the domain of pk.

  • invert (sk : SK) : Y (self.publicKey sk) → X (self.publicKey sk)

    Trapdoor inversion I(sk, ·) recovering an element of X (publicKey sk).

  • domain_nonempty (sk : SK) : Nonempty (X (self.publicKey sk))

    Every public key arising from a secret key has a nonempty domain.

def Cslib.Crypto.TrapdoorFunction.Correct {PK SK : Type} {X Y : PK → Type} (T : TrapdoorFunction PK SK X Y) :

Inversion correctness ([BS23], Section 10.2, Definition 10.2, p. 401): I(sk, F(pk, x)) = x for every secret key in the support of keyGen and every x in the domain.

theorem Cslib.Crypto.TrapdoorFunction.Correct.injective {PK SK : Type} {X Y : PK → Type} {T : TrapdoorFunction PK SK X Y} (h : T.Correct) {sk : SK} (hsk : sk ∈ T.keyGen.support) :

For a Correct trapdoor function scheme, F(pk, ·) is injective for every sk in the support of keyGen ([BS23], Section 10.2, p. 401).

The public pair (pk, y) seen by an inverter in Attack Game 10.2 and by a passive eavesdropper in Figure 10.1 ([BS23], Section 10.2 and Section 10.2.1, pp. 401–402).

  • publicKey : PK

    Alice's public key pk.

  • ciphertext : Y self.publicKey

    The image y = F(pk, x) under publicKey.

theorem Cslib.Crypto.TrapdoorFunction.encTranscript_ciphertext_polyTime {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → Transcript PK Y} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encTranscript encPK encY) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (encY (g✝ c).publicKey) (g✝ c).ciphertext) encIn✝ Turing.MultiTapeTM.encBits
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_mk_inO {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → PK} {T0 S0 : γ → ℕ} {x1 : (c : γ) → Y (x0 c)} {T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn encPK T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => (encY (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits T1 S1) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { publicKey := x0 x, ciphertext := x1 x }) encIn (encTranscript encPK encY) (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x
@[reducible, inline]
abbrev Cslib.Crypto.TrapdoorFunction.encTranscriptFields {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) :

The tuple of the fields of encTranscript.

theorem Cslib.Crypto.TrapdoorFunction.encTranscript_ciphertext_inO {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) :
Turing.MultiTapeTM.ComputableInO (fun (a : Transcript PK Y) => (encY a.publicKey) a.ciphertext) (encTranscript encPK encY) Turing.MultiTapeTM.encBits (fun (a : Transcript PK Y) => ((encTranscript encPK encY) a).length) fun (a : Transcript PK Y) => ((encTranscript encPK encY) a).length
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_mk_polyTime {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → PK} {x1 : (c : γ) → Y (x0 c)} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn encPK) (h1 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => (encY (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { publicKey := x0 x, ciphertext := x1 x }) encIn (encTranscript encPK encY)
def Cslib.Crypto.TrapdoorFunction.encTranscript {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) :

The encoding of a trapdoor-function Transcript: framed encPK publicKey followed by encY publicKey ciphertext (encTranscript_apply).

theorem Cslib.Crypto.TrapdoorFunction.encTranscript_publicKey_inO {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) :
Turing.MultiTapeTM.ComputableInO (fun (a : Transcript PK Y) => a.publicKey) (encTranscript encPK encY) encPK (fun (a : Transcript PK Y) => ((encTranscript encPK encY) a).length) fun (a : Transcript PK Y) => ((encTranscript encPK encY) a).length
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_mk_budget {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → PK} {x1 : (c : γ) → Y (x0 c)} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn encPK budget) (h1 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => (encY (x0 c)) (x1 c)) encIn Turing.MultiTapeTM.encBits budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { publicKey := x0 x, ciphertext := x1 x }) encIn (encTranscript encPK encY) budget
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_publicKey_polyTime {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {g✝ : γ✝ → Transcript PK Y} :
Turing.MultiTapeTM.ComputableInPolyTime g✝ encIn✝ (encTranscript encPK encY) → Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ✝) => (g✝ c).publicKey) encIn✝ encPK
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_publicKey_deg {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) :
Turing.MultiTapeTM.ComputableInDegree (fun (a : Transcript PK Y) => a.publicKey) (encTranscript encPK encY) encPK 1 1
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_ciphertext_budget {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → Transcript PK Y} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encTranscript encPK encY) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (encY (g✝ c).publicKey) (g✝ c).ciphertext) encIn✝ Turing.MultiTapeTM.encBits S✝
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_fields_deg {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) :
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_ciphertext_length_le {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) (a : Transcript PK Y) :
(Turing.MultiTapeTM.encBits ((fun (a : Transcript PK Y) => (encY a.publicKey) a.ciphertext) a)).length ≤ ((encTranscript encPK encY) a).length
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_publicKey_length_le {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) (a : Transcript PK Y) :
(encPK ((fun (a : Transcript PK Y) => a.publicKey) a)).length ≤ ((encTranscript encPK encY) a).length
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_publicKey_budget {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → Transcript PK Y} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ (encTranscript encPK encY) S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).publicKey) encIn✝ encPK S✝
@[simp]
theorem Cslib.Crypto.TrapdoorFunction.encTranscript_apply {PK : Type} {Y : PK → Type} (encPK : PK ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) (a : Transcript PK Y) :
(encTranscript encPK encY) a = (encTranscriptFields encPK encY) (a.publicKey, (encY a.publicKey) a.ciphertext)
@[reducible, inline]

A typed inverter for Attack Game 10.2 ([BS23], Section 10.2, p. 401, with security parameter n as in Definition 10.4, pp. 402–403): given n, a public key pk and y : Y pk, it outputs a candidate preimage in X pk.

def Cslib.Crypto.TrapdoorFunction.Inverter.IsPPT {PK : Type} {X Y : PK → Type} (encPK : PK ↪ List Bool) (encX : (pk : PK) → X pk ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) (inverter : Inverter PK X Y) :

An inverter is PPT when one uniform strict PPT machine reads (1ⁿ, pk, y) encoded by encPair encUnary (encTranscript encPK encY) and writes encX pk x'.

def Cslib.Crypto.TrapdoorFunction.keGuesserToInverter {PK : Type} {X Y : PK → Type} (adversary : KeyExchange.KeyGuesser (Transcript PK Y) fun (t : Transcript PK Y) => X t.publicKey) :
Inverter PK X Y

View a key-guessing adversary against trapdoor-function key exchange as an Inverter in Attack Game 10.2 ([BS23], Section 10.2.1, p. 402).

def Cslib.Crypto.TrapdoorFunction.inverterToKEGuesser {PK : Type} {X Y : PK → Type} (inverter : Inverter PK X Y) :

View an Inverter in Attack Game 10.2 as a key-guessing adversary against trapdoor-function key exchange (the inverse of keGuesserToInverter, added here for the converse direction of keyExchange_anonKESecure_iff_oneWay).

theorem Cslib.Crypto.TrapdoorFunction.isPPT_keGuesserToInverter {PK : Type} {X Y : PK → Type} {encPK : PK ↪ List Bool} {encX : (pk : PK) → X pk ↪ List Bool} {encY : (pk : PK) → Y pk ↪ List Bool} {adversary : KeyExchange.KeyGuesser (Transcript PK Y) fun (t : Transcript PK Y) => X t.publicKey} (hA : KeyExchange.KeyGuesser.IsPPT (encTranscript encPK encY) (fun (t : Transcript PK Y) => encX t.publicKey) adversary) :
Inverter.IsPPT encPK encX encY (keGuesserToInverter adversary)

keGuesserToInverter preserves uniform strict PPT efficiency.

theorem Cslib.Crypto.TrapdoorFunction.isPPT_inverterToKEGuesser {PK : Type} {X Y : PK → Type} {encPK : PK ↪ List Bool} {encX : (pk : PK) → X pk ↪ List Bool} {encY : (pk : PK) → Y pk ↪ List Bool} {inverter : Inverter PK X Y} (hI : Inverter.IsPPT encPK encX encY inverter) :
KeyExchange.KeyGuesser.IsPPT (encTranscript encPK encY) (fun (t : Transcript PK Y) => encX t.publicKey) (inverterToKEGuesser inverter)

inverterToKEGuesser preserves uniform strict PPT efficiency.

noncomputable def Cslib.Crypto.TrapdoorFunction.owGame {PK SK : Type} {X Y : PK → Type} [(pk : PK) → Fintype (X pk)] [(pk : PK) → DecidableEq (X pk)] (T : TrapdoorFunction PK SK X Y) (step : (pk : PK) → Y pk → ProbComp (X pk)) :

Attack Game 10.2 ([BS23], Section 10.2, p. 401): draw sk ← T.keyGen, draw x uniformly from X (T.publicKey sk), run step (T.publicKey sk) (T.eval (T.publicKey sk) x) and accept when its output equals x. Its advantage OWadv[A, T] is (T.owGame (A n)).succProbability.

def Cslib.Crypto.TrapdoorFunction.OneWay {PK SK : Type} {X Y : PK → Type} [(pk : PK) → Fintype (X pk)] [(pk : PK) → DecidableEq (X pk)] (T : ℕ → TrapdoorFunction PK SK X Y) (encPK : PK ↪ List Bool) (encX : (pk : PK) → X pk ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) :

One-wayness of a family of trapdoor function schemes ([BS23], Section 10.2, Attack Game 10.2 and Definition 10.3, p. 401, with Definition 10.4, pp. 402–403): every PPT inverter recovers a uniform preimage from (pk, F(pk, x)) with negligible probability.

Deviations from the source: the domain X pk and range Y pk may depend on the public key (the form Section 10.3 names for RSA and does not adopt, pp. 404–405); keys come from any PMF SK family without bundling the efficient recognizability, sampleability or polynomial-time G, F, I conditions of Definition 10.4, items 1–5 (#5657); and inverters are uniform strict PPT machines reading (1ⁿ, pk, y) via encPair encUnary (encTranscript encPK encY) and writing encX pk x.

Anonymous key exchange from a trapdoor function scheme #

noncomputable def Cslib.Crypto.TrapdoorFunction.keyExchangeExecution {PK SK : Type} {X Y : PK → Type} [(pk : PK) → Fintype (X pk)] (T : TrapdoorFunction PK SK X Y) :
PMF (KeyExchange.Outcome (Transcript PK Y) fun (t : Transcript PK Y) => X t.publicKey)

Honest execution of anonymous key exchange using a trapdoor function scheme T ([BS23], Section 10.2.1 and Figure 10.1, pp. 401–402): Alice draws sk ← T.keyGen and sends pk = T.publicKey sk; Bob draws x uniformly from X pk, computes y = T.eval pk x, sends y and outputs x; Alice computes and outputs T.invert sk y.

noncomputable def Cslib.Crypto.TrapdoorFunction.keyExchange {PK SK : Type} {X Y : PK → Type} [(pk : PK) → Fintype (X pk)] (T : ℕ → TrapdoorFunction PK SK X Y) :
KeyExchange (Transcript PK Y) fun (t : Transcript PK Y) => X t.publicKey

Anonymous two-party key exchange built from a family T of trapdoor function schemes ([BS23], Section 10.2.1 and Figure 10.1, pp. 401–402).

theorem Cslib.Crypto.TrapdoorFunction.keyExchange_correct {PK SK : Type} {X Y : PK → Type} [(pk : PK) → Fintype (X pk)] {T : ℕ → TrapdoorFunction PK SK X Y} (hcorr : ∀ (n : ℕ), (T n).Correct) :

When every T n is Correct, Alice's inverted key I(sk, F(pk, x)) equals Bob's chosen x ([BS23], Section 10.2.1, p. 402).

theorem Cslib.Crypto.TrapdoorFunction.Correct.anonKEGame_keyExchange {PK SK : Type} {X Y : PK → Type} [(pk : PK) → Fintype (X pk)] [(pk : PK) → DecidableEq (X pk)] {T : ℕ → TrapdoorFunction PK SK X Y} {n : ℕ} (hcorr : (T n).Correct) (adversary : KeyExchange.KeyGuesser (Transcript PK Y) fun (t : Transcript PK Y) => X t.publicKey) :
(keyExchange T).anonKEGame adversary n = (T n).owGame (keGuesserToInverter adversary n)

For a scheme family T that is Correct at parameter n, running anonKEGame on keyExchange T with adversary gives the exact same game as running (T n).owGame with keGuesserToInverter adversary n ([BS23], Section 10.2.1, p. 402).

theorem Cslib.Crypto.TrapdoorFunction.keyExchange_anonKESecure_iff_oneWay {PK SK : Type} {X Y : PK → Type} [(pk : PK) → Fintype (X pk)] [(pk : PK) → DecidableEq (X pk)] {T : ℕ → TrapdoorFunction PK SK X Y} (hcorr : ∀ (n : ℕ), (T n).Correct) (encPK : PK ↪ List Bool) (encX : (pk : PK) → X pk ↪ List Bool) (encY : (pk : PK) → Y pk ↪ List Bool) :
((keyExchange T).AnonKESecure (encTranscript encPK encY) fun (t : Transcript PK Y) => encX t.publicKey) ↔ OneWay T encPK encX encY

Anonymous key exchange from a correct trapdoor function scheme is key-guessing secure if and only if the scheme is one-way.

[BS23], Section 10.2.1 (p. 402), proves the OneWay → AnonKESecure direction (mpr), observing that any adversary guessing x from (pk, y) breaks Attack Game 10.2 with the exact same advantage (Correct.anonKEGame_keyExchange). The converse direction (mp), and hence the equivalence, is original here and follows immediately because keGuesserToInverter and inverterToKEGuesser are mutually inverse.