Documentation

Elligator.PrimalityCertificate

Primality certificates #

Elligator 1 is instantiated over concrete finite fields whose cardinality is a large prime, for instance q = 2^251 - 9 for Curve1174 (see [bernstein2013a], Section 4). Such a primality statement is far out of reach for the decision procedures that evaluate a Nat.Prime goal by trial division, so this file provides the infrastructure needed to check a Pratt certificate inside Lean.

Two ingredients are required:

Main results #

powMod m f b e computes b ^ e % m by binary exponentiation, with fuel parameter that has to bound the bit length of e; see powMod_eq.

Unlike b ^ e % m this is evaluated by the kernel in time linear in f, which makes it usable inside decide for exponents with hundreds of bits.

Equations
Instances For
    theorem Elligator.PrimalityCertificate.powMod_eq (m fuel b e : ) :
    e < 2 ^ fuelpowMod m fuel b e = b ^ e % m

    Correctness of binary modular exponentiation: as soon as the fuel bounds the bit length of the exponent, powMod computes the modular power.

    theorem Elligator.PrimalityCertificate.natCast_pow_eq_natCast {m : } (a e b fuel : ) (hfuel : e < 2 ^ fuel) (h : powMod m fuel a e = b % m) :
    a ^ e = b

    Modular powers inside ZMod m computed through powMod: if the binary exponentiation of a^e modulo m returns b % m, then (a : ZMod m)^e = b. This transports a kernel computation with numerals into an equation between residues.

    theorem Elligator.PrimalityCertificate.prime_of_pratt {p : } (a fuel : ) (L : List ) (hfuel : p - 1 < 2 ^ fuel) (hL : rL, Nat.Prime r) (hprod : p - 1 = L.prod) (ha : powMod p fuel a (p - 1) = 1 % p) (hchk : rL, powMod p fuel a ((p - 1) / r) 1 % p) :

    The Pratt (Lucas) primality criterion, phrased for kernel evaluation.

    If L is a list of primes whose product is p - 1 and if the base a has order exactly p - 1 modulo p, witnessed by a^(p - 1) ≡ 1 and a^((p - 1) / r) ≢ 1 for every r ∈ L, then p is prime. All modular powers are written through powMod, so the hypotheses are decidable by computation once p, a, F and L are numerals.