Documentation

CslibFrontier.Crypto.Computational.DiffieHellman.Finite

Discrete-logarithm and Diffie–Hellman experiments in a fixed group #

Fix an additive commutative group G that is a ZMod q-module, and an element g : G. Groups are written additively, so the textbook element g^a is a • g and g^(ab) is (a * b) • g. This module states the discrete-logarithm (DL), Computational Diffie–Hellman (CDH) and Decisional Diffie–Hellman (DDH) experiments of [BS23], Attack Games 10.4, 10.5 and 10.6, for this one group. Adversaries receive and return group elements and exponents; there are no encodings, security parameter or setup. Each experiment is an Experiment, a program read as the challenger's steps, and is evaluated only where its advantage is defined.

The definitions place no hypothesis on G, q or g. Results that use them state what they need, for example that g generates G. The asymptotic assumptions over a family of prime-order groups are in CslibFrontier/Crypto/Computational/DiscreteLog.lean and CslibFrontier/Crypto/Computational/DiffieHellman.lean.

Main definitions #

Main results #

References #

Discrete logarithm #

noncomputable def Cslib.Crypto.dlExperiment {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (A : G → ProbComp (ZMod q)) :

The discrete-logarithm experiment ([BS23], Attack Game 10.4) in the group generated by g: the challenger draws a uniform exponent a and gives the adversary a • g (the textbook g^a); the adversary wins when it outputs a.

noncomputable def Cslib.Crypto.dlAdvantage {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (A : G → ProbComp (ZMod q)) :

The discrete-logarithm advantage of A: its success probability in dlExperiment.

Computational Diffie–Hellman #

noncomputable def Cslib.Crypto.cdhExperiment {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (A : G → G → ProbComp G) :

The Computational Diffie–Hellman experiment ([BS23], Attack Game 10.5) in the group generated by g: the challenger draws uniform exponents a and b and gives the adversary a • g and b • g (the textbook g^a and g^b); the adversary wins when it outputs (a * b) • g.

noncomputable def Cslib.Crypto.cdhAdvantage {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (A : G → G → ProbComp G) :

The CDH advantage of A: its success probability in cdhExperiment.

Decisional Diffie–Hellman #

noncomputable def Cslib.Crypto.ddhRealExperiment {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (D : G → G → G → ProbComp Bool) :

The real world of the Decisional Diffie–Hellman experiment ([BS23], Attack Game 10.6, Experiment 0) in the group generated by g: the challenger draws uniform exponents a and b and gives the distinguisher a • g, b • g and (a * b) • g. The book's challenger also draws the unused γ; omitting it does not change the distribution.

noncomputable def Cslib.Crypto.ddhRandomExperiment {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (D : G → G → G → ProbComp Bool) :

The random world of the Decisional Diffie–Hellman experiment ([BS23], Attack Game 10.6, Experiment 1) in the group generated by g: the challenger draws independent uniform exponents a, b and c and gives the distinguisher a • g, b • g and c • g.

noncomputable def Cslib.Crypto.ddhAdvantage {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (D : G → G → G → ProbComp Bool) :

The DDH advantage of D: its distinguishing advantage between ddhRealExperiment and ddhRandomExperiment.

theorem Cslib.Crypto.eval_ddhRealExperiment {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (D : G → G → G → ProbComp Bool) :
ProbComp.eval (ddhRealExperiment q g D) = (Probability.PMF.uniformOfFintype (ZMod q)).bind fun (a : ZMod q) => (Probability.PMF.uniformOfFintype (ZMod q)).bind fun (b : ZMod q) => (D (a • g) (b • g) ((a * b) • g)).eval

The law of ddhRealExperiment: uniform exponents a and b sampled at the PMF level.

theorem Cslib.Crypto.eval_ddhRandomExperiment {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (D : G → G → G → ProbComp Bool) :

The law of ddhRandomExperiment: uniform exponents a, b and c sampled at the PMF level.

Reductions #

def Cslib.Crypto.dlToCDH {G : Type} [AddCommGroup G] {q : ℕ} [Module (ZMod q) G] (A : G → ProbComp (ZMod q)) (u v : G) :

The discrete-logarithm-to-CDH reduction: given (u, v), ask the discrete-logarithm adversary A for the exponent of u, and multiply v by its answer. When A returns a with u = a • g and v = b • g, the output is (a * b) • g.

def Cslib.Crypto.cdhToDDH {G : Type} [DecidableEq G] (A : G → G → ProbComp G) (u v w : G) :

The CDH-to-DDH reduction: given (u, v, w), ask the CDH adversary A for the shared element of u and v, and answer whether it is w.

Uniform masks #

theorem Cslib.Crypto.uniformOfFintype_bind_smul_add {G : Type} [AddCommGroup G] {q : ℕ} [NeZero q] [Module (ZMod q) G] {g : G} {α : Type u_1} (hg : Function.Surjective fun (c : ZMod q) => c • g) (m : G) (f : G → PMF α) :
((Probability.PMF.uniformOfFintype (ZMod q)).bind fun (c : ZMod q) => f (c • g + m)) = (Probability.PMF.uniformOfFintype (ZMod q)).bind fun (c : ZMod q) => f (c • g)

One-time group mask: when every element of G is a multiple of g, adding a fixed m to c • g for uniform c : ZMod q leaves the distribution of c • g unchanged.

theorem Cslib.Crypto.uniformOfFintype_bind_smul {G : Type} [AddCommGroup G] {q : ℕ} [NeZero q] [Module (ZMod q) G] {g : G} {α : Type u_1} [Fintype G] (hg : Function.Bijective fun (c : ZMod q) => c • g) (f : G → PMF α) :

When c ↦ c • g is a bijection ZMod q → G (that is, g generates G and G has q elements), the element c • g for uniform c : ZMod q is uniform on G.

Concrete bounds #

DL is at least as hard as CDH: whenever A finds a from a • g, dlToCDH A outputs a • (b • g) = (a * b) • g. No hypothesis on G, q or g is needed.

@[simp]
theorem Cslib.Crypto.ddhRealExperiment_cdhToDDH {G : Type} [AddCommGroup G] [DecidableEq G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (A : G → G → ProbComp G) :

In the real DDH world, cdhToDDH A runs the CDH experiment for A.

theorem Cslib.Crypto.probability_ddhRandomExperiment_cdhToDDH_le {G : Type} [AddCommGroup G] [DecidableEq G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (hg : Function.Injective fun (c : ZMod q) => c • g) (A : G → G → ProbComp G) :

In the random DDH world, cdhToDDH A accepts with probability at most 1 / q when g has order q: the independent c • g equals the adversary's output for at most one c. Injectivity of c ↦ c • g holds when g generates G and Nat.card G = q, and, for prime q, when g ≠ 0 (smul_left_injective).

theorem Cslib.Crypto.cdhAdvantage_le_ddhAdvantage_cdhToDDH_add {G : Type} [AddCommGroup G] [DecidableEq G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (hg : Function.Injective fun (c : ZMod q) => c • g) (A : G → G → ProbComp G) :
cdhAdvantage q g A ≤ ddhAdvantage q g (cdhToDDH A) + 1 / ↑q

CDH is at least as hard as DDH, up to 1 / q ([BS23], Section 10.5): when g has order q, the CDH advantage of A is at most the DDH advantage of cdhToDDH A plus 1 / q.