Primality certificate


In mathematics and computer science, a primality certificate or primality proof is a succinct, formal proof that a number is prime. Primality certificates allow the primality of a number to be rapidly checked without having to run an expensive or unreliable primality test. "Succinct" usually means that the proof should be at most polynomially larger than the number of digits in the number itself.
Primality certificates lead directly to proofs that problems such as primality testing and the complement of integer factorization lie in NP, the class of problems verifiable in polynomial time given a solution. These problems already trivially lie in co-NP. This was the first strong evidence that these problems are not NP-complete, since if they were, it would imply that NP is subset of co-NP, a result widely believed to be false; in fact, this was the first demonstration of a problem in NP intersect co-NP not known, at the time, to be in P.
Producing certificates for the complement problem, to establish that a number is composite, is straightforward: it suffices to give a nontrivial divisor. Standard probabilistic primality tests such as the Baillie–PSW primality test, the Fermat primality test, and the Miller–Rabin primality test also produce compositeness certificates in the event where the input is composite, but do not produce certificates for prime inputs.

Pratt certificates

The concept of primality certificates was historically introduced by the Pratt certificate, conceived in 1975 by Vaughan Pratt, who described its structure and proved it to have polynomial size and to be verifiable in polynomial time. It is based on the Lucas primality test, which is essentially the converse of Fermat's little theorem with an added condition to make it true:
Given such an a and the prime factorization of n − 1, it's simple to verify the above conditions quickly: we only need to do a linear number of modular exponentiations, since every integer has fewer prime factors than bits, and each of these can be done by exponentiation by squaring in O multiplications. Even with grade-school integer multiplication, this is only O time; using the multiplication algorithm with best-known asymptotic running time, due to David Harvey and Joris van der Hoeven, we can lower this to O3) time, or using soft-O notation Õ.
However, it is possible to trick a verifier into accepting a composite number by giving it a "prime factorization" of n − 1 that includes composite numbers. For example, suppose we claim that n = 85 is prime, supplying a = 4 and n − 1 = 6 × 14 as the "prime factorization". Then :
  • 4 is coprime to 85,
  • 485−1 ≡ 1,
  • 4/6 ≡ 16, 4/14 ≡ 16.
We would falsely conclude that 85 is prime. We don't want to just force the verifier to factor the number, so a better way to avoid this issue is to give primality certificates for each of the prime factors of n − 1 as well, which are just smaller instances of the original problem. We continue recursively in this manner until we reach a number known to be prime, such as 2. We end up with a tree of prime numbers, each associated with a witness a. For example, here is a complete Pratt certificate for the number 229:
  • 229,
  • * 2,
  • * 3,
  • ** 2,
  • * 19,
  • ** 2,
  • ** 3,
  • *** 2.
This proof tree can be shown to contain at most values other than 2 by a simple inductive proof. The result holds for 3; in general, take p > 3 and let its children in the tree be p1,..., pk. By the inductive hypothesis, the tree rooted at pi contains at most values, so the entire tree contains at most
since k ≥ 2, and p1...pk = p − 1. Since each value has at most log n bits, this also demonstrates that the certificate has a size of O bits.
Since there are O values other than 2, and each requires at most one exponentiation to verify, the total time is O3), or Õ, which is quite feasible for numbers in the range that computational number theorists usually work with.
However, while useful in theory and easy to verify, actually generating a Pratt certificate for n requires factoring n − 1 and other potentially large numbers. This is simple for some special numbers such as Fermat primes, but currently much more difficult than simple primality testing for large primes of general form.

Atkin–Goldwasser–Kilian–Morain certificates

To address the problem of efficient certificate generation for larger numbers, in 1986 Shafi Goldwasser and Joe Kilian described a new type of certificate based on the theory of elliptic curves. This was in turn used by A. O. L. Atkin and François Morain as the basis for Atkin-Goldwasser-Kilian-Morain certificates, which are the type of certificates generated and verified by elliptic curve primality proving systems. Just as Pratt certificates are based on Lucas's theorem, Atkin–Goldwasser–Kilian–Morain certificates are based on the following theorem of Goldwasser and Kilian :
Technically, an elliptic curve can only be constructed over a field, and is only a field if n is prime, so we seem to be assuming the result we're trying to prove. The difficulty arises in the elliptic-curve addition algorithm, which takes inverses in the field that may not exist in. However, it can be shown that if we merely perform computations as though the curve were well-defined and do not at any point attempt to invert an element with no inverse, the result is still valid; if we do encounter an element with no inverse, this establishes that n is composite.
To derive a certificate from this theorem, we first encode Mx, My, A, B, and q, then recursively encode the proof of primality for q < n, continuing until we reach a known prime. This certificate has size Õ and can be verified in Õ time. Moreover, the algorithm that generates these certificates can be shown to be expected polynomial time for all but a small fraction of primes, and this fraction exponentially decreases with the size of the primes. Consequently, it's well-suited to generating certified large random primes, an application that is important in cryptography applications such as generating provably valid RSA keys.
Time spent on generating an ECPP certificate is not bounded, but a heuristic argument gives Õ implemented naively as in Goldwasser-Kilian. Atkin and Morain lowered the number to Õ. FastECPP has lowered the time to Õ.

Pocklington-based certificates

Provable prime generation based on variants of Pocklington's theorem can be efficient techniques for generating primes with the added benefit of built in primality certificates. While these may seem to be special primes, notice that every prime integer could be generated with a Pocklington based provable generation algorithm.

Pocklington primality tests

Let where where are distinct primes with an integer greater than zero and a witness such that:
Then P is prime if one of the following holds:

Pocklington primality certificate

A Pocklington primality certificate consists of the prime P, a set primes dividing, each with their own Pocklington prime certificate or small enough to be a known prime, and a witness.
The steps needed for this certificate should be the sum of these steps:
  1. Verify that all are primes and that they divide, obtaining and in the process. This would take less time than the rest of the process.
  2. Verify that holds. This is the same complexity as the Fermat primality test, Õ.
  3. Verify that holds. This requires calculation of gcd, done for large numbers usually using the Extended Euclidean algorithm, over the number of primes provided. Each operation takes between Õ to Õ time depending on the relative magnitude of versus.
  4. Verify that the last step holds. This is approximately:
  5. * for version to
  6. * for version.
See also PARI/GP's documentation.

A small example

Let. Note that and,.
  • Using the 'witness' 2, equation is satisfied and using and.
  • For version, the certificate needs only.
  • for version, the certificate needs only, but there's a bit more work to do:
  • *
  • * and
  • * Using fails:
  • * Using succeeds:, and is prime.

    Gerbicz-based certificate

Gerbicz-based certificate seek to prove the correctness of a modular exponentiation process as used in the Proth and Fermat probabilistic tests as well as the early steps of the Pocklington test. It has also been adapted to the calculation of Lucas sequence terms, which is used in the deterministic Lucas–Lehmer and Lucas–Lehmer–Riesel tests. This type of certificate take space as well as time to produce.
The produced certificate takes space to transmit and squarings to verify.
It is applied to very large numbers where the exponentiation itself is a costly task. For example, a Gerbicz-Pietrzak proof was used to authenticate the Fermat primality test for, the Mersenne prime found in 2024.

Gerbicz-Pietrzak scheme

and allied projects such as PrimeGrid use Pavel Atnashev's "Gerbicz-Pietrzak" scheme, which combines Gerbicz's error checking for modular exponentiation with Pietrzak's verifiable delay function for producing an easily verifiable "proof" of a modular exponentiation to a power of 2m.
The Gerbicz error-checking scheme was originally defined for the Proth test, but was later extended to the Fermat primality test. The original form verifies the computation by adding an additional variable and an arbitrary scaling constant L. There is therefore a recurrence relation of which can be used to update d every L iterations of exponential doubling. There is also a relation, which is used to check the computation every B = L2 iterations. A mismatch would result in a rollback to a previously saved "checkpoint" tuple of.
With the addition of the Pietrzak VDF scheme, the calculating client generates a "certificate" file using the saved "checkpoint" residues from the computation, resulting in a file of elements. It uploads the certificate to a server, which then assigns it to a "verifier" client. The verifier then uses the non-interactive version of the Pietrzak scheme to check the result.
A generalization of the Pietrzak scheme to Lucas sequences has been published, in which the computation of, is verified.