Documentation

CslibFrontier.Crypto.Computational.DiffieHellman

The Computational and Decisional Diffie–Hellman assumptions #

Over a PrimeOrderGroupFamily, the Computational Diffie–Hellman (CDH) game ([BS23], Attack Game 10.5) draws public group parameters d from a setup law and runs the fixed-group experiment Cslib.Crypto.cdhExperiment in F.Carrier d: the adversary receives a • g and b • g (the textbook g^a and g^b) and wins when it outputs (a * b) • g. The Decisional Diffie–Hellman (DDH) games ([BS23], Attack Game 10.6) likewise run Cslib.Crypto.ddhRealExperiment and Cslib.Crypto.ddhRandomExperiment.

Adversaries receive and return group elements. Their efficiency is stated on encodings: CDHAdversary.IsPPT and DDHDistinguisher.IsPPT ask for one uniform strict PPT machine that reads encCDHInput or encDDHInput (the unary security parameter, group parameters and encoded elements) and writes the encoding of the adversary's output. encCDHInput_apply and encDDHInput_apply give the word layouts.

A distinguisher outputs a bit, so DDH is the same assumption as its word-level form over distinguishers that read the encoded tuple (ddh_iff_encoded). A CDH adversary must output a group element, whereas a word-level adversary may output any word. CDH, and hence the conclusion of DDH.cdh, is therefore the textbook assumption, which is weaker than the word-level CDH assumption; CslibFrontier.Crypto.Computational.DiffieHellman.Decodable restores the word-level form and equivalence CDH ↔ WordCDH for DecodablePrimeOrderGroupFamily (#4783).

We prove the implications DDH ⇒ CDH ⇒ DiscreteLog between the assumptions from the fixed-group bounds Cslib.Crypto.dlAdvantage_le_cdhAdvantage_dlToCDH and Cslib.Crypto.probability_ddhRandomExperiment_cdhToDDH_le. We also prove the random self-reducibility of DDH ([BS23], Section 10.11, Exercises 10.8–10.10, pp. 425–426): the distributional rerandomisation lemma (ddhRerandomizeLaw_real, ddhRerandomizeLaw_random), its efficient form ddhSelfReduceDistinguisher, average-case DDH from worst-case DDH with instances that may depend on the distinguisher (ddh_of_worstCase), and a Chernoff-amplified decider ddhAmplifiedDecider that turns a distinguisher with inverse-polynomial advantage into one that decides every triple except with negligible error. The Diffie–Hellman assumptions are hypotheses, not theorems.

Main definitions #

Main results #

References #

Adversary inputs and their encodings #

The input of a CDH adversary: the security parameter, public group parameters d and two elements of F.Carrier d, which are a • g and b • g in the experiment.

  • secParam : ℕ

    The security parameter, given to machines in unary.

  • groupParameters : F.Desc

    Public parameters selecting the group, its prime order and generator within the family. For Schnorr groups these contain the modulus p, subgroup order q and generator g.

  • 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.

The input of a DDH distinguisher: a CDH input and a candidate shared element, which is (a * b) • g in the real experiment and an independent c • g in the random one.

theorem Cslib.Crypto.PrimeOrderGroupFamily.encCDHInput_secParam_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.CDHInput} :
theorem Cslib.Crypto.PrimeOrderGroupFamily.encCDHInput_mk_inO (F : PrimeOrderGroupFamily) {γ : 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 : γ → ℕ} (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) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { secParam := x0 x, groupParameters := x1 x, leftPublic := x2 x, rightPublic := x3 x }) encIn F.encCDHInput (fun (x : γ) => T0 x + (T1 x + (T2 x + T3 x))) fun (x : γ) => S0 x + (S1 x + (S2 x + S3 x))
theorem Cslib.Crypto.PrimeOrderGroupFamily.encCDHInput_groupParameters_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.CDHInput} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ F.encCDHInput S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).groupParameters) encIn✝ F.encDesc S✝
theorem Cslib.Crypto.PrimeOrderGroupFamily.encCDHInput_mk_budget (F : PrimeOrderGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {budget x0 : γ → ℕ} {x1 : γ → F.Desc} {x2 x3 : (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) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { secParam := x0 x, groupParameters := x1 x, leftPublic := x2 x, rightPublic := x3 x }) encIn F.encCDHInput budget

The encoding of a CDH input: the unary security parameter, the group parameters and the words F.encode d u, F.encode d v of the public elements, each framed except the last (encCDHInput_apply).

theorem Cslib.Crypto.PrimeOrderGroupFamily.encCDHInput_leftPublic_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.CDHInput} :
theorem Cslib.Crypto.PrimeOrderGroupFamily.encCDHInput_rightPublic_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.CDHInput} :
theorem Cslib.Crypto.PrimeOrderGroupFamily.encCDHInput_mk_polyTime (F : PrimeOrderGroupFamily) {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → ℕ} {x1 : γ → F.Desc} {x2 x3 : (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) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (x : γ) => { secParam := x0 x, groupParameters := x1 x, leftPublic := x2 x, rightPublic := x3 x }) encIn F.encCDHInput
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDDHInput_candidateShared_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDDHInput_secParam_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDDHInput_toCDHInput_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
Turing.MultiTapeTM.ComputableInSpace g✝ encIn✝ F.encDDHInput S✝ → Turing.MultiTapeTM.ComputableInSpace (fun (c : γ✝) => (g✝ c).toCDHInput) encIn✝ F.encCDHInput S✝
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDDHInput_mk_inO (F : PrimeOrderGroupFamily) {γ : 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)))

The encoding of a DDH input: the fields of its CDH input followed by the word of the candidate shared element, each framed except the last (encDDHInput_apply).

theorem Cslib.Crypto.PrimeOrderGroupFamily.encDDHInput_groupParameters_budget (F : PrimeOrderGroupFamily) {γ✝ : 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.PrimeOrderGroupFamily.encDDHInput_mk_budget (F : PrimeOrderGroupFamily) {γ : 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
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDDHInput_rightPublic_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDDHInput_mk_polyTime (F : PrimeOrderGroupFamily) {γ : 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
theorem Cslib.Crypto.PrimeOrderGroupFamily.encDDHInput_leftPublic_budget (F : PrimeOrderGroupFamily) {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → F.DDHInput} :

The encoded identity of computed group parameters, computed as 0 • g.

The encoded sum of computed elements.

The encoded multiple of a computed element by a computed natural number.

The encoded negation of a computed element, computed as (q - 1) • x for the group order q.

The encoded difference of computed elements.

theorem Cslib.Crypto.PrimeOrderGroupFamily.computableInPolyTime_encode_cond {F : PrimeOrderGroupFamily} {α : Type} {enc : α ↪ List Bool} {d : α → F.Desc} {c : α → Bool} {x y : (a : α) → F.Carrier (d a)} (hc : Turing.MultiTapeTM.ComputableInPolyTime c enc Turing.MultiTapeTM.encBool) (hx : Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => F.encode (d a) (x a)) enc Turing.MultiTapeTM.encBits) (hy : Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => F.encode (d a) (y a)) enc Turing.MultiTapeTM.encBits) :
Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => F.encode (d a) (bif c a then x a else y a)) enc Turing.MultiTapeTM.encBits

The encoding of a computed choice between computed elements.

Computational Diffie–Hellman (CDH) #

@[reducible, inline]

A CDH adversary over the family: given the security parameter, public group parameters d and two elements of F.Carrier d, it outputs an element of F.Carrier d. CDHAdversary.IsPPT states its efficiency on encodings.

A CDH adversary is PPT when one uniform strict PPT machine reads encCDHInput and writes the encoding of the adversary's output element.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.cdhGame (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (adversary : F.CDHAdversary) (n : ℕ) :

The Computational Diffie–Hellman experiment ([BS23], Attack Game 10.5): choose group parameters d using the arbitrary setup law, then run Cslib.Crypto.cdhExperiment in the group F.Carrier d. No efficient sampler for setup is required.

The Computational Diffie–Hellman assumption for a family and a setup law: every PPT CDH adversary wins cdhGame with negligible probability. It is [BS23], Attack Game 10.5 and Definition 10.7 (pp. 409–410), read asymptotically as in Section 10.5.2 (pp. 413–414). The group parameters are drawn from setup, which need not be efficiently samplable, whereas the source draws them with an efficient system parameterization algorithm (Definition 10.9, p. 413); the assumption is the source's only for setup laws that an efficient algorithm samples, as for DiscreteLog.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.discreteLogAdversary (F : PrimeOrderGroupFamily) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (n : ℕ) (d : F.Desc) (u : F.Carrier d) :

The fixed-group discrete-logarithm adversary run by a word-level one: encode the instance, run the word-level adversary and read its output as a binary exponent, as discreteLogGame does.

theorem Cslib.Crypto.PrimeOrderGroupFamily.discreteLogGame_eq (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (n : ℕ) :
F.discreteLogGame setup adversary n = Game.withSetup (setup n) fun (d : F.Desc) => dlExperiment (F.order d) (F.generator d) (F.discreteLogAdversary adversary n d)

discreteLogGame averages Cslib.Crypto.dlExperiment of discreteLogAdversary over the setup law.

Turn a word-level discrete-logarithm adversary into a CDH adversary: run Cslib.Crypto.dlToCDH on its discreteLogAdversary.

Whenever the discrete-logarithm adversary recovers α, dlToCDHAdversary outputs the Diffie–Hellman shared element.

The discrete-logarithm-to-CDH reduction is uniform strict PPT when the discrete-logarithm adversary is.

CDH implies the discrete-logarithm assumption.

Decisional Diffie–Hellman (DDH) #

@[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. DDHDistinguisher.IsPPT states its efficiency on encodings.

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

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

The real DDH game ([BS23], Attack Game 10.6, Experiment 0): choose group parameters d using the arbitrary setup law, then run Cslib.Crypto.ddhRealExperiment in F.Carrier d.

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

The random DDH game ([BS23], Attack Game 10.6, Experiment 1): 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 family and a setup law: every PPT DDH distinguisher has negligible advantage between ddhRealGame and ddhRandomGame. It is [BS23], Attack Game 10.6 and Definition 10.8 (pp. 410–411), read asymptotically as in Section 10.5.2 (pp. 413–414). The group parameters are drawn from setup, which need not be efficiently samplable, whereas the source draws them with an efficient system parameterization algorithm (Definition 10.9, p. 413); the assumption is the source's only for setup laws that an efficient algorithm samples, as for DiscreteLog.

theorem Cslib.Crypto.PrimeOrderGroupFamily.DDHDistinguisher.IsPPT.comp {F : PrimeOrderGroupFamily} {distinguisher : F.DDHDistinguisher} (hD : distinguisher.IsPPT) {α : Type} {enc : α ↪ List Bool} {n : α → ℕ} {d : α → F.Desc} {u v w : (a : α) → F.Carrier (d a)} (hn : Turing.MultiTapeTM.ComputableInPolyTime n enc Turing.MultiTapeTM.encUnary) (hd : Turing.MultiTapeTM.ComputableInPolyTime d enc F.encDesc) (hu : Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => F.encode (d a) (u a)) enc Turing.MultiTapeTM.encBits) (hv : Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => F.encode (d a) (v a)) enc Turing.MultiTapeTM.encBits) (hw : Turing.MultiTapeTM.ComputableInPolyTime (fun (a : α) => F.encode (d a) (w a)) enc Turing.MultiTapeTM.encBits) :
Probability.IsPPTOn enc Turing.MultiTapeTM.encBool fun (a : α) => distinguisher (n a) (d a) (u a) (v a) (w a)

A PPT DDH distinguisher run on computed inputs is uniform strict PPT.

DDH is the word-level DDH assumption. Quantifying over distinguishers that read the encoded tuple (1ⁿ, d, encode u, encode v, encode w) as words, each with one uniform strict PPT machine on its flat layout, gives the same assumption as quantifying over typed distinguishers. A typed distinguisher's machine reads exactly that layout; conversely, a word distinguisher is typed by encoding its elements, and a typed one is a word distinguisher on that layout run on the encoded elements (IsPPTOn.exists_bool_factor), since its output is a single bit.

Turn a CDH adversary into a DDH distinguisher by running Cslib.Crypto.cdhToDDH in each group.

@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhRealGame_cdhToDDHDistinguisher (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (adversary : F.CDHAdversary) (n : ℕ) :
F.ddhRealGame setup (F.cdhToDDHDistinguisher adversary) n = F.cdhGame setup adversary n

In the real DDH game, cdhToDDHDistinguisher runs the CDH game.

theorem Cslib.Crypto.PrimeOrderGroupFamily.succProbability_ddhRandomGame_cdhToDDHDistinguisher_le (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (adversary : F.CDHAdversary) (n m : ℕ) (hm0 : 0 < m) (hm : ∀ d ∈ (setup n).support, m ≤ F.order d) :
(F.ddhRandomGame setup (F.cdhToDDHDistinguisher adversary) n).succProbability ≤ 1 / ↑m

In the random DDH game, cdhToDDHDistinguisher accepts with probability at most 1 / m whenever every supported group order is at least m > 0.

theorem Cslib.Crypto.PrimeOrderGroupFamily.succProbability_cdhGame_le_advantage_ddh_add (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (adversary : F.CDHAdversary) (n m : ℕ) (hm0 : 0 < m) (hm : ∀ d ∈ (setup n).support, m ≤ F.order d) :
(F.cdhGame setup adversary n).succProbability ≤ (F.ddhRealGame setup (F.cdhToDDHDistinguisher adversary) n).advantage (F.ddhRandomGame setup (F.cdhToDDHDistinguisher adversary) n) + 1 / ↑m

Quantitative reduction from CDH to DDH: when every supported group at parameter n has order at least m > 0, any CDH adversary's success probability is at most the DDH distinguishing advantage of cdhToDDHDistinguisher plus 1 / m.

The CDH-to-DDH reduction is uniform strict PPT when the CDH adversary is.

theorem Cslib.Crypto.PrimeOrderGroupFamily.DDH.cdh {F : PrimeOrderGroupFamily} {setup : ℕ → PMF F.Desc} (hDDH : F.DDH setup) {m : ℕ → ℕ} (hm0 : ∀ (n : ℕ), 0 < m n) (hm : ∀ (n : ℕ), ∀ d ∈ (setup n).support, m n ≤ F.order d) (hinv : Negligible fun (n : ℕ) => 1 / ↑(m n)) :
F.CDH setup

DDH implies CDH when every supported group at parameter n has order at least m n > 0 and 1 / m n is negligible. The conclusion is the textbook CDH assumption against adversaries that output group elements, which is weaker than the word-level CDH assumption in general; see DecodablePrimeOrderGroupFamily.DDH.wordCDH in CslibFrontier.Crypto.Computational.DiffieHellman.Decodable for decodable families.

theorem Cslib.Crypto.PrimeOrderGroupFamily.DDH.discreteLog {F : PrimeOrderGroupFamily} {setup : ℕ → PMF F.Desc} (hDDH : F.DDH setup) {m : ℕ → ℕ} (hm0 : ∀ (n : ℕ), 0 < m n) (hm : ∀ (n : ℕ), ∀ d ∈ (setup n).support, m n ≤ F.order d) (hinv : Negligible fun (n : ℕ) => 1 / ↑(m n)) :
F.DiscreteLog setup

DDH implies the discrete-logarithm assumption when every supported group at parameter n has order at least m n > 0 and 1 / m n is negligible.

Random self-reducibility of DDH #

def Cslib.Crypto.PrimeOrderGroupFamily.ddhRerandomize (F : PrimeOrderGroupFamily) (d : F.Desc) (u v w : F.Carrier d) (r s₁ s₂ : ZMod (F.order d)) :

Re-randomize a candidate DDH triple (u, v, w) in F.Carrier d using exponents r, s₁, s₂ : ZMod (F.order d).

theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhRerandomize_smul_generator (F : PrimeOrderGroupFamily) (d : F.Desc) (α β γ r s₁ s₂ : ZMod (F.order d)) :
F.ddhRerandomize d (α • F.generator d) (β • F.generator d) (γ • F.generator d) r s₁ s₂ = ((r * α + s₁) • F.generator d, (β + s₂) • F.generator d, ((r * α + s₁) * (β + s₂) + r * (γ - α * β)) • F.generator d)

Algebraic action of ddhRerandomize on multiples of the generator: a tuple error γ - α * β is scaled by r and added to the new Diffie–Hellman product (r * α + s₁) * (β + s₂).

The re-randomized triple distribution obtained by drawing r, s₁, s₂ : ZMod (F.order d) independently and uniformly.

The real DDH tuple distribution on F.Carrier d.

The random DDH tuple distribution on F.Carrier d: the triple that Cslib.Crypto.ddhRandomExperiment gives its distinguisher.

Random self-reducibility of DDH (real case): re-randomizing any fixed real DDH tuple (α • g, β • g, (α * β) • g) yields the exact uniform real DDH tuple distribution.

Random self-reducibility of DDH (random case): re-randomizing any fixed non-DDH tuple (α • g, β • g, γ • g) with γ ≠ α * β yields the exact uniform random DDH tuple distribution.

Approximately uniform exponents #

Sample one approximate uniform exponent modulo F.order d using n + |encNat (F.order d)| fair coins via ProbComp.sampleModNat, within statistical distance 1 / 2 ^ n of exact uniform on ZMod (F.order d).

sampleExp is uniform strict PPT whenever n and d are computable in polynomial time.

Replacing one sampleExp n d draw by an exact uniform draw on ZMod (F.order d) changes Game.advantage by at most 1 / 2 ^ n.

Distribution of a single modular exponent sampled via ProbComp.sampleModNat at parameter n and group parameters d, projected to ZMod (F.order d) (original).

Each modular exponent sampled by ProbComp.sampleModNat ((F.order d).size + n) (F.order d) is within statistical distance 1 / 2 ^ n of PMF.uniformOfFintype (ZMod (F.order d)) (original).

Efficient DDH random self-reduction #

The DDH random self-reduction ([BS23], Exercises 10.8–10.9, pp. 425–426): draw three approximately uniform exponents with sampleExp, re-randomize the input triple with ddhRerandomize, and run distinguisher on the result.

ddhSelfReduceDistinguisher is uniform strict PPT whenever distinguisher is.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_ddhRerandomizeLaw_ddhSelfReduceDistinguisher_le (F : PrimeOrderGroupFamily) (distinguisher : F.DDHDistinguisher) (n : ℕ) (d : F.Desc) (u v w : F.Carrier d) :
Game.advantage ((F.ddhRerandomizeLaw d u v w).bind fun (x : F.Carrier d × F.Carrier d × F.Carrier d) => match x with | (u', v', w') => (distinguisher n d u' v' w').eval) (F.ddhSelfReduceDistinguisher distinguisher n d u v w).eval ≤ 3 / 2 ^ n

Sampling loss of the DDH self-reduction: on any fixed triple, replacing the three exact uniform exponents of ddhRerandomizeLaw by the sampleExp draws of ddhSelfReduceDistinguisher changes the acceptance law by at most 3 / 2 ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhRealTupleLaw_bind_eq (F : PrimeOrderGroupFamily) (distinguisher : F.DDHDistinguisher) (n : ℕ) (d : F.Desc) :
((F.ddhRealTupleLaw d).bind fun (x : F.Carrier d × F.Carrier d × F.Carrier d) => match x with | (u, v, w) => (distinguisher n d u v w).eval) = ProbComp.eval (ddhRealExperiment (F.order d) (F.generator d) (distinguisher n d))

Running a distinguisher on the uniform real DDH tuple is the real DDH experiment.

theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhRandomTupleLaw_bind_eq (F : PrimeOrderGroupFamily) (distinguisher : F.DDHDistinguisher) (n : ℕ) (d : F.Desc) :
((F.ddhRandomTupleLaw d).bind fun (x : F.Carrier d × F.Carrier d × F.Carrier d) => match x with | (u, v, w) => (distinguisher n d u v w).eval) = ProbComp.eval (ddhRandomExperiment (F.order d) (F.generator d) (distinguisher n d))

Running a distinguisher on the uniform random DDH tuple is the random DDH experiment.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_ddhRealExperiment_ddhSelfReduceDistinguisher_le (F : PrimeOrderGroupFamily) (distinguisher : F.DDHDistinguisher) (n : ℕ) (d : F.Desc) (α β : ZMod (F.order d)) :
Game.advantage (ProbComp.eval (ddhRealExperiment (F.order d) (F.generator d) (distinguisher n d))) (F.ddhSelfReduceDistinguisher distinguisher n d (α • F.generator d) (β • F.generator d) ((α * β) • F.generator d)).eval ≤ 3 / 2 ^ n

On any fixed real DDH triple, ddhSelfReduceDistinguisher accepts within 3 / 2 ^ n of the real DDH experiment.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_ddhRandomExperiment_ddhSelfReduceDistinguisher_le (F : PrimeOrderGroupFamily) (distinguisher : F.DDHDistinguisher) (n : ℕ) (d : F.Desc) {α β γ : ZMod (F.order d)} (hγ : γ ≠ α * β) :
Game.advantage (ProbComp.eval (ddhRandomExperiment (F.order d) (F.generator d) (distinguisher n d))) (F.ddhSelfReduceDistinguisher distinguisher n d (α • F.generator d) (β • F.generator d) (γ • F.generator d)).eval ≤ 3 / 2 ^ n

On any fixed non-DDH triple, ddhSelfReduceDistinguisher accepts within 3 / 2 ^ n of the random DDH experiment.

Worst-case DDH #

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.ddhRerandomizeGame (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (u v w : (d : F.Desc) → F.Carrier d) (distinguisher : F.DDHDistinguisher) (n : ℕ) :

The DDH re-randomization game ([BS23], Exercises 10.8–10.9, pp. 425–426): draw group parameters d, re-randomize the fixed triple (u d, v d, w d) with exact uniform exponents, and run distinguisher on the result.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.ddhWorstCaseGame (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (u v w : (d : F.Desc) → F.Carrier d) (distinguisher : F.DDHDistinguisher) (n : ℕ) :

The worst-case DDH game: draw group parameters d and run distinguisher on the fixed triple (u d, v d, w d).

@[simp]
theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhRerandomizeGame_real (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α β : (d : F.Desc) → ZMod (F.order d)) (distinguisher : F.DDHDistinguisher) (n : ℕ) :
F.ddhRerandomizeGame setup (fun (d : F.Desc) => α d • F.generator d) (fun (d : F.Desc) => β d • F.generator d) (fun (d : F.Desc) => (α d * β d) • F.generator d) distinguisher n = F.ddhRealGame setup distinguisher n

Re-randomizing any family of real DDH triples (α d • g, β d • g, (α d * β d) • g) gives the average-case ddhRealGame ([BS23], Exercises 10.8–10.9, pp. 425–426).

theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhRerandomizeGame_random (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α β γ : (d : F.Desc) → ZMod (F.order d)) (distinguisher : F.DDHDistinguisher) (n : ℕ) (hγ : ∀ d ∈ (setup n).support, γ d ≠ α d * β d) :
F.ddhRerandomizeGame setup (fun (d : F.Desc) => α d • F.generator d) (fun (d : F.Desc) => β d • F.generator d) (fun (d : F.Desc) => γ d • F.generator d) distinguisher n = F.ddhRandomGame setup distinguisher n

Re-randomizing any family of non-DDH triples (α d • g, β d • g, γ d • g) with γ d ≠ α d * β d on the support of setup n gives the average-case ddhRandomGame ([BS23], Exercises 10.8–10.9, pp. 425–426).

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_ddhRerandomizeGame_eq (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α β α' β' γ' : (d : F.Desc) → ZMod (F.order d)) (distinguisher : F.DDHDistinguisher) (n : ℕ) (hγ' : ∀ d ∈ (setup n).support, γ' d ≠ α' d * β' d) :
(F.ddhRerandomizeGame setup (fun (d : F.Desc) => α d • F.generator d) (fun (d : F.Desc) => β d • F.generator d) (fun (d : F.Desc) => (α d * β d) • F.generator d) distinguisher n).advantage (F.ddhRerandomizeGame setup (fun (d : F.Desc) => α' d • F.generator d) (fun (d : F.Desc) => β' d • F.generator d) (fun (d : F.Desc) => γ' d • F.generator d) distinguisher n) = (F.ddhRealGame setup distinguisher n).advantage (F.ddhRandomGame setup distinguisher n)

DDH re-randomization advantage identity ([BS23], Exercises 10.8–10.9, pp. 425–426): re-randomizing a real triple family and a non-DDH triple family leaves exactly the average-case DDH advantage.

theorem Cslib.Crypto.PrimeOrderGroupFamily.DDH.ddhRerandomizeGame {F : PrimeOrderGroupFamily} {setup : ℕ → PMF F.Desc} (hDDH : F.DDH setup) (α β α' β' γ' : (d : F.Desc) → ZMod (F.order d)) (hγ' : ∀ᶠ (n : ℕ) in Filter.atTop, ∀ d ∈ (setup n).support, γ' d ≠ α' d * β' d) :
Game.Indistinguishable (F.ddhRerandomizeGame setup (fun (d : F.Desc) => α d • F.generator d) (fun (d : F.Desc) => β d • F.generator d) fun (d : F.Desc) => (α d * β d) • F.generator d) (F.ddhRerandomizeGame setup (fun (d : F.Desc) => α' d • F.generator d) (fun (d : F.Desc) => β' d • F.generator d) fun (d : F.Desc) => γ' d • F.generator d) DDHDistinguisher.IsPPT

DDH re-randomization indistinguishability ([BS23], Exercises 10.8–10.9, pp. 425–426): under DDH, no PPT distinguisher tells the re-randomization of a real triple family from that of a non-DDH triple family.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_ddhRerandomizeGame_ddhWorstCaseGame_le (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (u v w : (d : F.Desc) → F.Carrier d) (distinguisher : F.DDHDistinguisher) (n : ℕ) :
(F.ddhRerandomizeGame setup u v w distinguisher n).advantage (F.ddhWorstCaseGame setup u v w (F.ddhSelfReduceDistinguisher distinguisher) n) ≤ 3 / 2 ^ n

Sampling loss of the worst-case reduction: replacing the exact uniform exponents of ddhRerandomizeGame by ddhSelfReduceDistinguisher on the fixed triple changes the game by at most 3 / 2 ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_ddhRealGame_le_ddhWorstCaseGame (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α β α' β' γ' : (d : F.Desc) → ZMod (F.order d)) (distinguisher : F.DDHDistinguisher) (n : ℕ) (hγ' : ∀ d ∈ (setup n).support, γ' d ≠ α' d * β' d) :
(F.ddhRealGame setup distinguisher n).advantage (F.ddhRandomGame setup distinguisher n) ≤ (F.ddhWorstCaseGame setup (fun (d : F.Desc) => α d • F.generator d) (fun (d : F.Desc) => β d • F.generator d) (fun (d : F.Desc) => (α d * β d) • F.generator d) (F.ddhSelfReduceDistinguisher distinguisher) n).advantage (F.ddhWorstCaseGame setup (fun (d : F.Desc) => α' d • F.generator d) (fun (d : F.Desc) => β' d • F.generator d) (fun (d : F.Desc) => γ' d • F.generator d) (F.ddhSelfReduceDistinguisher distinguisher) n) + 6 / 2 ^ n

Quantitative worst-case-to-average-case DDH reduction: the average-case DDH advantage of distinguisher is at most the worst-case advantage of ddhSelfReduceDistinguisher distinguisher between a real triple family and a non-DDH triple family, plus 6 / 2 ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.ddh_of_worstCase (F : PrimeOrderGroupFamily) {setup : ℕ → PMF F.Desc} (hworst : ∀ (distinguisher : F.DDHDistinguisher), distinguisher.IsPPT → ∃ (α : (d : F.Desc) → ZMod (F.order d)) (β : (d : F.Desc) → ZMod (F.order d)) (α' : (d : F.Desc) → ZMod (F.order d)) (β' : (d : F.Desc) → ZMod (F.order d)) (γ' : (d : F.Desc) → ZMod (F.order d)), (∀ᶠ (n : ℕ) in Filter.atTop, ∀ d ∈ (setup n).support, γ' d ≠ α' d * β' d) ∧ Negligible fun (n : ℕ) => (F.ddhWorstCaseGame setup (fun (d : F.Desc) => α d • F.generator d) (fun (d : F.Desc) => β d • F.generator d) (fun (d : F.Desc) => (α d * β d) • F.generator d) distinguisher n).advantage (F.ddhWorstCaseGame setup (fun (d : F.Desc) => α' d • F.generator d) (fun (d : F.Desc) => β' d • F.generator d) (fun (d : F.Desc) => γ' d • F.generator d) distinguisher n)) :
F.DDH setup

Average-case DDH from worst-case DDH: if for every PPT distinguisher there are a real triple family (α d • g, β d • g, (α d * β d) • g) and a non-DDH triple family (α' d • g, β' d • g, γ' d • g), with γ' d ≠ α' d * β' d on the support of setup n for all sufficiently large n, between which it has negligible advantage, then DDH holds. The families may depend on the distinguisher: the premise says that for every distinguisher there are families, so fixed families that work for every PPT distinguisher (Game.Indistinguishable of the two ddhWorstCaseGames) also satisfy it. This formulation and ddhWorstCaseGame are this library's.

Worst-case DDH decider via Chernoff amplification ([BS23], Exercise 10.10) #

Chernoff-amplified worst-case DDH decider ([BS23], Section 10.11, Exercise 10.10, p. 426): given a DDH distinguisher and an inverse-advantage bound invEps, run N = (n + 3) * (7 * invEps n) ^ 2 independent trials of ddhSelfReduceDistinguisher on the input triple, on the reference DDH triple (0, 0, 0) and on the reference non-DDH triple (0, 0, g), and accept iff the input count cIn is at least as close to the real count as to the random one.

ddhAmplifiedDecider is uniform strict PPT whenever distinguisher is and invEps is computable in polynomial time in unary ([BS23], Exercise 10.10, p. 426).

theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhAmplifiedDecider_error_le_pow (F : PrimeOrderGroupFamily) (distinguisher : F.DDHDistinguisher) (invEps : ℕ → ℕ) (n : ℕ) (d : F.Desc) (α β γ : ZMod (F.order d)) (hpos : 0 < invEps n) (hadv : 1 / ↑(invEps n) ≤ ↑(ddhAdvantage (F.order d) (F.generator d) (distinguisher n d))) (hmod : 3 / 2 ^ n ≤ 1 / (12 * ↑(invEps n))) :
((F.ddhAmplifiedDecider distinguisher invEps n d (α • F.generator d) (β • F.generator d) (γ • F.generator d)).eval.toOuterMeasure {b : Bool | b ≠ decide (γ = α * β)}).toReal ≤ (1 / 2) ^ n

Quantitative worst-case DDH decision bound ([BS23], Section 10.11, Exercise 10.10, p. 426): if distinguisher n has DDH advantage at least 1 / invEps n in the group d and the sampling loss satisfies 3 / 2 ^ n ≤ 1 / (12 * invEps n), then on every triple (α • g, β • g, γ • g) the decider answers differently from decide (γ = α * β) with probability at most (1 / 2) ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.ddhAmplifiedDecider_correct_ge_one_sub_pow (F : PrimeOrderGroupFamily) (distinguisher : F.DDHDistinguisher) (invEps : ℕ → ℕ) (n : ℕ) (d : F.Desc) (α β γ : ZMod (F.order d)) (hpos : 0 < invEps n) (hadv : 1 / ↑(invEps n) ≤ ↑(ddhAdvantage (F.order d) (F.generator d) (distinguisher n d))) (hmod : 3 / 2 ^ n ≤ 1 / (12 * ↑(invEps n))) :
1 - (1 / 2) ^ n ≤ ((F.ddhAmplifiedDecider distinguisher invEps n d (α • F.generator d) (β • F.generator d) (γ • F.generator d)).eval (decide (γ = α * β))).toReal

Directional correctness of ddhAmplifiedDecider ([BS23], Section 10.11, Exercise 10.10, p. 426): under the hypotheses of ddhAmplifiedDecider_error_le_pow, on every triple (α • g, β • g, γ • g) the decider outputs decide (γ = α * β) with probability at least 1 - (1 / 2) ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.negligible_ddhAmplifiedDecider_error (F : PrimeOrderGroupFamily) {distinguisher : F.DDHDistinguisher} {invEps : ℕ → ℕ} (hinvEps : Turing.MultiTapeTM.ComputableInPolyTime invEps Turing.MultiTapeTM.encUnary Turing.MultiTapeTM.encUnary) (d : ℕ → F.Desc) (α β γ : (n : ℕ) → ZMod (F.order (d n))) (hpos : ∀ᶠ (n : ℕ) in Filter.atTop, 0 < invEps n) (hadv : ∀ᶠ (n : ℕ) in Filter.atTop, 1 / ↑(invEps n) ≤ ↑(ddhAdvantage (F.order (d n)) (F.generator (d n)) (distinguisher n (d n)))) :
Negligible fun (n : ℕ) => ((F.ddhAmplifiedDecider distinguisher invEps n (d n) (α n • F.generator (d n)) (β n • F.generator (d n)) (γ n • F.generator (d n))).eval.toOuterMeasure {b : Bool | b ≠ decide (γ n = α n * β n)}).toNNReal

Worst-case DDH decider with negligible error ([BS23], Exercise 10.10, p. 426): if invEps is computable in polynomial time in unary and distinguisher eventually has DDH advantage at least 1 / invEps n in the group d n, then on every sequence of triples (α n • g, β n • g, γ n • g) in d n, ddhAmplifiedDecider decides whether γ n = α n * β n with negligible error.