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 of the page. For coprime to 6, a curve modulo is with , and the points are computed with the addition rule of the code: for and ,
- if , then ;
- if and , the sum is ;
- if and , then ;
- if and , the computation stops;
and then , . An inverse of a number not coprime to also stops the computation. A computation that does not stop is carried out. All congruences are modulo unless stated.
Lemma 1 (reduction). Let be a prime factor of , with , and let be modulo . If a sequence of additions starting from points of is carried out, then reducing each computed point modulo (with ) gives the same result as doing the additions in the group . In particular, a computed reduces to .
Proof. As and , is an elliptic curve over , and the chord and tangent rule is its group law. We show for one addition that if the inputs reduce to , the output reduces to ; induction over the sequence then gives the lemma. If an input is , the output is the other input, which is right. In the first case is invertible modulo , so it is not modulo , and ; the group law uses the same chord formula, so the reduced output is . In the second case and , so and the sum is . In the third case and is invertible modulo , so ; the group law uses the tangent formula, which is the one computed. The fourth case does not occur, as the computation is carried out.
Lemma 2 (Goldwasser and Kilian). Let with , a curve modulo , a point of , , and a prime with . If is carried out with , and is carried out with , then is prime.
Proof. Let be a prime factor of . By Lemma 1, and in . As is a pair modulo , is the pair , not . So has order exactly , since is prime, and by Lagrange's theorem divides . Hasse's theorem gives . So , hence and . If were composite, it would have a prime factor . So is prime.
Lemma 3 (the exact bound). For integers and , holds if and only if and , where . This is the test of line L8 and of the checker.
Proof. Both sides of are positive, so it is equivalent to , and as , to . Expanding, , so the condition is . The right side is positive, so this holds if and only if and .
Lemma 4 (the leaf). For , line L4 returns exactly when is prime.
Proof. The code first divides by the 12 primes 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 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 of Feitsma and Galway), which we quote.
Lemma 5 (steps in the list). At every time, each element of , in order, satisfies the hypotheses of Lemma 2 except possibly that is prime; the first has , each , and the current is of the last element, or if is empty.
Proof. Initially is empty and . Line L12 appends a step only after line L6 has checked and , the code has checked (a gcd above 1 calls REJECT), the point was built with , line L8 has checked by Lemma 3, and and were carried out. Then becomes , which keeps the invariant. Line L16 removes the last element and sets to its number, which is the of the element before it, or ; the invariant holds again.
Theorem 1 (prime answers are right). If ECPP returns prime with certificate , then is prime.
Proof. The answer comes from line L4, so the current is prime by Lemma 4. By Lemma 5, for the last element of . By Lemma 2, is prime, and ; going back, are prime. If is empty, and is prime directly.
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 , and the last number with Lemma 4.
Lemma 6 (each REJECT is right). Whenever REJECT is called, the current is composite.
Proof. We go through the calls.
- Line L5: by Lemma 4, is not prime.
- Line L6: here . 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 with some number that lies strictly between 1 and , from an inverse or from a Jacobi symbol equal to 0, is a proper factor of .
- A failed square root. For a prime and , is a quadratic residue, and the Tonelli-Shanks algorithm with a non-residue (found with ) returns a root. So if and the computed has , is not prime. This covers the root of in line L7 and the points of line L11.
- The fourth case of the addition rule. If were prime, all points computed lie on the curve (Lemma 1 with ), and gives , so in the field .
- A curve with . For and the discriminant is or times a unit, and is coprime to . Otherwise with , and , with and . So for a prime the discriminant is never modulo .
- Line L13. Suppose is prime. Then , , is a root of modulo (the code checks ), and is the Hilbert class polynomial (the code checks that the computed coefficients are within 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 -invariant and its twists over have as orders exactly the numbers of the list for , and the twists of line L10 are one curve for each order: for the twist by a non-residue , for the four classes modulo fourth powers, and for the six classes modulo sixth powers, as is neither a square nor a cube. So one twist has exactly points, and every point on it has by Lagrange's theorem. On that twist, every has either , so another point is tried, or , so line L12 succeeds. Hence not every twist can have a point with , and line L13 cannot call REJECT.
Theorem 2 (composite answers are right). If ECPP returns composite, is composite.
Proof. Composite is returned only at line L15, inside REJECT with empty. By Lemma 5, then , and by Lemma 6, is composite.
Theorem 3 (termination). ECPP stops: it returns prime, returns composite, or stops at line L14 with no answer (only when 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 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 not empty also goes to line L16).
A jump from line L12 replaces by with : as for every listed order and , for . A jump from line L16 adds the current to the set bad, and that is not in bad before: a number in bad is never chosen again at line L8, and was either , which is not removed (line L15 returns instead), or a chosen at line L8 after it was last added. All numbers that enter bad are below , so line L16 runs at most times. Between two runs of line L16, line L12 runs at most as many times as the list can grow, and each step lowers , so at most times. So there are finitely many passes, and the method stops. In practice the list has steps and line L16 almost never runs.