Documentation

CslibFrontier.Crypto.Computational.DiffieHellman.SmallFactor

The small-prime-factor test for Decisional Diffie–Hellman #

In a cyclic group of order q whose order has a prime divisor l, whether a discrete logarithm is divisible by l is visible from raising to the power q / l: (q / l) • (a • g) = 0 exactly when l ∣ a.val (div_nsmul_smul_eq_zero_iff). Because l is prime, l divides (a * b).val in ZMod q exactly when l divides a.val or b.val (dvd_val_mul_iff), so a Diffie–Hellman triple (a • g, b • g, (a * b) • g) satisfies (q / l) • w = 0 ↔ (q / l) • u = 0 ∨ (q / l) • v = 0 with probability 1, whereas an independent uniform w = c • g matches with probability 1 - (3 * l - 2) * (l - 1) / l ^ 3. This generalizes the parity test (l = 2) of [BS23], Section 16.1.3, to arbitrary prime factors l ∣ q (Exercise 16.2(a), p. 707).

The book writes that the test has advantage "about 1 / l": here the exact advantage is ((3 * l - 2) * (l - 1)) / l ^ 3 (ddhAdvantage_ddhSmallFactorDistinguisher), which equals 1 / 2 at l = 2, is at least 1 / l for every prime l (inv_le_ddhAdvantage_ddhSmallFactorDistinguisher), and approaches 3 / l for large l.

The setting is that of CslibFrontier/Crypto/Computational/DiffieHellman/Finite.lean: an additive commutative group G that is a ZMod q-module ([NeZero q]) with c ↦ c • g injective on ZMod q. The fixed-group advantage places no bound on running time; polynomial-time efficiency over CyclicGroupFamily and the asymptotic failure of DDH when the order has a polynomially bounded prime factor are in CslibFrontier/Crypto/Computational/DiffieHellman/CyclicGroupFamily.lean. Not covered: the O(log q) operation count as a count of group operations, Exercise 16.2(b), a family of the groups (ZMod p)ˣ, and #5673's cleanup in CslibFrontier/Crypto/Computational/DiffieHellman/CyclicGroupFamily.lean.

Main definitions #

Main results #

References #

theorem Cslib.Crypto.div_nsmul_smul_eq_zero_iff {G : Type} [AddCommGroup G] {q l : ℕ} [NeZero q] [Module (ZMod q) G] {g : G} (hlq : l ∣ q) (hg : Function.Injective fun (c : ZMod q) => c • g) (a : ZMod q) :
(q / l) • a • g = 0 ↔ l ∣ a.val

In a cyclic group of order q generated by g, if l ∣ q, raising a • g to q / l gives 0 iff l divides a.val (generalization of [BS23], Lemma 16.1, p. 687; Exercise 16.2(a), p. 707).

theorem Cslib.Crypto.dvd_val_mul_iff {G : Type} [AddCommGroup G] {q l : ℕ} [NeZero q] [Module (ZMod q) G] {g : G} (hl : Nat.Prime l) (hlq : l ∣ q) (hg : Function.Injective fun (c : ZMod q) => c • g) (a b : ZMod q) :
l ∣ (a * b).val ↔ (q / l) • a • g = 0 ∨ (q / l) • b • g = 0

For prime l ∣ q, l divides (a * b).val in ZMod q iff (q / l) • (a • g) = 0 or (q / l) • (b • g) = 0 (generalization of [BS23], Lemma 16.2, p. 687; Exercise 16.2(a), p. 707).

The l-th-power DDH distinguisher of [BS23], Exercise 16.2(a) (p. 707): accept (u, v, w) iff (q / l) • w = 0 iff (q / l) • u = 0 ∨ (q / l) • v = 0.

In the real DDH experiment, ddhSmallFactorDistinguisher q l returns PMF.pure true when l is prime and divides q.

theorem Cslib.Crypto.probability_ddhRandomExperiment_ddhSmallFactorDistinguisher {G : Type} [AddCommGroup G] [DecidableEq G] (q l : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (hlq : l ∣ q) (hg : Function.Injective fun (c : ZMod q) => c • g) :
((ProbComp.eval (ddhRandomExperiment q g (ddhSmallFactorDistinguisher q l))) true).toReal = 1 - (3 * ↑l - 2) * (↑l - 1) / ↑l ^ 3

Acceptance probability of ddhSmallFactorDistinguisher q l in the random DDH experiment is 1 - (3 * l - 2) * (l - 1) / l ^ 3 ([BS23], Exercise 16.2(a), p. 707).

theorem Cslib.Crypto.ddhAdvantage_ddhSmallFactorDistinguisher {G : Type} [AddCommGroup G] [DecidableEq G] (q l : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (hl : Nat.Prime l) (hlq : l ∣ q) (hg : Function.Injective fun (c : ZMod q) => c • g) :
ddhAdvantage q g (ddhSmallFactorDistinguisher q l) = (3 * ↑l - 2) * (↑l - 1) / ↑l ^ 3

The exact fixed-group DDH advantage of ddhSmallFactorDistinguisher q l for prime l ∣ q is (3 * l - 2) * (l - 1) / l ^ 3 ([BS23], Exercise 16.2(a), p. 707). Since l ≥ 1, both subtractions in ℝ≥0 are exact (non-truncated). At l = 2 this equals 1 / 2, and for every prime l it is at least 1 / l and close to 3 / l for large l (reading the book's "advantage about 1 / l").

theorem Cslib.Crypto.inv_le_ddhAdvantage_ddhSmallFactorDistinguisher {G : Type} [AddCommGroup G] [DecidableEq G] (q l : ℕ) [NeZero q] [Module (ZMod q) G] (g : G) (hl : Nat.Prime l) (hlq : l ∣ q) (hg : Function.Injective fun (c : ZMod q) => c • g) :

ddhSmallFactorDistinguisher q l achieves fixed-group advantage at least 1 / l for every prime l ∣ q ([BS23], Exercise 16.2(a), p. 707).