Lecture 8: Primality Testing and Factoring Piotr Faliszewski

Slides:



Advertisements
Similar presentations
Prime recognition and factorization
Advertisements

WS Algorithmentheorie 03 – Randomized Algorithms (Primality Testing) Prof. Dr. Th. Ottmann.
Cryptography and Network Security
Chapter 8 – Introduction to Number Theory. Prime Numbers prime numbers only have divisors of 1 and self –they cannot be written as a product of other.
MS 101: Algorithms Instructor Neelima Gupta
Agrawal-Kayal-Saxena Presented by: Xiaosi Zhou
Primality Testing Patrick Lee 12 July 2003 (updated on 13 July 2003)
Announcements: 1. Congrats on reaching the halfway point once again! 2. DES graded soon 3. Short “pop” quiz on Ch 3. (Thursday at earliest) 4. Reminder:
Chapter 8 More Number Theory. Prime Numbers Prime numbers only have divisors of 1 and itself They cannot be written as a product of other numbers Prime.
Introduction to Modern Cryptography Lecture 6 1. Testing Primitive elements in Z p 2. Primality Testing. 3. Integer Multiplication & Factoring as a One.
COM 5336 Cryptography Lecture 7a Primality Testing
Notation Intro. Number Theory Online Cryptography Course Dan Boneh
Great Theoretical Ideas in Computer Science.
Announcements: 1. Term project groups and topics due tomorrow midnight Waiting for posts from most of you. Questions? This week: Primality testing, factoring.
and Factoring Integers (I)
Announcements: 1. Pass in Homework 5 now. 2. Term project groups and topics due by Friday 1.Can use discussion forum to find teammates 3. HW6 posted, due.
1 Fingerprint 2 Verifying set equality Verifying set equality v String Matching – Rabin-Karp Algorithm.
The RSA Cryptosystem and Factoring Integers (II) Rong-Jaye Chen.
Factoring 1 Factoring Factoring 2 Factoring  Security of RSA algorithm depends on (presumed) difficulty of factoring o Given N = pq, find p or q and.
מבוא מורחב - שיעור 6 1 Lecture 6 High order procedures Primality testing The RSA cryptosystem.
Cryptography Lecture 11: Oct 12. Cryptography AliceBob Cryptography is the study of methods for sending and receiving secret messages. adversary Goal:
and Factoring Integers
Announcements: 1. Pass in worksheet on using RSA now. 2. DES graded soon 3. Short “pop” quiz on Ch 3 (Thursday at earliest) 4. Term project groups and.
CSE 321 Discrete Structures Winter 2008 Lecture 8 Number Theory: Modular Arithmetic.
Theory I Algorithm Design and Analysis (9 – Randomized algorithms) Prof. Dr. Th. Ottmann.
Factoring Algorithms Ref: D. Stinson, Cryptography - Theory and Practice, 2001.
Chapter 8 – Introduction to Number Theory Prime Numbers
Cryptography and Network Security Chapter 8. Chapter 8 – Introduction to Number Theory The Devil said to Daniel Webster: "Set me a task I can't carry.
RSA Question 2 Bob thinks that p and q are primes but p isn’t. Then, Bob thinks ©Bob:=(p-1)(q-1) = Á(n). Is this true ? Bob chooses a random e (1 < e
Public key ciphers 1 Session 5.
The RSA Algorithm Based on the idea that factorization of integers into their prime factors is hard. ★ n=p . q, where p and q are distinct primes Proposed.
Topic 18: RSA Implementation and Security
CSE 321 Discrete Structures Winter 2008 Lecture 10 Number Theory: Primality.
Chapter 9 Mathematics of Cryptography Part III: Primes and Related Congruence Equations Copyright © The McGraw-Hill Companies, Inc. Permission required.
Software Security Seminar - 1 Chapter 11. Mathematical Background 발표자 : 안병희 Applied Cryptography.

RSA Parameter Generation Bob needs to: - find 2 large primes p,q - find e s.t. gcd(e, Á (pq))=1 Good news: - primes are fairly common: there are about.
MA/CSSE 473 Day 08 Randomized Primality Testing Carmichael Numbers Miller-Rabin test.
Cryptography Dec 29. This Lecture In this last lecture for number theory, we will see probably the most important application of number theory in computer.
MA/CSSE 473 Day 11 Primality testing summary Data Encryption RSA.
PRIMES is in P Manindra Agrawal NUS Singapore / IIT Kanpur.
Cryptography Lecture 7: RSA Primality Testing Piotr Faliszewski.
Analyzing and Testing justified Prime Numbers
6.4 Factoring.
Scott CH Huang COM 5336 Cryptography Lecture 6 Public Key Cryptography & RSA Scott CH Huang COM 5336 Cryptography Lecture 6.
9/22/15UB Fall 2015 CSE565: S. Upadhyaya Lec 7.1 CSE565: Computer Security Lecture 7 Number Theory Concepts Shambhu Upadhyaya Computer Science & Eng. University.
Ch1 - Algorithms with numbers Basic arithmetic Basic arithmetic Addition Addition Multiplication Multiplication Division Division Modular arithmetic Modular.
RSA cryptosystem--preview Suppose n=p  q and  (n)=(p-1)(q-1), where p and q are big primes. Select (find) a and b, such that a  b=1 mod  (n). K=(n,p,q,a,b),
Implementation Issues for Public Key Algorithms
6.3 Primality Testing. p2. (1) Prime numbers 1. How to generate large prime numbers? (1) Generate as candidate a random odd number n of appropriate size.
Primality Testing. Introduction The primality test provides the probability of whether or not a large number is prime. Several theorems including Fermat’s.
Implementation of Public Key Encryption Algorithms
Chapter 1 Algorithms with Numbers. Bases and Logs How many digits does it take to represent the number N >= 0 in base 2? With k digits the largest number.
MA/CSSE 473 Day 10 Primality Testing. MA/CSSE 473 Day 10 In-class exam: Friday, Sept 28 –You may bring a two-sided 8.5x11 inch piece of paper containing.
Lecture 6. RSA Use in Encryption to encrypt a message M the sender: – obtains public key of recipient PU={e,n} – computes: C = M e mod n, where 0≤M
Key Exchange in Systems VPN usually has two phases –Handshake protocol: key exchange between parties sets symmetric keys –Traffic protocol: communication.
MA/CSSE 473 Day 9 Primality Testing Encryption Intro.
PRIMES is in P Manindra Agrawal Neeraj Kayal Nitin Saxena Dept of CSE, IIT Kanpur.
RSA Encryption Greg Gronn Laura Trimmer. RSA Encryption  Requires two 30 digit prime numbers to create an encoding/decryption key.  Goal: analyze different.
Public Key Encryption Major topics The RSA scheme was devised in 1978
Mathematics of Cryptography
CSE565: Computer Security Lecture 7 Number Theory Concepts
Randomness and Computation: Some Prime Examples
Public Key Cryptosystems - RSA
Cryptography Lecture 22.
Introduction to Cryptography
Patrick Lee 12 July 2003 (updated on 13 July 2003)
Cryptography Lecture 18.
Cryptography Lecture 20.
Presentation transcript:

Lecture 8: Primality Testing and Factoring Piotr Faliszewski Cryptography Lecture 8: Primality Testing and Factoring Piotr Faliszewski

Previous Class Attacks on RSA Practical RSA Known digits attacks Low exponent attacks Short plaintext attacks Timing attacks Practical RSA Exponentiation modulo n Primality testing

Factoring and Primality Testing Input: n  N Output: nontrivial factor of n Primality testing Input n  N Output: the number is composite the number is probably prime Is there a difference? Yes! – primality testing much easier! You do not need to factor the number to see it is composite

Miller-Rabin Test Generalization of the Fermat’s test Principle if p is a prime then x2 = 1 (mod p) has only two solutions: x = 1 and x = -1 Why does the principle hold? Gist of the MR test find a number b such that b2 = 1 (mod p) If b  {-1,1} then composite

Miller-Rabin Test What are we doing? b0 = am (mod n) b1 = a2m (mod n) MR( int n ): let n-1 = 2km a  random in {2, 3, ..., n-2 } b0 = am (mod n) if b0 = ±1 (mod n) then declare prime for j = 1 to k-1 do bj = bj-12 (mod n) if bj = 1 (mod n) then declare composite if bj = -1 (mod n) then declare prime declare composite What are we doing? b0 = am (mod n) b1 = a2m (mod n) b2 = a4m (mod n) ... bj = a2jm (mod n) bk-1 = a(n-1)/2 (mod n)

Miller-Rabin Test: Examples k = 7, m = 3 a = 9 b0 = 93 = 344 (mod 385) b1 = 93*2 = 141 (mod 385) b2 = 93*22 = 246 (mod 385) b3 = 93*23 = 71 (mod 385) b4 = 93*24 = 36 (mod 385) b5 = 93*25 = 141 (mod 385) n = 3*11*17 = 561 n -1 = 560 = 24*35 k = 4, m = 35 a = 2 b0 = 235 = 263 (mod 561) b1 = 235*2 = 166 (mod 561) b2 = 235*22 = 67 (mod 561) b3 = 235*23 = 1 (mod 561) Proof of compositeness!

Miller-Rabin Test: Examples k = 4, m = 25 a = 3 b0 = 325 = 268 (mod 401) b1 = 325*2 = 45 (mod 401) b2 = 325*22 = 20 (mod 401) b3 = 325*23 = 400 (mod 401) = -1 (mod 401) n = 401 n -1 = 400 = 24*25 k = 4, m = 25 a = 2 b0 = 225 = 356 (mod 401) b1 = 225*2 = 20 (mod 401) b2 = 225*22 = 400 (mod 401) Evidence of primality!

Miller-Rabin Test if b0 = ±1 (mod n) i  {1, ..., k-1} Why this works? all bi’s (i > 0) will be 1 can’t find nontrivial roots of 1 i  {1, ..., k-1} if bi = 1 (mod n) then bi-1 is neither 1 nor -1 bi-12 = 1 (mod n) we found a nontrivial root if bi = -1 (mod n) then bi+1 through bk are all 1 (mod n) Why this works? n-1 = 2km b0 = am (mod n) b1 = a2m (mod n) b2 = a4m (mod n) ... bj = a2jm (mod n) bk-1 = a(n-1)/2 (mod n)

Miller-Rabin Test: Quality MR test is probabilistic Answer composite – the number is certainly composite prime – the number is prime with high probability Errors MR(n) says prime but n is composite Pr[error] ≤ ¼ Repeat the test to downgrade the prob. of error

Other Primality Tests Solovay-Strassen Test Deterministic test similar in nature to MR uses so called Jacobi symbol fast in practice probabilistic Deterministic test Agrawal, Kayal, and Saxena 2002 extremely slow Tests that prove primality MR tests compositeness! fairly slow needed in very few cases

Factoring Huge amount of work on factoring! Some best algorithms we look at some simple algorithms Some best algorithms quadratic sieve elliptic curve number field sieve Assumption Factor an odd integer produce one factor how to get all of them? O(e(1+o(1))sqrt(lnn lnln n)) O(e(1+o(1))sqrt(lnp lnln p)) O(e(1.92+o(1))(lnn)1/3(lnlnn)2/3)

Factoring Factoring There are about (n) = n / ln n primes ≤ n Input: n  N Output: nontrivial factor of n There are about (n) = n / ln n primes ≤ n Trivial methods divide by all numbers in {2, ... , n-1} or by all primes p p ≤ sqrt(n) These are exponential!

Fermat’s Method The principle The algorithm Examples express n as a difference of squares n = x2 - y2 n = (x-y)(x+y) The algorithm Compute: n + i2 for i  {1,2, ... } Stop when n + i2 is a square (i.e., x2 = n+i2) Then we have n = x2 – i2 Examples 15 = 42 – 12 = (4-1)(4+1) = 3*5 21 = 52 – 22 = 25 - 4 = (5-2)(5+2) = 3*7

Fermat’s Method The principle The algorithm Performance express n as a difference of squares n = x2 - y2 n = (x-y)(x+y) The algorithm Compute: n + i2 for i 2 {1,2, ... } Stop when n + i2 is a square (i.e., x2 = n+i2) Then we have n = x2 – i2 Performance depends on distance between x and y could be very slow! Conclusion for RSA p and q should differ by a large value

Pollard’s p-1 Method The method Goal of the method Example input: n choose a > 1 (e.g., a = 2) choose B let b = aB! (mod n) d = gcd( b - 1, n ) d is a factor of n Goal of the method factor n = pq... provided p-1 has only small prime factors Example n = 7 * 11 = 77 a = 2 B = 4, B! = 2*3*4 = 24 b = 224 = 71 (mod 77) gcd(b-1, n) = gcd(70,77) = 7

Pollard’s p-1 Method The method Goal of the method Example input: n choose a > 1 (e.g., a = 2) choose B let b = aB! (mod n) d = gcd( b - 1, n ) d is a factor of n Goal of the method factor n = pq... provided p-1 has only small prime factors Example n = 7 * 11 = 77 a = 2 B = 2, B! = 2 b = 22 = 4 (mod 77) gcd(b-1, n) = gcd(3,77) = 1

Pollard’s p-1 Method The method Goal of the method Example input: n choose a > 1 (e.g., a = 2) choose B let b = aB! (mod n) d = gcd( b - 1, n ) d is a factor of n Goal of the method factor n = pq... provided p-1 has only small prime factors Example n = 7 * 11 = 77 a = 2 B = 6, B! = 2*3*4*5*6 = 720 b = 2720 = 1 (mod 77) gcd(b-1, n) = gcd(0,77) = 77

Pollard’s p-1 Method In symbols: How to compute aB! b1 = a (mod n) b2 = b12 (mod n) ... bi = bi-1i How to compute aB! B! – can be very big 5! = 120 6! = 720 10! = 3628800 20! = 2432902008176640000 n! – about n log2 n bits

Pollard’s p-1 Method In symbols: How to compute aB! b1 = a (mod n) b2 = b12 (mod n) ... bi = bi-1i How to compute aB! a = 2, B = 4, n = 77 b1 = 2 (mod 77) b2 = 22 = 4 (mod 77) b3 = 43 = 64 (mod 77) b4 = 644 = 1677721 = 71 (mod 77)

Pollard’s p-1 Method The method Why does it work? input: n choose a > 1 (e.g., a = 2) choose B let b = aB! (mod n) d = gcd( b - 1, n ) d is a factor of n Why does it work? p – prime factor of n suppose: p-1 has only small prime factors Then likely p-1 | B! Then B! = k(n-1) b = (ap-1)k (mod p) b = 1 (mod p) p | b - 1

Pollard’s p-1 Method Potential problems Choice of B n = pq both p and q have small factors b = 1 (mod p) b = 1 (mod q) Method fails Choice of B too small  method won’t work too big  works slowly or fails Example n = 7 * 11 = 77 a = 2 B = 2  to small B = 4  worked B = 6  to big 7 - 1 = 6 = 2*3 2! – does not contain 3 4! – contains 2 and 3 6! – contains 2,3 and 5  covers both factors!

Pollard’s p-1 Method Conclusions for RSA How to defend? n = pq p-1 or q-1 has small prime factors? then RSA can be broken How to defend? p0  chose a large prime e.g., p0 > 1040 try numbers of the form: kp0 + 1 k – needs to be even! k > 1060 test kp0+1 for primality

Factoring Relation to squares Examples n – an integer x,y – to integers s.t. x2 = y2 (mod n) x  y (mod n) if such x, y exist then n is composite gcd( x-y, n ) is a nontrivial factor Examples 112 = 121 = 1 (mod 12) 52 = 25 = 1 (mod 12) 11  5 (mod 12) gcd(11-5, 12 ) = 6

Factoring Relation to squares Examples n – an integer x,y – to integers s.t. x2 ´ y2 (mod n) x  y (mod n) if such x, y exist then n is composite gcd( x-y, n ) is a nontrivial factor Examples 52 = 25 = 7 (mod 9) 142 = 196 = 7 (mod 9) 14 = 9+5 = 5 (mod 9) gcd(14-5, 9 ) = 9

Quadratic Sievie Idea try to apply the principle from the previous slide find x,y such that x2 = y2 (mod n) x  y (mod n) x  -y (mod n) finding such x, y  not obvious Take “random” squares Reduce modulo n Factor (hope for small factors!) Try to build squares from what you get

Quadratic Sieve: Example n = 3837523 93982 = 55  19 (mod n) 190952 = 22  5  11  13  19 (mod n) 19642 = 32  133 (mod n) 170782 = 26  32  11 (mod n) 80772 = 2  19 ( mod n) 33972 = 25  5  132 (mod n) 142622 = 52  72  13 (mod n) (9398  19095  1964  17078)2 = 28  32  56  112  134  192 = (24  3  53  11  132  19)2 (mod n) 22303872 = 25867052 (mod n) gcd( 2230387 – 2586705, 3837523) = 1093

Quadratic Sieve: Example n = 3837523 93982 = 55  19 (mod n) 190952 = 22  5  11  13  19 (mod n) 19642 = 32  133 (mod n) 170782 = 26  32  11 (mod n) 80772 = 2  19 ( mod n) 33972 = 25  5  132 (mod n) 142622 = 52  72  13 (mod n) (9398  8077  3397)2 = 26  56  132  192 = (23  53  13  19)2 (mod n) 35905232 = 2470002 (mod n) BUT: n – 247000 = 3590523  3590523 = -247000 (mod n)

How to Find the Squares? What squares to use? we want small prime factors? so x2 should be slightly above n Idea: Try integers close to: sqrt(i  n) + j small j, various i (sqrt(i  n) + j)2 ≈ in + 2j sqrt(in) +j2 approx: 2j sqrt(in) + j2 (mod n)