JStearn Dissertation
JStearn Dissertation
By
James Stearn
Supervisor: Dr. Maura Paterson
Department of Economics, Mathematics and Statistics
31st August 2021
Contents
Abstract 5
Declaration 6
1 Public-key cryptography 7
1.1 Fundamentals of public-key cryptography . . . . . . . . . . . . . . . . . . . . 7
1.2 RSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.1 The RSA Cryptosystem . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2.2 The RSA Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.2.3 Attacks on RSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.2.4 Security of RSA & parameter choices . . . . . . . . . . . . . . . . . . 10
2
Contents 3
4 Time complexity 44
4.1 Big O notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.2 Exponential time algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.2.1 Trial division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.2.2 Fermat’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.2.3 Euler’s method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.2.4 Pollard’s rho algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.3 Subexponential time algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.3.1 Dixon’s algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.3.2 Continued Fraction method . . . . . . . . . . . . . . . . . . . . . . . . 48
4.3.3 The Quadratic Sieve . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.3.4 The General Number Field Sieve . . . . . . . . . . . . . . . . . . . . . 48
5 Summary 49
Contents
List of Tables
4
Abstract
In §1, we introduce the number theoretic foundations of the RSA cryptosystem and dis-
cuss the RSA problem. We show that factorising represents the best general method for
attempting to break the RSA cryptosystem.
§4 outlines the time complexities of each algorithm, introducing notation used in the analysis
of algorithms. This chapter gives a quantifiable comparison of the theoretical running times
of the algorithms introduced in §2 & §3. We conclude with some consideration of future
prospects for factorising in §5, given possible theoretical and technological developments.
5
Declaration
6
Chapter 1
Public-key cryptography
To send a message securely in a classical (symmetric) cryptosystem, two parties must first
exchange some shared secret (the key) to enable encryption and decryption of the message.
Key exchange represents a critical vulnerability of the classical cryptosystem: an adversary
may intercept the exchange or retrieve the key post facto, thereby rendering the system
insecure. Continually changing keys presents further practical issues of secure distribution
and storage.
Public-key (asymmetric) cryptography resolves these issues by obviating the need to dis-
tribute a shared secret amongst the cryptosystem’s users. In a symmetric cryptosystem, the
decryption rule dk is identical to (or easily derived from) the encryption rule ek . [41] In a
public-key cryptosystem, each user has both a public key ek , used for encryption and pub-
lished publicly, and a distinct private key dk , used for decryption and kept secret. This allows
a user of the cryptosystem to send and receive messages securely without the vulnerability
inherent in an initial key exchange.
In 1976, Diffie and Hellman [14] published a viable method of public key exchange that
allowed two users to generate a shared secret securely over a public channel. In contrast
to the wartime cryptographers, who utilised mechanical methods to increase the complexity
of their ciphers, Diffie-Hellman key exchange exploits mathematical structures, namely the
multiplicative group of integers modulo a prime. In 1977, Rivest, Shamir, and Adleman
published the RSA cryptosystem, [37] building on ideas in Diffie and Hellman’s work.
7
Chapter 1. Public-key cryptography 8
1.2 RSA
In this section, we outline the mechanics of the RSA cryptosystem. We discuss its security
and the tractability of attacking the cryptosystem via number theoretic and computational
approaches.
Suppose Alice wishes to send a secure message to Bob. Bob first generates two large primes
p and q using one of a number of primality testing algorithms.
Definition 1.1. A semiprime n ∈ N is the product of exactly two (not necessarily unique)
primes.
Definition 1.2. ϕ(n) is Euler’s totient function: the number of positive integers up to
n coprime to n.
Definition 1.4. An arithmetic function f (n) is multiplicative if f (ab) = f (a)f (b) for all
a, b with (a, b) = 1.
Bob then chooses an e ∈ N such that (e,ϕ(n)) = 1 and calculates its inverse d modulo ϕ(n)
using the Extended Euclidean algorithm.
Definition 1.5. The pair (n, e) is an RSA public key. The integer n is an RSA modulus.
Definition 1.6. A corresponding RSA private key d is calculated d ≡ e−1 (mod ϕ(n))
To encrypt a message, Alice looks up Bob’s public key pair and encrypts the plaintext using
a one-way trapdoor function: a function that is easy to compute in one direction but difficult
to invert without some additional information (the private key). [16]
1.2. RSA
Chapter 1. Public-key cryptography 9
C = M e (mod n)
Bob may now decrypt C using his knowledge of the private key d :
M = C d (mod n).
Given a ciphertext, we require that the function is indeed invertible given knowledge of the
private key d, and hence that the plaintext may be retrieved by the recipient.
Proposition 1.9. RSA decryption of C using private key d returns the original plaintext M.
Proof.
C d (mod n) ≡ (M e )d (mod n)
≡ M ed (mod n)
≡ M kϕ(n)+1 (mod n) [as ed ≡ 1 (mod ϕ(n)]
≡ (M ϕ(n) )k × M (mod n)
≡ (1)k × M (mod n) [By Euler’s Theorem] [20]
≡ M (mod n)
Having demonstrated the correctness of the RSA algorithm, we now consider its security.
The difficulty of inverting the encryption function, i.e. the difficulty of finding eth roots
modulo n underlies the security of the cryptosystem.
1.2. RSA
Chapter 1. Public-key cryptography 10
Although there is no publicly known general attack on RSA, da Costa Boucinha describes
a number of specific attacks requiring implementation errors during the encryption process.
[11] These include repeated usage of the same modulus n and various known plaintext attacks
which require some partial knowledge of the plaintext. Careful selection of primes when
generating the modulus n and the use of random padding schemes defend against these
types of attack. Thus, as [11] makes clear, the most promising general attack is to attempt
to factorise the modulus n. Throughout this paper, we use n to represent an RSA modulus
to be factored.
A successful factorisation of n allows an attacker to calculate ϕ(n) and thereby decrypt all
messages encrypted using the corresponding public key. As the original RSA paper outlines,
‘the security of the [RSA] system rests in part on the difficulty of factoring the published
divisor, n.’ [37] As the difficulty of factorising generally increases with the size of the input,
by choosing larger primes to generate n, the security of the system may be (indefinitely)
increased.
In 1977, Rivest was quoted in Martin Gardner’s column Mathematical Games as estimating
that a 126-digit semiprime would take around ‘... 40 quadrillion years’ to factorise with the
technology and algorithms of the day. [17] Subsequent increases in computing power and
theoretical development of faster algorithms have increased the size of numbers that may be
factorised.
In 1991, RSA Laboratories issued the RSA Factoring Challenge - a list of large semiprimes
intended to stimulate research into the factorisation problem. These days, factorisation of
large numbers is distributed across a network with many researchers contributing optimisa-
tions and processing power to large-scale factorisation projects. Optimisation of algorithm
implementations is at the forefront of modern factorisation research. The problem of fac-
1.2. RSA
Chapter 1. Public-key cryptography 11
torising thus lies at the cutting-edge intersection of number theory and computer science.
Table 1.1 [36] shows some record factorisations to outline advances made in the field. Esti-
mates for the capabilities of factorising algorithms between 1970-90 are based on [35]. These
records are for general numbers; larger numbers with particular special forms have been
factorised but are not presented here.1
RSA-250 is a semiprime with 250 decimal digits (or 829 bits). In the original RSA paper,
the authors recommended ‘...using 100-digit prime numbers p and q, so that n has 200
[decimal] digits’ (∼512 bits). [37] The National Institute of Standards and Technology
(NIST) currently recommends the use of at least 2048-bit keys to ensure security for personal
use. [2] Developments in factorising technology have been fairly consistent since the early
nineties, enabling institutions to accurately assess when security standards require updating.
To summarise, provided that our chosen generating primes satisfy particular conditions (to
be detailed in later chapters), the size of the modulus n is the primary determinant of
the security of an RSA encryption. We now detail the development of a range of integer
factorisation algorithms, highlighting the improvements and optimisations of later algorithms
on earlier work.
1
RSA-576 & RSA-768 are labelled according to their number of binary, not decimal, digits
1.2. RSA
Chapter 2
2.1 Introduction
Note that a need not be prime, in which case there are a number of primality testing
algorithms that may be used in combination with a factorisation algorithm to determine the
unique prime factorisation of n. There are two main classes of factorisation algorithm:
Although general-purpose algorithms may appear more powerful, as we can input any number
and reasonably estimate the runtime based on its size, the special-purpose algorithms remain
useful. For example, a large number with a small prime factor may be factorised quickly
and efficiently by simply attempting division by small values for a. On the other hand, a
general-purpose algorithm will take as long to factor a 100-digit number with 1-digit and
99-digit prime factors as it would to factor one with two 50-digit factors. [45] It is therefore
instructive to review a range of approaches to factorising and utilise methods suitable for
the given situation.
12
Chapter 2. Integer factorisation algorithms 13
Fermat introduced a method of factorisation that has directly influenced the development of
modern methods. We thus review it here for historical context.
Henceforth, we may assume the integer to be factored is odd, as even integers have an obvious
prime factor. We begin with a theorem of elementary number theory.
Theorem 2.4. Every odd integer may be written as the difference of two squares.
Fermat’s method entails searching for x, y ∈ Z such that n = x2 − y 2 . Once such x & y are
found, we may write n = (x + y)(x − y) and a factorisation has been found. It is possible
that this gives a trivial factorisation, in which case a new x, y pair must be found.
xi yi2 = x2i − n yi
41 48 6.928...
42 131 11.446...
43 216 14.697...
44 303 17.407...
45 392 19.799...
46 483 21.977...
47 576 24
Having found a square, we may write n = 472 − 242 , then n = (47 + 24)(47 − 24).
Thus, 1633 = 71 × 23.
Note that if the two factors are ‘close’ together, Fermat’s method will find them quickly.
This needs to be taken into account when generating an RSA modulus. In the worst case
however, Fermat’s method is slower than trial division.
Euler employed a similar method to Fermat to factor larger numbers. As the proof of
the method outlines the derivation of values used in a factorisation, we show it here for
completeness. [9]
Proposition 2.6. Let n be an odd integer, expressible as the sum of two squares in two
distinct ways: n = a2 + b2 = c2 + d2 for some a, b, c, d ∈ Z with b < d; a, c odd, and b, d even.
Proof. Suppose n is expressible as the sum of two squares in two distinct ways.
Factorising gives: (a − c)(a + c) = (d − b)(d + b)
As r = (a − c, d − b), then: a − c = rs and d − b = rt for some s, t ∈ Z with (s, t) = 1.
By a similar process to Fermat’s method, we have found that we may write 4453 as
4453 = 632 +222 and 4453 = 332 +582 . We can calculate greatest common divisors efficiently
using the Extended Euclidean algorithm.
a = 63 a − c = 30 r = (30, 36) = 6
b = 22 a + c = 96 u = (96, 80) = 16
c = 33 d − b = 36 s = a − c/r = 5
d = 58 d + b = 80 t = d − b/r = 6
Taking the values from the last column and substituting into (2.2), gives:
n = ( 26 )2 + ( 16 2
2 2
2 ) (5 + 6 )
Euler’s method relies on being able to express n as the sum of two squares in more than one
way. Moreover, to be of any use, we must be able to find these sums in an efficient manner.
Unfortunately, its utility is severely limited by the following theorem:
Theorem 2.8. Sum of two squares theorem: For n ∈ Z, n is the sum of two squares if
and only if all primes p of the form p ≡ 3(mod 4) in the prime factorisation of n have even
powers .
In 1975, John Pollard introduced a novel factorisation method in his paper ‘A Monte Carlo
Method for Factorization’. Pollard’s method utilises a pseudo-randomly generated sequence,
hence the paper’s title.
To factorise n, the method proceeds by generating a sequence with some polynomial f ∈ Z[x].
[33] Pollard originally used f (x) = x2 − 1.1 An initial value x0 ∈ N is chosen randomly such
that x < n. The sequence is now generated recursively: [45]
xi ≡ f (xi−1 ) (mod n)
As n is finite, there are a finite number of congruence classes modulo n, so the sequence
must eventually repeat and cycle.
Now consider some non-trivial factor d of n. Both the sequences xi (mod d) and xi (mod n)
must eventually cycle, but it is likely that xi (mod d) will cycle sooner, as d < n, so there are
fewer congruence classes modulo d. It is therefore likely there exists some pair xi , xj such
that:
xi ≡ xj (mod d)
(2.3)
xi 6≡ xj (mod n)
Of course, we don’t know d in advance, so to find it, we could check the gcd of each xi with
all previous xj values until a non-trivial factor is found (if (2.3) does not hold, (xi − xj , n)
will be a trivial factor). This becomes quite inefficient as the number of xi s grows, so Pollard
used Floyd’s cycle-finding algorithm to detect a cycle. This algorithm works by incrementally
checking xi and x2i for a repeated value in order to identify a cycle. [45]
Floyd’s cycle-finding algorithm greatly increases efficiency as it requires only that we check
(x2i − xi , n) for each i, until a non-trivial factor is found. When plotted as a graph, the even-
tual cycling of the xi (mod d) sequence resembles the Greek letter ρ, hence the algorithm’s
name.
1
[33] conjectures that all polynomials x2 ±a with a 6= 0, 2 work equally well.
factor is found. Intermediate calculations of the algorithm are shown in the table on the
next page.
One particular advantage of Pollard’s rho algorithm is that it does not require much storage,
as only a few xi values need to be stored at any one time.
So (x8 − x4 , 6497) = 73 and the algorithm has found a non-trivial factor of 6497 (we could
have stopped the calculations in the final column here).
We therefore find the factorisation 6497 = 73 × 89.
It is possible that the sequence modulo d and modulo n will repeat at the same xi value, in
which case the gcd will be n and the algorithm will fail to find a non-trivial factor. [45] In
this case, we initialise with a different x0 value or change our polynomial f (x).
The greatest success of Pollard’s rho algorithm was its use (in a slightly adapted form) in the
8
factorisation of the 8th Fermat number F8 = 22 + 1. [4] F8 has 78 decimal digits and was
factored in 1980 by Pollard and Brent, who would go on to factor larger Fermat numbers
such as F10 . [6] Brent’s optimisation consists of a cycle-finding algorithm ∼36% faster than
Floyd’s algorithm, leading to an overall speed up of ∼24% for the entire algorithm. [5]
Besides this optimisation, the overall approach is the same, so we do not describe the details
here.
factors. For further details, see [29]. We now proceed to the general-purpose algorithms.
Most general-purpose algorithms exploit an idea based upon Fermat’s method, perhaps first
introduced by Maurice Kraitchik. [34] Recall from §2.2.2 that in order to factorise n, we
attempt to find some values x, y such that x2 − y 2 = n. The closely related congruence
x2 ≡ y 2 (mod n) is fundamental to the general-purpose algorithms. Kraitchik observed:
Proposition 2.10. If x and y are two integers less than n, such that x 6= y and x + y 6= n,
and x2 ≡ y 2 (mod n), then (x − y, n) and (x + y, n) are possibly non-trivial factors of n.
The congruence above is sometimes known as Legendre’s congruence. [45] To see why Propo-
sition 2.10 holds, we tabulate the possibilities for a semiprime n = pq with p, q prime, as
used in RSA: [8]
Thus, if we are able to find x, y such that Legendre’s congruence holds, there is a probability
2
of 3 that we will find a non-trivial factor. Each algorithm varies in the manner in which the
congruence of squares is found.
We begin ahistorically with Dixon’s algorithm, which uses a number of concepts employed
in more complex algorithms. In §2.3.3 , we outline one of the earliest general-purpose al-
gorithms, the Continued Fraction (or CFRAC) method. We build upon these concepts in
discussion of the Quadratic Sieve in §2.3.4, leading naturally into a review of the General
Number Field Sieve in §3.
Rather than attempting to find x and y such that x2 ≡ y 2 (mod n), Dixon’s method requires
only that we find a number of relations:
Definition 2.11. A number is B-smooth if all of its prime factors pi satisfy pi ≤ B for
some B ∈ N. [45]
Dixon’s method is an improvement on Fermat’s, as there are more smooth numbers satisfying
(2.4) than the stricter requirement x2 ≡ y 2 (mod n). To see how we generate a congruence
of squares using these relations, consider the following example:
Example 2.14. We will factorise n = 1537 using the factor base PB = {2, 3, 5, 7, 11}
By calculating x2 (mod 1537) for random x values and searching for 11-smooth numbers, we
find the relations in Table 2.5.2
We may now generate a square using linear algebra. Provided we have B+1 or more vectors
vi ∈ FB
2 , there must be a non-trivial linear dependence between them. Gaussian elimination
or another algorithm for solving systems of linear equations may now be used to find a
combination of vectors which sum to the zero vector.
In this case, we see by inspection that adding the first 3 vectors v1 + v2 + v3 gives:
(1 1 0 1 0) + (1 1 0 0 0) + (0 0 0 1 0) = (0 0 0 0 0)
This is equivalent to multiplying x1 , x2 , x3 and ensures that all prime powers are even. This
gives the congruence of squares:
We now calculate (858 + 626, 1537) = 53 and (828 − 626, 1537) = 29 to find the factorisation
1537 = 29 × 53.
It’s possible that this method gives a trivial factorisation of n, in which case we try again
with a different combination of relations or an expanded factor base. It is clear that the
speed of this method (and others based upon it) relies on finding enough relations efficiently.
In addition, we require some efficient way of determining smoothness. With a smaller factor
base, finding a linear dependency is faster but we risk not being able to find enough smooth
values to guarantee a dependency. [34] Thus, our choice of factor base is critical to the
algorithm’s runtime.
We now consider the Continued Fraction method, which uses continued fractions to find
relations of the form (2.4).
Lehmer and Powers introduced the Continued Fraction (CFRAC) method in a 1931 paper,
but it was not until the 1970’s that computers were powerful enough to fully exploit their
ideas.
b0
a0 +
b1
a1 +
b2
a2 +
bn
··· +
an
ai , bi ∈ Z and all ai positive for i > 0.
If all bi = 1, the continued fraction is regular.
Ai
√
We first generate a sequence of convergents Bi to kn, and set Wi = A2i − Bi2 kn.
√
For details on finding the continued fraction representation of n and generating convergents,
see §2.5 and §2.6 of [21].
Example 2.18. We shall factorise n = 1711 using the Continued Fraction method.
We set k = 1 in this expansion and will use the factor base PB = {−1, 2, 3, 5}.
Note that we include -1 in the factor base. This allows us to consider negative congruences,
which may be of smaller absolute value, and thus more likely to be smooth. As we require
that the power of -1 in our final congruence be even, the linear algebra step is unchanged.
√
The continued fraction expansion of 1711 is:
√ 1
1711 = 41 +
1
2+
1
1+
1
2+
1
1+
13 + · · ·
We show the convergents in Table 2.6. Note that only convergents with Wi smooth are
shown for clarity.
Ai
Bi (mod 1711) Wi = A2i − 1711 × Bi2 (mod 1711) Factorisation of Wi Vector
41
1 -30 −1 × 2 × 3 × 5 (1 1 1 1)
83
2 45 32 × 5 (0 0 0 1)
455
11 -6 −1 × 2 × 3 (1 1 1 0)
1113
151 5 1×5 (0 0 0 1)
1129
1403 -54 −1 × 2 × 33 (1 1 1 0)
We observe that summing the third and fifth vectors generates the zero vector (0 0 0 0).
By the definition of Wi , we have Wi ≡ A2i (mod n), giving the congruence:
Finally, we calculate (395 + 18, 1711) = 59 and (395 − 18, 1711) = 29 and obtain the factori-
sation 1711 = 29 × 59.
In 1970, Morrison and Brillhart developed a computer implementation of CFRAC and used
7
it to factorise the seventh Fermat number, 22 + 1, a number with 39 decimal digits. [31]
Although this represented a significant milestone in factorising technology, the CFRAC al-
gorithm was soon superseded by a forerunner to today’s methods, the Quadratic Sieve of
Carl Pomerance.
The sieve inverts this process: rather than dividing every value by each prime in our factor
base to determine if they are smooth, we instead fix a prime pi ∈ PB and determine all values
which are divisible by pi . Pomerance’s choice of polynomial facilitates this step. Recall from
§2.3.2 that Dixon’s method seeks x2 ≡ y (mod n) where y is B-smooth.
Once B+1 xi with f (xi ) smooth are found, we use linear algebra to find a subset S with: [8]
Y Y q
f (xi ) = (pi i )2
xi ∈S pi ∈PB
Y Y Y
a2 = (x2i ) ≡ (x2i − n) ≡ f (xi ) = b2 (mod n) (2.6)
xi ∈S xi ∈S xi ∈S
Proposition 2.19. If p|f (xi ) for p ∈ PB , then p|f (xi + kp) for k ∈ Z.
The Tonelli-Shanks algorithm is an efficient method for doing this. [44] We sieve over an
interval [−u ≤ xi ≤ u] that is heuristically expected to generate enough smooth values of
f (xi ). To do this, a 2u × B array is initialised with the 2u values of f (xi ) in the first column.
For xi solving (2.7) we divide f (xi ) by pj and put the result in the jth column. We can then
divide all further values f (xi + kpj ) in the interval by pj by Proposition 2.19.
This process only works if n is a quadratic residue modulo p (otherwise (2.7) has no solutions),
so we must modify our factor base PB to contain only primes satisfying this condition. The
process is then repeated for each pj ∈ PB . Finally the array is scanned for values of ±1, which
indicate that the f (xi ) factors completely over the factor base. As Pomerance mentions, f (xi )
values divisible by paj for a > 2 will not equal 1 unless we sieve further by higher powers of
pj . For example, 60 would be reduced to 2 after sieving only by 21 , 31 , and 51 . [35]
Example 2.20. We will sieve the interval [0,60] for smooth values of f (xi ) = x2i − n and
use this to factorise n = 2291 with PB = {−1, 2, 3, 5, 7, 11}.
We first need to solve (2.7) modulo the pj ∈ PB . We find that 2291 is a quadratic non-residue
modulo 3, so we remove 3 from our factor base.
Besides p = 2, for any p for which n is a quadratic modulo, there will be 2 solutions. We
find x2i ≡ 2291 (mod 5) has solutions x ≡ 1 (mod 5) & x ≡ 4 (mod 5).
We thus go to the 1st and 4th rows in the column p = 5 and divide f (xi ) by 5. We continue
down the column, dividing by 5 in the (1 + 5k)th and (4 + 5k)th positions. To sieve by higher
powers, we next solve x2i ≡ 2291 (mod 52 ) and repeat this process.
Table 2.7 shows the results of sieving with PB = {−1, 2, 5, 7, 11} and some small values of
paj . We only tabulate a few selected values with small factors for clarity, including any xi
that are found to generate smooth f (xi ) values, shown in bold.
xi x2i − 2291 2 5 52 53 7 72 73 11
1 -2290 -1145 -229 - - - - - -
4 -2275 - -455 -91 - -13 - - -
17 -2002 -1001 - - - -143 - - -13
24 -1715 - -343 - - -49 -7 -1 -
31 -1330 -665 -133 - - -19 - - -
39 -770 -385 -77 - - -11 - - -1
46 -175 - -35 -7 - -1 - - -
49 110 55 11 - - - - - 1
51 310 155 31 - - - - - -
60 1309 - - - - 187 - - 17
After scanning the sieve, we find the following smooth values and use them to generate the
exponent matrix:
xi f (xi ) Factorisation
1 0 1 1 0
24 -1715 −1 × 5 × 73
→
1 1 1 1 1
39 -770 −1 × 2 × 5 × 7 × 11
1 0 0 1 0
46 -175 −1 × 52 × 7
0 1 1 0 1
49 110 2 × 5 × 11
Although we have only collected 4 smooth values and a dependency is not guaranteed, in
this case we are fortunate that v2 + v3 + v4 = (0 0 0 0 0).
Calculating as usual (87906 + 1559, 2291) = 29 and (87906 − 1559, 2291) = 79 gives the
factorisation 2291 = 29 × 79.
As there are fewer primes allowed in our factor base due to the quadratic residue condition, we
may miss some f (xi ) values with only small prime factors, but we save time by only dividing
by a pj once we already know that pj |f (xi ). This represents a huge gain in efficiency over
naive trial division methods of finding smooth values.
Pomerance introduced an optimisation in [34] that further speeds up the sieving process.
Rather than dividing by the pj ’s directly, we instead initialise the array with the values of
log f (xi ) and subtract log pj , which is equivalent to dividing by pj by the Second Log Law. As
the logarithms are computed only roughly, this is much quicker than division by (potentially)
large numbers. The array is then scanned for values close to 0, which correspond to values
likely to be smooth. Only at this point is time-consuming trial division performed, in order
to verify that the f (xi ) actually is smooth. In this way, we only perform trial division on
values highly likely to be smooth.
Depending on the initial accuracy of the logarithms, there will be some small percentage of
misidentified non-smooth values tested, but the prior time savings more than make up for
these unnecessary divisions.
Example 2.21. We show the sieving process using logarithms only for xi = 24, 31 as exam-
ples. Recall from Table 2.7 that xi = 24 gave a smooth f (xi ).
A further improvement on the algorithm was developed by Peter Montgomery. [34] As the
values of f (xi ) grow larger, it becomes increasingly more unlikely that they will be smooth
over the factor base. Montgomery proposed employing multiple quadratic polynomials to
increase the number of smooth values found. These days, it is this form of the algorithm
that is generally used, and that has made the factorisation of 60-80 digit numbers feasible
on a home computer.
During the mid-90’s Lenstra and Manasse exploited the parallelisation of the sieve to dis-
tribute factorising projects over the internet. [35] Sample factorisation data from this project
is shown below to give a more realistic example of the size of factor bases and primes required
for a successful factorisation with MPQS. [28] Table 2.9 also indicates the rapid growth in
computation time as the size of the modulus increases.3
The Quadratic Sieve set many factoring records throughout the 1980’s, before it too, was
superseded by the current fastest-known algorithm, the General Number Field Sieve (GNFS).
For n with less than 120 digits or so, [19] MPQS remains the fastest algorithm due to the
complexity of setting up the GNFS. Above this threshold, the GNFS begins to be faster.
In this section, we have described some important general-purpose algorithms and laid the
mathematical foundations for an outline of the General Number Field Sieve in §3.
3
Sieving time is given in units of MIPS-years; at the time, 1 MY equalled 1 year of processing on a VAX
11/780. [28]
3.1 Foundations
3.1.1 History
The foundations of the General Number Field Sieve can be traced to ideas circulated in a
letter by John Pollard in 1988 for factorising a special class of numbers: those of the form
re +s with small positive r, s. In his letter, Pollard proposed F9 , with 155 decimal digits, as a
potential candidate for factorisation using what is now called the Special Number Field Sieve
(SNFS). This was successfully achieved in 1990, by A Lenstra, H Lenstra, and Manasse. [26]
The General Number Field Sieve employs similar ideas but removes the input conditions and
works with integers of any form, at the expense of some speed. We thus concentrate on the
GNFS for the remainder of this chapter. For further information on the SNFS, see [27] and
§4 & 5 of [26].
The key innovation of Pollard’s idea was to expand the search for smooth values beyond the
ring Z, using algebraic number fields. If we can find rings that generate more smooth values
than Z, we should in theory be able to find relations faster. Such an idea is not obvious
- smoothness is easily understood when dealing with integers, but how do we apply it to
elements not in Z? To answer this, we will need to extend our concept of smoothness.
A second, more intuitive, innovation is to use polynomials other than quadratics as our gen-
erating polynomial f (xi ). If some higher-power polynomials generate more smooth values
than quadratics, again, we may find relations faster. The expansion of our scope to other
28
Chapter 3. The General Number Field Sieve 29
rings requires some knowledge of algebraic number theory; we outline the necessary mathe-
matical background in §3.2. In §3.3, we present the theory required to extend our concept of
smoothness, and discuss sieving for the GNFS in §3.4. The final step of calculating a square
root in an algebraic number field is discussed in §3.5.
φ(1R ) = (1S )
To generate a congruence of squares using rings other than Z, we construct a ring homo-
morphism. We first choose a monic, irreducible polynomial f (x) of degree d with rational
coefficients. Typically for numbers in the 120-150 digit range, we set d = 5.
Proposition 3.2. Let θ be the root of a monic, irreducible polynomial f (x) of degree d
with rational coefficients. The set of all polynomials in θ with rational coefficients is a ring,
denoted Q(θ).
By Theorem 2.2.2 of [8], Q(θ) is a field and the elements of Q(θ) may be represented as
Q-linear combinations of elements of the set R = {1, θ, θ2 , . . . , θd−1 }, i.e. R forms a basis for
Q(θ).
Definition 3.4. A number field K is an extension of the field Q that is a finite dimensional
vector space. We call the dimension of the vector space the degree of K.
The set of all algebraic integers in a field F ⊆ C is called the ring of integers.
Definition 3.5. The ring of integers OK of the number field K ⊆ C is defined: OK = K∩A
where A is the ring of algebraic integers.
As Q(θ) is a field, we now form a subring of OQ(θ) by Proposition 2.3.2 of [8], as follows:
Proposition 3.6. Given a root θ of a monic, irreducible polynomial f(x) such that:
f (x) = xn + · · · + a2 x2 + a1 x + a0 with ai ∈ Z,
the set of Z-linear combinations of the elements {1, θ, θ2 , . . . , θd−1 }, forms a subring of OQ(θ) ,
denoted Z[θ].
It is this ring Z[θ] which we will use to find smooth values. By using Z-linear combinations
of the elements, we can ignore denominators in our representations of the elements. This
simplification does have some important consequences; our ring is now possibly a proper
subring of OQ(θ) , which causes some complications, which we shall resolve once we have
found smooth values in Z[θ].
How then do we use the ring Z[θ] and a ring homomorphism to generate a congruence of
squares? Consider the following mapping: [35]
Proposition 3.7. Given f (x) satisfying the conditions of Proposition 3.6, a root θ ∈ C, and
m ∈ Z/nZ such that f (m) ≡ 0 (mod n), the function φ : Z[θ] → Z/nZ defined by:
φ(1) = 1 (mod n)
φ(θ) = m (mod n)
is a ring homomorphism.
We will use this homomorphism to construct the required congruence using smooth values
in Z[θ] and Z.
Suppose we have found a set S of pairs of coprime integers (a, b) such that:
Y Y
(a + bθ) = β 2 for β ∈ Z[θ], and (a + bm) = y 2 for y ∈ Z (3.1)
(a,b)∈S (a,b)∈S
Then setting x = φ(β) and applying the homomorphism of Proposition 3.7 gives: [35]
Y Y Y
x2 ≡ φ(β)2 ≡ φ(β 2 ) ≡ φ (a + bθ) ≡ φ(a+bθ) ≡ (a+bm) ≡ y 2 (mod n)
(a,b)∈S (a,b)∈S (a,b)∈S
(3.2)
The congruence of (3.2) is the heart of the Number Field Sieve. Note that in order to find
our factors using this congruence we must calculate (x + y, n) and (x − y, n). We therefore
need to find x, or what is equivalent, calculate the square root of a product of algebraic
numbers, a non-trivial procedure which we shall outline in §3.5. Conversely, finding y is
straight-forward as y 2 ∈ Z.
To generate Z[θ], we require a monic, irreducible polynomial f (x) with integer coefficients.
A simple way of finding one is the base-m method. [10] We choose m first and construct our
1
polynomial to satisfy the condition f (m) ≡ 0 (mod n). m is chosen such that m ≈ n d .
Writing n in base-m then gives:
The base-m method was suggested in early papers on the GNFS. However, our initial choice
of polynomial can greatly affect the efficiency of the algorithm, with ‘tuned’ polynomials
yielding greater numbers of smooth values. This is a particularly active area of GNFS
research, for further details see [32] and [22].
By the congruence (3.2) and the definitions of (3.1), we need to find a set of coprime integers
Y Y
(a, b) such that the products (a + bθ) and (a + bm) are squares in their respective
(a,b)∈S (a,b)∈S
rings.
Y
To find (a + bm) square, we use essentially the same process as in the quadratic sieve,
(a,b)∈S
except we now have two variables a, b rather than the single variable x of (2.5).
In practice, we fix b ∈ Z and sieve over an interval [−u ≤ a ≤ u], seeking smooth values of
(a + bm). We then increment b by 1 and repeat the process.
Definition 3.8. The rational factor base is a set PR of primes p ≤ BR for some bound
BR .
To find the array positions for sieving, we note that p|(a + bm) ⇐⇒ a ≡ −bm (mod p).
Then ai = −bm + kp for some k ∈ Z and −u ≤ a ≤ u, so we can calculate all possible values
of ai in the interval. [8]
The array is initialised with the values of (a + bm) and we proceed to divide by p in the ai th
positions. The entire process is then repeated for the next p ∈ PR . We thus find smooth
values in a manner similar to that of the quadratic sieve. We must now extend the concept
of smoothness to the ring Z[θ].
Definition 3.11. A unique factorisation domain (UFD) is a ring R satisfying the fol-
lowing conditions: [40, §4.5]
The principal issue with extending the concept of smoothness is that Z[θ] is not necessarily
a unique factorisation domain. So the elements of Z[θ] may not be ‘factored’ uniquely into
irreducible elements. To resolve this, we instead consider factorisation of ideals into prime
ideals, which will be unique, provided we are working in a Dedekind domain.
To find (a, b) pairs with (a + bθ) smooth, the general idea is to first choose an ‘algebraic’
factor base, a set of prime ideals of Z[θ]. We then consider the principal ideal ha + bθi
generated by each element (a + bθ) and check to see if it factorises completely into prime
ideals of our factor base. Those which do are smooth over the algebraic factor base and the
(a, b) pair is useful.
We now describe the details of determining smoothness in Z[θ]. We begin with an important
fact about the ring of integers.
Theorem 3.14. Every non-zero ideal of OQ(θ) can be written as a product of prime ideals,
uniquely up to the order of factors.
We can use this property of the ring of integers to uniquely factorise ideals in the ring Q(θ)
into prime ideals and thereby extend our concept of smoothness. As the elements α ∈ Z[θ]
are algebraic integers, to simplify this approach we instead work with the norm of α.
Theorem 3.15. Let K = Q(θ) be a number field of degree d. Then there are exactly d
distinct monomorphisms σi : Q(θ) → C (i = 1, . . . , d).
Definition 3.16. Let K = Q(θ) be a number field of degree d and let σ1 , . . . , σd be the d
monomorphisms σi : Q(θ) → C of Theorem 3.15.
Definition 3.17. Let I be a non-zero ideal. The norm of an ideal is defined as:
The following two results highlight the usefulness of these two functions.
Theorem 3.18. Given a monic, irreducible polynomial of degree d with integer coefficients,
a root θ ∈ C, and an element α ∈ Z[θ], N (α) is a multiplicative function N (α) : Z[θ] → Z.
Theorem 3.19. Given a monic, irreducible polynomial of degree d with rational coefficients,
a root θ ∈ C, and I a non-zero ideal of K, N (I) is a multiplicative function N (I) : OK → Z+ .
If a = hai is a principal ideal, then N (hai) = |N (a)|.
Thus the norm conveniently maps elements α ∈ Z[θ] to integers. For a principal ideal
generated by α, the norm of the ideal is a positive integer and is equal to the absolute value
of the norm N (α). Rather than working with α ∈ C, we can now work with integers. To
simplify sieving, we restrict the algebraic factor base to first-degree prime ideals only. [8]
Definition 3.20. A first-degree prime ideal p of a Dedekind domain is a prime ideal such
that N (p) = p for some prime p.
This definition is justified by the following theorem, which relates prime ideals p to prime
numbers in Z.
First-degree prime ideals are convenient to work with as they may be simply represented by
pairs of integers (r, p), due to the following theorem:
Theorem 3.22. Let f (x) be a monic, irreducible polynomial with integer coefficients, and
θ ∈ C a root of f (x).
Consider the set of pairs (r, p) with r ∈ Z/pZ, f (r) ≡ 0 (mod p) and p a prime integer. There
exists a bijection between this set and the set of first-degree prime ideals of Z[θ].
We now show that each first-degree prime ideal maps to a unique (r, p) pair satisfying the
conditions of the theorem. Let p be a first-degree prime ideal of Z[θ]. Then N (p) = p for
some prime p by definition.
N (p) = p =⇒ Z[θ]/p ∼
= Z/pZ. There exists an epimorphism φ : Z[θ] → Z/pZ with
ker(φ) = p. [8, Theorem 3.1.7]
≡ rd + ad−1 rd−1 . . . a1 r + a0
≡ f (r) (mod p)
So r is a root of f (x) (mod p) and p maps to the unique pair (r, p). We now show that a
pair (r, p) with r ∈ Z/pZ, f (r) ≡ 0 (mod p) and p prime maps to a unique first-degree prime
ideal p.
There exists an epimorphism φ : Q[θ] → Q[r], φ(a) ≡ a (mod p) for all a ∈ Z and φ(θ) = r
(mod p). [8, Theorem 2.2.2]
Let ker(φ) = p so that p is an ideal of Z[θ]. Then Z[θ]/p ∼
= Z/pZ and N (p) = p. So (r, p)
maps to a unique first-degree prime ideal p of Z[θ].
Theorem 3.22 shows that there is a unique (r, p) representative for each first-degree prime
ideal in Z[θ]. We are finally in a position to define the algebraic factor base.
Definition 3.25. The algebraic factor base is a set PA of first-degree prime ideals of
Z[θ], represented by pairs (r, p) with r ∈ Z/pZ, f (r) ≡ 0 (mod p) and p a prime, p ≤ BA for
some bound BA . Each pair represents a unique first-degree prime ideal of Z[θ].
By the unique factorisation of a principal ideal hβi = pe11 pe22 . . . pekk to prime ideals pi , the
multiplicativity of N (α) and Theorems 3.19 and 3.21, we have: [8]
N (hβi) = |N (β)| = N (pe11 pe22 . . . pekk ) = N (pe11 )N (pe22 ) . . . N (pekk ) = (pf11 )e1 (pf22 )e2 . . . (pfkk )ek
(3.5)
for primes pi ; ei , fi ∈ Z+ and 1 ≤ i ≤ k.
Note that the primes need not be distinct, as the norms of different prime ideals may be
factorised by the same prime p, but to different powers. We now define a function that tracks
the powers of p in N (a + bθ) for (a + bθ) generating a principal ideal ha + bθi which factorises
fully over the algebraic factor base. [10, Remark 5.2]
Definition 3.26. Let f be a monic, irreducible polynomial of degree d with integer coeffi-
cients, and a root θ ∈ C.
Let (a, b) be coprime integers, p a prime integer and r ∈ R(p) = {r : f (r) ≡ 0 (mod p)}.
We define:
ordp (N (a + bθ)) if a + br ≡ 0 (mod p)
ep,r (a + bθ) =
0
otherwise
To use the function ep,r we need to generalise for the case in which Z[θ] 6= OK . (This will
usually be the case in practice.) To do this, we consider the following group homomorphism.
Theorem 3.27. There exists, for each prime ideal pi ∈ Z[θ] a group homomorphism
lpi : Q(θ) → Z such that:
Using this homomorphism, we obtain the following important results: [10, Corollary 5.5]
Theorem 3.28. Let (a, b) be coprime integers and p a prime ideal in Z[θ].
If p is not a first-degree prime ideal, then lp (a + bθ) = 0.
Proof. Let p be a prime ideal of Z[θ] with lp (a + bθ) > 0. As in Theorem 3.22, there exists
an epimorphism φ : Z[θ] → Z[θ]/p with ker(φ) = p.
Then Z[θ]/p ∼
= Fpe by Theorem 3.21, where Fpe is the finite field with pe elements and p
prime. So Z[θ]/p contains an isomorphic copy of Z/pZ.
lp (a + bθ) > 0 =⇒ p | ha + bθi by point 2 of Theorem 3.27, so (a + bθ) ∈ p.
Then ker(φ) = p =⇒ φ(a + bθ) ≡ 0 (mod p).
Z[θ]/ker(φ) ∼
= Im φ and ker(φ) = p =⇒ Z[θ]/p ∼
= Z/pZ, so p is a first-degree prime ideal
of Z[θ] by Theorem 3.22. [8, Theorem 3.1.9]
Theorem 3.29. Let (a, b) be coprime integers and p a prime ideal in Z[θ].
If p is a first-degree prime ideal, corresponding to a pair (r, p), then lp (a + bθ) = ep,r (a + bθ).
Proof. Let lp (a + bθ) > 0. Then p | ha + bθi by Theorem 3.27 and (a + bθ) ∈ p.
Consider the epimorphism φ : Z[θ] → Z/pZ, with φ(θ) = r (mod p) and φ(a) = a (mod p)
for a ∈ Z. Then ker(φ) = p. (a + bθ) ∈ p =⇒ φ(a + bθ) ≡ 0 (mod p).
Then φ(a + bθ) ≡ a + br ≡ 0 (mod p).
Let a + br ≡ 0 (mod p) for the first-degree prime ideal p, represented by the pair (r, p).
Then a + br (mod p)≡ 0 ≡ φ(a + bθ) and a + bθ ∈ ker(φ). So a + bθ ∈ p.
a + bθ ∈ p =⇒ p | ha + bθi, so lp (a + bθ) > 0 by point 2 of Theorem 3.27.
We now show for a first-degree prime ideal p represented by pair (r, p), that
p | N (a + bθ) ⇐⇒ a + br ≡ 0 (mod p). Then lp (a + bθ) = ep,r (a + bθ) as required.
So p | N (a + bθ) ⇐⇒ p | f (− ab ) as p - b.
p | f (− ab ) =⇒ f (− ab ) ≡ 0 (mod p), so a ≡ −br (mod p) for r with f (r) ≡ 0 (mod p). Thus
the (r, p) pair determines a first-degree prime ideal p.
To show uniqueness of the (r, p) pair corresponding to p, let lp1 (a+bθ) > 0 and lp2 (a+bθ) > 0
for first-degree prime ideals p1 & p2 , represented by pairs (r1 , p) and (r2 , p) respectively.
Then a + br1 ≡ 0 (mod p) and a + br2 ≡ 0 (mod p) =⇒ r1 ≡ r2 (mod p).
So p1 = p2 and the (r, p) pair with lp (a + bθ) > 0 is unique. [8, Theorem 3.1.9]
Applying Theorems 3.28 & 3.29, we have a way of determining whether an ideal factors over
the algebraic factor base; namely, it factors if N (a + bθ) factors completely into primes pi
of the (r, p) pairs that represent the first-degree prime ideals. Such an element (a + bθ) is
smooth over the algebraic factor base.
Now that we can find smooth values of (a+bθ), we need to consider how to find a square β 2 ∈
Z[θ] to satisfy the congruence (3.2). Unfortunately, the usual approach of forming a product
with only even exponents gives a necessary, but not sufficient, condition for constructing a
square β 2 ∈ Z[θ] (See Proposition 5.3 of [10]). This process ensures that N ( (a + bθ)) is a
Q
Q
square, which is not a strong enough condition to guarantee that (a + bθ) itself is a square
in Z[θ]. We consider the problem of finding β 2 ∈ Z[θ] in the next section.
Our issue arises, as mentioned previously, as we are working with ideals of Z[θ] and not of
OK (See §6 of [10] for further details). This problem was resolved by a proposal of Adleman.
[35] Adleman suggested the use of first-degree primes not in the factor base as a means of
Q
heuristically testing (a + bθ) for squareness in Z[θ].
Recall that our ring homomorphism in (3.2) is defined for β ∈ Z[θ]. In practice, we allow
Q
the product (a + bθ) to be square in Q(θ), rather than only Z[θ], as this is less restrictive.
By a clever use of the Legendre symbol, we can test the product for squareness in Z[θ]. We
first require a lemma of [10, 6.6]:
Y
Lemma 3.30. Let S be as in (3.1) and (a + bθ) = α2 for some α ∈ Q(θ).
(a,b)∈S
Let f be a monic, irreducible polynomial of degree d with integer coefficients, and a root θ ∈ C.
Y
Then α ∈ OQ(θ) and f 0 (θ)2 · (a + bθ) is a square in Z[θ].
(a,b)∈S
Y
Theorem 3.31. Let S be a set of pairs of coprime integers (a, b) with (a + bθ) = α2
(a,b)∈S
for some α2 ∈ Q(θ). Let q be an odd prime and s ∈ R(q) with R the set in Definition 3.26,
such that:
f 0 (s) 6= 0 (mod q)
Then:
Y a + bs
=1 (3.6)
q
(a,b)∈S
Proof. Let q be the kernel of the ring homomorphism φ : Z[α] → Fq which maps θ to s (mod
q). Then q corresponds to the pair (s, q).
Define χq : Z[θ] − q → {±1} as the composition of Z[θ] − q → Fq − {0} with the Legendre
symbol Fq − {0} → {±1}.
Y
Then χq (a + bθ) = ( a+bs 0 2
q ). We have by the previous lemma that f (θ) · (a + bθ) =
(a,b)∈S
δ 2 ∈ Z[θ] for some δ.
To put this theorem to use, we essentially generate a further set PQ of first-degree prime
ideals not in the algebraic factor base.
Definition 3.32. The quadratic character base PQ is a set of first-degree prime ideals,
represented by (s, q) pairs with pA < qi , where pA is the largest prime in the (r, p) pairs of
the algebraic factor base.
Y
By checking that (3.6) holds across all (s, q) pairs in PQ , it is highly likely that (a + bθ)
(a,b)∈S
is a square. By adding more (s, q) pairs to PQ , we can increase this probability.
To summarise , we have developed methods for testing whether an (a, b) pair is smooth over
Y
the algebraic factor base, and can test whether the product of such pairs (a + bθ) is a
(a,b)∈S
likely square in Z[θ]. In the next section, we outline how to apply these ideas to construct
the algebraic sieve.
3.4 Sieving
To sieve in Z[θ], we use a procedure almost identical in form to the sieving process in Z
outlined in §3.3.1. By Theorem 3.29, N (a + bθ) factorises over the primes of (r, p) ∈ PA if
and only if, a + br ≡ 0 (mod p).
Note that p | ha + bθi ⇐⇒ a ≡ −br (mod p). Then a = −br + kp for some k ∈ Z.
To sieve, we again fix b and sieve over an interval [−u ≤ a ≤ u]. Once the positions are
calculated, we initialise the sieve with the values N (a + bθ) and divide by p at the ai th
positions where ai = −br + kp. We then increment b and the process is repeated until
enough smooth values have been obtained.
Sieving in Z[θ] is thus ostensibly identical to sieving in Z, which simplifies computer imple-
mentation of the GNFS. One further point of implementation is to store the elements of PR
as pairs of integers (m (mod p), p), to align with the form of elements of PA . This further
simplifies the sieving code. [8, §3.8]
Once we have found enough simultaneously smooth values in Z[θ] and Z, we need to perform
the linear algebra step to find a set S such that (3.1) holds. Due to the large size of the factor
base used in a GNFS factorisation, the exponent matrix becomes increasingly unwieldy to
work with. To give an idea of the size of this matrix, we first show the form of a binary
3.4. Sieving
Chapter 3. The General Number Field Sieve 41
vector vi representing an (a, b) pair with (a + bm) and (a + bθ) smooth over their respective
factor bases.
Exponents of pi ∈PR Quadratic character bits
z }| { z }| {
vi = |{z}
0 0 1 0 0 0 1 . . . 0 |1 1 0 1 1 {z
0 0 0 . . . 1} 0 0 1 1 0 0 . . . 0
Sign bit Exponents of pi ∈PA
0
if a + bm > 0
With the sign bit =
1
otherwise
After sieving and linear algebra processing, we obtain a set S of (a, b) pairs satisfying (3.1).
One final issue is that in order to calculate (x ± y, n) and obtain a factorisation, we need to
calculate x = φ(β).
There are a number of solutions to this problem, as discussed in [43]. We shall sketch one of
the earlier ideas, proposed by Couveignes in [12]. By a clever use of the Chinese Remainder
theorem, we can circumvent the difficulties of finding β and calculate x without requiring
intermediate values.
z ≡ x1 (mod p1 )
z ≡ x2 (mod p2 )
..
.
z ≡ xk (mod pk )
k
X
z= ai xi Pi is the unique solution modulo P .
i=1
Our approach is to calculate x modulo primes pi , which can be done efficiently by the Shanks-
Tonelli algorithm, amongst other methods. If we use enough primes such that their product
P > x, and solve the system of congruences by Theorem 3.33, then we find x ≡ z (mod P ).
x (mod n) = z − rP (mod n)
= z (mod n) − rP (mod n)
k
X
= ai xi Pi (mod n) − rP (mod n)
i=1
k k
X X ai xi 1
= ai xi Pi (mod n) − b( ) + cP (mod n)
pi 2
i=1 i=1
In this manner, none of the intermediate values calculated will exceed n and x can be found
efficiently. For further details on calculating x (mod pi ), see [12] and [8, §4.7 & §4.8].
Y
Once x has been computed, we calculate the square root of y 2 = (a + bm) and generate
(a,b)∈S
our required congruence (3.2). Finally, we calculate (x ± y, n) and the factorisation of n is
complete.
Time complexity
In order to compare the efficiency of the algorithms presented in previous chapters, we now
outline their time complexities. To measure time complexity, we consider the algorithm’s
asymptotic behaviour, that is, the number of elementary operations required to complete the
algorithm in the worst-case scenario. By design, an RSA modulus n, being a large semiprime
with no small prime factors, represents the worst-case for factorising.
To describe the time complexity of an algorithm, we use Big O notation. [39, §7]
Then we say f (x) ∈ O(g(x)) as x → ∞ if ∃C, x0 ∈ R such that |f (x)| ≤ Cg(x) for all x ≥ x0 .
For the remainder of the chapter, let f (x) represent the number of elementary operations
of an algorithm as a function of the size of the input. When working with large inputs, the
highest order of the expression for running time dominates the other terms, so it is this term
that describes the asymptotic behaviour.
Example 4.2. The total number of steps taken to complete an algorithm with input x is
f (x) = 7x5 + 3x3 + 2x + 1.
The x5 term will dominate the runtime for large inputs, with the constant coefficient 7 having
relatively minimal effect.
44
Chapter 4. Time complexity 45
As the runtime grows with the size of the input, the theoretical time complexity of the
algorithm translates directly to the amount of real-world computing time required to run
the algorithm.
Definition 4.3. We say that a problem is tractable [42, §2.4] if there is an algorithm to
solve it that runs in polynomial time or faster; i.e. f (x) ∈ O(xn ) for some n ∈ N.
It is important to note that an expression for the time complexity of an algorithm is de-
pendent upon the encoding of the input. [42] For our purposes, the RSA modulus n is
encoded in binary and therefore the input has size log2 (n) bits. So a function f (n) ∈ O(n)
is exponential in the size of the input.
We now outline the time complexities of the algorithms discussed in §2. We begin with the
exponential time algorithms.
2r/2
π(2r/2 ) ≈
ln 2r/2
2r/2
≈ r
2 ln 2
2r/2 r
So we need to make approximately r trial divisions, so f (x) ∈ O(2 2 ), which is expo-
2 ln 2
nential in the size of the input.
Provided n does not satisfy the conditions of Theorem 2.8, it can be factorised using Euler’s
√
method in time O( n).
By considering the Birthday Paradox, for a prime p dividing n we would expect a sequence
√
of f (xi )’s to cycle before O( p) steps. [13, §5.2] This is only conjectured, as it is based on
the assumption that the f (xi ) values behave like random numbers. Pollard’s rho thus has
√ √
time complexity O( p) ≤ O( 4 n), so is heuristically exponential in the size of the input.
We now consider the subexponential time algorithms, which are asymptotically faster than
the previous algorithms. We first require some additional notation.
Then we say f (x) ∈ o(g(x)) as x → ∞ if ∀ε ∈ R+ , ∃C such that |f (x)| ≤ εg(x) for all x ≥ C.
Little-o notation is used to show that a function f (x) grows much more slowly than some
function g(x).
Definition 4.7. An algorithm has subexponential running time if f (x) ∈ 2o(n) where o(n)
represents little-o notation as in Definition 4.6.
Dixon’s algorithm was the first subexponential algorithm with a rigorous proof of its runtime,
hence its primacy in the discussion of §2.
√ √
Proposition 4.8. Dixon’s method has expected runtime O e((3 2) ln n ln ln n)
Suppose we have a list of integers L of length N in the range [1, n]. We seek values xi in this
range such that f (xi ) = x2i (mod n) is B-smooth. We choose xi ∈ L randomly and factorise
x2 (mod n) to determine whether it is B-smooth. This factorisation step takes O(B ln n)
operations. [15] Once B+1 B-smooth values are found, we proceed to the linear algebra step.
Gaussian elimination requires O(B 3 ) operations. The final step of calculating a gcd requires
O(ln n) operations.
Thus, the method can be reduced to an optimisation problem in which we select our bound B
on the factor base to minimise the number of f (xi )’s that need to be checked for smoothness.
We must also optimise the length N of our list L such that we are almost certain to find
enough smooth values of f (xi ).
√
(2 ln n ln ln n)
Proposition 4.9. Set B = e and N = (B 2 + 1). Then the average number of
√ √
operations to factorise by Dixon’s algorithm is O e((3 2) ln n ln ln n) .
Although the Continued Fraction method was the first subexponential algorithm, its runtime
has not been rigorously proved. Heuristically, the Continued Fraction method has expected
√
runtime O e( 2 ln n ln ln n) . [45]
The Quadratic Sieve improves upon earlier methods by checking for smoothness far more
quickly using the sieving process discussed in §2.3.4. This improves its expected runtime to
√
O e( ln n ln ln n) . [35]
The major speedup of the GNFS comes through generating auxiliary numbers bounded
0 1 2
by ec (ln n) (ln ln n) with c0 a constant. [35] This compares favourably with the auxiliary
3 3
√
numbers used in the Quadratic Sieve, which are around the size n.
1 2
q
This gives the GNFS expected running time O e c(ln n) 3 (ln ln n) 3
with c = 3 64
9 . [35]
See [28] for further discussion on the heuristic runtime of the GNFS.
Summary
The introduction of the RSA cryptosystem has stimulated significant research into a canon-
ical ‘hard’ problem. Since then, Legendre’s congruence has been fruitfully mined to produce
the current fastest known algorithm, the General Number Field Sieve. In 2009, Kleinjung
et al. factorised the 768-bit number RSA-768 using the GNFS. The sieving process was
distributed, taking almost two years, and the entire computation took more than 1020 oper-
ations. The team optimistically predicted that a 1024-bit modulus could be factored ‘...well
within the next decade.’ [23].
Although their prediction was not borne out, the factorisation of RSA-250, an 829-bit num-
ber, was announced on February 28th , 2020. [46] With the consistent increase in compu-
tational power, such records will continue to fall. However, without a further theoretical
breakthrough, ever larger keys should guarantee the security of RSA for the foreseeable fu-
ture. While the time complexity of our best algorithms remains non-polynomial, the problem
of factorising a large integer remains insurmountable.
One potential challenge to the security of RSA lies in recent developments in quantum com-
puting. In 1994, Peter Shor published a quantum algorithm that factorises n in O (log n)2+ .
[45] However, this polynomial-time algorithm remains theoretical until the development of
viable quantum computers. History has shown that even the most seemingly impregnable
cryptosystems eventually succumb to the determined cryptanalyst. Given that the RSA
problem is well-defined and understood, it seems inevitable that it too will eventually be
broken. The question remains: will this be via a classical theoretical, or a quantum techno-
logical, breakthrough?
49
Bibliography
[1] Bach, E. (1991). Toward a theory of Pollard’s rho method. Information and Computation,
90(2), 139-155.
[2] Barker, E., & Dang, Q. (2015). NIST special publication 800–57 part 3: Application-
specific key management guidance. NIST Special Publication, 800, 57.
[3] Bhaskar, J. (2008). Sum of two squares. University of Chicago (REU 2008).
[4] Brent, R. P., & Pollard, J. M. (1981). Factorization of the eighth Fermat number. Mathe-
matics of Computation, 36(154), 627. https://doi.org/10.1090/s0025-5718-1981-0606520-
5
[5] Brent, R. P. (1980). An improved Monte Carlo factorization algorithm. BIT, 20(2),
176–184. https://doi.org/10.1007/bf01933190
[6] Brent, R. P. (1999). Factorization of the tenth Fermat number. Mathematics of Compu-
tation, 68(225), 429–452. https://doi.org/10.1090/s0025-5718-99-00992-8
[7] Brent, R. P. (2000). Recent progress and prospects for integer factorisation algorithms.
In International Computing and Combinatorics Conference (pp. 3-22). Springer, Berlin,
Heidelberg.
[8] Briggs, M. E. (1998). An introduction to the general number field sieve (Dissertation,
Virginia Tech).
[9] Brillhart, J. (2009). A note on Euler’s factoring problem. The American Mathematical
Monthly, 116(10), 928-931.
[10] Buhler, J. P., Lenstra, H. W., & Pomerance, C. (1993). Factoring integers with the
number field sieve. In The development of the number field sieve (pp. 50-94). Springer,
Berlin, Heidelberg.
50
Bibliography 51
[12] Couveignes, J. M. (1993). Computing a square root for the number field sieve. In The
development of the number field sieve (pp. 95-102). Springer, Berlin, Heidelberg.
[13] Crandall, R., & Pomerance, C. B. (2010). Prime Numbers: A Computational Perspective
(2nd ed.). Springer.
[14] Diffie, W., & Hellman, M. (1976). New directions in cryptography. IEEE transactions
on Information Theory, 22(6), 644-654.
[16] Galbraith, S. (2012). The Mathematics of Public Key Cryptography. Cambridge: Cam-
bridge University Press.
[17] Gardner, M. (1977, August). Mathematical Games. In Scientific American. New York:
Munn & Co.
[18] Hardy, G. H., & Wright, E. M. (1979). An introduction to the theory of numbers. Oxford
University Press.
[20] Jones, G. A., & Jones, J. M. (1998). Elementary Number Theory (Springer Undergrad-
uate Mathematics Series) (Corrected ed.). Springer.
[22] Kleinjung, T. (2006). On polynomial selection for the general number field sieve. Math-
ematics of Computation, 75(256), 2037–2047. https://doi.org/10.1090/s0025-5718-06-
01870-9
[23] Kleinjung, T., Aoki, K., Franke, J., Lenstra, A. K., Thomé, E., Bos, J. W., ... &
Zimmermann, P. (2010, August). Factorization of a 768-bit RSA modulus. In Annual
Cryptology Conference (pp. 333-350). Springer, Berlin, Heidelberg.
Bibliography
Bibliography 52
[25] Lehmer, D. H., & Powers, R. E. (1931). On factoring large numbers. Bulletin of the
American Mathematical Society, 37(10), 770–777. https://doi.org/10.1090/s0002-9904-
1931-05271-x
[26] Lenstra, A. K., Lenstra, H. W., Manasse, M. S., & Pollard, J. M. (1993). The factor-
ization of the ninth Fermat number. Mathematics of Computation, 61(203), 319-349.
[27] Lenstra, A. K., Lenstra, H. W., Manasse, M. S., & Pollard, J. M. (1993). The number
field sieve. In The development of the number field sieve (pp. 11-42). Springer, Berlin,
Heidelberg.
[28] Lenstra, A. K. (2000). Integer factoring. Towards a quarter-century of public key cryp-
tography, 31-58.
[29] Lenstra, H. W. (1987). Factoring Integers with Elliptic Curves. The Annals of Mathe-
matics, 126(3), 649. https://doi.org/10.2307/1971363
[30] Montgomery, P. L. (1995, May). A block Lanczos algorithm for finding dependencies over
GF (2). In International Conference on the Theory and Applications of Cryptographic
Techniques (pp. 106-120). Springer, Berlin, Heidelberg.
[31] Morrison, M. A., & Brillhart, J. (1975). A Method of Factoring and the Factorization
of F7 . Mathematics of Computation, 29(129), 183. https://doi.org/10.2307/2005475
[32] Murphy, B. A. (1999). Polynomial selection for the number field sieve integer factorisa-
tion algorithm. Australian National University.
[33] Pollard, J. M. (1975). A monte carlo method for factorization. BIT, 15(3), 331–334.
https://doi.org/10.1007/bf01933667
[34] Pomerance C. (1985). The Quadratic Sieve Factoring Algorithm. In: Beth T., Cot N.,
Ingemarsson I. (eds) Advances in Cryptology. EUROCRYPT 1984. Lecture Notes in
Computer Science, vol 209. Springer, Berlin, Heidelberg.
[35] Pomerance, C. (1996). A tale of two sieves. In Notices Amer. Math. Soc.
[37] Rivest, R. L., Shamir, A., and Adleman, L. (1978). A method for obtaining digital
signatures and public-key cryptosystems., Communications of the ACM, 21(2), 120–126.
Bibliography
Bibliography 53
[38] Silverman, R. D. (1987). The multiple polynomial quadratic sieve. Mathematics of Com-
putation, 48(177), 329. https://doi.org/10.1090/s0025-5718-1987-0866119-8
[39] Sipser, M. (2014). Introduction to the Theory of Computation (3rd ed.). Cengage India.
[40] Stewart, I., & Tall, D. (2001). Algebraic Number Theory and Fermat’s Last Theorem:
Third Edition (3rd ed.). A K Peters/CRC Press.
[41] Stinson, D. R., & Paterson, M. (2018). Cryptography: Theory and Practice (Textbooks
in Mathematics) (4th ed.). Chapman and Hall/CRC.
[42] Talbot, J., and Welsh, D. (2006). Complexity and Cryptography: An Introduction (1st
ed.). Cambridge University Press.
[43] Thomé, E. (2012, July). Square root algorithms for the number field sieve. In Inter-
national Workshop on the Arithmetic of Finite Fields (pp. 208-224). Springer, Berlin,
Heidelberg.
[44] Tornarı́a, G. (2002, April). Square roots modulo p. In Latin American Symposium on
Theoretical Informatics (pp. 430-434). Springer, Berlin, Heidelberg.
[45] Yan, S. Y. (2010). Primality Testing and Integer Factorization in Public-Key Cryptog-
raphy (Advances in Information Security, 11) Springer.
Bibliography