Documentation

CslibFrontier.Crypto.Computational.DiffieHellman.CyclicGroupFamily

Decisional Diffie–Hellman over cyclic group families, and small prime factors of the order #

This module states the Decisional Diffie–Hellman assumption over a CyclicGroupFamily: Attack Game 10.6 of [BS23] (p. 410) without the restriction that the order is prime, as in Exercise 10.24 (p. 431). Its declarations have the shapes of the prime-order ones in CslibFrontier/Crypto/Computational/DiffieHellman.lean, and on a prime-order family the two assumptions agree (PrimeOrderGroupFamily.ddh_toCyclicGroupFamily_iff).

The small-prime-factor test of [BS23], Exercise 16.2(a) (p. 707) (Cslib.Crypto.ddhSmallFactorDistinguisher in CslibFrontier/Crypto/Computational/DiffieHellman/SmallFactor.lean), generalizes the parity test of Section 16.1.3 (Cslib.Crypto.ddhParityDistinguisher in CslibFrontier/Crypto/Computational/DiffieHellman/EvenOrder.lean) from l = 2 to any prime factor l ∣ F.order d. Parameterized by a factor selector factor : ℕ → F.Desc → ℕ, CyclicGroupFamily.ddhSmallFactorDistinguisher F factor is computed by one uniform strict PPT machine on encDDHInput whenever factor is polynomial time (CyclicGroupFamily.isPPT_ddhSmallFactorDistinguisher). Whenever factor n d is a prime divisor of F.order d at most bound n, its distinguishing advantage is at least (bound n)⁻¹ (CyclicGroupFamily.inv_le_advantage_ddhSmallFactorDistinguisher), so DDH fails whenever a polynomial-time selector finds a polynomially bounded prime factor infinitely often (CyclicGroupFamily.not_ddh_of_prime_factor). In particular:

Main definitions #

Main results #

Implementation notes #

DDHInput, encDDHInput, DDHDistinguisher, DDHDistinguisher.IsPPT, ddhRealGame, ddhRandomGame and DDH repeat the prime-order declarations over CyclicGroupFamily, with the same games Cslib.Crypto.ddhRealExperiment and Cslib.Crypto.ddhRandomExperiment. ddh_toCyclicGroupFamily_iff ties the two assumptions together. Removing this repeated boilerplate after PrimeOrderGroupFamily settles is tracked separately in #5673.

Not covered: the O(log q) operation count of Exercise 16.2(a) as a count of group operations (only polynomial time on encDDHInput is proved), Exercise 16.2(b), and a family of the groups (ZMod p)ˣ. For such a family with odd primes p, not_ddh_of_even_order applies, since the order p - 1 is even; without it, the book's conclusion that DDH does not hold in Z_p^* (p. 687, and the remark after Exercise 10.24) is proved here only in the fixed-group form ddhAdvantage_units_ddhParityDistinguisher.

References #

Distinguisher inputs and the DDH assumption #

The input of a DDH distinguisher: the security parameter, public group parameters d and three elements of F.Carrier d, which are a • g, b • g and the candidate shared element.

  • secParam : ℕ

    The security parameter, given to machines in unary.

  • groupParameters : F.Desc

    Public parameters selecting the group, its order and generator within the family.

  • leftPublic : F.Carrier self.groupParameters

    The first public element, a • g in the experiment.

  • rightPublic : F.Carrier self.groupParameters

    The second public element, b • g in the experiment.

  • candidateShared : F.Carrier self.groupParameters

    The candidate shared element: (a * b) • g in the real experiment, an independent c • g in the random one.

theorem Cslib.Crypto.CyclicGroupFamily.encDDHInput_secParam_budget (F : CyclicGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
theorem Cslib.Crypto.CyclicGroupFamily.encDDHInput_rightPublic_budget (F : CyclicGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
theorem Cslib.Crypto.CyclicGroupFamily.encDDHInput_mk_budget (F : CyclicGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {budget x0 : γ → ℕ} {x1 : γ → F.Desc} {x2 x3 x4 : (c : γ) → F.Carrier (x1 c)} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn Turing.MultiTapeTM.encUnary budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn F.encDesc budget) (h2 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => F.encode (x1 c) (x2 c)) encIn Turing.MultiTapeTM.encBits budget) (h3 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => F.encode (x1 c) (x3 c)) encIn Turing.MultiTapeTM.encBits budget) (h4 : Turing.MultiTapeTM.ComputableInSpace (fun (c : γ) => F.encode (x1 c) (x4 c)) encIn Turing.MultiTapeTM.encBits budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { secParam := x0 x, groupParameters := x1 x, leftPublic := x2 x, rightPublic := x3 x, candidateShared := x4 x }) encIn F.encDDHInput budget

The encoding of a DDH input: the unary security parameter, the group parameters and the words of the three elements, each framed except the last (encDDHInput_apply). It has the layout of PrimeOrderGroupFamily.encDDHInput.

theorem Cslib.Crypto.CyclicGroupFamily.encDDHInput_candidateShared_budget (F : CyclicGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
theorem Cslib.Crypto.CyclicGroupFamily.encDDHInput_leftPublic_budget (F : CyclicGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
theorem Cslib.Crypto.CyclicGroupFamily.encDDHInput_groupParameters_budget (F : CyclicGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ F.encDDHInput S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).groupParameters) encIn✝ F.encDesc S✝
theorem Cslib.Crypto.CyclicGroupFamily.encDDHInput_mk_inO (F : CyclicGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {x0 T0 S0 : γ → ℕ} {x1 : γ → F.Desc} {T1 S1 : γ → ℕ} {x2 : (c : γ) → F.Carrier (x1 c)} {T2 S2 : γ → ℕ} {x3 : (c : γ) → F.Carrier (x1 c)} {T3 S3 : γ → ℕ} {x4 : (c : γ) → F.Carrier (x1 c)} {T4 S4 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encUnary T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn F.encDesc T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => F.encode (x1 c) (x2 c)) encIn Turing.MultiTapeTM.encBits T2 S2) (h3 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => F.encode (x1 c) (x3 c)) encIn Turing.MultiTapeTM.encBits T3 S3) (h4 : Turing.MultiTapeTM.ComputableInO (fun (c : γ) => F.encode (x1 c) (x4 c)) encIn Turing.MultiTapeTM.encBits T4 S4) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { secParam := x0 x, groupParameters := x1 x, leftPublic := x2 x, rightPublic := x3 x, candidateShared := x4 x }) encIn F.encDDHInput (fun (x : γ) => T0 x + (T1 x + (T2 x + (T3 x + T4 x)))) fun (x : γ) => S0 x + (S1 x + (S2 x + (S3 x + S4 x)))
theorem Cslib.Crypto.CyclicGroupFamily.encDDHInput_mk_polyTime (F : CyclicGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → ℕ} {x1 : γ → F.Desc} {x2 x3 x4 : (c : γ) → F.Carrier (x1 c)} (h0 : Turing.MultiTapeTM.ComputableInPolyTime x0 encIn Turing.MultiTapeTM.encUnary) (h1 : Turing.MultiTapeTM.ComputableInPolyTime x1 encIn F.encDesc) (h2 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => F.encode (x1 c) (x2 c)) encIn Turing.MultiTapeTM.encBits) (h3 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => F.encode (x1 c) (x3 c)) encIn Turing.MultiTapeTM.encBits) (h4 : Turing.MultiTapeTM.ComputableInPolyTime (fun (c : γ) => F.encode (x1 c) (x4 c)) encIn Turing.MultiTapeTM.encBits) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { secParam := x0 x, groupParameters := x1 x, leftPublic := x2 x, rightPublic := x3 x, candidateShared := x4 x }) encIn F.encDDHInput
@[reducible, inline]

A DDH distinguisher over the family: given the security parameter, public group parameters d and three elements of F.Carrier d, it outputs a bit.

A DDH distinguisher is PPT when one uniform strict PPT machine reads encDDHInput and writes the distinguisher's output bit.

noncomputable def Cslib.Crypto.CyclicGroupFamily.ddhRealGame (F : CyclicGroupFamily) (setup : ℕ → PMF F.Desc) (distinguisher : F.DDHDistinguisher) (n : ℕ) :

The real DDH game ([BS23], Attack Game 10.6, Experiment 0, with the order not required to be prime as in Exercise 10.24): choose group parameters d using the arbitrary setup law, then run Cslib.Crypto.ddhRealExperiment in F.Carrier d.

noncomputable def Cslib.Crypto.CyclicGroupFamily.ddhRandomGame (F : CyclicGroupFamily) (setup : ℕ → PMF F.Desc) (distinguisher : F.DDHDistinguisher) (n : ℕ) :

The random DDH game ([BS23], Attack Game 10.6, Experiment 1, with the order not required to be prime as in Exercise 10.24): choose group parameters d using the arbitrary setup law, then run Cslib.Crypto.ddhRandomExperiment in F.Carrier d.

The Decisional Diffie–Hellman assumption for a cyclic group family and a setup law ([BS23], Attack Game 10.6, printed p. 410, with the order not required to be prime, as in Exercise 10.24, printed p. 431): every PPT DDH distinguisher has negligible advantage between ddhRealGame and ddhRandomGame. This is a hypothesis, not a theorem; on a prime-order family it is PrimeOrderGroupFamily.DDH (PrimeOrderGroupFamily.ddh_toCyclicGroupFamily_iff).

Agreement with the prime-order assumption #

A distinguisher over F is PPT for F.toCyclicGroupFamily exactly when it is PPT for F: the two input encodings agree.

On a prime-order family the DDH assumption over cyclic group families is the prime-order one.

Small prime factors and the parity test in families #

The small-prime-factor DDH distinguisher of [BS23], Exercise 16.2(a) (p. 707), parameterized by a factor selector factor : ℕ → F.Desc → ℕ: in the group selected by d it runs Cslib.Crypto.ddhSmallFactorDistinguisher (F.order d) (factor n d). When used inside not_ddh_of_polynomiallyBounded_minFac, factor selects the greatest prime factor of F.order d up to the polynomial bound C * (n + 1) ^ D where the exercise names the smallest prime factor; both yield the same failure theorem.

The small-factor test is efficient: whenever factor is computable in polynomial time on encPair encUnary F.encDesc → encNat, one uniform strict PPT machine computes ddhSmallFactorDistinguisher F factor on encDDHInput. It divides F.order d by factor n d and multiplies each encoded element by the quotient using F.smul.

theorem Cslib.Crypto.CyclicGroupFamily.inv_le_advantage_ddhSmallFactorDistinguisher (F : CyclicGroupFamily) (setup : ℕ → PMF F.Desc) (factor : ℕ → F.Desc → ℕ) (n B : ℕ) (hsupport : ∀ d ∈ (setup n).support, Nat.Prime (factor n d) ∧ factor n d ∣ F.order d ∧ factor n d ≤ B) :

If every d ∈ (setup n).support has order divisible by a prime factor n d ≤ B, then ddhSmallFactorDistinguisher F factor achieves distinguishing advantage at least (B : ℝ≥0)⁻¹ at security parameter n.

theorem Cslib.Crypto.CyclicGroupFamily.not_ddh_of_prime_factor (F : CyclicGroupFamily) {setup : ℕ → PMF F.Desc} (factor : ℕ → F.Desc → ℕ) (hfactor : Turing.MultiTapeTM.ComputableInPolyTime (fun (p : ℕ × F.Desc) => factor p.1 p.2) (Turing.MultiTapeTM.encPair Turing.MultiTapeTM.encUnary F.encDesc) Turing.MultiTapeTM.encNat) (bound : ℕ → ℕ) (hbound : PolynomiallyBounded bound) (hle : ∃ᶠ (n : ℕ) in Filter.atTop, ∀ d ∈ (setup n).support, Nat.Prime (factor n d) ∧ factor n d ∣ F.order d ∧ factor n d ≤ bound n) :
¬F.DDH setup

General prime-factor DDH failure criterion (underlying [BS23], Exercise 10.24 and Exercise 16.2(a)): whenever a polynomial-time factor selector factor outputs, for infinitely many security parameters n, a prime divisor of F.order d at most bound n across (setup n).support for a polynomially bounded bound, F.DDH setup fails.

theorem Cslib.Crypto.CyclicGroupFamily.not_ddh_of_polynomiallyBounded_minFac (F : CyclicGroupFamily) {setup : ℕ → PMF F.Desc} (bound : ℕ → ℕ) (hbound : PolynomiallyBounded bound) (hmin : ∃ᶠ (n : ℕ) in Filter.atTop, ∀ d ∈ (setup n).support, 1 < F.order d ∧ (F.order d).minFac ≤ bound n) :
¬F.DDH setup

DDH fails when a small prime factor is polynomially bounded ([BS23], Exercise 16.2(a), p. 707): if for infinitely many security parameters n, every group d in the support of setup n has 1 < F.order d and smallest prime factor (F.order d).minFac ≤ bound n for a polynomially bounded bound, then DDH does not hold.

The distinguisher instantiated in the proof (ddhSmallFactorDistinguisher F fun n d => Nat.findGreatest (fun i => i.Prime ∧ F.order d % i = 0) (C * (n + 1) ^ D)) tests the greatest prime factor up to C * (n + 1) ^ D where the exercise names the smallest prime factor; the theorem is the same, since any prime divisor up to bound n gives advantage at least (bound n)⁻¹. The proof establishes polynomial time on encDDHInput, not the O(log q) operation count.

The parity test of [BS23], Section 16.1.3 (p. 687), as a distinguisher over the family: in the group selected by d it runs Cslib.Crypto.ddhParityDistinguisher (F.order d).

The parity test is efficient: one uniform strict PPT machine computes ddhParityDistinguisher on encDDHInput. It computes F.order d / 2, multiplies each encoded element by it with F.smul and compares the results with the encoded identity.

theorem Cslib.Crypto.CyclicGroupFamily.not_ddh_of_even_order {F : CyclicGroupFamily} {setup : ℕ → PMF F.Desc} (heven : ∀ (n : ℕ), ∀ d ∈ (setup n).support, Even (F.order d)) :
¬F.DDH setup

DDH fails in families of even order ([BS23], Exercise 10.24, p. 431): when every group the setup law can produce has even order, the parity test, which is PPT (isPPT_ddhParityDistinguisher), has advantage 1 / 2 for every security parameter, so the DDH assumption does not hold.