Documentation

CslibFrontier.Crypto.Computational.DiscreteLog.PohligHellman

Pohlig–Hellman subgroup reduction, digit step, and composite-order transcript extraction #

In a finite cyclic group $G = \langle g \rangle$ of composite order $q$, the Pohlig–Hellman algorithm ([KL20], Section 10.2.1, pp. 374–375) reduces the discrete-logarithm problem in $G$ to discrete logarithms in subgroups of order $q_i$ for a factorization $q = \prod_i q_i$ into pairwise coprime factors, and recombines the residues via the Chinese Remainder Theorem. This file proves the correctness core of that reduction, a digit step used in KL's prime-power refinement, and some further composite-order extraction lemmas of our own:

  1. Subgroup reduction and CRT uniqueness (pohligHellman_subgroup_modEq, pohligHellman_crt_modEq) ([KL20], Section 10.2.1, Equation (10.2), Lemma 10.4 and the paragraph after it, pp. 374–375): if $h = g^x$ and $x_i$ solves $(g^{q/q_i})^{x_i} = h^{q/q_i}$, then $x_i \equiv x \pmod{q_i}$; hence any $y$ with $y \equiv x_i \pmod{q_i}$ for every $i$ satisfies $y \equiv x \pmod q$. The algorithm itself, the subgroup solvers, and its running time are not formalised.
  2. Prime-power digit step (pohligHellman_step, pohligHellman_nsmul_step), an ingredient of [KL20], Exercises 10.4(a)–(b) and 10.5 (pp. 382–383): suppose $D p \mid q$ and $x \bmod D$ has already been recovered. Raising $g^x \cdot g^{q - (x \bmod D)}$ to the exponent $q / (D p)$ projects onto the subgroup of order $p$ generated by $g^{q/p}$ and isolates the next base-$p$ digit $t = \lfloor x / D \rfloor \bmod p$: $$(g^x \cdot g^{q - (x \bmod D)})^{q / (D p)} = (g^{q/p})^{t} \iff t = (x / D) \bmod p.$$

The remaining material is original to this library and is not taken from [KL20]: a smooth/rough trial-division split of $q$, combined with special-soundness extraction from two Schnorr transcripts in a composite-order group.

  1. Smooth/rough factor decomposition (smoothDivisorSeq): Iterated trial division up to a bound $T + 1$ decomposes $q = D \cdot L$ where $D = \text{smoothDivisorSeq}(q, T, m \cdot T)$ is $(T + 1)$-smooth (smoothDivisorSeq_prime_le) and, once $q < 2^m$, the cofactor $L = q / D$ has no prime factors $\le T + 1$ (smoothDivisorSeq_not_dvd_div), making $D$ and $L$ coprime (coprime_smoothDivisorSeq_div) and every prime divisor of $L$ strictly greater than $T + 1$ (prime_gt_of_dvd_div_smoothDivisorSeq).
  2. CRT combination and composite-order transcript extraction (hasLargePrimeCollision, coprime_challenge_diff, extractModRough, crtCombine, schnorr_transcript_relation, crtCombine_extractModRough_eq): Given $x \bmod D$ for the $(T + 1)$-smooth part $D$ and two accepting Schnorr transcripts $(r_1, s_1), (r_2, s_2)$ without a collision modulo any prime factor $p > T$ of $q$, the challenge difference is coprime to the $(T + 1)$-rough cofactor $L$ (coprime_challenge_diff), so extractModRough recovers $x \bmod L$ and crtCombine reconstructs the full discrete logarithm $x < q$. crtCombine and its correctness crtCombine_eq are in CslibFrontier/Foundations/Data/Nat/ChineseRemainder.lean, which this module imports publicly.

Main definitions #

Main results #

References #

Pohlig–Hellman subgroup reduction #

theorem Cslib.Crypto.pohligHellman_subgroup_modEq {M : Type u_1} [Group M] (g : M) {q qi : ℕ} (hg : orderOf g = q) (hq : 0 < q) (hqi : qi ∣ q) (x xi : ℕ) (h : (g ^ (q / qi)) ^ xi = (g ^ x) ^ (q / qi)) :
xi ≡ x [MOD qi]

Pohlig–Hellman subgroup reduction ([KL20], Section 10.2.1, Equation (10.2) and Lemma 10.4, p. 375): if g has order q > 0, qi ∣ q, and xi solves the subgroup instance (g ^ (q / qi)) ^ xi = (g ^ x) ^ (q / qi), then xi ≡ x [MOD qi].

theorem Cslib.Crypto.pohligHellman_nsmul_subgroup_modEq {M : Type u_1} [AddGroup M] (g : M) {q qi : ℕ} (hg : addOrderOf g = q) (hq : 0 < q) (hqi : qi ∣ q) (x xi : ℕ) (h : xi • (q / qi) • g = (q / qi) • x • g) :
xi ≡ x [MOD qi]

Additive Pohlig–Hellman subgroup reduction: if g has additive order q > 0, qi ∣ q, and xi • ((q / qi) • g) = (q / qi) • (x • g), then xi ≡ x [MOD qi].

theorem Cslib.Crypto.pohligHellman_crt_modEq {M : Type u_1} [Group M] (g h : M) {q : ℕ} (hg : orderOf g = q) (hq : 0 < q) {qs : List ℕ} (hcop : List.Pairwise Nat.Coprime qs) (hprod : qs.prod = q) {x : ℕ} (hx : g ^ x = h) (sol : ℕ → ℕ) (hsol : ∀ qi ∈ qs, (g ^ (q / qi)) ^ sol qi = h ^ (q / qi)) {y : ℕ} (hy : ∀ qi ∈ qs, y ≡ sol qi [MOD qi]) :
y ≡ x [MOD q]

Pohlig–Hellman CRT uniqueness ([KL20], Section 10.2.1, p. 375): let g have order q = ∏ qs with pairwise coprime qs, let h = g ^ x, and let sol qi solve each subgroup instance (g ^ (q / qi)) ^ sol qi = h ^ (q / qi). Then every y with y ≡ sol qi [MOD qi] for all qi ∈ qs satisfies y ≡ x [MOD q], so the residues determine x modulo q.

theorem Cslib.Crypto.pohligHellman_nsmul_crt_modEq {M : Type u_1} [AddGroup M] (g h : M) {q : ℕ} (hg : addOrderOf g = q) (hq : 0 < q) {qs : List ℕ} (hcop : List.Pairwise Nat.Coprime qs) (hsum : qs.prod = q) {x : ℕ} (hx : x • g = h) (sol : ℕ → ℕ) (hsol : ∀ qi ∈ qs, sol qi • (q / qi) • g = (q / qi) • h) {y : ℕ} (hy : ∀ qi ∈ qs, y ≡ sol qi [MOD qi]) :
y ≡ x [MOD q]

Additive Pohlig–Hellman CRT uniqueness: for g of additive order q = ∏ qs with pairwise coprime qs, h = x • g, and sol qi • ((q / qi) • g) = (q / qi) • h for all qi ∈ qs, every y with y ≡ sol qi [MOD qi] for all qi ∈ qs satisfies y ≡ x [MOD q].

Pohlig–Hellman prime-power digit step #

theorem Cslib.Crypto.pohligHellman_step {M : Type u_1} [Group M] (g : M) {q : ℕ} (hg : orderOf g = q) (hq : 0 < q) {D p : ℕ} (hDp : D * p ∣ q) (x t : ℕ) (ht : t < p) :
(g ^ x * g ^ (q - x % D)) ^ (q / (D * p)) = (g ^ (q / p)) ^ t ↔ t = x / D % p

Pohlig–Hellman prime-power digit step (ingredient of [KL20], Exercises 10.4(a)–(b) and 10.5, pp. 382–383): for an element g of order q > 0 in a group M, a divisor D * p ∣ q, and a candidate digit t < p, the subgroup projection (g ^ x * g ^ (q - x % D)) ^ (q / (D * p)) equals (g ^ (q / p)) ^ t if and only if t = x / D % p.

theorem Cslib.Crypto.pohligHellman_nsmul_step {M : Type u_1} [AddGroup M] (g : M) {q : ℕ} (hg : addOrderOf g = q) (hq : 0 < q) {D p : ℕ} (hDp : D * p ∣ q) (x t : ℕ) (ht : t < p) :
(q / (D * p)) • (x • g + (q - x % D) • g) = t • (q / p) • g ↔ t = x / D % p

Additive Pohlig–Hellman prime-power digit step: for an element g of additive order q > 0, a divisor D * p ∣ q, and a candidate digit t < p, (q / (D * p)) • (x • g + (q - x % D) • g) = t • ((q / p) • g) if and only if t = x / D % p.

Smooth/rough trial-division decomposition (original, not from [KL20]) #

Trial-division divisor schedule: at step k, the candidate factor is k % T + 2, and the accumulated divisor grows by k % T + 2 whenever the product divides q.

Every term of smoothDivisorSeq q T divides q.

theorem Cslib.Crypto.smoothDivisorSeq_pos {q : ℕ} (hq : 0 < q) (T k : ℕ) :

When 0 < q, every term of smoothDivisorSeq q T is positive.

One trial-division step never loses divisibility: smoothDivisorSeq q T k divides smoothDivisorSeq q T (k + 1).

theorem Cslib.Crypto.smoothDivisorSeq_mono (q T : ℕ) {k k' : ℕ} (h : k ≤ k') :

smoothDivisorSeq q T is divisibility-monotone in the step count k.

theorem Cslib.Crypto.smoothDivisorSeq_prime_le {q T : ℕ} (hT : 0 < T) {ℓ : ℕ} (hℓ : Nat.Prime ℓ) (k : ℕ) (h : ℓ ∣ smoothDivisorSeq q T k) :
ℓ ≤ T + 1

$(T + 1)$-smoothness of smoothDivisorSeq: every prime factor ℓ of smoothDivisorSeq q T k satisfies ℓ ≤ T + 1.

theorem Cslib.Crypto.smoothDivisorSeq_not_dvd_div {q T m : ℕ} (hq : 0 < q) (hqm : q < 2 ^ m) {ℓ : ℕ} (hℓ : Nat.Prime ℓ) (hℓT : ℓ ≤ T + 1) :
¬ℓ ∣ q / smoothDivisorSeq q T (m * T)

Exhaustion of small prime factors: after m passes of length T (q < 2 ^ m), no prime ℓ ≤ T + 1 divides the cofactor q / smoothDivisorSeq q T (m * T).

theorem Cslib.Crypto.coprime_smoothDivisorSeq_div {q T m : ℕ} (hq : 0 < q) (hT : 0 < T) (hqm : q < 2 ^ m) :
(smoothDivisorSeq q T (m * T)).Coprime (q / smoothDivisorSeq q T (m * T))

Coprimality of the smooth divisor and its cofactor: for 0 < q < 2 ^ m and 0 < T, smoothDivisorSeq q T (m * T) and q / smoothDivisorSeq q T (m * T) are coprime.

theorem Cslib.Crypto.prime_gt_of_dvd_div_smoothDivisorSeq {q T m : ℕ} (hq : 0 < q) (hqm : q < 2 ^ m) {ℓ : ℕ} (hℓ : Nat.Prime ℓ) (h : ℓ ∣ q / smoothDivisorSeq q T (m * T)) :
T + 1 < ℓ

Every prime factor of the cofactor q / smoothDivisorSeq q T (m * T) exceeds T + 1.

CRT combination and composite-order transcript extraction (original) #

Boolean test for whether two challenges r₁, r₂ collide modulo some prime factor p > T of the group order q.

@[simp]
theorem Cslib.Crypto.hasLargePrimeCollision_eq_false_iff {T q r₁ r₂ : ℕ} :
hasLargePrimeCollision T q r₁ r₂ = false ↔ ∀ p ∈ q.primeFactors, T < p → r₁ % p ≠ r₂ % p
theorem Cslib.Crypto.coprime_challenge_diff {q T L r₁ r₂ : ℕ} (hL : L ∣ q) (hq : 0 < q) (hr₂ : r₂ ≤ q) (hbig : ∀ (ℓ : ℕ), Nat.Prime ℓ → ℓ ∣ L → T < ℓ) (hcoll : hasLargePrimeCollision T q r₁ r₂ = false) :
((r₁ + (q - r₂)) % L).Coprime L

When no prime factor p > T of q divides r₁ - r₂ (hasLargePrimeCollision T q r₁ r₂ = false), the shifted challenge difference (r₁ + (q - r₂)) % L is coprime to any divisor L ∣ q whose prime factors all exceed T.

def Cslib.Crypto.extractModRough (q L s₁ s₂ inv : ℕ) :

Recover x % L from two transcript responses (s₁, s₂) and an inverse inv of the challenge difference modulo L.

theorem Cslib.Crypto.extractModRough_eq_mod {q L x r₁ s₁ r₂ s₂ : ℕ} (hL : L ∣ q) (hr₂ : r₂ ≤ q) (hs₂ : s₂ ≤ q) (hrel : ↑s₁ - ↑s₂ = ↑x * (↑r₁ - ↑r₂)) (inv : ℕ) (hinv : ↑inv * ↑((r₁ + (q - r₂)) % L) = 1) :
extractModRough q L s₁ s₂ inv = x % L

Given the linear transcript relation s₁ - s₂ = x * (r₁ - r₂) in ZMod q and an inverse inv of (r₁ + (q - r₂)) % L modulo a divisor L ∣ q, extractModRough q L s₁ s₂ inv equals x % L.

theorem Cslib.Crypto.crtCombine_extractModRough_eq {q D L x r₁ s₁ r₂ s₂ invDiff invD : ℕ} (hq : D * L = q) (hx : x < q) (hr₂ : r₂ ≤ q) (hs₂ : s₂ ≤ q) (hrel : ↑s₁ - ↑s₂ = ↑x * (↑r₁ - ↑r₂)) (hinvDiff : ↑invDiff * ↑((r₁ + (q - r₂)) % L) = 1) (hinvD : ↑invD * ↑D = 1) :
crtCombine D L (x % D) (extractModRough q L s₁ s₂ invDiff) invD = x

Composite-order discrete-logarithm recovery (original): combining a residue a = x % D on the smooth divisor D with extractModRough on the cofactor L (where D * L = q) recovers the exact discrete logarithm x < q, given an inverse of D modulo L.

theorem Cslib.Crypto.schnorr_transcript_relation {M : Type u_1} [Group M] (g : M) {q : ℕ} (hg : orderOf g = q) (x r₁ s₁ r₂ s₂ : ℕ) (h : g ^ s₁ * (g ^ x) ^ (-↑r₁) = g ^ s₂ * (g ^ x) ^ (-↑r₂)) :
↑s₁ - ↑s₂ = ↑x * (↑r₁ - ↑r₂)

Schnorr transcript congruence in a cyclic group (original): if g has order q and two transcripts (r₁, s₁) and (r₂, s₂) share the same commitment g ^ s₁ * (g ^ x) ^ (-r₁) = g ^ s₂ * (g ^ x) ^ (-r₂), then s₁ - s₂ = x * (r₁ - r₂) in ZMod q.

theorem Cslib.Crypto.schnorr_nsmul_transcript_relation {M : Type u_1} [AddGroup M] (g : M) {q : ℕ} (hg : addOrderOf g = q) (x r₁ s₁ r₂ s₂ : ℕ) (h : s₁ • g + -↑r₁ • x • g = s₂ • g + -↑r₂ • x • g) :
↑s₁ - ↑s₂ = ↑x * (↑r₁ - ↑r₂)

Additive Schnorr transcript congruence: if g has additive order q and two transcripts (r₁, s₁) and (r₂, s₂) share the same commitment s₁ • g + (-r₁) • (x • g) = s₂ • g + (-r₂) • (x • g), then s₁ - s₂ = x * (r₁ - r₂) in ZMod q.