Documentation

CslibFrontier.Crypto.Computational.Factoring.PollardRho

Pollard's rho factoring and Floyd cycle-detection bounds #

Pollard's rho algorithm ([KL20], Section 10.1.2, Algorithm 10.2, pp. 368–369) searches for a nontrivial factor of a composite integer $N$ by iterating a pseudorandom walk $F : (\mathbb{Z}/N\mathbb{Z})^\times \to (\mathbb{Z}/N\mathbb{Z})^\times$ with Floyd's tortoise-and-hare cycle-finding schedule $(x_t, y_t) = (F^{[t]}(x_0), F^{[2t]}(x_0))$ and testing whether $d = \gcd(|x_t - y_t|, N)$ is a nontrivial divisor $1 < d < N$:

  1. Soundness (isNontrivialFactor_of_rhoFactorLoop_eq_some, eq_prime_of_rhoFactorLoop_eq_some): Every output some d of rhoFactorLoop N F B x y satisfies IsNontrivialFactor N d (d ∣ N ∧ 1 < d ∧ d < N). When $N = p \cdot q$ is a product of two primes, any returned factor satisfies d = p ∨ d = q.
  2. Exact failure characterization (rhoFactorLoop_eq_none_iff, rhoFactorLoop_start_eq_none_iff): rhoFactorLoop N F B x₀ x₀ = none if and only if for every step $1 \le t \le B$, the tortoise and hare states $(F^{[t]}(x_0), F^{[2t]}(x_0))$ fail to yield a nontrivial GCD with $N$.
  3. Nontrivial GCD from a modulo-$p$ collision (isNontrivialFactor_rhoGcd_of_modEq): Whenever $p \mid N$ ($1 < p$), $a \ne b$ in $(\mathbb{Z}/N\mathbb{Z})^\times$, and $a \equiv b \pmod p$, their GCD candidate rhoGcd N a b is a nontrivial divisor of $N$.
  4. Floyd's cycle-detection persistence theorem (floyd_cycle_modEq): If $F$ is congruence-compatible modulo $p$, any collision $F^{[i]}(x) \equiv F^{[j]}(x) \pmod p$ at indices $i < j$ implies a tortoise-and-hare collision $F^{[t]}(x) \equiv F^{[2t]}(x) \pmod p$ at some step $1 \le t \le j$.

The birthday-bound analysis (via [KL20], Lemma A.15) and the heuristic $O(N^{1/4} \cdot \mathrm{polylog}(N))$ running time are not formalised here.

Main definitions #

Main results #

References #

def Cslib.Crypto.rhoGcd (N : ℕ) (a b : (ZMod N)ˣ) :

Candidate divisor gcd(|a - b|, N) computed at each step of Pollard's rho algorithm ([KL20], Algorithm 10.2, p. 369).

A natural number d is a nontrivial factor of N if d ∣ N and 1 < d < N.

Instances For
    def Cslib.Crypto.rhoFactorLoop (N : ℕ) (F : (ZMod N)ˣ → (ZMod N)ˣ) :
    ℕ → (ZMod N)ˣ → (ZMod N)ˣ → Option ℕ

    Floyd tortoise-and-hare loop of Pollard's rho factoring algorithm ([KL20], Section 10.1.2, Algorithm 10.2, p. 369): iterate (x, y) ↦ (F x, F (F y)) for at most B steps and return the first nontrivial GCD rhoGcd N x' y'.

    Soundness and exact failure characterization #

    theorem Cslib.Crypto.isNontrivialFactor_of_rhoFactorLoop_eq_some {N : ℕ} {F : (ZMod N)ˣ → (ZMod N)ˣ} {B : ℕ} {x y : (ZMod N)ˣ} {d : ℕ} :

    Soundness of rhoFactorLoop: every some d returned by rhoFactorLoop N F B x y is a nontrivial divisor of N (IsNontrivialFactor N d).

    theorem Cslib.Crypto.eq_prime_of_isNontrivialFactor_mul {p q d : ℕ} (hp : Nat.Prime p) (hq : Nat.Prime q) (h : IsNontrivialFactor (p * q) d) :
    d = p ∨ d = q

    Any nontrivial factor of a semiprime p * q (with p, q prime) equals p or q.

    theorem Cslib.Crypto.eq_prime_of_rhoFactorLoop_eq_some {p q B : ℕ} (hp : Nat.Prime p) (hq : Nat.Prime q) {F : (ZMod (p * q))ˣ → (ZMod (p * q))ˣ} {x y : (ZMod (p * q))ˣ} {d : ℕ} (h : rhoFactorLoop (p * q) F B x y = some d) :
    d = p ∨ d = q

    Semiprime soundness of rhoFactorLoop: for N = p * q with p, q prime, any factor d returned by rhoFactorLoop (p * q) F B x y satisfies d = p ∨ d = q.

    theorem Cslib.Crypto.rhoFactorLoop_eq_none_iff (N : ℕ) (F : (ZMod N)ˣ → (ZMod N)ˣ) (B : ℕ) (x y : (ZMod N)ˣ) :
    rhoFactorLoop N F B x y = none ↔ ∀ (t : ℕ), 1 ≤ t → t ≤ B → ¬IsNontrivialFactor N (rhoGcd N (F^[t] x) ((F ∘ F)^[t] y))

    Stepwise characterization of when rhoFactorLoop N F B x y returns none.

    theorem Cslib.Crypto.rhoFactorLoop_start_eq_none_iff (N : ℕ) (F : (ZMod N)ˣ → (ZMod N)ˣ) (B : ℕ) (x₀ : (ZMod N)ˣ) :
    rhoFactorLoop N F B x₀ x₀ = none ↔ ∀ (t : ℕ), 1 ≤ t → t ≤ B → ¬IsNontrivialFactor N (rhoGcd N (F^[t] x₀) (F^[2 * t] x₀))

    Exact failure characterization from a common start state x₀: rhoFactorLoop N F B x₀ x₀ = none if and only if no step 1 ≤ t ≤ B produces a nontrivial GCD between F^[t] x₀ and F^[2 * t] x₀.

    Nontrivial GCD from a modulo-p collision #

    theorem Cslib.Crypto.isNontrivialFactor_rhoGcd_of_modEq {N p : ℕ} (hpN : p ∣ N) (hp1 : 1 < p) [NeZero N] {a b : (ZMod N)ˣ} (hne : a ≠ b) (hmod : (↑a).val ≡ (↑b).val [MOD p]) :

    Good-pair GCD lemma ([KL20], Section 10.1.2, p. 368): if p ∣ N (1 < p) and two distinct units a ≠ b in (ZMod N)ˣ are congruent modulo p, then rhoGcd N a b is a nontrivial factor of N.

    Floyd's tortoise-and-hare cycle-detection theorem #

    theorem Cslib.Crypto.floyd_cycle_modEq {N p : ℕ} {F : (ZMod N)ˣ → (ZMod N)ˣ} (hF : ∀ (u v : (ZMod N)ˣ), (↑u).val ≡ (↑v).val [MOD p] → (↑(F u)).val ≡ (↑(F v)).val [MOD p]) {x : (ZMod N)ˣ} {i j : ℕ} (hij : i < j) (hcoll : (↑(F^[i] x)).val ≡ (↑(F^[j] x)).val [MOD p]) :
    ∃ (t : ℕ), 1 ≤ t ∧ t ≤ j ∧ (↑(F^[t] x)).val ≡ (↑(F^[2 * t] x)).val [MOD p]

    Floyd's cycle-detection persistence theorem (the technique of [KL20], Section 6.4.2, Algorithm 6.9, p. 180, as used for Pollard's rho in Section 10.1.2, p. 369): if F is congruence-compatible modulo p, then any collision (F^[i] x : ZMod N).val ≡ (F^[j] x : ZMod N).val [MOD p] at indices i < j implies that there exists a step 1 ≤ t ≤ j at which the tortoise F^[t] x and hare F^[2 * t] x collide modulo p.