<<

Z∗ Z∗ MATH/CSCI 4116: CRYPTOGRAPHY, FALL 2014 Then G is a subgroup of n, thus |G| 6 | n|. Since n is not a Fermat pseudo- Z∗ Z∗ Handout 3: The Miller-Rabin , there exists some b ∈ n with b 6∈ G, thus |G| < | n|. It follows that 1 Z∗ n−1 |G| 6 2 | n| 6 2 . Finally, whenever b ∈ {1,...,n − 1} and b 6∈ G, then b Peter Selinger n−1 fails the test; there are at least 2 such elements. 1.3 (Fermat test). 1 Fermat Input: n > 2 and t > 1. Output: If n is prime, output “yes”. If n is not a , output “no” A primality test is an algorithm that, given an n, decides whether n is prime with at least 1 − 1/2t, “yes” with probability at most 1/2t. or not. The most naive algorithm, trial , is hopelessly inefficient when n is Algorithm: Pick t independent, uniformly distributed random b1,...,bt ∈ very large. Fortunately, there exist much more efficient for determining −1 . If n mod for all , output “yes”, else output “no”. whether n is prime. The most common such algorithms are probabilistic; they {1,...,n − 1} bi ≡ 1( n) i give the correct answer with very high probability. All efficient primality testing algorithms are based, in one way or another, on Fermat’s Little Theorem. Proof. We prove that the output of the algorithm is as specified. If n is prime, then the algorithm outputs “yes” by Fermat’s Little Theorem. If n is not a Fermat Theorem 1.1 (Fermat). If is prime, then for all b ∈{1,...,p − 1}, pseudoprime, then by Proposition 1.2, n passes the test at base bi with probability at most 1 . Hence the probability that n passes all t tests is at most 1/2t.  −1 2 bp ≡ 1(mod p). Algorithm 1.3 can distinguish prime numbers from non-Fermat-pseudoprimes. Definition (Fermat pseudoprime). Let n > 2 and b ∈{1,...,n−1}. We say that We did not specify its behavior if the input is a Carmichael . As a matter of n−1 the number n passes the Fermat pseudoprime test at base b if b ≡ 1(mod n). fact, if the input is a , the algorithm will usually output “yes”, A number n is called a Fermat pseudoprime if it passes the Fermat pseudoprime but will output “no” with a small probability (namely, when n has a common test for all b ∈ Z∗ . n prime factor with one of the bi).

By Fermat’s Little Theorem, every is a Fermat pseudoprime. Un- fortunately, the converse does not hold. There are Fermat pseudoprimes that 2 Carmichael numbers are not prime. Such numbers are called Carmichael numbers. The first few Carmichael numbers are 561, 1105, 1729,... Before describing an improved version of the primality testing algorithm, we prove some useful propertiesof Carmichael numbers, i.e., non-prime Fermat pseu- Nevertheless, the notion of a Fermat pseudoprime is a useful notion, not least doprimes. because there is a very efficient probabilistic algorithm for checking whether a e ∗ > Z e given number n is a Fermat pseudoprime. Lemma 2.1. Let p be a with e 2. Then the p has an element of p. Proposition 1.2. If n is not a Fermat pseudoprime, then n fails the Fermat pseu- e−1 Z Z∗ doprime test at base b for at least half of the elements b ∈{1,...,n − 1}. Proof. Consider G = {1+ p x | x ∈ pe }. Clearly G is a subgroup of pe with p elements. Since p is prime, each element g ∈ G has order 1 or p. The only Proof. Suppose n is not a Fermat pseudoprime, and let element of G of order 1 is 1, hence e.g. g =1+ pe−1 has order p.  Z n−1 Z∗ Proposition 2.2. Let n be a Carmichael number. Then n is odd, andwe can factor G = {b ∈ n | b ≡ 1(mod n)}⊆ n. n = m1m2, where m1,m2 > 3 and gcd(m1,m2)=1.

1 2 Proof. To show that n is odd, assume on the contrary that it is even. Then n > Proof. Let n − 1=2sl as before. If n is not a Fermat pseudoprime, then the 4, since 2 is not a Carmichael number. Moveover, n − 1 is odd, so we have result follows from Proposition 1.2 and Remark 3.1. So let us consider the case n−1 (−1) ≡ −1(mod n). It follows that n fails the Fermat pseudoprime test at where n is a Carmichael number. By Proposition 2.2, we can write n = m1m2, l base b = −1. where m1,m2 > 3 and gcd(m1,m2)=1. Since l is odd, we have (−1) 6≡ 1(mod n). Let r be the maximal integer such that there exists some b ∈ Z∗ with To show that n has the desired , it suffices to show that two distinct r n 2 l 6 primes occur in the prime factorization of n. Since n is not itself prime, this is b 6≡ 1(mod n). Note that 0 r 2. ∗ 2r G = {b ∈ Z | b l ≡±1(mod n)}. Suppose, for contradiction, that n = pe. Then, by Lemma 2.1, there is an element n ∗ −1 Z n ∗ ∗ x ∈ n of order p. Since n is a Fermat pseudoprime, we also have x ≡ Clearly, G is a subgroup of Z , hence |G| divides |Z |. We now show that G is n n r 1(mod n), hence p|n − 1. But this is impossible since p|n.  a strict of Z∗ . By definition of r, there exists some b ∈ Z∗ with b2 l 6≡ n r n 1(mod n). Then either b 6∈ G, or else b2 l ≡ −1(mod n). In the latter case, use ′ Z∗ ′ the Chinese Remainder Theorem to define b ∈ n such that b ≡ b(mod m1) ′ ′2rl ′2rl 3 Strong Pseudoprimes and b ≡ 1(mod m2). Then b ≡ −1(mod m1) and b ≡ 1(mod m2). This r ′2 l ′ Z∗ implies b 6≡ ±1(mod n), hence b 6∈ G. In either case, G 6= n. Thus, Definition (). Let n be odd and write n − 1=2sl, where l is Z∗ 1 Z∗ n−1 |G| < | n|, hence |G| 6 2 | n| 6 2 . odd. Given b, compute the following elements of Z : n Finally, we claim that for all b ∈ {1,...,n − 1} with b 6∈ G, n fails the strong − n−1 l 2l 4l 2s 1l 2sl n−1 pseudoprime test at base b. Indeed, either b is not a , in which case b 6≡ b , b , b , ..., b , b = b . r+1 r 1(mod n). Or else, b2 l ≡ 1(mod n) but b2 l 6≡ ±1(mod n), causing the test to l n−1 We say that n passes the strong pseudoprime test at base b if either b ≡ 1(mod n) fail. As there are at least 2 elements in {1,...,n − 1}\ G, we are done.  r or b2 l ≡−1(mod n) for some 0 6 r

3 4