Docsity

The Quadratic Sieve Algorithm for Factoring Composite Numbers, Study notes of Computer science

Partial preview of the text

Download The Quadratic Sieve Algorithm for Factoring Composite Numbers and more Study notes Computer science in PDF only on Docsity!

The Quadratic Sieve Factoring Algorithm

Eric Landquist

MATH 488: Cryptographic Algorithms

December 14, 2001

1 Introduction

Mathematicians have been attempting to find better and faster ways to fac- tor composite numbers since the beginning of time. Initially this involved dividing a number by larger and larger primes until you had the factoriza- tion. This trial division was not improved upon until Fermat applied the factorization of the difference of two squares: a^2 − b^2 = (a − b)(a + b). In his method, we begin with the number to be factored: n. We find the smallest square larger than n, and test to see if the difference is square. If so, then we can apply the trick of factoring the difference of two squares to find the factors of n. If the difference is not a perfect square, then we find the next largest square, and repeat the process.

While Fermat’s method is much faster than trial division, when it comes to the real world of factoring, for example factoring an RSA modulus several hundred digits long, the purely iterative method of Fermat is too slow. Sev- eral other methods have been presented, such as the Elliptic Curve Method discovered by H. Lenstra in 1987 and a pair of probabilistic methods by Pollard in the mid 70’s, the p − 1 method and the ρ method. The fastest algorithms, however, utilize the same trick as Fermat, examples of which are the Continued Fraction Method, the Quadratic Sieve (and it variants), and the Number Field Sieve (and its variants). The exception to this is the El- liptic Curve Method, which runs almost as fast as the Quadratic Sieve. The remainder of this paper focuses on the Quadratic Sieve Method.

2 The Quadratic Sieve

The Quadratic Sieve, hereafter simply called the QS, was invented by Carl Pomerance in 1981, extending earlier ideas of Kraitchik and Dixon. The QS was the fastest known factoring algorithm until the Number Field Sieve was discovered in 1993. Still the QS is faster than the Number Field Sieve for numbers up to 110 digits long.

A second criterion for these primes is that they should be less than some bound B, which depends on the size of n. We will discuss this when we analyze the running time. We also say that this factor base is smooth: that every prime in the set is relatively small.

3.2 Sieving

Once we have a set of primes for our factor base, we begin to take numbers x from our sieving interval and calculate Q(x), and check to see if it factors completely over our factor base. If it factors, it is said to have smoothness. If it does not, we throw it out, and we go on to the next element of our sieving interval. If we are dealing with a large factor base, though, it is incredibly inefficient to consider numbers one at a time and check all the primes in the factor base for divisibility. Instead, we will work with the entire sieving interval at once. If we are working in parallel, each processor would work over a different subinterval. Here is how it works. If p is a prime factor of Q(x), then p|Q(x + p). Conversely, if x ≡ y (mod p), then Q(x) ≡ Q(y) (mod p). So for each prime p in our factor base, we solve

Q(x) = s^2 ≡ 0 (mod p), x ∈ Zp.

This can be solved using the Shanks-Tonelli Algorithm. We will obtain two solutions, which we call s 1 p and s 2 p = p − s 1 p. Then those Q(xi) with the xi in our sieving interval are divisible by p when xi = s 1 p, s 2 p + pk for some integer k.

There are a couple ways to do the sieving from here. One way is to take a subinterval (depending on the size of your memory), and put Q(xi) in an array for each xi in the subinterval. For each p, start at s 1 p and s 2 p and divide out the highest power of p possible for each array element in arith- metic progression, recording the appropriate powers (mod 2) of p in a vector. You will have one vector for each of the factorable Q(xi) and each entry corresponds to a unique prime in the factor base. Once all the primes have had their turn sieving the interval, those array elements which are now 1 are those that factor completely over the factor base. The vector of powers of the primes can then be put into a matrix A. We repeat this process until we have enough entires in A to continue. This is explained below.

A second way is less exact, but is much quicker. Instead of working with the values of Q(x) over some subinterval, record the number of bits of the Q(xi) in an array. For every element in the particular arithmetic progessions for p, subtract the number of bits of p. After every prime in the factor base has had their turn, those elements with remaining “bits” close to 0 are likely to be completely factorable over those primes. We need to take into account round-off error and the fact that many numbers are not square-free. For numbers that are not squre-free, we can sieve over the subinterval a second time picking out solutions to Q(x) ≡ 0 (mod p^2 ) and so on. When all that is done, we set an upper bound on the number of bits we will consider. There will likely be fully factorable numbers that slip through at this point, but the time saved will more than make up for it. The numbers that meet this threshold condition will then be factored, by looking at the arithmetic progressions again so we can quickly nail down which primes divide which of the Q(xi).

Most implementations of the QS do not resieve the interval looking for powers of primes, so we will look at the sieving at a slightly deeper level. If we don’t resieve with powers of primes, the threshold value becomes very important and powers of 2 becomes more significant. Fortunately we have a trick to deal with 2 to some extent. If Q(x) = r^2 − n, and we assume that r is odd, then 2|Q(x). We can work with n slightly so that a higher power of 2 always divides Q(x). If we want 8 to always divide Q(x) when it is even, we consider n (mod 8). If n ≡ 3 , 7 (mod 8), then 2‖Q(x). If n ≡ 5 (mod 8), then 4‖Q(x). Finally, if n ≡ 1 (mod 8), then 8|Q(x). So to make 8 divide Q(x) every time it is even, set n := 5n if n ≡ 3 (mod 8), set n := 3n if n ≡ 5 (mod 8), and n := 7n if n ≡ 7 (mod 8). Once the prime p = 2 is taken care of, sieve for the rest of the primes, subtracting the logarithms as above. Our threshold will then be

1 2

ln(n) + ln(M ) − T ln(pmax)

where T is some value around 2 and pmax is the largest prime in the factor base. Silverman [8] suggested that T = 1.5 for factoring 30-digit numbers, T = 2 for 45-digit numbers, and T = 2.6 for 66-digit numbers, for example.

If you are factoring an RSA modulus, then you know the factors are prime, so you are done.

4 Variant: The Multiple Polynomial Quadratic

Sieve (MPQS)

As the name suggests, the MPQS uses several polynomials instead of Q(x) in the algorithm, and was first suggested by Peter Montgomery. These poly- nomials are all of the form

Q(x) = ax^2 + 2bx + c,

where a, b, and c are chosen according to certain guidelines below. The mo- tivation for this approach is that by using several polynomials, we can make the sieving interval much smaller, which makes Q(x) smaller, which in turn will mean that a greater proportion of values of Q(x) completely factor over the factor base.

In choosing our coefficients, let a be a square. Then choose 0 ≤ b < a so that b^2 ≡ n (mod a). This can only be true if n is a square mod q for every prime q|a. So we wish to choose a with a known factorization such

that

( n q

) = 1 for every q|a. Lastly, we choose c so that b^2 − 4 ac = n. When

we find an Q(x) that factors well, notice that

aQ(x) = (ax)^2 + abx + ac = (ax + b)^2 − n.

So (ax + b)^2 ≡ aQ(x) (mod n).

Recall that a is square, so that Q(x) must be.

Suppose that our sieving interval is [−M, M ]. We wish to optimize M and the value of Q(x) over this interval. One way to do this is to determine our coefficients so that the minimum and maximum values of Q(x) on [−M, M ] have roughly the same magnitude, but be opposite in sign. Our minimum is at x = −b/a. Since we chose 0 ≤ b < a, − 1 < −b/a ≤ 0, and Q(−b/a) =

−n/a. So obviously our maximum is at −M or M , and is roughly a

(^2) M 2 −n a. We want this to be about n/a, so we choose

a ≈

2 n M

One cause for concern with this method is the cost of switching poly- nomials. Pomerance [6] says that if the cost of switching polynomials is about 25-30% of the total cost, then it would be disadvantageous to use this method. When changing a polynomial, we obviously need new coefficients, but for each new polynomial we also need to solve Q(x) ≈ 0 (mod p) for each prime p in our factor base, which is the heaviest load in switching poly- nomials. A scheme that Pomerance calls “self-initialization” can help to signif- icantly reduce the cost of switching polynomials. The trick is to fix the constant a in several of the polynomials. We still want a ≈

√ 2 n M , so let^ a^ be the product of k primes, p, which have a magnitude of about

( √ 2 n M

) 1 /k each,

each of which satisfy

( n p

)

. We still need to find b such that b^2 ≡ n (mod a).

In fact since there are k prime factors of a, there are 2k−^1 values for b. Then the initialization problem for the polynomials: finding solutions to Q(x) ≡ 0 (mod p) for each polynomial and for each prime p in the factor base can be done all at once. The main advantage to this variation is of course reducing the size of the factor base and sieving interval. Silverman [8] gives some suggestions for n up to 66 digits. The optimal size of the factor base varies with the machine being used, though a good estimate for the number of primes is about a tenth as many as the number of primes needed for the original QS. This also means that the sieving interval would be about a thousandth the size. Another advantage to this system is that it aids in parallel processing, with each processor working with a different polynomial. If each processor generates its own polynomial(s), then it can work fairly independently, only communicating with the central server when it has sieved the whole interval.

5 Variant: The Double Large Prime MPQS

This version of the QS was employed by Lenstra, Manasse, and several others in 1993 and 1994 to factor RSA-129 and reveal the message “The magic words

7 Running Time

If the number of primes in our factor base was very small, we would not need very many factorizations of Q(x) in order to obtain a possible factor of n. The problem with that though is finding every a few full factorizations would take a very long time, since a very small proportion of numbers factor over a small set of primes. If we were to create an enormous list of primes so that just about everything would factor of that factor base, then our problem would be getting all those numbers to create a large enough matrix to reduce. So the number of primes must be set to optimize performance. It turns out that this optimum value for the size of the factor base is roughly

B =

( e

ln(n)ln(ln(n))

)√ 2 / 4 .

The sieving interval then turns out to be about the cube of this:

M =

( e

ln(n)ln(ln(n))

) 3 √ 2 / 4 .

For example, when RSA-129 was factored in 1994, a factor base of 524, primes was used.

Some notes about components of the running time first. The optimum size of the factor base has been given, and further analysis tells us that the sieving time should be roughly three times the matrix reduction time. With B primes in the factor base, this step runs in less than O(B^3 ) time, which gives us the size of the sieving interval. The heuristics estimate given previously says that the optimal umber of primes is ( e

ln(n)ln(ln(n))

)√ 2 / 4 ,

which determines the size of our sieving interval and so on. Put this all together and we have an asymptotic running time for the QS of

O

( e

  1. 125 ln(n)ln(ln(n))

) .

With the improvements by Wiedemann in the Gaussian elimination, though, the running time comes down to being asymptotic to

O

( e

ln(n)ln(ln(n))

) .

The Number Field Sieve, by comparision, which is the fastest publicly known factoring algorithm has running time

O

( e^1 .9223((ln(n)) 1 / (^3) (ln(ln(n))) 2 / (^3) )) .

The Number Field Sieve is the same as the QS from the sieving step on. It has a larger matrix to do the elimination step on, but the initial steps are much more efficient than the QS.

8 RSA

The security of the RSA cryptosystem relies on the difficulty of factoring inte- gers. We have mentioned the successful factoring of a 129 digit RSA modulus. Currently RSA moduli of 512 bits, or about 155 digits would be feasible to factor, and in fact have been factored. In August, 1999, a team including Arjen Lenstra and Peter Montgomery factored a 512 bit RSA modulus us- ing the Number Field Sieve in 8400 mips years (8400 million instructions per second-years) [2]. Current estimates say that a 768 bit modulus will be good until 2004, so for short term or personal use, such a key size is ade- quate. For corporate use, a 1024 bit modulua is suggested, and a 2048 bit modulus is suggested for much more permanent usage. These suggestions take into account possible advances in factoring techniques and for processor speed increases. Riesel [7] shows that it is possible to create an algorithm to factor integers in nearly polynomial time, so there is certainly room for improvements. However, if a quantum computer is ever built with a sufficient number of qubits, Peter Shor has discovered an algorithm to factor integers in polynomial time on it. Then RSA would have to be retired in favor of other encryption schemes as the moduli required to be secure would be much larger than what would be convenient.

References

[1] Bressoud, David. Factorization and Primality Testing. Springer-Verlag, New York, 1989.

[2] Cavallar, S., Lioen, W., te Riele, H., Dodson, B., Lenstra, A., Mont- gomery, P., Murphy, B., et al. “Factorization of a 512-bit RSA modulus, Eurocrypt (2000) (submitted).