Elliptic curve certificates

Elliptic curve certificates

A Pocklington certificate needs the factorisation of n−1n - 1, and for most large primes that is out of reach. An elliptic curve gives a second chance, and a third, and as many as needed: any curve modulo nn whose number of points has a large prime factor will do. This is how primes of hundreds of digits are proven in practice.

The theorem

Let nn be prime to 6, EE a curve y2=x3+ax+by^2 = x^3 + ax + b modulo nn, and PP a point on it. Suppose m=kqm = kq with qq prime and

q>(n1/4+1)2,m⋅P=O,k⋅P≠O (a finite point, with every division along the way possible). q > \left(n^{1/4} + 1\right)^2, \qquad m\cdot P = O, \qquad k\cdot P \ne O \ \text{(a finite point, with every division along the way possible)}.

Then nn is prime (Goldwasser and Kilian, 1986). The reason is short. If nn had a prime factor p≤np \le \sqrt n, then modulo pp the point kPkP would have order exactly qq in E(Fp)E(\mathbb{F}_p). But that group has at most (p+1)2≤(n1/4+1)2<q(\sqrt p + 1)^2 \le (n^{1/4} + 1)^2 < q elements, by Hasse's theorem. So the certificate is the curve, the point, mm and qq, together with a certificate for qq, which is about the size of n/kn/k: a chain that descends until Pocklington or trial division finishes it.

import { provePrime, verifyCertificate, isPrime } from "@ratmath/numtheory";

const n = 10n ** 60n + 7n;
const r = provePrime(n);
r.certificate.kind;            // "elliptic"
r.certificate.discriminant;    // -7
r.certificate.m;               // 1000000000000000000000000000002000000000000000000000000000008n
r.certificate.q;               // 26641539363749891267808119193147605196373n, a 41-digit prime
r.certificate.certificate.kind;   // "pocklington": q − 1 could be factored far enough
verifyCertificate(r.certificate); // { valid: true }

provePrime(n, { elliptic: false }).reason;   // "only 55 of the 200 bits of n − 1 could be factored and certified (a third are needed)"
isPrime(2n ** 255n - 19n);     // true: n − 1 = 2² · 3 · 65147 · (a 71-digit prime), and that prime is certified with curves

Where the curve comes from

Goldwasser and Kilian picked random curves and counted their points with Schoof's algorithm, which is far too slow to do many times. Atkin and Morain turned it around: build a curve whose number of points is known in advance.

If 4n=t2+∣D∣v24n = t^2 + |D|v^2 for a negative discriminant DD, then there are curves modulo nn with exactly n+1−tn + 1 - t and n+1+tn + 1 + t points: those with complex multiplication by DD. Their j-invariants are the roots modulo nn of the Hilbert class polynomial HDH_D. For the example above, 4n=(2⋅1030)2+7⋅224n = (2\cdot10^{30})^2 + 7\cdot2^2, so D=−7D = -7 works with t=±2⋅1030t = \pm2\cdot10^{30}, and m=n+1+2⋅1030m = n + 1 + 2\cdot10^{30} happens to be 23⋅11⋅29⋅6091⋅10343⋅2334666712^3 \cdot 11 \cdot 29 \cdot 6091 \cdot 10343 \cdot 233466671 times a prime. The search runs through discriminants in order, solves 4n=t2+∣D∣v24n = t^2 + |D|v^2 by Cornacchia's algorithm, and keeps a candidate mm when small factors can be stripped from it to leave a large enough probable prime.

Class polynomials

import { classPolynomial, classNumber } from "@ratmath/numtheory";

classPolynomial(-7);      // [3375n, 1n]: x + 3375, so j = −3375 = −15³
classPolynomial(-163);    // [262537412640768000n, 1n]: j = −640320³
classPolynomial(-23);     // [12771880859375n, -5151296875n, 3491750n, 1n]
classNumber(-23);         // 3n: the degree of H_D is the class number

HD(x)=∏(x−j(τ))H_D(x) = \prod (x - j(\tau)), the product over the reduced forms (a,b,c)(a, b, c) of discriminant DD (see Quadratic forms) with τ=(−b+D)/2a\tau = (-b + \sqrt D)/2a. The j-function is evaluated from its definition j=E43/Δj = E_4^3/\Delta in fixed-point complex arithmetic with enough digits, and the product, which must have whole coefficients, is rounded and the rounding checked. The famous near-integer eπ163=262537412640768743.99999999999925…e^{\pi\sqrt{163}} = 262537412640768743.99999999999925\ldots is this in miniature: j(τ)=1/q+744+196884q+⋯j(\tau) = 1/q + 744 + 196884q + \cdots is a whole number while q=−e−π163q = -e^{-\pi\sqrt{163}} is tiny.

What has to be trusted

Very little. The class polynomial is computed numerically, square roots modulo nn assume nn is prime, and the search takes shortcuts. None of that matters for soundness: all of it only serves to find a curve and a point, and the certificate is then checked by the independent verifier, which knows nothing about complex multiplication. It checks that the point is on the curve, that the discriminant of the curve is a unit modulo nn, the size of qq, the certificate of qq, and the two multiplications. Its curve arithmetic uses plain affine coordinates and insists that every divisor is a unit modulo nn, so each step is a true group operation modulo every prime factor of nn at once; a shortcut through projective coordinates would not have that property. A mistake in the search can only mean that no certificate is found.

The tests attack the verifier directly: they build composite numbers n=p rn = p\,r, curves and points whose orders modulo both primes are known, and offer every prime factor of the order as qq. All are rejected.

How far it goes

Discriminants up to 5000 with class number up to 12 are tried by default (options maxDiscriminant, maxClassNumber). Primes of 60 digits take a fraction of a second, 150 digits a couple of seconds, 230 digits under ten seconds. The search can fail, and then provePrime says so and isPrime refuses, as before.

Try itEdit the code and run it with @ratmath/numtheory and Core's Rational in scope. The last line's value is shown; PRINT(…) adds lines, TEX(…) typesets math.
Ctrl/⌘ + Enter runs