Documentation

VCVio.CryptoFoundations.HardnessAssumptions.DiffieHellman

Discrete Logarithm Assumptions (DLog / CDH / DDH) #

Standard hardness assumptions for cryptographic groups, formalized using Mathlib's Module F G for scalar multiplication.

Mathematical setup #

We model a cyclic group as:

Notation correspondence #

Textbook (multiplicative)This file (additive / EC-style)
g^aa • g
g^a · g^b = g^{a+b}a • g + b • g = (a + b) • g
(g^a)^b = g^{ab}b • (a • g) = (b * a) • g

Assumptions #

DLog (Discrete Logarithm) #

A DLog adversary receives a generator and a group element, and tries to find the discrete logarithm (scalar).

Instances For
    def DiffieHellman.dlogExp {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [DecidableEq F] [SampleableType F] (g : G) (adversary : DLogAdversary F G) :

    DLog experiment: sample a random scalar x, give the adversary (g, x • g), and check whether the adversary's guess equals x.

    Instances For

      CDH (Computational Diffie-Hellman) #

      A CDH adversary receives (g, a • g, b • g) and tries to compute (a * b) • g. _F is a phantom type parameter for the scalar field, enabling Lean to infer F at call sites of cdhExp.

      Instances For
        def DiffieHellman.cdhExp {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [SampleableType F] [DecidableEq G] (g : G) (adversary : CDHAdversary F G) :

        CDH experiment: sample random scalars a, b, give the adversary (g, a • g, b • g), and check whether the adversary's output equals (a * b) • g.

        Instances For

          DDH (Decisional Diffie-Hellman) #

          A DDH adversary receives (g, A, B, T) and guesses whether T = (a * b) • g (real) or T is a random group element (random). _F is a phantom type parameter for the scalar field, enabling Lean to infer F at call sites of ddhExp and related definitions.

          Instances For
            def DiffieHellman.ddhExp {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [SampleableType F] (g : G) (adversary : DDHAdversary F G) :

            DDH experiment: sample random scalars a, b and a bit. If the bit is true, set c = a * b (the real DH scalar); otherwise sample c ← $ᵗ F independently. The adversary receives (g, a • g, b • g, c • g) and wins by guessing the bit.

            All sampling is from the scalar field F, so the experiment is well-defined for any Module F G without requiring that g generates all of G.

            Instances For
              noncomputable def DiffieHellman.ddhGuessAdvantage {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [SampleableType F] (g : G) (adversary : DDHAdversary F G) :

              DDH advantage: absolute distance from random guessing (1/2). Uses with absolute value rather than ℝ≥0∞ subtraction, which would silently saturate at zero for adversaries that guess the wrong bit more often than not.

              Instances For

                DDH: Two-game formulation #

                def DiffieHellman.ddhExpReal {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [SampleableType F] (g : G) (adversary : DDHAdversary F G) :

                DDH real game: the adversary receives a genuine DH triple (g, a • g, b • g, (a * b) • g).

                Instances For
                  def DiffieHellman.ddhExpRand {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [SampleableType F] (g : G) (adversary : DDHAdversary F G) :

                  DDH random game: the adversary receives (g, a • g, b • g, c • g) with independent c ← $ᵗ F.

                  Instances For
                    noncomputable def DiffieHellman.ddhDistAdvantage {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [SampleableType F] (g : G) (adversary : DDHAdversary F G) :

                    Two-game DDH advantage: |Pr[output 1 | real] - Pr[output 1 | random]|.

                    Instances For

                      Baseline success probability for matching an independently uniform DH target sampled from the scalar space and mapped into the subgroup generated by g.

                      Instances For

                        Standard reductions among DLog / CDH / DDH #

                        Reduction from CDH solving to DDH distinguishing: compute a candidate DH share and compare it with the target group element. This is the concrete reduction underlying the hardness implication DDH ⇒ CDH.

                        Instances For
                          def DiffieHellman.dlogToCDHReduction {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] (adversary : DLogAdversary F G) :

                          Reduction from DLog solving to CDH solving: recover the two exponents separately and rebuild the shared DH value. This is the concrete reduction underlying CDH ⇒ DLog.

                          Instances For

                            Direct DLog-to-DDH reduction obtained by composing the standard DLog-to-CDH and CDH-to-DDH reductions. This is the concrete reduction underlying DDH ⇒ DLog.

                            Instances For
                              theorem DiffieHellman.ddhExp_probOutput_sub_half {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [SampleableType F] (g : G) (adversary : DDHAdversary F G) :
                              Pr[= true | ddhExp g adversary].toReal - 1 / 2 = (Pr[= true | ddhExpReal g adversary].toReal - Pr[= true | ddhExpRand g adversary].toReal) / 2

                              The single-game DDH decomposes: Pr[win] - 1/2 = (Pr[real=1] - Pr[rand=1]) / 2.

                              theorem DiffieHellman.ddhDistAdvantage_eq_two_mul_ddhGuessAdvantage {F : Type} [Field F] {G : Type} [AddCommGroup G] [Module F G] [SampleableType F] (g : G) (adversary : DDHAdversary F G) :
                              ddhDistAdvantage g adversary = 2 * ddhGuessAdvantage g adversary

                              The two DDH advantage formulations are related by a factor of 2: ddhDistAdvantage = 2 * ddhGuessAdvantage.

                              In the real DDH game, the CDH-to-DDH reduction succeeds exactly when the underlying CDH adversary computed the correct shared DH value.

                              In the random DDH game, the CDH-to-DDH reduction only matches the target with the uniform baseline probability. The bijectivity assumption identifies scalar samples with uniformly sampled group elements in the subgroup generated by g.

                              Concrete form of the hardness implication DDH ⇒ CDH: a CDH solver can only beat the uniform DH-target baseline by the DDH distinguishing advantage of the associated adversary-map reduction.

                              Concrete form of the hardness implication CDH ⇒ DLog: if a DLog adversary succeeds with probability p, the induced CDH adversary succeeds with probability at least p^2.

                              Concrete form of the hardness implication DDH ⇒ DLog, obtained by composing the previous two adversary-map reductions.

                              Generable relation for discrete log #

                              def DiffieHellman.dlogGenerable {F : Type} [Field F] [SampleableType F] {G : Type} [AddCommGroup G] [Module F G] [DecidableEq G] (g : G) :
                              GenerableRelation G F fun (pk : G) (sk : F) => decide (sk g = pk)

                              The discrete log relation is generable by sampling sk ← $ᵗ F and returning (sk • g, sk).

                              Instances For

                                Cyclic group instantiation helpers #

                                A generator g is nondegenerate if fun a => a.val • g surjects onto G, ruling out the trivial case. Uses additive notation consistent with Module F G.

                                Instances For