RSA and Primality Testing
Total Page:16
File Type:pdf, Size:1020Kb
RSA and Primality Testing Joan Boyar, IMADA, University of Southern Denmark Studieretningsprojekter 2010 1 / 81 Outline Outline Symmetric key ■ Symmetric key cryptography Public key Number theory ■ RSA Public key cryptography RSA Modular ■ exponentiation Introduction to number theory RSA RSA ■ RSA Greatest common divisor Primality testing ■ Modular exponentiation Correctness of RSA Digital signatures ■ Greatest common divisor ■ Primality testing ■ Correctness of RSA ■ Digital signatures with RSA 2 / 81 Caesar cipher Outline Symmetric key Public key Number theory A B C D E F G H I J K L M N O RSA 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 RSA Modular D E F G H I J K L M N O P Q R exponentiation RSA 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 RSA Greatest common divisor Primality testing P Q R S T U V W X Y Z Æ Ø Å Correctness of RSA Digital signatures 15 16 17 18 19 20 21 22 23 24 25 26 27 28 S T U V W X Y Z Æ Ø Å A B C 18 19 20 21 22 23 24 25 26 27 28 0 1 2 E(m)= m + 3(mod 29) 3 / 81 Symmetric key systems Outline Suppose the following was encrypted using a Caesar cipher and the Symmetric key Public key Danish alphabet. The key is unknown. What does it say? Number theory RSA RSA Modular exponentiation RSA ZQOØQOØ, RI. RSA Greatest common divisor Primality testing Correctness of RSA Digital signatures 4 / 81 Symmetric key systems Outline Suppose the following was encrypted using a Caesar cipher and the Symmetric key Public key Danish alphabet. The key is unknown. What does it say? Number theory RSA RSA Modular exponentiation RSA ZQOØQOØ, RI. RSA Greatest common divisor Primality testing Correctness of RSA What does this say about how many keys should be possible? Digital signatures 5 / 81 Symmetric key systems Outline Symmetric key ■ Caesar Cipher Public key Number theory ■ RSA RSA Modular ■ exponentiation RSA RSA ■ Enigma Greatest common divisor Primality testing ■ DES Correctness of RSA Digital signatures ■ Blowfish ■ IDEA ■ Triple DES ■ AES 6 / 81 Public key cryptography Outline Bob — 2 keys -PK ,SK Symmetric key B B Public key Number theory PK — Bob’s public key RSA B RSA SKB — Bob’s private (secret) key Modular exponentiation RSA For Alice to send m to Bob, RSA Greatest common Alice computes: c = E(m, PKB). divisor Primality testing Correctness of RSA To decrypt c, Bob computes: Digital signatures r = D(c, SKB). r = m It must be “hard” to compute SKB from PKB. 7 / 81 Introduction to Number Theory Outline Definition. Suppose a, b ZZ, a> 0. Symmetric key ∈ Public key Suppose c ZZ s.t. b = ac. Then a divides b. Number theory ∃ ∈ a b. RSA | RSA a is a factor of b. Modular exponentiation b is a multiple of a. RSA RSA e f means e does not divide f. Greatest common | divisor Primality testing Theorem. a, b, c ZZ. Then Correctness of RSA ∈ Digital signatures 1. if a b and a c, then a (b + c) | | | 2. if a b, then a bc c ZZ | | ∀ ∈ 3. if a b and b c, then a c. | | | 8 / 81 Outline Definition. p ZZ, p> 1. Symmetric key ∈ Public key p is prime if 1 and p are the only positive integers which divide p. Number theory RSA 2, 3, 5, 7, 11, 13, 17,... RSA p is composite if it is not prime. Modular exponentiation 4, 6, 8, 9, 10, 12, 14, 15, 16,... RSA RSA Greatest common divisor Primality testing Correctness of RSA Digital signatures 9 / 81 Outline Theorem. a ZZ, d IN Symmetric key ∈ ∈ Public key unique q,r, 0 r<d s.t. a = dq + r Number theory ∃ ≤ RSA RSA Modular exponentiation d – divisor RSA a – dividend RSA Greatest common q – quotient divisor Primality testing r – remainder = a mod d Correctness of RSA Digital signatures Definition. gcd(a, b) = greatest common divisor of a and b = largest d ZZ s.t. d a and d b ∈ | | If gcd(a, b) = 1, then a and b are relatively prime. 10 / 81 Outline Definition. a b (mod m) — a is congruent to b modulo m Symmetric key ≡ Public key if m (a b). Number theory | − RSA RSA m (a b) k ZZ s.t. a = b + km. Modular | − ⇒ ∃ ∈ exponentiation RSA Theorem. a b (mod m) c d (mod m) RSA ≡ ≡ Greatest common Then a + c b + d (mod m) and ac bd (mod m). divisor ≡ ≡ Primality testing Correctness of RSA Digital signatures Proof.(of first) k ,k s.t. ∃ 1 2 a = b + k1m c = d + k2m a + c = b + k1m + d + k2m = b + d +(k1 + k2)m 11 / 81 Outline Definition. a b (mod m) — a is congruent to b modulo m Symmetric key ≡ Public key if m (a b). Number theory | − RSA RSA m (a b) k ZZ s.t. a = b + km. Modular | − ⇒ ∃ ∈ exponentiation RSA Examples. RSA Greatest common divisor 1. 15 22 (mod 7)? 15 = 22 (mod 7)? Primality testing ≡ Correctness of RSA Digital signatures 2. 15 1 (mod 7)? 15=1(mod 7)? ≡ 3. 15 37 (mod 7)? 15 = 37 (mod 7)? ≡ 4. 58 22 (mod 9)? 58 = 22 (mod 9)? ≡ 12 / 81 RSA — a public key system Outline NA = pA qA, where pA,qA prime. Symmetric key · Public key gcd(eA, (pA 1)(qA 1)) = 1. Number theory − − RSA eA dA 1 (mod (pA 1)(qA 1)). RSA · ≡ − − Modular exponentiation ■ PKA =(NA,eA) RSA RSA ■ Greatest common SKA =(NA,dA) divisor Primality testing eA Correctness of RSA To encrypt: c = E(m, PKA)= m (mod NA). Digital signatures dA To decrypt: r = D(c, PKA)= c (mod NA). r = m. 13 / 81 RSA — a public key system Outline NA = pA qA, where pA,qA prime. Symmetric key · Public key gcd(eA, (pA 1)(qA 1)) = 1. Number theory − − RSA eA dA 1 (mod (pA 1)(qA 1)). RSA · ≡ − − Modular exponentiation ■ PKA =(NA,eA) RSA RSA ■ Greatest common SKA =(NA,dA) divisor Primality testing eA Correctness of RSA To encrypt: c = E(m, PKA)= m (mod NA). Digital signatures dA To decrypt: r = D(c, PKA)= c (mod NA). r = m. Example: p = 5, q = 11, e = 3, d = 27, m = 8. Then N = 55. e d = 81. So e d =1(mod 4 10). · · · To encrypt m: c = 83 (mod 55) = 17. To decrypt c: r = 1727 (mod 55) = 8. 14 / 81 Security of RSA Outline The primes p and q are kept secret with d . Symmetric key A A A Public key Number theory Suppose Eve can factor N . RSA A RSA Modular exponentiation Then she can find pA and qA. RSA From them and eA, she finds dA. RSA Greatest common divisor Primality testing Then she can decrypt just like Alice. Correctness of RSA Digital signatures Factoring must be hard! 15 / 81 Factoring Outline Symmetric key Theorem. N composite N has a prime divisor √N Public key ⇒ ≤ Number theory RSA RSA Factor(n) Modular exponentiation RSA for i = 2 to √n do RSA Greatest common check if i divides n divisor if it does then output (i,n/i) Primality testing Correctness of RSA endfor Digital signatures output -1 if divisor not found Corollary There is an algorithm for factoring N (or testing primality) which does O(√N) tests of divisibility. 16 / 81 Factoring Outline Symmetric key Check all possible divisors between 2 and √n. Public key Not finished in your grandchildren’s life time for n with 1024 bits. Number theory RSA RSA Problem The length of the input is n = log2(N + 1) . So the Modular n/2 ⌈ ⌉ exponentiation running time is O(2 ) — exponential. RSA RSA Greatest common Open Problem Does there exist a polynomial time factoring divisor Primality testing algorithm? Correctness of RSA Digital signatures Use primes which are at least 512 (or 1024) bits long. So 2511 p ,q < 2512. ≤ A A So p 10154. A ≈ 17 / 81 RSA Outline How do we implement RSA? Symmetric key Public key Number theory We need to find: p ,q ,N ,e ,d . RSA A A A A A RSA We need to encrypt and decrypt. Modular exponentiation RSA RSA Greatest common divisor Primality testing Correctness of RSA Digital signatures 18 / 81 RSA — encryption/decryption Outline k Symmetric key We need to encrypt and decrypt: compute a (mod n). Public key Number theory 2 RSA a (mod n) a a (mod n) — 1 modular multiplication RSA ≡ · Modular exponentiation RSA RSA Greatest common divisor Primality testing Correctness of RSA Digital signatures 19 / 81 Modular Exponentiation Outline Theorem. For all nonnegative integers, b, c, m, Symmetric key Public key b c (mod m)=(b (mod m)) (c (mod m)) (mod m). Number theory · · RSA 2 2 RSA Example: a a (mod n)=(a (mod n))(a (mod n)) (mod n). Modular · exponentiation RSA RSA Greatest common divisor 83 (mod 55) = 8 82 (mod 55) Primality testing · Correctness of RSA = 8 64 (mod 55) Digital signatures · = 8 (9+55) (mod 55) · = 72 + (8 55) (mod 55) · = 17 + 55 + (8 55) (mod 55) · = 17 20 / 81 RSA — encryption/decryption Outline k Symmetric key We need to encrypt and decrypt: compute a (mod n). Public key Number theory a2 (mod n) a a (mod n) — 1 modular multiplication RSA ≡ · RSA a3 (mod n) a (a a (mod n)) (mod n) — 2 mod mults Modular ≡ · · exponentiation RSA RSA Greatest common divisor Primality testing Correctness of RSA Digital signatures 21 / 81 RSA — encryption/decryption Outline k Symmetric key We need to encrypt and decrypt: compute a (mod n).