Elliptic curves and the ECM algorithm

Sebastiano Tronto

ALTEN Scientific Software Evening

Part I: Numbers

The integers

The number line

The integers modulo N

The number clock

The integers modulo N - Division

What about division?

Integers modulo N - Division

Integers modulo N - Division


def extended_gcd(a, b):
    if b == 0:
        return a, 1, 0
    g, x, y = extended_gcd(b, a % b)
    return g, y, x - y*(a // b)

Division always works if \(N\) is a prime number!

Modular arithmetic - recap

The number line

Part II: Elliptic Curves

Elliptic curves

An elliptic curve is a curve with equation \[ y^2 = x^3+Ax+B \] Where \(A\) and \(B\) are numbers with \[4A^3+27B^2\neq 0\]

\(y^2=x^3-x+1\)
\((A=-1, B=1\))
An elliptic curve

Elliptic curves

\(y^2=x^3+13x-34\)
\((A=13, B=-34\))
An elliptic curve
\(y^2=x^3-x\)
\((A=-1, B=0\))
An elliptic curve

Elliptic curves

Elliptic curve sum

Elliptic curves - sum operation - example 1

Elliptic curve sum

Elliptic curves - sum operation - example 1

Elliptic curve sum

Elliptic curves - sum operation - example 1

Elliptic curve sum

Elliptic curves - sum operation - example 2

Elliptic curve sum

Elliptic curves - sum operation - example 2

Elliptic curve sum

Elliptic curves - sum operation - example 2

Elliptic curve sum

Elliptic curves - sum operation - example 3

Elliptic curve sum

Elliptic curves - sum operation - example 3

Elliptic curve sum

Elliptic curves - sum operation - example 3

Elliptic curve sum

Elliptic curves - sum operation - code


# Computes p+q on the elliptic curve y^2 = x^3 + Ax + B
def ec_sum(p: Point, q: Point, A: double) -> Point:
    if p.is_zero:
        return q
    if q.is_zero:
        return p
    if p.x == q.x and p.y == -q.y:
        return Point(is_zero = True)

    if p.x != q.x:
        k = (p.y - q.y) / (p.x - q.x)
    else:
        k = (3 * p.x**2 + A) / (p.y + q.y)

    new_x = k**2 - p.x - q.x
    new_y = k * (p.x - new_x) - p.y
    return Point(x = new_x, y = new_y)

@dataclass
class Point:
    x: int = 0
    y: int = 0
    is_zero: bool = False

Elliptic curves - recap

The number line

Part III: The Elliptic Curve Factorization Method

Integer factorization

Every positive integer can be written as the product of prime numbers

Integer factorization - high-level procedure


# Returns the list of prime factors of n
def factorize(n: int) -> list:
    if n == 1:
        return []

    if is_prime(n):
        return [n]

    f = find_factor(n)

    return factorize(f) + factorize(n//f)

Find Factor - Elliptic Curve Method

To find a factor of \(n\):

  1. Take a random elliptic curve \(E\) and a random point \(P\) of \(E\)
  2. Take a suitable number \(m\)
  3. Try to compute \(m\cdot P = P+P+\cdots+P\quad\) (\(m\) times) with coordinates modulo \(n\)
  4. If you attempt an impossible division by some number \(d\), return \(\operatorname{GCD}(n,d)\)
  5. Go back to 1.

Find Factor - Elliptic Curve Method - Example

Demo time!

git.tronto.net/ecm

Elliptic Curve Method - Questions

Q: Aren't we just computing the \(\operatorname{GCD}\) with random numbers?

A: Yes, but elliptic curve operations produce "good candidates" for these random numbers.

Elliptic Curve Method - Questions

Q: Can we do the same without elliptic curves?

A: Yes, with Pollard's \(p-1\) Algorithm, but ECM is faster.

Elliptic Curve Method - Questions

Q: Are there objects that are more complicated than elliptic curves and can make the method even faster?

A: Yes, there are higher-dimensional Abelian Varieties and other Algebraic Groups, but they are much harder (if not impossible) to implement efficiently.

More questions?

Drinks!