Let
E
be an elliptic curve defined over the finite field
F
q
, where
q
=
p
n
for
p
a prime and
n
an integer
≥
1
. Over a field of characteristic
≠
2
,
3
an elliptic curve can be given by a (short) Weierstrass equation

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

Hasse's theorem states that if
E
/
F
q
is an elliptic curve over the finite field
F
q
, then
♯
E
(
F
q
)
satisfies

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

In order to compute
t
(
mod
l
)
for a prime
l
≠
p
, we make use of the theory of the Frobenius endomorphism
ϕ
and division polynomials. Note that considering primes
l
≠
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
q
=
p
since there are more efficient, so called
p
adic algorithms for small-characteristic fields.

Given the elliptic curve
E
defined over
F
q
we consider points on
E
over
F
¯
q
, the algebraic closure of
F
q
; i.e. we allow points with coordinates in
F
¯
q
. The Frobenius endomorphism of
F
¯
q
over
F
q
extends to the elliptic curve by
ϕ
:
(
x
,
y
)
↦
(
x
q
,
y
q
)
.

This map is the identity on
E
(
F
q
)
and one can extend it to the point at infinity
O
, making it a group morphism from
E
(
F
q
¯
)
to itself.

The Frobenius endomorphism satisfies a quadratic polynomial which is linked to the cardinality of
E
(
F
q
)
by the following theorem:

**Theorem:** The Frobenius endomorphism given by
ϕ
satisfies the characteristic equation

ϕ
2
−
t
ϕ
+
q
=
0
,
where

t
=
q
+
1
−
♯
E
(
F
q
)
Thus we have for all
P
=
(
x
,
y
)
∈
E
that
(
x
q
2
,
y
q
2
)
+
q
(
x
,
y
)
=
t
(
x
q
,
y
q
)
, where + denotes addition on the elliptic curve and
q
(
x
,
y
)
and
t
(
x
q
,
y
q
)
denote scalar multiplication of
(
x
,
y
)
by
q
and of
(
x
q
,
y
q
)
by
t
.

One could try to symbolically compute these points
(
x
q
2
,
y
q
2
)
,
(
x
q
,
y
q
)
and
q
(
x
,
y
)
as functions in the coordinate ring
F
q
[
x
,
y
]
/
(
y
2
−
x
3
−
A
x
−
B
)
of
E
and then search for a value of
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
l
for various small primes
l
. Fixing an odd prime
l
, we now move on to solving the problem of determining
t
l
, defined as
t
(
mod
l
)
, for a given prime
l
≠
2
,
p
. If a point
(
x
,
y
)
is in the
l
-torsion subgroup
E
[
l
]
=
{
P
∈
E
(
F
q
¯
)
∣
l
P
=
O
}
, then
q
P
=
q
¯
P
where
q
¯
is the unique integer such that
q
≡
q
¯
(
mod
l
)
and
∣
q
¯
∣<
l
/
2
. Note that
ϕ
(
O
)
=
O
and that for any integer
r
we have
r
ϕ
(
P
)
=
ϕ
(
r
P
)
. Thus
ϕ
(
P
)
will have the same order as
P
. Thus for
(
x
,
y
)
belonging to
E
[
l
]
, we also have
t
(
x
q
,
y
q
)
=
t
¯
(
x
q
,
y
q
)
if
t
≡
t
¯
(
mod
l
)
. Hence we have reduced our problem to solving the equation

(
x
q
2
,
y
q
2
)
+
q
¯
(
x
,
y
)
≡
t
¯
(
x
q
,
y
q
)
,
where
t
¯
and
q
¯
have integer values in
[
−
(
l
−
1
)
/
2
,
(
l
−
1
)
/
2
]
.

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
(
x
q
2
,
y
q
2
)
+
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
F
q
[
x
,
y
]
/
(
y
2
−
x
3
−
A
x
−
B
,
ψ
l
)
. This means in particular that the degree of X and Y defined via
(
X
(
x
,
y
)
,
Y
(
x
,
y
)
)
:=
(
x
q
2
,
y
q
2
)
+
q
¯
(
x
,
y
)
is at most 1 in y and at most
(
l
2
−
3
)
/
2
in x.

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

q
¯
(
x
,
y
)
=
(
x
q
¯
,
y
q
¯
)
=
(
x
−
ψ
q
¯
−
1
ψ
q
¯
+
1
ψ
q
¯
2
,
ψ
2
q
¯
2
ψ
q
¯
4
)
where
ψ
n
is the nth division polynomial. Note that
y
q
¯
/
y
is a function in x only and denote it by
θ
(
x
)
.

We must split the problem into two cases: the case in which
(
x
q
2
,
y
q
2
)
≠
±
q
¯
(
x
,
y
)
, and the case in which
(
x
q
2
,
y
q
2
)
=
±
q
¯
(
x
,
y
)
. Note that these equalities are checked modulo
ψ
l
.

By using the addition formula for the group
E
(
F
q
)
we obtain:

X
(
x
,
y
)
=
(
y
q
2
−
y
q
¯
x
q
2
−
x
q
¯
)
2
−
x
q
2
−
x
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
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
(
y
q
2
−
y
q
¯
)
2
=
y
2
(
y
q
2
−
1
−
y
q
¯
/
y
)
2
. Since
q
2
−
1
is even, by replacing
y
2
by
x
3
+
A
x
+
B
, we rewrite the expression as

(
x
3
+
A
x
+
B
)
(
(
x
3
+
A
x
+
B
)
q
2
−
1
2
−
θ
(
x
)
)
and have that

X
(
x
)
≡
(
x
3
+
A
x
+
B
)
(
(
x
3
+
A
x
+
B
)
q
2
−
1
2
−
θ
(
x
)
)
mod
ψ
l
(
x
)
.
Now if
X
≡
x
t
¯
q
mod
ψ
l
(
x
)
for one
t
¯
∈
[
0
,
(
l
−
1
)
/
2
]
then
t
¯
satisfies

ϕ
2
(
P
)
∓
t
¯
ϕ
(
P
)
+
q
¯
P
=
O
for all l-torsion points P.

As mentioned earlier, using Y and
y
t
¯
q
we are now able to determine which of the two values of
t
¯
(
t
¯
or
−
t
¯
) works. This gives the value of
t
≡
t
¯
(
mod
l
)
. Schoof's algorithm stores the values of
t
¯
(
mod
l
)
in a variable
t
l
for each prime l considered.

We begin with the assumption that
(
x
q
2
,
y
q
2
)
=
q
¯
(
x
,
y
)
. Since l is an odd prime it cannot be that
q
¯
(
x
,
y
)
=
−
q
¯
(
x
,
y
)
and thus
t
¯
≠
0
. The characteristic equation yields that
t
¯
ϕ
(
P
)
=
2
q
¯
P
. And consequently that
t
¯
2
q
¯
≡
(
2
q
)
2
(
mod
l
)
. This implies that q is a square modulo l. Let
q
≡
w
2
(
mod
l
)
. Compute
w
ϕ
(
x
,
y
)
in
F
q
[
x
,
y
]
/
(
y
2
−
x
3
−
A
x
−
B
,
ψ
l
)
and check whether
q
¯
(
x
,
y
)
=
w
ϕ
(
x
,
y
)
. If so,
t
l
is
±
2
w
(
mod
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
−
w
, our assumption that
(
x
q
2
,
y
q
2
)
=
+
q
¯
(
x
,
y
)
is false, thus
(
x
q
2
,
y
q
2
)
=
−
q
¯
(
x
,
y
)
. The characteristic equation gives
t
l
=
0
.

If you recall, our initial considerations omit the case of
l
=
2
. Since we assume q to be odd,
q
+
1
−
t
≡
t
(
mod
2
)
and in particular,
t
2
≡
0
(
mod
2
)
if and only if
E
(
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
(
x
0
,
0
)
. Thus
t
2
≡
0
(
mod
2
)
if and only if the polynomial
x
3
+
A
x
+
B
has a root in
F
q
, if and only if
gcd
(
x
q
−
x
,
x
3
+
A
x
+
B
)
≠
1
.

Input:
1. An elliptic curve

E
=
y
2
−
x
3
−
A
x
−
B
.
2. An integer

q for a finite field

F
q
with

q
=
p
b
,
b
≥
1
.
Output:
The number of points of

E over

F
q
.
Choose a set of odd primes

S not containing

p such that
N
=
∏
l
∈
S
l
>
4
q
.
**Put**
t
2
=
0
**if**
gcd
(
x
q
−
x
,
x
3
+
A
x
+
B
)
≠
1
, **else**
t
2
=
1
.
Compute the division polynomial
ψ
l
.
All computations in the loop below are performed

in the ring
F
q
[
x
,
y
]
/
(
y
2
−
x
3
−
A
x
−
B
,
ψ
l
)
.
**For**
l
∈
S
**do**:
**Let**
q
¯
be the unique integer such that
q
≡
q
¯
(
mod
l
)
and
∣
q
¯
∣<
l
/
2
.
Compute
(
x
q
,
y
q
)
,
(
x
q
2
,
y
q
2
)
and
(
x
q
¯
,
y
q
¯
)
.
**if**
x
q
2
≠
x
q
¯
**then**
Compute
(
X
,
Y
)
.
**for**
1
≤
t
¯
≤
(
l
−
1
)
/
2
**do**:
**if**
X
=
x
t
¯
q
**then**
**if**
Y
=
y
t
¯
q
**then**
t
l
=
t
¯
;
**else**
t
l
=
−
t
¯
.
**else if** q is a square modulo

l **then**
compute w with
q
≡
w
2
(
mod
l
)
compute
w
(
x
q
,
y
q
)
**if**
w
(
x
q
,
y
q
)
=
(
x
q
2
,
y
q
2
)
**then**
t
l
=
2
w
**else if**
w
(
x
q
,
y
q
)
=
(
x
q
2
,
−
y
q
2
)
**then**
t
l
=
−
2
w
**else**
t
l
=
0
**else**
t
l
=
0
Use the Chinese Remainder Theorem to compute

t modulo

N
from the equations

x
≡
t
l
(
mod
l
)
, where

l
∈
S
.
Output

q
+
1
−
t
.

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

In the 1990s, Noam Elkies, followed by A. O. L. Atkin, devised improvements to Schoof's basic algorithm by restricting the set of primes
S
=
{
l
1
,
…
,
l
s
}
considered before to primes of a certain kind. These came to be called Elkies primes and Atkin primes respectively. A prime
l
is called an Elkies prime if the characteristic equation:
ϕ
2
−
t
ϕ
+
q
=
0
splits over
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:
O
(
l
)
rather than
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
O
(
log
q
)
bound are Elkies primes, this yields an algorithm that is more efficient than Schoof's, with an expected running time of
O
(
log
6
q
)
using naive arithmetic, and
O
~
(
log
4
q
)
using fast arithmetic. It should be noted that while this heuristic assumption is known to hold for most elliptic curves, it is not known to hold in every case, even under the GRH.

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
E
(
F
p
)
with prime
p
.
Schoof's algorithm implementation for
E
(
F
2
m
)
.