Documentation

CslibFrontier.Crypto.Computational.DiffieHellman.SelfReduction

Exact success probability of the DL and CDH self-reductions in a fixed group #

Fix an additive commutative group G that is a ZMod q-module and an element g : G, as in CslibFrontier/Crypto/Computational/DiffieHellman/Finite.lean; the textbook g^a is a • g. [BS23], Section 10.5.1, turns an adversary A that finds the discrete logarithm of a random group element with probability ε into an algorithm B that finds the discrete logarithm of every element with probability ε (Theorem 10.2), and Exercise 10.6 asks for the same for CDH. This module writes these algorithms as programs that call A once per attempt, and computes their exact output probabilities in one fixed group. This layer has no cost model, so it does not state that B is efficient, which Theorem 10.2 also claims, nor the consequence over a group family, that worst-case hardness of the discrete logarithm implies average-case hardness. Both are in CslibFrontier/Crypto/Computational/DiffieHellman/SelfReduction/Family.lean, for word-level adversaries over a PrimeOrderGroupFamily.

Write ε = dlAdvantage q g A, the success probability of A in the discrete-logarithm experiment for g. Footnote 1 of the book (p. 411) fixes the group and generator in the same way. The book draws a uniform input u and asks for Dlog_g(u); the experiment draws a uniform exponent a and asks for a, which is the same when g generates a group of order q.

Exercise 10.5 itself needs no lemma here. Part (a) is uniformOfFintype_bind_smul_add with uniformOfFintype_bind_smul, and part (b) is the identity ((α + ρ) * β) • g = (α * β) • g + ρ • (β • g), one step of module.

The book takes G cyclic of prime order q, generated by g. The results below need neither primality nor a generator. The exact equalities for k attempts assume instead that c ↦ c • g is injective on ZMod q (that g has order q), and every result except soundness concerns an input of the form α • g; in the book's setting both hold for every input. Testing an answer needs DecidableEq G. Probabilities are values of ProbComp.eval in ℝ≥0∞, and ε : ℝ≥0 is coerced.

Main definitions #

Main results #

References #

The programs #

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

One masked call of a discrete-logarithm adversary A on u: draw a uniform exponent σ, run A on u + σ • g (the textbook u · g^σ) and subtract σ from its answer. This is the algorithm B in the proof of [BS23], Theorem 10.2 (p. 412), without its final test.

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

At most k masked calls of A on u (dlRerandomize), returning the first answer x with x • g = u, or none when all k answers fail this test. dlSelfReduce q g A 1 is the algorithm B in the proof of [BS23], Theorem 10.2 (p. 412), with none for its output fail. The book tests g^α₁ = u · g^σ and then outputs α₁ - σ; this program tests (α₁ - σ) • g = u, which is the same test by sub_smul.

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

One call of a CDH adversary A on (u, v) with both inputs masked: draw uniform exponents ρ and τ, run A on (u + ρ • g, v + τ • g) and subtract τ • u + ρ • v + (ρ * τ) • g from its answer. When u = α • g and v = β • g, the correct answer for the masked inputs is ((α + ρ) * (β + τ)) • g, and the subtraction leaves (α * β) • g.

[BS23], Exercise 10.6 (p. 425) asks for such an algorithm without giving one; this construction is ours. It has no fail output: as the remark after the exercise notes, under DDH there is no way to recognize a correct answer.

One attempt #

theorem Cslib.Crypto.eval_dlRerandomize_smul_apply {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (A : G → ProbComp (ZMod q)) (α : ZMod q) :
(dlRerandomize q g A (α • g)).eval α = (ProbComp.eval (dlExperiment q g A)) true

One masked call on α • g returns α with probability exactly the discrete-logarithm advantage of A, whatever α: substituting a = α + σ, a bijection of ZMod q, turns the event into A (a • g) = a for uniform a. The substitution is on exponents, not group elements, so no hypothesis on G, q or g is needed.

theorem Cslib.Crypto.smul_eq_of_mem_support_dlSelfReduce {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] {A : G → ProbComp (ZMod q)} {k : ℕ} {u : G} {x : ZMod q} (hx : some x ∈ (dlSelfReduce q g A k u).eval.support) :
x • g = u

Soundness of the discrete-logarithm self-reduction. Every answer some x that dlSelfReduce can return is a discrete logarithm of its input: x • g = u. This is the claim of [BS23], Theorem 10.2 (pp. 411–412), that B outputs either fail or Dlog_g(u), here for every u and k and with no hypothesis on the group.

theorem Cslib.Crypto.eval_dlSelfReduce_one_smul_some {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (A : G → ProbComp (ZMod q)) (α : ZMod q) :
(dlSelfReduce q g A 1 (α • g)).eval (some α) = ↑(dlAdvantage q g A)

The probability in [BS23], Theorem 10.2 (pp. 411–412), in a fixed group: on input α • g, one attempt returns α with probability exactly ε = dlAdvantage q g A. The theorem's claim that B is efficient is not stated here; the family-level form is Cslib.Crypto.PrimeOrderGroupFamily.le_toOuterMeasure_dlSelfReduceRetryAdversary_one, and Cslib.Crypto.PrimeOrderGroupFamily.isPPTOn_dlSelfReduceRetryAdversary certifies its program. The book takes G cyclic of prime order q with generator g, where every input is α • g for its discrete logarithm α; this needs neither hypothesis.

Repeated attempts #

theorem Cslib.Crypto.eval_dlSelfReduce_smul_none_le {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (A : G → ProbComp (ZMod q)) (k : ℕ) (α : ZMod q) :
(dlSelfReduce q g A k (α • g)).eval none ≤ (1 - ↑(dlAdvantage q g A)) ^ k

k attempts on α • g all fail with probability at most (1 - ε) ^ k, with no hypothesis on the group. The bound is an equality when c ↦ c • g is injective (eval_dlSelfReduce_smul_none); otherwise an attempt can also succeed with another discrete logarithm of α • g.

theorem Cslib.Crypto.eval_dlSelfReduce_smul_none {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (hg : Function.Injective fun (c : ZMod q) => c • g) (A : G → ProbComp (ZMod q)) (k : ℕ) (α : ZMod q) :
(dlSelfReduce q g A k (α • g)).eval none = (1 - ↑(dlAdvantage q g A)) ^ k

When c ↦ c • g is injective on ZMod q (that is, g has order q), k attempts on α • g all fail with probability exactly (1 - ε) ^ k.

theorem Cslib.Crypto.eval_dlSelfReduce_smul_some {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (hg : Function.Injective fun (c : ZMod q) => c • g) (A : G → ProbComp (ZMod q)) (k : ℕ) (α : ZMod q) :
(dlSelfReduce q g A k (α • g)).eval (some α) = 1 - (1 - ↑(dlAdvantage q g A)) ^ k

When c ↦ c • g is injective, k attempts on α • g return α with probability exactly 1 - (1 - ε) ^ k, the probability in the remark after [BS23], Theorem 10.2 (p. 412).

theorem Cslib.Crypto.eval_dlSelfReduce_smul_none_le_exp_mul {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (A : G → ProbComp (ZMod q)) (k : ℕ) (α : ZMod q) :
((dlSelfReduce q g A k (α • g)).eval none).toReal ≤ Real.exp (-(↑k * ↑(dlAdvantage q g A)))

k attempts on α • g all fail with probability at most exp (-(k ε)), with no hypothesis on the group or on ε.

theorem Cslib.Crypto.eval_dlSelfReduce_smul_none_le_exp {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (A : G → ProbComp (ZMod q)) (hε : 0 < dlAdvantage q g A) (n : ℕ) (α : ZMod q) :

The remark after [BS23], Theorem 10.2 (p. 412), failure form: when 0 < ε, n ⌈1 / ε⌉ attempts on α • g all fail with probability at most exp (-n). The book leaves 0 < ε implicit in the count; here ⌈ε⁻¹⌉₊ = 0 when ε = 0, and the test file shows that the bound then fails. No hypothesis on the group is needed: when the loop does not fail, it returns a discrete logarithm of α • g (smul_eq_of_mem_support_dlSelfReduce).

theorem Cslib.Crypto.one_sub_exp_le_eval_dlSelfReduce_smul_some {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (hg : Function.Injective fun (c : ZMod q) => c • g) (A : G → ProbComp (ZMod q)) (hε : 0 < dlAdvantage q g A) (n : ℕ) (α : ZMod q) :
1 - Real.exp (-↑n) ≤ ((dlSelfReduce q g A (n * ⌈(dlAdvantage q g A)⁻¹⌉₊) (α • g)).eval (some α)).toReal

The remark after [BS23], Theorem 10.2 (p. 412): when c ↦ c • g is injective and 0 < ε, n ⌈1 / ε⌉ attempts on α • g return α with probability at least 1 - exp (-n). The book writes this as 1 - (1 - ε)^(n⌈1/ε⌉) ≥ 1 - exp(-n), whose left side is the exact probability of eval_dlSelfReduce_smul_some.

Computational Diffie–Hellman #

theorem Cslib.Crypto.eval_cdhSelfReduce_smul_apply {G : Type} [AddCommGroup G] (q : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) [DecidableEq G] (A : G → G → ProbComp G) (α β : ZMod q) :
(cdhSelfReduce q g A (α • g) (β • g)).eval ((α * β) • g) = (ProbComp.eval (cdhExperiment q g A)) true

The success probability asked for in [BS23], Exercise 10.6 (p. 425), in a fixed group: on every input (α • g, β • g), cdhSelfReduce returns the Diffie–Hellman element (α * β) • g with probability exactly the CDH advantage of A. The construction is ours, since the exercise gives none, and its efficiency is not stated here; the family-level form is Cslib.Crypto.PrimeOrderGroupFamily.advantage_cdhSelfReduceAdversary_le, and Cslib.Crypto.PrimeOrderGroupFamily.isPPT_cdhSelfReduceAdversary certifies its program. The book takes G cyclic of prime order q with generator g; this needs neither hypothesis.