Documentation

CslibFrontier.Crypto.Computational.DiffieHellman.SelfReduction.Family

The DL and CDH self-reductions over a prime-order group family #

[BS23], Section 10.5.1, turns an efficient algorithm A that finds the discrete logarithm of a random element of a fixed group with probability ε into an efficient algorithm B that, on every input, outputs fail or the discrete logarithm and outputs the latter with probability ε (Theorem 10.2), and Exercise 10.6 asks for the same for CDH. The fixed-group module CslibFrontier/Crypto/Computational/DiffieHellman/SelfReduction.lean computes the exact output probabilities of these algorithms with uniform masks and no cost model. This module states them as adversaries over a PrimeOrderGroupFamily, proves that they are uniform strict PPT whenever A is, and derives the family-level consequences.

Here ε is dlAdvantage (F.order d) (F.generator d) (F.discreteLogAdversary A n d), the success probability of the word-level adversary A read in the group selected by d (succProbability_discreteLogGame_pure). Footnote 1 of the book (p. 411) fixes the group in the same way.

The reduction reads only words: on every input word its certificates hold, and the loop's test rejects every word that encodes no group element (eq_nil_of_mem_support_dlSelfReduceRetryAdversary_of_not_mem_range).

Differences from the book #

Main definitions #

Main results #

References #

The programs #

@[reducible, inline]

The input (n, d, w) of a word-level discrete-logarithm adversary: the security parameter in unary and the group parameters, each framed, then the instance word. It is the input encoding in DiscreteLog.

One masked call of a word-level discrete-logarithm adversary on the input word x.2: draw σ with sampleExp, run the adversary on x.2 + σ • g computed with F.add and F.smul, and subtract σ from its answer as natural numbers, ofBits answer + (q - σ % q), which the game reads modulo q.

At most k n checked attempts, each a masked call (dlSelfReduceAdversary) followed by the test x • g = u computed on encodings, returning the first answer that passes its test, or the empty word when none does. With k = fun _ => 1 this is the algorithm B in the proof of [BS23], Theorem 10.2 (p. 412), with the empty word for its output fail.

One call of a CDH adversary with both inputs masked: draw ρ and τ with sampleExp, run the adversary on (u + ρ • g, v + τ • g) and subtract τ • u + ρ • v + (ρ * τ) • g, as Cslib.Crypto.cdhSelfReduce does with uniform masks. [BS23], Exercise 10.6 (p. 425) gives no construction; this one is this library's.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.dlWorstCaseGame (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α : (d : F.Desc) → ZMod (F.order d)) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (n : ℕ) :

The worst-case discrete-logarithm game for the instances α d • g: draw group parameters d with the setup law and run the word-level adversary on the encoding of α d • g. It wins when its answer, read as an exponent, is α d. This game is this library's.

noncomputable def Cslib.Crypto.PrimeOrderGroupFamily.cdhWorstCaseGame (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α β : (d : F.Desc) → ZMod (F.order d)) (adversary : F.CDHAdversary) (n : ℕ) :

The worst-case CDH game for the instance pairs (α d • g, β d • g): draw group parameters d with the setup law and run the CDH adversary on the pair. It wins when it outputs (α d * β d) • g. This game is this library's.

Certificates #

The masked call is efficient: if the word-level adversary is uniform strict PPT, so is dlSelfReduceAdversary.

The checked loop is efficient: if the word-level adversary is uniform strict PPT and the number of attempts k n is computable in polynomial time in unary, dlSelfReduceRetryAdversary is uniform strict PPT.

The loop with n * (2 * invEps n) attempts, the count of negligible_dlSelfReduceRetryAdversary_error, is uniform strict PPT when invEps is computable in polynomial time in unary.

The CDH self-reduction is efficient: if the CDH adversary is uniform strict PPT, so is cdhSelfReduceAdversary.

One masked call #

theorem Cslib.Crypto.PrimeOrderGroupFamily.discreteLogAdversary_dlSelfReduceAdversary (F : PrimeOrderGroupFamily) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (n : ℕ) (d : F.Desc) (u : F.Carrier d) :
F.discreteLogAdversary (F.dlSelfReduceAdversary adversary) n d u = do let σ ← F.sampleExp n d let α₁ ← F.discreteLogAdversary adversary n d (u + ↑σ • F.generator d) pure (α₁ - ↑σ)

On the encoding of an element u, the word-level masked call is one masked call of the fixed-group adversary F.discreteLogAdversary adversary n d, with the mask drawn by sampleExp in place of the uniform mask of Cslib.Crypto.dlRerandomize.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_dlSelfReduceAdversary_le (F : PrimeOrderGroupFamily) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (n : ℕ) (d : F.Desc) (α : ZMod (F.order d)) :
Experiment.advantage ((fun (x : ZMod (F.order d)) => decide (x = α)) <$> F.discreteLogAdversary (F.dlSelfReduceAdversary adversary) n d (α • F.generator d)) (dlExperiment (F.order d) (F.generator d) (F.discreteLogAdversary adversary n d)) ≤ 1 / 2 ^ n

One masked call on every instance: on α • g, the masked call returns α with the probability with which the adversary wins the discrete-logarithm experiment in the group d, up to 1 / 2 ^ n, the sampling loss of sampleExp. With a uniform mask the two are equal (Cslib.Crypto.eval_dlRerandomize_smul_apply).

Worst case against average case, discrete logarithm #

In the group selected by d, the discrete-logarithm game with the constant setup law is the fixed-group experiment: its success probability is the ε of [BS23], Theorem 10.2, for the adversary read in d.

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_dlWorstCaseGame_discreteLogGame_le (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α : (d : F.Desc) → ZMod (F.order d)) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (n : ℕ) :
(F.dlWorstCaseGame setup α (F.dlSelfReduceAdversary adversary) n).advantage (F.discreteLogGame setup adversary n) ≤ 1 / 2 ^ n

The masked call wins the worst-case game on the instances α d • g within 1 / 2 ^ n of the adversary's success in the average-case game, for every setup law.

theorem Cslib.Crypto.PrimeOrderGroupFamily.succProbability_discreteLogGame_le_dlWorstCaseGame (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α : (d : F.Desc) → ZMod (F.order d)) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (n : ℕ) :
(F.discreteLogGame setup adversary n).succProbability ≤ (F.dlWorstCaseGame setup α (F.dlSelfReduceAdversary adversary) n).succProbability + 1 / 2 ^ n

The adversary's average-case success is at most the masked call's worst-case success plus 1 / 2 ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.discreteLog_of_worstCase (F : PrimeOrderGroupFamily) {setup : ℕ → PMF F.Desc} (hworst : ∀ (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)), (Probability.IsPPTOn F.encDiscreteLogInput Turing.MultiTapeTM.encBits fun (input : ℕ × F.Desc × List Bool) => adversary input.1 input.2) → ∃ (α : (d : F.Desc) → ZMod (F.order d)), Negligible fun (n : ℕ) => (F.dlWorstCaseGame setup α adversary n).succProbability) :
F.DiscreteLog setup

Average-case discrete-logarithm hardness from worst-case hardness: if for every uniform strict PPT word-level adversary there are instances α d • g on which it wins the worst-case game with negligible probability, then DiscreteLog holds for the setup law. The instances may depend on the adversary. The book states this implication only informally (p. 412: "if it is hard in the worst case, then it must be hard on average"); this formulation and dlWorstCaseGame are this library's. Cslib.Crypto.PrimeOrderGroupFamily.ddh_of_worstCase is the DDH analogue, with the same quantifier order.

The checked loop #

Soundness of the loop on every input word: on (d, w) the loop outputs the empty word (the book's fail) or a word that reads as an exponent x with F.encode d (x • g) = w. This is the claim of [BS23], Theorem 10.2 (pp. 411–412), that B outputs fail or Dlog_g(u), for any number of attempts.

On the encoding of an element u, the loop outputs the empty word or a discrete logarithm of u.

On a word that encodes no element of the group d, the loop outputs the empty word.

theorem Cslib.Crypto.PrimeOrderGroupFamily.one_sub_pow_le_toOuterMeasure_dlSelfReduceRetryAdversary (F : PrimeOrderGroupFamily) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (k : ℕ → ℕ) (n : ℕ) (d : F.Desc) (α : ZMod (F.order d)) :
1 - (1 - ↑(dlAdvantage (F.order d) (F.generator d) (F.discreteLogAdversary adversary n d) - 1 / 2 ^ n)) ^ k n ≤ (F.dlSelfReduceRetryAdversary adversary k n (d, F.encode d (α • F.generator d))).eval.toOuterMeasure {out : List Bool | out ≠ [] ∧ ↑(Turing.MultiTapeTM.ofBits out) = α}

The loop on every instance: on the encoding of α • g, k n checked attempts return a nonempty word that reads as α with probability at least 1 - (1 - (ε - 1 / 2 ^ n)) ^ k n, where ε is the adversary's success in the group d. The iteration remark after [BS23], Theorem 10.2 (p. 412) gives 1 - (1 - ε) ^ k without the sampling loss. The event excludes the empty word, the book's fail, for the reason given at le_toOuterMeasure_dlSelfReduceRetryAdversary_one.

theorem Cslib.Crypto.PrimeOrderGroupFamily.le_toOuterMeasure_dlSelfReduceRetryAdversary_one (F : PrimeOrderGroupFamily) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (n : ℕ) (d : F.Desc) (α : ZMod (F.order d)) :
↑(dlAdvantage (F.order d) (F.generator d) (F.discreteLogAdversary adversary n d) - 1 / 2 ^ n) ≤ (F.dlSelfReduceRetryAdversary adversary (fun (x : ℕ) => 1) n (d, F.encode d (α • F.generator d))).eval.toOuterMeasure {out : List Bool | out ≠ [] ∧ ↑(Turing.MultiTapeTM.ofBits out) = α}

[BS23], Theorem 10.2, with the sampling loss: on the encoding of every instance α • g, one checked attempt returns a nonempty word that reads as α with probability at least ε - 1 / 2 ^ n, where ε is the adversary's success in the group d.

The bound is on the output word, not on the exponent that the discrete-logarithm game reads from it. The game reads the empty word, the book's fail, as 0, so on the instance α = 0 the game-level bound le_eval_discreteLogAdversary_dlSelfReduceRetryAdversary_one holds even for a loop that always fails. Excluding the empty word gives the book's claim that B returns an answer other than fail, the discrete logarithm, with probability ε, for every u.

The book's equality = ε is Cslib.Crypto.eval_dlSelfReduce_one_smul_some for the fixed-group program with a uniform mask; here the mask is drawn by sampleExp, and only the lower bound is stated. The attempt is efficient (isPPTOn_dlSelfReduceRetryAdversary).

theorem Cslib.Crypto.PrimeOrderGroupFamily.one_sub_pow_le_eval_discreteLogAdversary_dlSelfReduceRetryAdversary (F : PrimeOrderGroupFamily) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (k : ℕ → ℕ) (n : ℕ) (d : F.Desc) (α : ZMod (F.order d)) :
1 - (1 - ↑(dlAdvantage (F.order d) (F.generator d) (F.discreteLogAdversary adversary n d) - 1 / 2 ^ n)) ^ k n ≤ (F.discreteLogAdversary (F.dlSelfReduceRetryAdversary adversary k) n d (α • F.generator d)).eval α

The bound of one_sub_pow_le_toOuterMeasure_dlSelfReduceRetryAdversary for the exponent that the discrete-logarithm game reads from the loop's answer. At α = 0 it holds for every loop, since the game reads the empty word as 0.

The bound of le_toOuterMeasure_dlSelfReduceRetryAdversary_one for the exponent that the discrete-logarithm game reads from the loop's answer. At α = 0 it holds for every loop, since the game reads the empty word as 0.

theorem Cslib.Crypto.PrimeOrderGroupFamily.dlSelfReduceRetryAdversary_error_le_pow (F : PrimeOrderGroupFamily) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (invEps : ℕ → ℕ) (n : ℕ) (d : F.Desc) (α : ZMod (F.order d)) (hadv : 1 / ↑(invEps n) ≤ ↑(F.discreteLogGame (fun (x : ℕ) => PMF.pure d) adversary n).succProbability) (hmod : 1 / 2 ^ n ≤ 1 / (2 * ↑(invEps n))) :
((F.dlSelfReduceRetryAdversary adversary (fun (n : ℕ) => n * (2 * invEps n)) n (d, F.encode d (α • F.generator d))).eval.toOuterMeasure {out : List Bool | out = [] ∨ ↑(Turing.MultiTapeTM.ofBits out) ≠ α}).toReal ≤ (1 / 2) ^ n

The iteration remark after [BS23], Theorem 10.2 (p. 412), in a fixed group with the sampling loss: if the adversary wins the discrete-logarithm game in the group d with probability at least 1 / invEps n and 1 / 2 ^ n ≤ 1 / (2 * invEps n), then on the encoding of every instance α • g the loop with n * (2 * invEps n) attempts errs, that is returns the empty word or a word that does not read as α, with probability at most (1 / 2) ^ n. The book runs n ⌈1 / ε⌉ attempts and bounds the error by exp (-n). The second hypothesis forces 0 < invEps n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.discreteLogAdversary_dlSelfReduceRetryAdversary_error_le_pow (F : PrimeOrderGroupFamily) (adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)) (invEps : ℕ → ℕ) (n : ℕ) (d : F.Desc) (α : ZMod (F.order d)) (hadv : 1 / ↑(invEps n) ≤ ↑(F.discreteLogGame (fun (x : ℕ) => PMF.pure d) adversary n).succProbability) (hmod : 1 / 2 ^ n ≤ 1 / (2 * ↑(invEps n))) :
((F.discreteLogAdversary (F.dlSelfReduceRetryAdversary adversary fun (n : ℕ) => n * (2 * invEps n)) n d (α • F.generator d)).eval.toOuterMeasure {x : ZMod (F.order d) | x ≠ α}).toReal ≤ (1 / 2) ^ n

The bound of dlSelfReduceRetryAdversary_error_le_pow for the exponent that the discrete-logarithm game reads from the loop's answer: it reads an exponent other than α with probability at most (1 / 2) ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.negligible_dlSelfReduceRetryAdversary_error (F : PrimeOrderGroupFamily) {adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)} {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) ≤ ↑(F.discreteLogGame (fun (x : ℕ) => PMF.pure (d n)) adversary n).succProbability) :
Negligible fun (n : ℕ) => ((F.dlSelfReduceRetryAdversary adversary (fun (n : ℕ) => n * (2 * invEps n)) n (d n, F.encode (d n) (α n • F.generator (d n)))).eval.toOuterMeasure {out : List Bool | out = [] ∨ ↑(Turing.MultiTapeTM.ofBits out) ≠ α n}).toNNReal

Discrete logarithm on every instance with negligible error: if invEps is computable in polynomial time in unary and, for large n, 0 < invEps n and the adversary wins the discrete-logarithm game in the group d n with probability at least 1 / invEps n, then on the encoding of every sequence of instances α n • g in d n the loop with n * (2 * invEps n) attempts errs, that is returns the empty word or a word that does not read as α n, with negligible probability. The loop is uniform strict PPT (isPPTOn_dlSelfReduceRetryAdversary_invEps). This is the conclusion of the remark after [BS23], Theorem 10.2 (p. 412), "if 1/ε is poly-bounded, we can efficiently compute the discrete logarithm of any group element with negligible failure probability", with invEps in place of ⌈1 / ε⌉.

theorem Cslib.Crypto.PrimeOrderGroupFamily.negligible_discreteLogAdversary_dlSelfReduceRetryAdversary_error (F : PrimeOrderGroupFamily) {adversary : ℕ → F.Desc × List Bool → ProbComp (List Bool)} {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) ≤ ↑(F.discreteLogGame (fun (x : ℕ) => PMF.pure (d n)) adversary n).succProbability) :
Negligible fun (n : ℕ) => ((F.discreteLogAdversary (F.dlSelfReduceRetryAdversary adversary fun (n : ℕ) => n * (2 * invEps n)) n (d n) (α n • F.generator (d n))).eval.toOuterMeasure {x : ZMod (F.order (d n)) | x ≠ α n}).toNNReal

The conclusion of negligible_dlSelfReduceRetryAdversary_error for the exponent that the discrete-logarithm game reads from the loop's answer: it reads an exponent other than α n with negligible probability.

Computational Diffie–Hellman #

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_cdhSelfReduceAdversary_le (F : PrimeOrderGroupFamily) (adversary : F.CDHAdversary) (n : ℕ) (d : F.Desc) (α β : ZMod (F.order d)) :
Experiment.advantage ((fun (w : F.Carrier d) => decide (w = (α * β) • F.generator d)) <$> F.cdhSelfReduceAdversary adversary n d (α • F.generator d) (β • F.generator d)) (cdhExperiment (F.order d) (F.generator d) (adversary n d)) ≤ 2 / 2 ^ n

[BS23], Exercise 10.6, with the sampling loss: on every pair (α • g, β • g), cdhSelfReduceAdversary returns (α * β) • g with the probability with which the adversary wins the CDH experiment in the group d, up to 2 / 2 ^ n, the loss of the two sampleExp masks. The exercise asks for equality; with uniform masks it holds (Cslib.Crypto.eval_cdhSelfReduce_smul_apply). The reduction is efficient (isPPT_cdhSelfReduceAdversary).

theorem Cslib.Crypto.PrimeOrderGroupFamily.advantage_cdhWorstCaseGame_cdhGame_le (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α β : (d : F.Desc) → ZMod (F.order d)) (adversary : F.CDHAdversary) (n : ℕ) :
(F.cdhWorstCaseGame setup α β (F.cdhSelfReduceAdversary adversary) n).advantage (F.cdhGame setup adversary n) ≤ 2 / 2 ^ n

cdhSelfReduceAdversary wins the worst-case game on the pairs (α d • g, β d • g) within 2 / 2 ^ n of the adversary's success in the average-case CDH game, for every setup law.

theorem Cslib.Crypto.PrimeOrderGroupFamily.succProbability_cdhGame_le_cdhWorstCaseGame (F : PrimeOrderGroupFamily) (setup : ℕ → PMF F.Desc) (α β : (d : F.Desc) → ZMod (F.order d)) (adversary : F.CDHAdversary) (n : ℕ) :
(F.cdhGame setup adversary n).succProbability ≤ (F.cdhWorstCaseGame setup α β (F.cdhSelfReduceAdversary adversary) n).succProbability + 2 / 2 ^ n

The adversary's average-case CDH success is at most the reduction's worst-case success plus 2 / 2 ^ n.

theorem Cslib.Crypto.PrimeOrderGroupFamily.cdh_of_worstCase (F : PrimeOrderGroupFamily) {setup : ℕ → PMF F.Desc} (hworst : ∀ (adversary : F.CDHAdversary), adversary.IsPPT → ∃ (α : (d : F.Desc) → ZMod (F.order d)) (β : (d : F.Desc) → ZMod (F.order d)), Negligible fun (n : ℕ) => (F.cdhWorstCaseGame setup α β adversary n).succProbability) :
F.CDH setup

Average-case CDH hardness from worst-case hardness: if for every uniform strict PPT CDH adversary there are pairs (α d • g, β d • g) on which it wins the worst-case game with negligible probability, then CDH holds for the setup law. The pairs may depend on the adversary. This formulation and cdhWorstCaseGame are this library's. Cslib.Crypto.PrimeOrderGroupFamily.ddh_of_worstCase is the DDH analogue, with the same quantifier order.