Modern Elliptic Curve Factorization, Part 2
April 27, 2010
The elliptic curve factorization algorithm is remarkably similar to Pollard’s p-1 algorithm:
define p-1 (n, B1, B2)
|
1 |
define ecf (n, B1, B2, C)
|
q = 2 | 2 | Qx,z ∈ C // random point |
for p ∈ π(2 … B1) | 3 | for p ∈ π(2 … B1) |
a = ⌊log p B1⌋
|
4 |
a = ⌊log p B1⌋
|
q = qpa (mod n)
|
5 | Q = pa ⊗C Q |
g = gcd (q, n)
|
6 |
g = gcd (Qz, n)
|
if (1 < g < n) return g | 7 | if (1 < g < n) return g |
for p ∈ π(B1 … B2) | 8 | for p ∈ π(B1 … B2) |
q = qp (mod n)
|
9 | Q = p ⊗C Q |
10 |
g = g × Qz (mod n)
|
|
g = gcd (q, n)
|
11 |
g = gcd (g, n)
|
if (1 < g < n) return g | 12 | if (1 < g < n) return g |
return failure | 13 | return failure |
Lines 3 and 8 loop over the same lists of primes. Line 4 computes the same maximum exponent. Lines 6 and 7, and lines 11 and 12, compute the same greatest common divisor. And line 13 returns the same failure. The structures of the two algorithms are identical. Also, note that both algorithms use variables that retain their meaning from the first stage (lines 2 to 7) to the second stage (lines 8 to 12).
Lines 2, 5, 9 and 10 differ because p-1 is based on modular arithmetic and ecf
is based on elliptic arithmetic (note that the ⊗C operator, otimes-sub-C, indicates elliptic multiplication on curve C). The most important difference is on the first line, where ecf
has an extra argument C indicating the choice of elliptic curve. If the p-1 method fails, there is nothing to do, but if the ecf
method fails, you can try again with a different curve.
Use of Montgomery’s elliptic curve parameterization from the previous exercise is a huge benefit. Lenstra’s original algorithm, which is the first stage of the modern algorithm, required that we check the greatest common divisor at each step, looking for a failure of the elliptic arithmetic. With the modern algorithm, we compute the greatest common divisor only once, at the end, because Montgomery’s parameterization has the property that a failure of the elliptic arithmetic propagates through the calculation. And without inversions, Montgomery’s parameterization is also much faster to calculate. Brent’s parameterization of the randomly-selected curve is also important, as it guarantees that the order of the curve (the number of points) will be a multiple of 12, which has various good mathematical properties that we won’t enumerate here.
There is a simple coding trick that can speed up the second stage. Instead of multiplying each prime times Q, we iterate over i from B1 + 1 to B2, adding 2Q at each step; when i is prime, the current Q can be accumulated into the running solution. Again, we defer the calculation of the greatest common divisor until the end of the iteration.
Your task is to write a function that performs 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.