Documentation

CslibFrontier.Crypto.Computational.DiffieHellman.GapCDH

Gap-CDH and the random-oracle Diffie–Hellman KEM #

Over a group of prime order q with generator g from a PrimeOrderGroupFamily, the gap computational Diffie–Hellman (gap-CDH) experiment ([KL20], §12.4.4, p. 434) draws uniform exponents a, b, gives the adversary (a • g, b • g) together with a decisional Diffie–Hellman oracle O_b answering a query (U, V) with true exactly when V = b • U, and accepts when the adversary outputs (a * b) • g.

The random-oracle KEM of [KL20], Construction 12.19 (p. 431), has public key h = x • g for a uniform exponent x; encapsulation draws a uniform y and outputs the ciphertext y • g with key H (y • h), and decapsulation of c returns H (x • c). The CCA experiment ([KL20], Definition 12.13, p. 425) gives the adversary the public key, the challenge ciphertext and either the real key or an independent key, together with the random oracle H and a decapsulation oracle that refuses the challenge ciphertext.

We prove the concrete per-group step of [KL20], Theorem 12.22 (p. 435); the asymptotic theorem is Cslib.Crypto.DecodablePrimeOrderGroupFamily.GapCDH.dhKEMROMINDCCA in CslibFrontier.Crypto.Computational.DiffieHellman.GapCDH.Decodable. The distinguishing advantage of every CCA adversary against the KEM is at most the success probability of an explicit gap-CDH adversary dhKEMToGapCDH (advantage_dhKEMCCAGame_le_ideal). Its exponents are drawn exactly uniformly, so it is an ideal-sampling step toward the cited theorem. The reduction runs the KEM adversary, answering hash and decapsulation queries consistently from a table of past queries by asking the DDH oracle whether a hash point z and a ciphertext c satisfy z = x • c; it then outputs the first hash point z with z = x • c⋆ for the challenge ciphertext c⋆.

Main definitions #

Main results #

Implementation notes #

The statement is concrete for one group of the family. KEM adversaries are deterministic oracle programs; a randomized adversary reduces to these by fixing its coins, since the bound holds for every coin sequence. The key distribution is an arbitrary finite sampler, which covers the uniform ℓ-bit keys of Construction 12.19. Unlike the textbook proof, the reduction outputs 0 when the public key is 0, which is then the correct answer, so the bound has no additive term.

The proof replaces the eagerly sampled random function by a lazily sampled one (Cslib.RandomOracle.interpret_eq_lazy), programs the real key at the point x • c⋆, and compares the real and ideal runs until the random oracle is first evaluated at x • c⋆. The reduction's tables represent the lazy random-oracle cache exactly, and an evaluation at x • c⋆ leaves a hash entry the reduction extracts.

References #

The queries of a CCA adversary against the Diffie–Hellman KEM: random-oracle evaluations and decapsulations.

  • hash {G : Type} (point : G) : DHKEMQuery G

    Evaluate the random oracle at a group element.

  • decaps {G : Type} (ciphertext : G) : DHKEMQuery G

    Decapsulate a ciphertext.

@[reducible, inline]

Hash queries return keys; decapsulation queries return a key, or none on the challenge.

@[reducible, inline]

The interface of a DDH oracle: a query (U, V) is answered by a bit.

@[reducible, inline]

A gap-CDH adversary maps (a • g, b • g) to a guess, with fresh coins and the oracle O_b.

def Cslib.Crypto.PrimeOrderGroupFamily.dhKEMEncaps (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (H : F.Carrier d → K) (h : F.Carrier d) (y : ZMod (F.order d)) :
F.Carrier d × K

Encapsulation of Construction 12.19 with hash function H, public key h and exponent y: the ciphertext y • g and the key H (y • h).

def Cslib.Crypto.PrimeOrderGroupFamily.dhKEMDecaps (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (H : F.Carrier d → K) (x : ZMod (F.order d)) (ciphertext : F.Carrier d) :
K

Decapsulation of Construction 12.19 with hash function H and secret key x.

theorem Cslib.Crypto.PrimeOrderGroupFamily.dhKEMDecaps_encaps (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (H : F.Carrier d → K) (x y : ZMod (F.order d)) :
F.dhKEMDecaps d H x (F.dhKEMEncaps d H (x • F.generator d) y).1 = (F.dhKEMEncaps d H (x • F.generator d) y).2

Decapsulating an encapsulation under the matching secret key recovers its key.

@[reducible, inline]

A CCA adversary against the KEM maps (public key, challenge ciphertext, key) to a guess, querying the random oracle and the decapsulation oracle.

@[reducible, inline]

The reduction's table of answered queries: hash points (inl) and decapsulated ciphertexts (inr), each with the key returned for it.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.ddhOracle (F : PrimeOrderGroupFamily) (d : F.Desc) (y : ZMod (F.order d)) (query : F.Carrier d × F.Carrier d) :

The DDH oracle O_y of [KL20], §12.4.4: (U, V) is answered true exactly when V = y • U.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.runDDH (F : PrimeOrderGroupFamily) (d : F.Desc) {α : Type} (y : ZMod (F.order d)) (program : ProbOracleComp (F.DDHSpec d) α) :
PMF α

Run a program with fresh uniform coins and the DDH oracle O_y.

The gap-CDH experiment ([KL20], §12.4.4): on (a • g, b • g) and with the oracle O_b, the adversary must output (a * b) • g.

def Cslib.Crypto.PrimeOrderGroupFamily.dhKEMAnswer (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (H : F.Carrier d → K) (x : ZMod (F.order d)) (challenge : F.Carrier d) (q : DHKEMQuery (F.Carrier d)) :
DHKEMSpec (F.Carrier d) K q

The honest answer to a KEM query, for hash function H, secret key x and challenge ciphertext challenge.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.dhKEMCCAGame (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} [Fintype (F.Carrier d)] [Finite K] (sampleKey : ProbComp K) (adversary : F.DHKEMAdversary d K) (bit : Bool) :

The CCA experiment for Construction 12.19 in the random-oracle model ([KL20], Definition 12.13): H is a random function with keys drawn by sampleKey, and the adversary receives the real key when bit is true and an independent key otherwise.

def Cslib.Crypto.PrimeOrderGroupFamily.simHandler (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (sampleKey : ProbComp K) (challenge : F.Carrier d) (q : DHKEMQuery (F.Carrier d)) :

The reduction's answers to KEM queries: consistent keys from its table, and no answer to the challenge ciphertext.

The first hash point z of a table with z = x • challenge, or 0 if there is none.

The gap-CDH adversary of the concrete per-group step of [KL20], Theorem 12.22: on (c⋆, h) it runs the KEM adversary on public key h, challenge ciphertext c⋆ and a fresh key, answers its queries with simHandler, and outputs the hash point x • c⋆ if the adversary asked for it.

Executing the reduction against the DDH oracle #

@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_pure (F : PrimeOrderGroupFamily) (d : F.Desc) {α : Type} (y : ZMod (F.order d)) (a : α) :
F.runDDH d y (pure a) = PMF.pure a
theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_bind (F : PrimeOrderGroupFamily) (d : F.Desc) {α β : Type} (y : ZMod (F.order d)) (program : ProbOracleComp (F.DDHSpec d) α) (next : α → ProbOracleComp (F.DDHSpec d) β) :
F.runDDH d y (program >>= next) = (F.runDDH d y program).bind fun (a : α) => F.runDDH d y (next a)
theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_sample (F : PrimeOrderGroupFamily) (d : F.Desc) {α : Type} (y : ZMod (F.order d)) (program : ProbComp α) :
F.runDDH d y (ProbOracleComp.sample program) = program.eval
noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.lowerHandler (F : PrimeOrderGroupFamily) (d : F.Desc) {σ ι : Type} {spec : OracleSpec ι} (y : ZMod (F.order d)) (handler : (q : ι) → StateT σ (ProbOracleComp (F.DDHSpec d)) (spec q)) (q : ι) :
StateT σ PMF (spec q)

A stateful handler over the DDH interface, with every call executed against O_y.

theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_run_interpret (F : PrimeOrderGroupFamily) (d : F.Desc) {α σ ι : Type} {spec : OracleSpec ι} (y : ZMod (F.order d)) (handler : (q : ι) → StateT σ (ProbOracleComp (F.DDHSpec d)) (spec q)) (program : OracleComp spec α) (s : σ) :
F.runDDH d y ((OracleComp.interpret handler program).run s) = (OracleComp.interpret (F.lowerHandler d y handler) program).run s

Executing a stateful handler against the DDH oracle executes each of its calls.

The reduction's tables represent a lazy random-oracle cache #

Whether a SimTable label matches a hash query z under DDH exponent y.

Whether a SimTable label matches a decapsulation query c under DDH exponent y.

theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_simHandler_hash (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (y : ZMod (F.order d)) (sampleKey : ProbComp K) (challenge z : F.Carrier d) (table : F.SimTable d K) :
F.runDDH d y ((F.simHandler d sampleKey challenge (DHKEMQuery.hash z)).run table) = match Option.map Prod.snd (List.find? (fun (e : (F.Carrier d ⊕ F.Carrier d) × K) => F.hashMatches d y z e.1) table) with | some key => PMF.pure (key, table) | none => PMF.map (fun (key : DHKEMSpec (F.Carrier d) K (DHKEMQuery.hash z)) => (key, (Sum.inl z, key) :: table)) sampleKey.eval

PMF law of simHandler on .hash z against O_y.

theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_simHandler_decaps (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (y : ZMod (F.order d)) (sampleKey : ProbComp K) (challenge c : F.Carrier d) (table : F.SimTable d K) :
F.runDDH d y ((F.simHandler d sampleKey challenge (DHKEMQuery.decaps c)).run table) = if c = challenge then PMF.pure (none, table) else match Option.map Prod.snd (List.find? (fun (e : (F.Carrier d ⊕ F.Carrier d) × K) => F.decapsMatches d y c e.1) table) with | some key => PMF.pure (some key, table) | none => PMF.map (fun (key : K) => (some key, (Sum.inr c, key) :: table)) sampleKey.eval

PMF law of simHandler on .decaps c against O_y.

@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_extractDH_nil (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (y : ZMod (F.order d)) (challenge : F.Carrier d) :
F.runDDH d y (F.extractDH d challenge []) = PMF.pure 0
@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_extractDH_cons_inl (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (y : ZMod (F.order d)) (challenge z : F.Carrier d) (key : K) (rest : F.SimTable d K) :
F.runDDH d y (F.extractDH d challenge ((Sum.inl z, key) :: rest)) = if z = y • challenge then PMF.pure z else F.runDDH d y (F.extractDH d challenge rest)
@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.runDDH_extractDH_cons_inr (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} (y : ZMod (F.order d)) (challenge c : F.Carrier d) (key : K) (rest : F.SimTable d K) :
F.runDDH d y (F.extractDH d challenge ((Sum.inr c, key) :: rest)) = F.runDDH d y (F.extractDH d challenge rest)

Programming the random oracle at one point #

The CCA experiment with a lazily sampled random oracle #

The reduction #

Concrete per-group step of Theorem 12.22 #

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_dhKEMCCAGame_le_ideal (F : PrimeOrderGroupFamily) (d : F.Desc) {K : Type} [Fintype (F.Carrier d)] [Finite K] (sampleKey : ProbComp K) (adversary : F.DHKEMAdversary d K) :
(F.dhKEMCCAGame d sampleKey adversary true).advantage (F.dhKEMCCAGame d sampleKey adversary false) ≤ (F.gapCDHGame d (F.dhKEMToGapCDH d sampleKey adversary)).succProbability

Concrete per-group ideal-sampling step of [KL20], Theorem 12.22 (p. 435), not the cited result (exponents are drawn from PMF.uniformOfFintype (ZMod (F.order d))); the asymptotic fair-coin theorem is Cslib.Crypto.DecodablePrimeOrderGroupFamily.GapCDH.dhKEMROMINDCCA (CslibFrontier/Crypto/Computational/DiffieHellman/GapCDH/Decodable.lean). The CCA advantage of every adversary against dhKEMCCAGame is at most the success probability of the gap-CDH adversary dhKEMToGapCDH built from it.