SageMath library for constructing elliptic curves
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

ecfactory: A SageMath Library for Constructing Elliptic Curves


The ecfactory library is developed by the SCIPR Lab project and contributors (see AUTHORS file) and is released under the MIT License (see LICENSE file). The library implements algorithms to construct elliptic curves with certain desired properties; specifically, it provides the following functionality.

  1. Complex Multiplication method
  2. Cocks-Pinch method
  3. Dupont-Enge-Morain method
  4. Solver for Pell equations
  5. Miyaji-Nakabayashi-Takano curves
  6. Barreto-Naehrig curves
  7. Elliptic-curve chains (via the Cocks-Pinch method)
  8. Elliptic-curve cycles (via MNT curves)

Each of the above is packaged as a Python module in a corresponding subfolder under the ecfactory folder.

Throughout, a curve E is specified as a tuple (q,t,r,k,D) where: q is the prime size of the base field; t is the trace of Frobenius; r is the prime size of the subgroup (which can be the size of the entire group); k is the embedding degree; and D is the (negative) fundamental discriminant. From the tuple (q,t,r,k,D), the curve equation can be found using the Complex Multiplication method.


The library requires a working SageMath installation, and has been tested on SageMath version 6.8 and 7.2.


To install, add the library to the SAGE_PATH environment variable:

$ export SAGE_PATH="path/to/library/:$SAGE_PATH"

To import and use the library, write

import ecfactory

Methods can now be invoked as


For example,,5)

To import only one module, write

import ecfactory.module_name as other_name

Methods can now be invoked more concisely as


For example,

import ecfactory.dupont_enge_morain as dem,5)


Each subfolder contains a readme, code examples, and unit tests. The methods are described in the readme, and the code examples show how to run the relevant methods. Many of the algorithms and tests are probabilistic, and the random seed can be set using set_random_seed(s).

Additionally, the utils module contains global functions that filter the curves found by all algorithms. See the utils folder for more details.