FLINT3.7.0-dev
Algorithm

The elliptic curve method

Cost
Heuristically Lp[1/2,2]L_p[1/2, \sqrt 2] multiplications modulo NN to find a prime factor pp.

The elliptic curve method (ECM) of Lenstra [Len1987] finds a prime factor pp of NN in a time that depends mainly on the size of pp. It is the method of choice for factors of 20 to 40 digits in numbers too large for the quadratic sieve, and fmpz_factor runs it before the sieve to remove medium-sized factors. The implementation follows Montgomery [Mon1987] and Zimmermann and Dodson [ZD2006].

The idea#

Pollard's p−1p - 1 method computes aE mod Na^E \bmod N for a highly composite exponent EE, and finds pp if the order of aa modulo pp, a divisor of p−1p - 1, divides EE. It thus succeeds only if p−1p - 1 is smooth. ECM replaces the multiplicative group of Fp\mathbb F_p by the group of points of an elliptic curve over Fp\mathbb F_p. By Hasse's theorem [Sil2009, Theorem V.1.1] its order lies in [p+1−2p,p+1+2p][p + 1 - 2\sqrt p, p + 1 + 2\sqrt p], and as the curve varies the order is distributed over this interval roughly like a random integer of that size. Trying many curves gives many independent chances of a smooth group order.

One computes with a curve and a point PP defined modulo NN, as if Z/NZ\mathbb{Z}/N\mathbb{Z} were a field. In projective coordinates, a multiple kPkP is a point (X:Z)(X : Z); if the order of PP modulo pp divides kk, then kPkP is the point at infinity modulo pp, so pp divides ZZ and gcd⁡(Z,N)\gcd(Z, N) reveals pp, unless the same happens modulo all prime factors of NN at once, which is unlikely.

Montgomery curves#

FLINT uses curves in Montgomery form By2=x3+Ax2+xB y^2 = x^3 + A x^2 + x and represents a point by its xx-coordinate in projective form (X:Z)(X : Z), which identifies PP and −P-P but suffices for scalar multiplication. With a24=(A+2)/4a_{24} = (A + 2)/4, the doubling and the differential addition (which needs the difference of the two points) are

X2P=(X+Z)2(X−Z)2,Z2P=4XZ((X−Z)2+a24⋅4XZ),XP+Q=ZP−Q((XP−ZP)(XQ+ZQ)+(XP+ZP)(XQ−ZQ))2,ZP+Q=XP−Q((XP−ZP)(XQ+ZQ)−(XP+ZP)(XQ−ZQ))2,\begin{aligned} X_{2P} &= (X + Z)^2 (X - Z)^2, \\ Z_{2P} &= 4XZ \bigl((X - Z)^2 + a_{24} \cdot 4XZ\bigr), \\ X_{P+Q} &= Z_{P-Q} \bigl((X_P - Z_P)(X_Q + Z_Q) + (X_P + Z_P)(X_Q - Z_Q)\bigr)^2, \\ Z_{P+Q} &= X_{P-Q} \bigl((X_P - Z_P)(X_Q + Z_Q) - (X_P + Z_P)(X_Q - Z_Q)\bigr)^2, \end{aligned}

about ten multiplications modulo NN for a doubling and an addition together, and no inversion. The Montgomery ladder computes kPkP by keeping the pair (mP,(m+1)P)(mP, (m+1)P), whose difference is always PP, and replacing it by (2mP,(2m+1)P)(2mP, (2m+1)P) or ((2m+1)P,(2m+2)P)((2m+1)P, (2m+2)P) for each bit of kk.

Curves are chosen by Suyama's parametrisation [Suy1985; ZD2006]: for a random σ\sigma, put u=σ2−5u = \sigma^2 - 5, v=4σv = 4\sigma, the starting point x0=u3/v3x_0 = u^3/v^3 and a24=(v−u)3(3u+v)/(16u3v)a_{24} = (v - u)^3(3u + v)/(16 u^3 v). The group order of these curves is divisible by 12, which increases the probability that it is smooth. The inversion needed for a24a_{24} may itself reveal a factor of NN.

Stage 1#

Algorithm 1: ECM stage 1

Input: NN, a curve and a point PP modulo NN, a bound B1B_1.

Output: a factor of NN, or the point Q=kPQ = kP with k=∏p≤B1p⌊log⁡pB1⌋k = \prod_{p \le B_1} p^{\lfloor \log_p B_1 \rfloor}.

  1. For each prime p≤B1p \le B_1, replace PP by p⌊log⁡pB1⌋Pp^{\lfloor \log_p B_1 \rfloor} P with the Montgomery ladder, and if 1<gcd⁡(ZP,N)<N1 < \gcd(Z_P, N) < N, return the GCD.
  2. Return Q=PQ = P.

If the order of the starting point modulo pp is B1B_1-smooth (a product of prime powers at most B1B_1), it divides kk and stage 1 finds pp. The cost is about 1.44B11.44 B_1 ladder steps. FLINT takes the GCD after every prime, which costs little since B1B_1 is small in its applications.

Stage 2#

Often the order of PP is B1B_1-smooth except for one larger prime ℓ\ell with B1<ℓ≤B2B_1 < \ell \le B_2. Stage 2 tests all these primes at once with the standard continuation. Choose a primorial DD (the product of the first few primes) close to B2\sqrt{B_2}; every prime ℓ\ell in (B1,B2](B_1, B_2] can be written ℓ=mD±j\ell = mD \pm j with 1≤j<D/21 \le j < D/2 and gcd⁡(j,D)=1\gcd(j, D) = 1.

Lemma 1. Let QQ be a point modulo a prime pp and ℓ=mD±j\ell = mD \pm j. If ℓQ=O\ell Q = O, then x(mDQ)=x(jQ)x(mDQ) = x(jQ), that is, XmDQZjQ−XjQZmDQ≡0(modp)X_{mDQ} Z_{jQ} - X_{jQ} Z_{mDQ} \equiv 0 \pmod p.

Proof. ℓQ=O\ell Q = O means mDQ=∓jQmDQ = \mp jQ, and x(−R)=x(R)x(-R) = x(R) for every point RR, since the xx-coordinate does not distinguish a point from its negative.

Algorithm 2: ECM stage 2 (standard continuation)

Input: NN, the point QQ from stage 1, bounds B1<B2B_1 < B_2, the primorial DD.

Output: a factor of NN or failure.

  1. Compute jQjQ for all odd j<D/2j < D/2 (by differential additions of 2Q2Q), and DQDQ.
  2. g←1g \gets 1. For mm from about B1/DB_1/D to about B2/DB_2/D (computing mDQmDQ by differential additions of DQDQ): for each jj with gcd⁡(j,D)=1\gcd(j, D) = 1 such that mD+jmD + j or mD−jmD - j is prime, set g←g⋅(XmDQZjQ−XjQZmDQ) mod Ng \gets g \cdot (X_{mDQ} Z_{jQ} - X_{jQ} Z_{mDQ}) \bmod N.
  3. Return gcd⁡(g,N)\gcd(g, N) if it is a nontrivial factor.

By Lemma 1, if the order of QQ modulo pp is a prime in (B1,B2](B_1, B_2], then p∣gp \mid g. The cost is about D/4+B2/DD/4 + B_2/D point operations and three multiplications per prime ℓ\ell, and a single GCD. Asymptotically faster versions of stage 2, using fast polynomial arithmetic [ZD2006], are not implemented.

Parameters and complexity#

The probability that a random integer near pp is Lp[1/2,α]L_p[1/2, \alpha]-smooth is heuristically Lp[1/2,−1/(2α)]L_p[1/2, -1/(2\alpha)]. Taking B1=Lp[1/2,1/2]B_1 = L_p[1/2, 1/\sqrt 2] balances the cost of a curve against the number of curves needed, for a total of Lp[1/2,2]L_p[1/2, \sqrt 2] operations modulo NN [Len1987]. In practice the parameters are tuned experimentally: fmpz_factor_smooth uses B2=100B1B_2 = 100 B_1 and the values of B1B_1 and of the number of curves shown on Factoring integers, which find a factor of the given size with probability about 1/31/3 per size class. For example, to find a factor of 40 bits it runs 18 curves with B1=610B_1 = 610, and for 60 bits 42 curves with B1=14000B_1 = 14000.

Use in FLINT#

The stages are exposed as fmpz_factor_ecm_select_curve, fmpz_factor_ecm_stage_I and fmpz_factor_ecm_stage_II.

int fmpz_factor_ecm(fmpz_t f, ulong curves, ulong B1, ulong B2, flint_rand_t state, const fmpz_t n_in)
int n_factor_ecm(ulong * f, ulong curves, ulong B1, ulong B2, flint_rand_t state, ulong n)
int n_ll_factor_ecm(nn_ptr factor, ulong nhi, ulong nlo, ulong curves, ulong B1, ulong B2, flint_rand_t state)
int fmpz_factor_smooth(fmpz_factor_t factor, const fmpz_t n, slong bits, int proved)

Referenced from#

References#

  • [Len1987] H. W. Lenstra, Jr., "Factoring integers with elliptic curves", Annals of Mathematics 126 (1987), 649–673
  • [Mon1987] P. L. Montgomery, "Speeding the Pollard and elliptic curve methods of factorization", Mathematics of Computation 48 (1987), 243-264, https://doi.org/10.1090/S0025-5718-1987-0866113-7
  • [ZD2006] P. Zimmermann and B. Dodson, "20 years of ECM", Algorithmic Number Theory (ANTS VII), LNCS 4076 (2006), 525–542
  • [Sil2009] J. H. Silverman, The Arithmetic of Elliptic Curves, 2nd edition, Graduate Texts in Mathematics 106, Springer (2009)
  • [Suy1985] H. Suyama. Informal preliminary report (8). Letter to R. P. Brent, 1985.
Cite this page

The FLINT team, “The elliptic curve method,” FLINT: Fast Library for Number Theory, documentation, version 3.7.0-dev, 2026. https://flintlib.org/doc/algorithms/number-theory/ecm.html (generated 2026-11-02).