YALE UNIVERSITY
DEPARTMENT OF COMPUTER SCIENCE

CPSC 467a: Cryptography and Computer Security Notes 13 (rev. 2)
Professor M. J. Fischer October 22, 2008



Lecture Notes 13

53 Chinese Remainder Theorem

We now return to a basic result of number theory that will be used later.

Let n1,n2,,nk be positive pairwise relatively prime positive integers1 , let n = i=1kni, and let ai ∈ Zi for i = 1,,k. Consider the system of congruence equations with unknown x:

x  ≡   a1 (mod  n1)
x  ≡   a2 (mod  n2)
    ..
    .
x  ≡   ak (mod nk)
(1)

The Chinese Remainder Theorem says that (1) has a unique solution in Zn.

To solve for x, let

Ni = n∕ni = n◟1n2..◝.◜ni-1◞ ⋅n◟i+1◝.◜..nk◞,

and compute Mi = Ni-1 mod ni, for 1 i k. Note that Ni-1 (mod ni) exists since gcd(Ni,ni) = 1 by the pairwise relatively prime condition. We can compute Ni-1 using the methods of section 47 (lecture notes 11). Now let

      k
x = (∑  a M N  ) mod n
     i=1 i  i i
(2)

If ji, then MjNj 0 (mod ni) since ni|Nj. On the other hand, MiNi 1 (mod ni) by definition of Mi. Hence,

    ∑k
x ≡    aiMiNi ≡  0◟a1 +-..◝.◜+-0ai-1◞+1ai + 0◟ai+1◝..◜.0ak◞ ≡ ai (mod ni)
    i=1
(3)

for all 1 i k, establishing that (2) is a solution of (1).

To see that the solution is unique in Zn, let χ be the mapping x↦→(x mod n1,,x mod nk). χ is a surjection2 from Zn to Zn1 ×× Znk since we have just shown for all (a1,,ak) ∈ Zn1 ×× Znk that there exists x ∈ Zn such that χ(x) = (a1,,ak). Since also |Zn| = |Zn1 ××Znk|, χ is a bijection, and (1) has only one solution in Zn.

A less slick but more direct way of seeing the same thing is to suppose that x = u and x = v are both solutions to (1). Then u v (mod ni), so ni|(u - v) for all i. By the pairwise relatively prime condition on the ni, it follows that n|(u - v), so u v (mod n). Hence, the solution is unique in Zn.

54 Homomorphic property of χ

The bijection χ is interesting in its own right, for it establishes a one-to-one correspondence between members of Zn and k-tuples (a1,,ak) in Zn1 × × Znk. This lets us reason about and compute with k-tuples and then translate the results back to Zn.

The homomorphic property of χ means that performing an arithmetic operation on x ∈ Zn corresponds to performing the similar operation on each of the components of χ(x). More precisely, let be one of the arithmetic operations +, -, or ×. If χ(x) = (a1,,ak) and χ(y) = (b1,,bk), then

χ ((x ⊙ y) mod n) = ((a1 ⊙ b1) mod n1, ..., (ak ⊙ bk) mod nk).
(4)

In other words, if one first performs z = (x y) mod n and then computes z mod ni, the result is the same as if one instead first computed ai = (x mod ni) and bi = (y mod ni) and then performed (ai bi) mod ni. This relies on the fact that (z mod n) mod ni = z mod ni, which holds because ni n.

55 RSA Decryption Works for All of Zn

In section 44 (lecture notes 10), we showed that RSA decryption works when m,c ∈ Z*n but omitted the proof that it actually works for all m,c ∈ Zn. We now use the Chinese Remainder Theorem to supply this missing piece.

Let n = pq be an RSA modulus, p,q distinct primes, and let e and d be the RSA encryption and decryption exponents, respectively. We show med m (mod n) for all m ∈ Zn.

Define a = (m mod p) and b = (m mod q), so

m ≡  a (mod p)
m  ≡ b (mod q)
(5)

Raising both sides to the power ed gives

med ≡  aed (mod p)
 med ≡ bed (mod  q)
(6)

We now argue that aed a (mod p). If a 0 (mod p), then obviously aed 0 a (mod p). If a ⁄≡ 0 (mod p), then gcd(a,p) = 1 since p is prime, so a ∈ Z*p. By Euler’s theorem,

aϕ(p) ≡ 1 (mod p)

Since ed 1 (mod ϕ(n)), we have ed = 1 + (n) = 1 + (p)ϕ(q) for some integer u. Hence,

 ed    1+u ϕ(p)ϕ(q)     ( ϕ(p))uϕ(q)      uϕ(q)
a  ≡ a          ≡ a ⋅ a         ≡ a ⋅1     ≡ a (mod p)
(7)

Similarly,

bed ≡ b (mod  q)
(8)

Combining the pair (6) with (7) and (8) yields

  ed
m   ≡  a (mod p)
 med ≡ b (mod q)
Thus, med is a solution to the system of equations
x ≡ a (mod  p)
 x ≡ b (mod  q)
(9)

From (5), m is also a solution of (9). By the Chinese Remainder Theorem, the solution to (9) is unique modulo n, so med m (mod n) as desired.

56 RSA Security

Several possible attacks on RSA are discussed below and their relative computational difficulties discussed.

56.1 Factoring n

The security of RSA depends on the computational difficulty of several different problems, corresponding to different ways that Eve might attempt to break the system. The first of these is the RSA factoring problem: Given a number n that is known to be the product of two primes p and q, find p and q. Clearly if Eve can find p and q, then she can compute the decryption key d from the public encryption key e (in the same way that Alice did when generating the key) and subsequently decrypt all ciphertexts.

56.2 Computing ϕ(n)

Eve doesn’t really need to know the factors of n in order to compute d. It is enough for her to know ϕ(n). Computing ϕ(n) is no harder than factoring n since ϕ(n) is easily computed given the factors of n, but is it perhaps easier? If it were, then Eve would have a possible attack on RSA different from factoring n. It turns out that it is not easier, for if Even knows ϕ(n), then she can factor n. She simply sets up the system of quadratic equations

   n  =   pq
ϕ(n)  =   (p - 1)(q - 1)
in two unknowns p and q and solves for p and q using standard methods of algebra.

56.3 Finding d

Another possibility is that Eve might somehow be able to compute d from e and n even without the ability to factor n or compute ϕ(n). That would represent yet another attack that couldn’t be ruled out by the assumption that the RSA factoring problem is hard. However, that too is not possible, as we now show.

Suppose Eve knows n and e and is somehow able to obtain d. Then Eve can factor n by a probabilistic algorithm. The algorithm is presented in Figure56.1.


To factor n:

/* Find s, t such that ed - 1 = 2st and t is odd */

s = 0; t = ed - 1;

while (t is even ) {s++; t∕=2;}

/* Search for non-trivial square root of 1 (mod n) */

do {

/* Find a random square root b of 1 (mod n) */

choose a ∈ Z*n at random;

b = at mod n;

while (b2 ⁄≡ 1 (mod n)) b = b2 mod n;

} while (b ≡±1 (mod n));

/* Factor n */

p = gcd(b - 1,n);

q = n∕p;

return (p,q);

}


Figure 56.1: Algorithm for factoring n given d.


We begin by finding unique integers s and t such that 2st = ed- 1 and t is odd. This is always possible since ed - 10. One way to find s and t is to express ed - 1 in binary. Then s is the number of trailing zeros and t is the value of the binary number that remains after the trailing zeros are removed. Since ed - 1 0 (mod ϕ(n)) and 4ϕ(n) (since both p - 1 and q - 1 are even), it follows that s 2.

Now, for each a chosen at random from Z*n, define a sequence b0,b1,,bs, where bi = a2it mod n, 0 i s. Each number in the sequence is the square of the number preceding it modulo n. The last number in the sequence is 1 by Euler’s theorem and the fact that ϕ(n)(ed- 1). Since 12 mod n = 1, every element of the sequence following the first 1 is also 1. Hence, the sequence consists of a (possibly empty) block of non-1 elements, following by a block of 1’s.

It is easily verified that b0 is the value of b when the innermost while loop is first entered, and bk is the value of b after the kth iteration of that loop. The loop executes at most s- 1 times since it terminates just before the first 1 is encounter, that is, when b2 1 (mod n). At this time, b = bk is a square root of 1 (mod n).

Over the reals, we know that each positive number has two square roots, one positive and one negative, and no negative numbers have real square roots. Over Z*n for n = pq, it turns out that 14 of the numbers have square roots, and each number that has a square root actually has four. Since 1 does have a square root modulo n (itself), there are four possibilities for b: ±1 mod n and ±r mod n for some r ∈ Z*n, r ⁄≡±1 (mod n).

The do loop terminates if and only if b ⁄≡±1 (mod n). At that point we can factor n. Since b2 1 (mod n), we have n(b2 - 1) = (b + 1)(b- 1). But since b ⁄≡±1 (mod n), n does not divide b + 1 and n does not divide b - 1. Therefore, one of the factors of n divides b + 1 and the other divides b - 1. Hence, gcd(b - 1,n) is a non-trivial factor of n.

It can be shown that there is at least a 0.5 probability that b ⁄≡±1 (mod n) for the b computed by this algorithm in response to a randomly chosen a ∈ Z*n. Hence, the expected number of iterations of the do loop is at most 2. (See Evangelos Kranakis, Primality and Cryptography, Theorem 5.1 for details.)

Here’s a simple example of the use of this algorithm. Suppose n = 5 × 11 = 55, e = 3, and d = 27. (These are possible RSA values since ϕ(n) = 40 and ed = 81 1 (mod 40).) Then ed - 1 = 80 = (1010000)2, so s = 4 and t = 5.

Now, suppose we take a = 2. We compute the sequence of b’s as follows:

     t          5
b0 = a  mo2d n = 2  mod255 = 32
b1 = (b0)2mod  n = (32 )2 mod 55 = 1024 mod  55 = 34
b2 = (b1) mod  n = (34 ) mod 55 = 1156 mod  55 = 1
b3 = (b2)2 mod n = (1 )2 mod 55 = 1
b4 = (b3)2 mod n = (1 )2 mod 55 = 1

Since the last bi1 in this sequence is 34, and 34 ⁄≡-1 (mod 55), then 34 is a non-trivial square root of 1 modulo 55. It follows that gcd(34 - 1,55) = 11 is a prime divisor of n.

56.4 Finding plaintext

Eve isn’t really interested in factoring n, computing ϕ(n), or finding d, except as a means to read Alice’s secret messages. Hence, the problem we would like to be hard is the problem of computing the plaintext m given an RSA public key (n,e) and a ciphertext c. The above shows that this problem is no harder than factoring n, computing ϕ(n), or finding d, but it does not rule out the possibility of some clever way of decrypting messages without actually finding the decryption key. Perhaps there is some feasible probabilistic algorithm that finds m with non-negligible probability, maybe not even for all ciphertexts c but for some non-negligible fraction of them. Such a method would “break” RSA and render it useless in practice. No such algorithm has been found, but neither has the possibility been ruled out, even under the assumption that the factoring problem itself is hard.

57 Primitive Roots

We have completed our discussion of RSA. We turn next to other number-theoretic techniques with important cryptographic applications. We begin by looking in greater detail at the structure of Z*n, the set of integers relatively prime to n.

Let g ∈ Z*n and consider the successive powers g,g2,g3,, all taken modulo n. Because Z*n is finite, this sequence must eventually repeat. By Euler’s theorem, this sequence contains 1 since gk = 1 (in Zn) for k = ϕ(n). Let k be the smallest positive integer such that gk = 1. We call k the order of g and write ord(g) = k. The elements {g,g2,,gk = 1} form a subgroup S of Z*n. The order of S (number of elements in S) is ord(g); hence ord(g)ϕ(n). We say that g generates S and that S is cyclic.

We say g is a primitive root of n if g generates all of Z*n, that is, every element of Z*n can be written as g raised to some power modulo n. By definition, this holds if and only if ord(g) = ϕ(n). Not every integer n has primitive roots. By Gauss’s theorem, the numbers having primitive roots are 1,2,4,pk,2pk, where p is an odd prime and k 1. In particular, every prime has primitive roots.

The number of primitive roots of p is ϕ(ϕ(p)). This is because if g is a primitive root of p and x ∈ Z*ϕ(p), then gx is also a primitive root of p. Why? We need to argue that every element h in Z*p can be expressed as (gx)y for some y. Since g is a primitive root, we know that h g (mod p) for some . We wish to find y such that gxy g (mod n). By Euler’s theorem, this is possible if the congruence equation xy (mod ϕ(n)) has a solution y. We know that a solution exists if gcd(x,ϕ(n)) = 1. But this is the case since x was chosen to be in Z*ϕ(p).