# Schoof's algorithm

Schoof's algorithm is an efficient algorithm to count points on elliptic curves over finite fields. The algorithm has applications in elliptic curve cryptography where it is important to know the number of points to judge the difficulty of solving the discrete logarithm problem in the group of points on an elliptic curve.

The algorithm was published by René Schoof in 1985 and it was a theoretical breakthrough, as it was the first deterministic polynomial time algorithm for counting points on elliptic curves. Before Schoof's algorithm, approaches to counting points on elliptic curves such as the naive and baby-step giant-step algorithms were, for the most part, tedious and had an exponential running time.

This article explains Schoof's approach, laying emphasis on the mathematical ideas underlying the structure of the algorithm.

## IntroductionEdit

Let ${\displaystyle E}$  be an elliptic curve defined over the finite field ${\displaystyle \mathbb {F} _{q}}$ , where ${\displaystyle q=p^{n}}$  for ${\displaystyle p}$  a prime and ${\displaystyle n}$  an integer ${\displaystyle \geq 1}$ . Over a field of characteristic ${\displaystyle \neq 2,3}$  an elliptic curve can be given by a (short) Weierstrass equation

${\displaystyle y^{2}=x^{3}+Ax+B}$

with ${\displaystyle A,B\in \mathbb {F} _{q}}$ . The set of points defined over ${\displaystyle \mathbb {F} _{q}}$  consists of the solutions ${\displaystyle (a,b)\in \mathbb {F} _{q}^{2}}$  satisfying the curve equation and a point at infinity ${\displaystyle O}$ . Using the group law on elliptic curves restricted to this set one can see that this set ${\displaystyle E(\mathbb {F} _{q})}$  forms an abelian group, with ${\displaystyle O}$  acting as the zero element. In order to count points on an elliptic curve, we compute the cardinality of ${\displaystyle E(\mathbb {F} _{q})}$ . Schoof's approach to computing the cardinality ${\displaystyle \sharp E(\mathbb {F} _{q})}$  makes use of Hasse's theorem on elliptic curves along with the Chinese remainder theorem and division polynomials.

## Hasse's theoremEdit

Hasse's theorem states that if ${\displaystyle E/\mathbb {F} _{q}}$  is an elliptic curve over the finite field ${\displaystyle \mathbb {F} _{q}}$ , then ${\displaystyle \sharp E(\mathbb {F} _{q})}$  satisfies

${\displaystyle \mid q+1-\sharp E(\mathbb {F} _{q})\mid \leq 2{\sqrt {q}}.}$

This powerful result, given by Hasse in 1934, simplifies our problem by narrowing down ${\displaystyle \sharp E(\mathbb {F} _{q})}$  to a finite (albeit large) set of possibilities. Defining ${\displaystyle t}$  to be ${\displaystyle q+1-\sharp E(\mathbb {F} _{q})}$ , and making use of this result, we now have that computing the cardinality of ${\displaystyle t}$  modulo ${\displaystyle N}$  where ${\displaystyle N>4{\sqrt {q}}}$ , is sufficient for determining ${\displaystyle t}$ , and thus ${\displaystyle \sharp E(\mathbb {F} _{q})}$ . While there is no efficient way to compute ${\displaystyle t{\pmod {N}}}$  directly for general ${\displaystyle N}$ , it is possible to compute ${\displaystyle t{\pmod {l}}}$  for ${\displaystyle l}$  a small prime, rather efficiently. We choose ${\displaystyle S=\{l_{1},l_{2},...,l_{r}\}}$  to be a set of distinct primes such that ${\displaystyle \prod l_{i}=N>4{\sqrt {q}}}$ . Given ${\displaystyle t{\pmod {l_{i}}}}$  for all ${\displaystyle l_{i}\in S}$ , the Chinese remainder theorem allows us to compute ${\displaystyle t{\pmod {N}}}$ .

In order to compute ${\displaystyle t{\pmod {l}}}$  for a prime ${\displaystyle l\neq p}$ , we make use of the theory of the Frobenius endomorphism ${\displaystyle \phi }$  and division polynomials. Note that considering primes ${\displaystyle l\neq p}$  is no loss since we can always pick a bigger prime to take its place to ensure the product is big enough. In any case Schoof's algorithm is most frequently used in addressing the case ${\displaystyle q=p}$  since there are more efficient, so called ${\displaystyle p}$  adic algorithms for small-characteristic fields.

## The Frobenius endomorphismEdit

Given the elliptic curve ${\displaystyle E}$  defined over ${\displaystyle \mathbb {F} _{q}}$  we consider points on ${\displaystyle E}$  over ${\displaystyle {\bar {\mathbb {F} }}_{q}}$ , the algebraic closure of ${\displaystyle \mathbb {F} _{q}}$ ; i.e. we allow points with coordinates in ${\displaystyle {\bar {\mathbb {F} }}_{q}}$ . The Frobenius endomorphism of ${\displaystyle {\bar {\mathbb {F} }}_{q}}$  over ${\displaystyle \mathbb {F} _{q}}$  extends to the elliptic curve by ${\displaystyle \phi :(x,y)\mapsto (x^{q},y^{q})}$ .

This map is the identity on ${\displaystyle E(\mathbb {F} _{q})}$  and one can extend it to the point at infinity ${\displaystyle O}$ , making it a group morphism from ${\displaystyle E({\bar {\mathbb {F} _{q}}})}$  to itself.

The Frobenius endomorphism satisfies a quadratic polynomial which is linked to the cardinality of ${\displaystyle E(\mathbb {F} _{q})}$  by the following theorem:

Theorem: The Frobenius endomorphism given by ${\displaystyle \phi }$  satisfies the characteristic equation

${\displaystyle \phi ^{2}-t\phi +q=0,}$  where ${\displaystyle t=q+1-\sharp E(\mathbb {F} _{q})}$

Thus we have for all ${\displaystyle P=(x,y)\in E}$  that ${\displaystyle (x^{q^{2}},y^{q^{2}})+q(x,y)=t(x^{q},y^{q})}$ , where + denotes addition on the elliptic curve and ${\displaystyle q(x,y)}$  and ${\displaystyle t(x^{q},y^{q})}$  denote scalar multiplication of ${\displaystyle (x,y)}$  by ${\displaystyle q}$  and of ${\displaystyle (x^{q},y^{q})}$  by ${\displaystyle t}$ .

One could try to symbolically compute these points ${\displaystyle (x^{q^{2}},y^{q^{2}})}$ , ${\displaystyle (x^{q},y^{q})}$  and ${\displaystyle q(x,y)}$  as functions in the coordinate ring ${\displaystyle \mathbb {F} _{q}[x,y]/(y^{2}-x^{3}-Ax-B)}$  of ${\displaystyle E}$  and then search for a value of ${\displaystyle t}$  which satisfies the equation. However, the degrees get very large and this approach is impractical.

Schoof's idea was to carry out this computation restricted to points of order ${\displaystyle l}$  for various small primes ${\displaystyle l}$ . Fixing an odd prime ${\displaystyle l}$ , we now move on to solving the problem of determining ${\displaystyle t_{l}}$ , defined as ${\displaystyle t{\pmod {l}}}$ , for a given prime ${\displaystyle l\neq 2,p}$ . If a point ${\displaystyle (x,y)}$  is in the ${\displaystyle l}$ -torsion subgroup ${\displaystyle E[l]=\{P\in E({\bar {\mathbb {F} _{q}}})\mid lP=O\}}$ , then ${\displaystyle qP={\bar {q}}P}$  where ${\displaystyle {\bar {q}}}$  is the unique integer such that ${\displaystyle q\equiv {\bar {q}}{\pmod {l}}}$  and ${\displaystyle \mid {\bar {q}}\mid  . Note that ${\displaystyle \phi (O)=O}$  and that for any integer ${\displaystyle r}$  we have ${\displaystyle r\phi (P)=\phi (rP)}$ . Thus ${\displaystyle \phi (P)}$  will have the same order as ${\displaystyle P}$ . Thus for ${\displaystyle (x,y)}$  belonging to ${\displaystyle E[l]}$ , we also have ${\displaystyle t(x^{q},y^{q})={\bar {t}}(x^{q},y^{q})}$  if ${\displaystyle t\equiv {\bar {t}}{\pmod {l}}}$ . Hence we have reduced our problem to solving the equation

${\displaystyle (x^{q^{2}},y^{q^{2}})+{\bar {q}}(x,y)\equiv {\bar {t}}(x^{q},y^{q}),}$

where ${\displaystyle {\bar {t}}}$  and ${\displaystyle {\bar {q}}}$  have integer values in ${\displaystyle [-(l-1)/2,(l-1)/2]}$ .

## Computation modulo primesEdit

The lth division polynomial is such that its roots are precisely the x coordinates of points of order l. Thus, to restrict the computation of ${\displaystyle (x^{q^{2}},y^{q^{2}})+{\bar {q}}(x,y)}$  to the l-torsion points means computing these expressions as functions in the coordinate ring of E and modulo the lth division polynomial. I.e. we are working in ${\displaystyle \mathbb {F} _{q}[x,y]/(y^{2}-x^{3}-Ax-B,\psi _{l})}$ . This means in particular that the degree of X and Y defined via ${\displaystyle (X(x,y),Y(x,y)):=(x^{q^{2}},y^{q^{2}})+{\bar {q}}(x,y)}$  is at most 1 in y and at most ${\displaystyle (l^{2}-3)/2}$  in x.

The scalar multiplication ${\displaystyle {\bar {q}}(x,y)}$  can be done either by double-and-add methods or by using the ${\displaystyle {\bar {q}}}$ th division polynomial. The latter approach gives:

${\displaystyle {\bar {q}}(x,y)=(x_{\bar {q}},y_{\bar {q}})=\left(x-{\frac {\psi _{{\bar {q}}-1}\psi _{{\bar {q}}+1}}{\psi _{\bar {q}}^{2}}},{\frac {\psi _{2{\bar {q}}}}{2\psi _{\bar {q}}^{4}}}\right)}$

where ${\displaystyle \psi _{n}}$  is the nth division polynomial. Note that ${\displaystyle y_{\bar {q}}/y}$  is a function in x only and denote it by ${\displaystyle \theta (x)}$ .

We must split the problem into two cases: the case in which ${\displaystyle (x^{q^{2}},y^{q^{2}})\neq \pm {\bar {q}}(x,y)}$ , and the case in which ${\displaystyle (x^{q^{2}},y^{q^{2}})=\pm {\bar {q}}(x,y)}$ . Note that these equalities are checked modulo ${\displaystyle \psi _{l}}$ .

Case 1: ${\displaystyle (x^{q^{2}},y^{q^{2}})\neq \pm {\bar {q}}(x,y)}$

By using the addition formula for the group ${\displaystyle E(\mathbb {F} _{q})}$  we obtain:

${\displaystyle X(x,y)=\left({\frac {y^{q^{2}}-y_{\bar {q}}}{x^{q^{2}}-x_{\bar {q}}}}\right)^{2}-x^{q^{2}}-x_{\bar {q}}.}$

Note that this computation fails in case the assumption of inequality was wrong.

We are now able to use the x-coordinate to narrow down the choice of ${\displaystyle {\bar {t}}}$  to two possibilities, namely the positive and negative case. Using the y-coordinate one later determines which of the two cases holds.

We first show that X is a function in x alone. Consider ${\displaystyle (y^{q^{2}}-y_{\bar {q}})^{2}=y^{2}(y^{q^{2}-1}-y_{\bar {q}}/y)^{2}}$ . Since ${\displaystyle q^{2}-1}$  is even, by replacing ${\displaystyle y^{2}}$  by ${\displaystyle x^{3}+Ax+B}$ , we rewrite the expression as

${\displaystyle (x^{3}+Ax+B)((x^{3}+Ax+B)^{\frac {q^{2}-1}{2}}-\theta (x))}$

and have that

${\displaystyle X(x)\equiv (x^{3}+Ax+B)((x^{3}+Ax+B)^{\frac {q^{2}-1}{2}}-\theta (x)){\bmod {\psi }}_{l}(x).}$

Here, it seems not right, we throw away ${\displaystyle x^{q^{2}}-x_{\bar {q}}}$ ?

Now if ${\displaystyle X\equiv x_{\bar {t}}^{q}{\bmod {\psi }}_{l}(x)}$  for one ${\displaystyle {\bar {t}}\in [0,(l-1)/2]}$  then ${\displaystyle {\bar {t}}}$  satisfies

${\displaystyle \phi ^{2}(P)\mp {\bar {t}}\phi (P)+{\bar {q}}P=O}$

for all l-torsion points P.

As mentioned earlier, using Y and ${\displaystyle y_{\bar {t}}^{q}}$  we are now able to determine which of the two values of ${\displaystyle {\bar {t}}}$  (${\displaystyle {\bar {t}}}$  or ${\displaystyle -{\bar {t}}}$ ) works. This gives the value of ${\displaystyle t\equiv {\bar {t}}{\pmod {l}}}$ . Schoof's algorithm stores the values of ${\displaystyle {\bar {t}}{\pmod {l}}}$  in a variable ${\displaystyle t_{l}}$  for each prime l considered.

Case 2: ${\displaystyle (x^{q^{2}},y^{q^{2}})=\pm {\bar {q}}(x,y)}$

We begin with the assumption that ${\displaystyle (x^{q^{2}},y^{q^{2}})={\bar {q}}(x,y)}$ . Since l is an odd prime it cannot be that ${\displaystyle {\bar {q}}(x,y)=-{\bar {q}}(x,y)}$  and thus ${\displaystyle {\bar {t}}\neq 0}$ . The characteristic equation yields that ${\displaystyle {\bar {t}}\phi (P)=2{\bar {q}}P}$ . And consequently that ${\displaystyle {\bar {t}}^{2}{\bar {q}}\equiv (2q)^{2}{\pmod {l}}}$ . This implies that q is a square modulo l. Let ${\displaystyle q\equiv w^{2}{\pmod {l}}}$ . Compute ${\displaystyle w\phi (x,y)}$  in ${\displaystyle \mathbb {F} _{q}[x,y]/(y^{2}-x^{3}-Ax-B,\psi _{l})}$  and check whether ${\displaystyle {\bar {q}}(x,y)=w\phi (x,y)}$ . If so, ${\displaystyle t_{l}}$  is ${\displaystyle \pm 2w{\pmod {l}}}$  depending on the y-coordinate.

If q turns out not to be a square modulo l or if the equation does not hold for any of w and ${\displaystyle -w}$ , our assumption that ${\displaystyle (x^{q^{2}},y^{q^{2}})=+{\bar {q}}(x,y)}$  is false, thus ${\displaystyle (x^{q^{2}},y^{q^{2}})=-{\bar {q}}(x,y)}$ . The characteristic equation gives ${\displaystyle t_{l}=0}$ .

Additional case ${\displaystyle l=2}$

If you recall, our initial considerations omit the case of ${\displaystyle l=2}$ . Since we assume q to be odd, ${\displaystyle q+1-t\equiv t{\pmod {2}}}$  and in particular, ${\displaystyle t_{2}\equiv 0{\pmod {2}}}$  if and only if ${\displaystyle E(\mathbb {F} _{q})}$  has an element of order 2. By definition of addition in the group, any element of order 2 must be of the form ${\displaystyle (x_{0},0)}$ . Thus ${\displaystyle t_{2}\equiv 0{\pmod {2}}}$  if and only if the polynomial ${\displaystyle x^{3}+Ax+B}$  has a root in ${\displaystyle \mathbb {F} _{q}}$ , if and only if ${\displaystyle \gcd(x^{q}-x,x^{3}+Ax+B)\neq 1}$ .

## The algorithmEdit

    Input:
1. An elliptic curve ${\displaystyle E=y^{2}-x^{3}-Ax-B}$ .
2. An integer q for a finite field ${\displaystyle F_{q}}$  with ${\displaystyle q=p^{b},b\geq 1}$ .
Output:
The number of points of E over ${\displaystyle F_{q}}$ .
Choose a set of odd primes S not containing p such that ${\displaystyle N=\prod _{l\in S}l>4{\sqrt {q}}.}$
Put ${\displaystyle t_{2}=0}$  if ${\displaystyle \gcd(x^{q}-x,x^{3}+Ax+B)\neq 1}$ , else ${\displaystyle t_{2}=1}$ .
Compute the division polynomial ${\displaystyle \psi _{l}}$ .
All computations in the loop below are performed in the ring ${\displaystyle \mathbb {F} _{q}[x,y]/(y^{2}-x^{3}-Ax-B,\psi _{l}).}$
For ${\displaystyle l\in S}$  do:
Let ${\displaystyle {\bar {q}}}$  be the unique integer such that  ${\displaystyle q\equiv {\bar {q}}{\pmod {l}}}$  and ${\displaystyle \mid {\bar {q}}\mid  .
Compute ${\displaystyle (x^{q},y^{q})}$ , ${\displaystyle (x^{q^{2}},y^{q^{2}})}$  and ${\displaystyle (x_{\bar {q}},y_{\bar {q}})}$ .
if ${\displaystyle x^{q^{2}}\neq x_{\bar {q}}}$  then
Compute ${\displaystyle (X,Y)}$ .
for ${\displaystyle 1\leq {\bar {t}}\leq (l-1)/2}$  do:
if ${\displaystyle X=x_{\bar {t}}^{q}}$  then
if ${\displaystyle Y=y_{\bar {t}}^{q}}$  then
${\displaystyle t_{l}={\bar {t}}}$ ;
else
${\displaystyle t_{l}=-{\bar {t}}}$ .
else if q is a square modulo l then
compute w with ${\displaystyle q\equiv w^{2}{\pmod {l}}}$
compute ${\displaystyle w(x^{q},y^{q})}$
if ${\displaystyle w(x^{q},y^{q})=(x^{q^{2}},y^{q^{2}})}$  then
${\displaystyle t_{l}=2w}$
else if ${\displaystyle w(x^{q},y^{q})=(x^{q^{2}},-y^{q^{2}})}$  then
${\displaystyle t_{l}=-2w}$
else
${\displaystyle t_{l}=0}$
else
${\displaystyle t_{l}=0}$
Use the Chinese Remainder Theorem to compute t modulo N
from the equations ${\displaystyle t\equiv t_{l}{\pmod {l}}}$ , where ${\displaystyle l\in S}$ .
Output ${\displaystyle q+1-t}$ .


## ComplexityEdit

Most of the computation is taken by the evaluation of ${\displaystyle \phi (P)}$  and ${\displaystyle \phi ^{2}(P)}$ , for each prime ${\displaystyle l}$ , that is computing ${\displaystyle x^{q}}$ , ${\displaystyle y^{q}}$ , ${\displaystyle x^{q^{2}}}$ , ${\displaystyle y^{q^{2}}}$  for each prime ${\displaystyle l}$ . This involves exponentiation in the ring ${\displaystyle R=\mathbb {F} _{q}[x,y]/(y^{2}-x^{3}-Ax-B,\psi _{l})}$  and requires ${\displaystyle O(\log q)}$  multiplications. Since the degree of ${\displaystyle \psi _{l}}$  is ${\displaystyle {\frac {l^{2}-1}{2}}}$ , each element in the ring is a polynomial of degree ${\displaystyle O(l^{2})}$ . By the prime number theorem, there are around ${\displaystyle O(\log q)}$  primes of size ${\displaystyle O(\log q)}$ , giving that ${\displaystyle l}$  is ${\displaystyle O(\log q)}$  and we obtain that ${\displaystyle O(l^{2})=O(\log ^{2}q)}$ . Thus each multiplication in the ring ${\displaystyle R}$  requires ${\displaystyle O(\log ^{4}q)}$  multiplications in ${\displaystyle \mathbb {F} _{q}}$  which in turn requires ${\displaystyle O(\log ^{2}q)}$  bit operations. In total, the number of bit operations for each prime ${\displaystyle l}$  is ${\displaystyle O(\log ^{7}q)}$ . Given that this computation needs to be carried out for each of the ${\displaystyle O(\log q)}$  primes, the total complexity of Schoof's algorithm turns out to be ${\displaystyle O(\log ^{8}q)}$ . Using fast polynomial and integer arithmetic reduces this to ${\displaystyle {\tilde {O}}(\log ^{5}q)}$ .

## Improvements to Schoof's algorithmEdit

In the 1990s, Noam Elkies, followed by A. O. L. Atkin, devised improvements to Schoof's basic algorithm by restricting the set of primes ${\displaystyle S=\{l_{1},\ldots ,l_{s}\}}$  considered before to primes of a certain kind. These came to be called Elkies primes and Atkin primes respectively. A prime ${\displaystyle l}$  is called an Elkies prime if the characteristic equation: ${\displaystyle \phi ^{2}-t\phi +q=0}$  splits over ${\displaystyle \mathbb {F} _{l}}$ , while an Atkin prime is a prime that is not an Elkies prime. Atkin showed how to combine information obtained from the Atkin primes with the information obtained from Elkies primes to produce an efficient algorithm, which came to be known as the Schoof–Elkies–Atkin algorithm. The first problem to address is to determine whether a given prime is Elkies or Atkin. In order to do so, we make use of modular polynomials, which come from the study of modular forms and an interpretation of elliptic curves over the complex numbers as lattices. Once we have determined which case we are in, instead of using division polynomials, we are able to work with a polynomial that has lower degree than the corresponding division polynomial: ${\displaystyle O(l)}$  rather than ${\displaystyle O(l^{2})}$ . For efficient implementation, probabilistic root-finding algorithms are used, which makes this a Las Vegas algorithm rather than a deterministic algorithm. Under the heuristic assumption that approximately half of the primes up to an ${\displaystyle O(\log q)}$  bound are Elkies primes, this yields an algorithm that is more efficient than Schoof's, with an expected running time of ${\displaystyle O(\log ^{6}q)}$  using naive arithmetic, and ${\displaystyle {\tilde {O}}(\log ^{4}q)}$  using fast arithmetic. Although this heuristic assumption is known to hold for most elliptic curves, it is not known to hold in every case, even under the GRH.

## ImplementationsEdit

Several algorithms were implemented in C++ by Mike Scott and are available with source code. The implementations are free (no terms, no conditions), and make use of the MIRACL library which is distributed under the AGPLv3.

• Schoof's algorithm implementation for ${\displaystyle E(\mathbb {F} _{p})}$  with prime ${\displaystyle p}$ .
• Schoof's algorithm implementation for ${\displaystyle E(\mathbb {F} _{2^{m}})}$ .

• G. Musiker: Schoof's Algorithm for Counting Points on ${\displaystyle E(\mathbb {F} _{q})}$ . Available at http://www.math.umn.edu/~musiker/schoof.pdf