## Modern Elliptic Curve Factorization, Part 1

### April 23, 2010

We discussed Hendrik Lenstra’s algorithm for factoring integers using elliptic curves in three previous exercises. After Lenstra published his algorithm in 1987, mathematicians studied the algorithm extensively and made many improvements. In this exercise, and the next, we will study a two-stage version of elliptic curve factorization that features improved elliptic arithmetic and is much faster than Lenstra’s original algorithm. Today’s exercise looks at the improved elliptic arithmetic; we will look at the two-stage algorithm in the next exercise.

If you look at Lenstra’s original algorithm, much of the time is spent calculating modular inverses. Peter Montgomery worked out a way to eliminate the modular inverses by changing the elliptic arithmetic; instead of using the curve *y*^{2} = *x*^{3} + *ax* + *b*, Montgomery uses the curve *y*^{2} = *x*^{3} + *ax*^{2} + *x*. Additionally, he does a co-ordinate transform to eliminate the *y* variable, so we don’t need to figure out which of the quadratic roots to follow. Finally, Montgomery stores the numerator and denominator of the *a* parameter separately, eliminating the modular inverse. We won’t give more of the math; for those who are interested, a good reference is *Prime Numbers: A Computational Perspective* by Richard Crandall and Carl Pomerance.

Here are the elliptic addition, doubling and multiplication rules for Montgomery’s elliptic curves:

A curve is given by the formula

y^{2}=x^{3}+ (A/_{n}A– 2)_{d}x^{2}+x(modn).A point is stored as a two-tuple containing its

xandzco-ordinates.To add two points

P_{1}(x_{1},z_{1}) andP_{2}(x_{2},z_{2}), given the pointP_{0}(x_{0},z_{}0) =P_{1}–P_{2}(notice that the curve is not used in the calculation):

x= ((x_{1}-z_{1}) × (x_{2}+z_{2}) + (x_{1}+z_{1}) × (x_{2}-z_{2}))^{2}×z_{0}modn

z= ((x_{1}-z_{1}) × (x_{2}+z_{2}) – (x_{1}+z_{1}) × (x_{2}-z_{2}))^{2}×x_{0}modnTo double the point

P:

x= (x+z)^{2}× (x-z)^{2}× 4 ×Admodn

z= (4 ×Ad× (x-z)^{2}+t×An) ×tmodnwheret= (x+z)^{2}– (x-z)^{2}Multiplication is done by an adding/doubling ladder, similar to the method used in the Lucas chain in the exercise on the Baillie-Wagstaff primality checker; the Lucas chain is needed so that we always have the point

P_{1}-P_{2}. For instance, the product 13Pis done by the following ladder:2

P= double(P)

3P= add(2P,P,P)

4P= double(2P)

6P= double(3P)

7P= add(4P, 3P,P)

13P= add(7P,6P,P)

Richard Brent gave a method to find a suitable elliptic curve and a point on the curve given an initial seed *s* on the half-open range [6, *n*), with all operations done modulo *n*:

u=s^{2}– 5

v= 4s

A= (_{n}v-u)^{3}(3u+v)

A= 4_{d}u^{3}v

P= (u^{3},v^{3})

Your task today is to write the three functions that add, double, and multiply points on an elliptic curve and the function that finds a curve and a point on the curve; the payoff will be in the next exercise that presents elliptic curve factorization. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

[…] today’s Programming Praxis exercise we have to implement an algorithm for curve factorization. The Scheme […]

My Haskell solution (see http://bonsaicode.wordpress.com/2010/04/23/programming-praxis-modern-elliptic-curve-factorization-part-1/ for a version with comments):

Python version.

Hi Programmingpraxis

Could you tell me if my implementation is correct or not specially for multiPoint function as i was trying to reduce one more call of mulitpOint function.

[…] previous example except using Montgomery curve rather than Lenstra curve. Programmingpraxis used Montgomery curve to find the prime factorisation. I personally feel that Lenstra algorithm worked fine when […]