Algorithm Search⌘K

Proofs: Pollard's rho algorithm for discrete logarithms

These are the human proofs of Pollard's rho algorithm for discrete logarithms, at full length.

Correctness of Pollard's rho algorithm for discrete logarithms full

This proof shows: correctness, termination.

Let pp be prime, g∈(Z/pZ)∗g \in (\mathbb{Z}/p\mathbb{Z})^* of order nn, H=⟨g⟩H = \langle g \rangle and h∈(Z/pZ)∗h \in (\mathbb{Z}/p\mathbb{Z})^*. All exponent arithmetic is modulo nn, which is well defined because gn=1g^n = 1 and, when h∈Hh \in H, hn=1h^n = 1.

Lemma 1 (membership). h∈Hh \in H if and only if hn=1h^n = 1.

Proof. If h=gxh = g^x then hn=(gn)x=1h^n = (g^n)^x = 1. Conversely, (Z/pZ)∗(\mathbb{Z}/p\mathbb{Z})^* is cyclic of order p−1p - 1, and n∣p−1n \mid p - 1. A cyclic group has exactly one subgroup of each order dividing its order, and that subgroup is the set of solutions of yn=1y^n = 1, which has at most nn elements since it is the set of roots of a polynomial of degree nn over a field. HH has nn elements and all satisfy yn=1y^n = 1, so HH is exactly this set. □\square

So line L1 returns NONE exactly when h∉Hh \notin H. From now on assume h∈Hh \in H, say h=gx∗h = g^{x^*} with 0≤x∗<n0 \le x^* < n. If h=1h = 1 then x∗=0x^* = 0 and line L2 is correct, so assume h≠1h \ne 1.

Lemma 2 (invariant). Throughout an attempt, x=gahbx = g^a h^b and X=gAhBX = g^A h^B.

Proof. Line L5 sets x=ga0hb0x = g^{a_0} h^{b_0} with (a,b)=(a0,b0)(a, b) = (a_0, b_0), and line L6 copies it. Each case of STEP preserves the relation: gahb⋅h=gahb+1g^a h^b \cdot h = g^a h^{b+1} (line L17), (gahb)2=g2ah2b(g^a h^b)^2 = g^{2a} h^{2b} (line L18) and gahb⋅g=ga+1hbg^a h^b \cdot g = g^{a+1} h^b (line L19); reducing exponents modulo nn changes nothing since gn=hn=1g^n = h^n = 1. □\square

Lemma 3 (each attempt ends). Let x0=ga0hb0x_0 = g^{a_0} h^{b_0} and xi+1=f(xi)x_{i+1} = f(x_i), where ff is the element part of STEP for the current partition. After round ii of the loop of lines L7 to L10, x=xix = x_i and X=x2iX = x_{2i}, and the loop ends after at most nn rounds.

Proof. The first claim follows by induction, since line L8 applies ff once and line L9 twice; the element part of STEP depends only on the element, not on the exponents. The sequence lies in the finite set HH of size nn, so there are μ≥0\mu \ge 0 and λ≥1\lambda \ge 1 with xi+λ=xix_{i + \lambda} = x_i for all i≥μi \ge \mu, and μ+λ≤n\mu + \lambda \le n. Let ii be the least multiple of λ\lambda with i≥max⁡(μ,1)i \ge \max(\mu, 1); then i≤μ+λ≤ni \le \mu + \lambda \le n and x2i=xix_{2i} = x_i because 2i−i2i - i is a multiple of λ\lambda and i≥μi \ge \mu. □\square

Lemma 4 (the congruence). When the loop of line L10 ends, sx∗≡A−a(modn)s x^* \equiv A - a \pmod n with s=b−B mod ns = b - B \bmod n.

Proof. By Lemma 2, gahb=x=X=gAhBg^a h^b = x = X = g^A h^B. Substituting h=gx∗h = g^{x^*} gives ga+bx∗=gA+Bx∗g^{a + b x^*} = g^{A + B x^*}, so a+bx∗≡A+Bx∗(modn)a + b x^* \equiv A + B x^* \pmod n since gg has order nn. □\square

Lemma 5 (the candidates). If s≢0s \not\equiv 0 and d=gcd⁡(s,n)d = \gcd(s, n), then d∣A−ad \mid A - a, and the solutions in {0,…,n−1}\{0, \dots, n - 1\} of sz≡A−a(modn)s z \equiv A - a \pmod n are exactly y+tn/dy + t n/d for 0≤t<d0 \le t < d, where yy is computed at line L13. In particular x∗x^* is one of them.

Proof. By Lemma 4 the congruence has the solution x∗x^*, so dd, which divides ss and nn, divides A−aA - a. Dividing by dd, sz≡A−a(modn)s z \equiv A - a \pmod n is equivalent to (s/d)z≡(A−a)/d(modn/d)(s/d) z \equiv (A - a)/d \pmod{n/d}. Since gcd⁡(s/d,n/d)=1\gcd(s/d, n/d) = 1, s/ds/d is invertible modulo n/dn/d, and the unique solution modulo n/dn/d is yy, with 0≤y<n/d0 \le y < n/d. The solutions modulo nn are the dd integers y+tn/dy + t n/d with 0≤t<d0 \le t < d, all in {0,…,n−1}\{0, \dots, n - 1\}. □\square

Soundness. Line L15 returns a value only after checking gz=hg^z = h for it, with 0≤z<n0 \le z < n; since gg has order nn, such a zz equals x∗x^*. Line L1 returns NONE only if hn≠1h^n \ne 1, which by Lemma 1 means h∉Hh \notin H. So every output is correct.

Completeness of an attempt. If line L12 passes, then by Lemma 5 one of the dd candidates is x∗x^*, and line L15 returns it. So an attempt fails only when s≡0s \equiv 0 or d>⌊n⌋+1d > \lfloor \sqrt n \rfloor + 1.

Termination with probability one. Each attempt ends by Lemma 3, so it remains to show that some attempt succeeds. In line L16 the partition is a uniformly random map H→{1,2,3}H \to \{1, 2, 3\} and a0,b0a_0, b_0 are uniform, independently of earlier attempts. We exhibit one choice that succeeds; since there are finitely many choices, each attempt after the first then succeeds with probability at least some q>0q > 0, and the number of attempts is finite with probability 11 (it is dominated by a geometric random variable).

Take (a0,b0)=(0,0)(a_0, b_0) = (0, 0), so x0=1x_0 = 1, and the partition with S1={1}S_1 = \{1\}, S2=∅S_2 = \emptyset and S3=H∖{1}S_3 = H \setminus \{1\}. Then x1=hx_1 = h with (a1,b1)=(0,1)(a_1, b_1) = (0, 1). Since h≠1h \ne 1, the next steps multiply by gg: x1+j=hgj=gx∗+jx_{1 + j} = h g^j = g^{x^* + j} with (a,b)=(j,1)(a, b) = (j, 1), and these differ from 11 for 0≤j<n−x∗0 \le j < n - x^*. At j=n−x∗j = n - x^* the walk returns to x0=1x_0 = 1. So μ=0\mu = 0 and λ=n−x∗+1≥2\lambda = n - x^* + 1 \ge 2, and every pass around the cycle visits S1S_1 exactly once. Floyd's loop stops at i=λi = \lambda, where the tortoise has made one pass and the hare two, so b=1b = 1 and B=2B = 2 (exponents of hh grow only at line L17). Hence s≡−1s \equiv -1, d=1d = 1, line L12 passes, and by the completeness of an attempt the algorithm returns x∗x^*.

This proves termination with probability one for the algorithm as stated, with uniformly random partitions. An implementation draws the partition from a small keyed family, such as x↦(κx mod p) mod 3x \mapsto (\kappa x \bmod p) \bmod 3 for a random unit κ\kappa; for such a family, the success probability of an attempt is the subject of the random walk heuristic rather than of this proof. Under that heuristic b−Bb - B is uniform modulo nn, so for prime nn an attempt fails with probability about 1/n1/n. ■\blacksquare

Back to Pollard's rho algorithm for discrete logarithms