Algorithm Search⌘K

Proofs: Elliptic curve primality proving

These are the human proofs of Elliptic curve primality proving, at full length.

ECPP is always right and always stops full

This proof shows: correctness, termination.

We use the pseudocode ECPP(N)(N) of the page. For nn coprime to 6, a curve modulo nn is E:y2=x3+ax+bE: y^2 = x^3 + ax + b with gcd⁡(4a3+27b2,n)=1\gcd(4a^3 + 27b^2, n) = 1, and the points are computed with the addition rule of the code: for P1=(x1,y1)P_1 = (x_1, y_1) and P2=(x2,y2)P_2 = (x_2, y_2),

  • if x1≢x2x_1 \not\equiv x_2, then λ=(y2−y1)(x2−x1)−1\lambda = (y_2 - y_1)(x_2 - x_1)^{-1};
  • if x1≡x2x_1 \equiv x_2 and y1+y2≡0y_1 + y_2 \equiv 0, the sum is OO;
  • if x1≡x2x_1 \equiv x_2 and y1≡y2y_1 \equiv y_2, then λ=(3x12+a)(2y1)−1\lambda = (3x_1^2 + a)(2y_1)^{-1};
  • if x1≡x2x_1 \equiv x_2 and y1≢±y2y_1 \not\equiv \pm y_2, the computation stops;

and then x3=λ2−x1−x2x_3 = \lambda^2 - x_1 - x_2, y3=λ(x1−x3)−y1y_3 = \lambda(x_1 - x_3) - y_1. An inverse of a number not coprime to nn also stops the computation. A computation that does not stop is carried out. All congruences are modulo nn unless stated.

Lemma 1 (reduction). Let pp be a prime factor of nn, with gcd⁡(n,6)=1\gcd(n, 6) = 1, and let Eˉ\bar E be EE modulo pp. If a sequence of additions starting from points of EE is carried out, then reducing each computed point modulo pp (with O↦OO \mapsto O) gives the same result as doing the additions in the group Eˉ(Fp)\bar E(\mathbb{F}_p). In particular, a computed [k]P[k]P reduces to [k]Pˉ[k]\bar P.

Proof. As p≥5p \ge 5 and p∤4a3+27b2p \nmid 4a^3 + 27b^2, Eˉ\bar E is an elliptic curve over Fp\mathbb{F}_p, and the chord and tangent rule is its group law. We show for one addition that if the inputs reduce to Pˉ1,Pˉ2∈Eˉ(Fp)\bar P_1, \bar P_2 \in \bar E(\mathbb{F}_p), the output reduces to Pˉ1+Pˉ2\bar P_1 + \bar P_2; induction over the sequence then gives the lemma. If an input is OO, the output is the other input, which is right. In the first case x2−x1x_2 - x_1 is invertible modulo nn, so it is not 00 modulo pp, and xˉ1≠xˉ2\bar x_1 \ne \bar x_2; the group law uses the same chord formula, so the reduced output is Pˉ1+Pˉ2\bar P_1 + \bar P_2. In the second case xˉ1=xˉ2\bar x_1 = \bar x_2 and yˉ1=−yˉ2\bar y_1 = -\bar y_2, so Pˉ2=−Pˉ1\bar P_2 = -\bar P_1 and the sum is OO. In the third case Pˉ1=Pˉ2\bar P_1 = \bar P_2 and 2y12 y_1 is invertible modulo nn, so yˉ1≠0\bar y_1 \ne 0; the group law uses the tangent formula, which is the one computed. The fourth case does not occur, as the computation is carried out. □\square

Lemma 2 (Goldwasser and Kilian). Let n>1n > 1 with gcd⁡(n,6)=1\gcd(n, 6) = 1, EE a curve modulo nn, PP a point of EE, k≥1k \ge 1, and qq a prime with q>(n1/4+1)2q > (n^{1/4} + 1)^2. If U=[k]PU = [k]P is carried out with U≠OU \ne O, and [q]U[q]U is carried out with [q]U=O[q]U = O, then nn is prime.

Proof. Let pp be a prime factor of nn. By Lemma 1, [k]Pˉ=Uˉ[k]\bar P = \bar U and [q]Uˉ=O[q]\bar U = O in Eˉ(Fp)\bar E(\mathbb{F}_p). As UU is a pair (x,y)(x, y) modulo nn, Uˉ\bar U is the pair (xˉ,yˉ)(\bar x, \bar y), not OO. So Uˉ\bar U has order exactly qq, since qq is prime, and by Lagrange's theorem qq divides #Eˉ(Fp)\#\bar E(\mathbb{F}_p). Hasse's theorem gives #Eˉ(Fp)≤p+1+2p=(p+1)2\#\bar E(\mathbb{F}_p) \le p + 1 + 2\sqrt p = (\sqrt p + 1)^2. So (p+1)2≥q>(n1/4+1)2(\sqrt p + 1)^2 \ge q > (n^{1/4} + 1)^2, hence p>n1/4\sqrt p > n^{1/4} and p>np > \sqrt n. If nn were composite, it would have a prime factor p≤np \le \sqrt n. So nn is prime. □\square

Lemma 3 (the exact bound). For integers q>1q > 1 and n≥1n \ge 1, q>(n1/4+1)2q > (n^{1/4} + 1)^2 holds if and only if A>0A > 0 and A2>16(q+1)2qA^2 > 16 (q + 1)^2 q, where A=q2+6q+1−nA = q^2 + 6q + 1 - n. This is the test of line L8 and of the checker.

Proof. Both sides of q>(n1/4+1)2q > (n^{1/4}+1)^2 are positive, so it is equivalent to q−1>n1/4\sqrt q - 1 > n^{1/4}, and as q−1>0\sqrt q - 1 > 0, to (q−1)4>n(\sqrt q - 1)^4 > n. Expanding, (q−1)4=q2+6q+1−4(q+1)q(\sqrt q - 1)^4 = q^2 + 6q + 1 - 4(q + 1)\sqrt q, so the condition is A>4(q+1)qA > 4(q + 1)\sqrt q. The right side is positive, so this holds if and only if A>0A > 0 and A2>16(q+1)2qA^2 > 16(q+1)^2 q. □\square

Lemma 4 (the leaf). For 0≤n<2640 \le n < 2^{64}, line L4 returns exactly when nn is prime.

Proof. The code first divides by the 12 primes 2,…,372, \ldots, 37 and then runs the strong test to these bases. A prime passes the strong test to every base it does not divide. No composite below 2642^{64} is a strong pseudoprime to all of the first 12 prime bases; this is a computed fact (Sorenson and Webster, Mathematics of Computation 86, 2017, with the earlier list of base 2 pseudoprimes below 2642^{64} of Feitsma and Galway), which we quote. □\square

Lemma 5 (steps in the list). At every time, each element (ni,ai,bi,Pi,ki,qi)(n_i, a_i, b_i, P_i, k_i, q_i) of CC, in order, satisfies the hypotheses of Lemma 2 except possibly that qiq_i is prime; the first has n1=Nn_1 = N, each ni+1=qin_{i+1} = q_i, and the current nn is qq of the last element, or NN if CC is empty.

Proof. Initially CC is empty and n=Nn = N. Line L12 appends a step only after line L6 has checked gcd⁡(n,6)=1\gcd(n, 6) = 1 and n≥264>1n \ge 2^{64} > 1, the code has checked gcd⁡(4a3+27b2,n)=1\gcd(4a^3 + 27b^2, n) = 1 (a gcd above 1 calls REJECT), the point PP was built with y2≡x3+ax+by^2 \equiv x^3 + ax + b, line L8 has checked q>(n1/4+1)2q > (n^{1/4} + 1)^2 by Lemma 3, and U=[k]P≠OU = [k]P \ne O and [q]U=O[q]U = O were carried out. Then nn becomes qq, which keeps the invariant. Line L16 removes the last element and sets nn to its number, which is the qq of the element before it, or NN; the invariant holds again. □\square

Theorem 1 (prime answers are right). If ECPP(N)(N) returns prime with certificate CC, then NN is prime.

Proof. The answer comes from line L4, so the current nn is prime by Lemma 4. By Lemma 5, n=qtn = q_t for the last element of CC. By Lemma 2, ntn_t is prime, and nt=qt−1n_t = q_{t-1}; going back, nt−1,…,n1=Nn_{t-1}, \ldots, n_1 = N are prime. If CC is empty, n=Nn = N and NN is prime directly. □\square

The same argument shows that the checker verify_certificate of the code accepts only primes: it tests each hypothesis of Lemma 2 for each row, the links ni+1=qin_{i+1} = q_i, and the last number with Lemma 4.

Lemma 6 (each REJECT is right). Whenever REJECT(n)(n) is called, the current nn is composite.

Proof. We go through the calls.

  • Line L5: by Lemma 4, n<264n < 2^{64} is not prime.
  • Line L6: here n≥264n \ge 2^{64}. A multiple of 2 or 3 above 3 is composite, a square above 1 is composite, and an odd prime passes the strong test to the base 2.
  • A gcd of nn with some number that lies strictly between 1 and nn, from an inverse or from a Jacobi symbol equal to 0, is a proper factor of nn.
  • A failed square root. For a prime nn and (c/n)=1(c/n) = 1, cc is a quadratic residue, and the Tonelli-Shanks algorithm with a non-residue zz (found with (z/n)=−1(z/n) = -1) returns a root. So if (c/n)=1(c/n) = 1 and the computed yy has y2≢cy^2 \not\equiv c, nn is not prime. This covers the root of DD in line L7 and the points of line L11.
  • The fourth case of the addition rule. If nn were prime, all points computed lie on the curve (Lemma 1 with p=np = n), and x1=x2x_1 = x_2 gives y12=y22y_1^2 = y_2^2, so y1=±y2y_1 = \pm y_2 in the field Fn\mathbb{F}_n.
  • A curve with gcd⁡(4a3+27b2,n)=n\gcd(4a^3 + 27b^2, n) = n. For D=−3D = -3 and D=−4D = -4 the discriminant is 27g2e27 g^{2e} or −4g3e-4 g^{3e} times a unit, and gg is coprime to nn. Otherwise c=j(j−1728)−1c = j (j - 1728)^{-1} with j≢0,1728j \not\equiv 0, 1728, and 4(−3c)3+27(2c)2=108c2(1−c)4(-3c)^3 + 27(2c)^2 = 108 c^2 (1 - c), with c≢0c \not\equiv 0 and 1−c=−1728(j−1728)−1≢01 - c = -1728 (j - 1728)^{-1} \not\equiv 0. So for a prime nn the discriminant is never 00 modulo nn.
  • Line L13. Suppose nn is prime. Then (D/n)=1(D/n) = 1, 4n=u2+∣D∣v24n = u^2 + |D| v^2, jj is a root of HDH_D modulo nn (the code checks HD(j)≡0H_D(j) \equiv 0), and HDH_D is the Hilbert class polynomial (the code checks that the computed coefficients are within 10−1010^{-10} of integers; we assume the rounding is right). By the theory of complex multiplication (Deuring; Atkin and Morain, Section 3; Crandall and Pomerance, Algorithm 7.5.9), the curve with jj-invariant jj and its twists over Fn\mathbb{F}_n have as orders exactly the numbers of the list for DD, and the twists of line L10 are one curve for each order: for D≠−3,−4D \ne -3, -4 the twist by a non-residue gg, for D=−4D = -4 the four classes geg^e modulo fourth powers, and for D=−3D = -3 the six classes modulo sixth powers, as gg is neither a square nor a cube. So one twist has exactly mm points, and every point PP on it has [m]P=O[m]P = O by Lagrange's theorem. On that twist, every PP has either [k]P=O[k]P = O, so another point is tried, or [q]([k]P)=[m]P=O[q]([k]P) = [m]P = O, so line L12 succeeds. Hence not every twist can have a point with [q]U≠O[q]U \ne O, and line L13 cannot call REJECT. □\square

Theorem 2 (composite answers are right). If ECPP(N)(N) returns composite, NN is composite.

Proof. Composite is returned only at line L15, inside REJECT(n)(n) with CC empty. By Lemma 5, then n=Nn = N, and by Lemma 6, nn is composite. □\square

Theorem 3 (termination). ECPP(N)(N) stops: it returns prime, returns composite, or stops at line L14 with no answer (only when CC is empty).

Proof. First, one pass from line L2 to the next "go to L2" takes a finite number of operations. The table of line L7 is finite, each DD has at most 6 orders, the loop of line L10 has at most 6 twists, and the code bounds the tries for a point and for a root. Each power, gcd, square root and Euclid chain is a loop that ends. So each pass ends with a return, a stop, or a jump to line L2 from line L12 or line L16 (line L14 with CC not empty also goes to line L16).

A jump from line L12 replaces nn by qq with q<nq < n: as m≤n+1+2n=(n+1)2m \le n + 1 + 2\sqrt n = (\sqrt n + 1)^2 for every listed order and k≥2k \ge 2, q≤(n+1)2/2<nq \le (\sqrt n + 1)^2/2 < n for n≥6n \ge 6. A jump from line L16 adds the current nn to the set bad, and that nn is not in bad before: a number in bad is never chosen again at line L8, and nn was either NN, which is not removed (line L15 returns instead), or a qq chosen at line L8 after it was last added. All numbers that enter bad are below NN, so line L16 runs at most NN times. Between two runs of line L16, line L12 runs at most as many times as the list CC can grow, and each step lowers nn, so at most NN times. So there are finitely many passes, and the method stops. In practice the list has O(log⁡N)O(\log N) steps and line L16 almost never runs. □\square

■\blacksquare

Back to Elliptic curve primality proving