CS 312 - Modular Division and RSA1 RSA Public Key Encryption To do RSA we need fast Modular Exponentiation and Primality generation which we have shown.

Slides:



Advertisements
Similar presentations
RSA COSC 201 ST. MARY’S COLLEGE OF MARYLAND FALL 2012 RSA.
Advertisements

MS 101: Algorithms Instructor Neelima Gupta
22C:19 Discrete Structures Integers and Modular Arithmetic
BY : Darshana Chaturvedi.  INTRODUCTION  RSA ALGORITHM  EXAMPLES  RSA IS EFFECTIVE  FERMAT’S LITTLE THEOREM  EUCLID’S ALGORITHM  REFERENCES.
Public Key Encryption Algorithm
Week 3 - Friday.  What did we talk about last time?  AES  Public key cryptography.
22C:19 Discrete Math Integers and Modular Arithmetic Fall 2010 Sukumar Ghosh.
and Factoring Integers (I)
RSA ( Rivest, Shamir, Adleman) Public Key Cryptosystem
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2002 Tuesday, 26 November Number-Theoretic Algorithms Chapter 31.
6/20/2015 5:05 AMNumerical Algorithms1 x x1x
1 Lecture #10 Public Key Algorithms HAIT Summer 2005 Shimrit Tzur-David.
Chapter 4 – Finite Fields Introduction  will now introduce finite fields  of increasing importance in cryptography AES, Elliptic Curve, IDEA, Public.
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.
WS Algorithmentheorie 03 – Randomized Algorithms (Public Key Cryptosystems) Prof. Dr. Th. Ottmann.
Codes, Ciphers, and Cryptography-RSA Encryption
Lecture 6: Public Key Cryptography
CSE 311 Foundations of Computing I Lecture 12 Primes, GCD, Modular Inverse Spring
Lecture 15 Lecture’s outline Public algorithms (usually) that are each other’s inverse.
Introduction to Modular Arithmetic and Public Key Cryptography.
MATH 224 – Discrete Mathematics
Module :MA3036NI Cryptography and Number Theory Lecture Week 7
RSA Public Key Algorithm. RSA Algorithm history  Invented in 1977 at MIT  Named for Ron Rivest, Adi Shamir, and Len Adleman  Based on 2 keys, 1 public.
RSA and its Mathematics Behind
Great Theoretical Ideas in Computer Science.
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
Prelude to Public-Key Cryptography Rocky K. C. Chang, February
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.
1 Lecture 9 Public Key Cryptography Public Key Algorithms CIS CIS 5357 Network Security.
MA/CSSE 473 Day 11 Primality testing summary Data Encryption RSA.
Implementing RSA Encryption in Java
Introduction to Algorithms Second Edition by Cormen, Leiserson, Rivest & Stein Chapter 31.
Modular Arithmetic with Applications to Cryptography Lecture 47 Section 10.4 Wed, Apr 13, 2005.
Elements of Coding and Encryption Continuation 1.
RSA Prepared by: SITI ZAINAH ADNAN
MA/CSSE 473 Day 10 Primality testing summary Data Encryption RSA.
The RSA Algorithm. Content Review of Encryption RSA An RSA example.
YSLInformation Security -- Public-Key Cryptography1 Prime and Relatively Prime Numbers Divisors: We say that b  0 divides a if a = mb for some m, where.
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
RSA and its Mathematics Behind July Topics  Modular Arithmetic  Greatest Common Divisor  Euler’s Identity  RSA algorithm  Security in RSA.
CSE 311: Foundations of Computing Fall 2014 Lecture 12: Primes, GCD.
22C:19 Discrete Structures Integers and Modular Arithmetic Fall 2014 Sukumar Ghosh.
Information Security Lab. Dept. of Computer Engineering 87/121 PART I Symmetric Ciphers CHAPTER 4 Finite Fields 4.1 Groups, Rings, and Fields 4.2 Modular.
MA/CSSE 473 Day 06 Euclid's Algorithm. MA/CSSE 473 Day 06 Student Questions Odd Pie Fight Euclid's algorithm (if there is time) extended Euclid's algorithm.
RSA The algorithm was publicly described in 1977 by Ron Rivest, Adi Shamir, and Leonard Adleman at MIT Partly used for PGP (Pretty Good Privacy) to encrypt.
Lecture 6.1: Misc. Topics: Number Theory CS 250, Discrete Structures, Fall 2011 Nitesh Saxena.
ENCRYPTION TAKE 2: PRACTICAL DETAILS David Kauchak CS52 – Spring 2015.
POON TENG HIN.  RSA  Shamir’s Three-Pass Protocol  Other issues.
David Kauchak CS52 – Spring 2015
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
CS 4803 Fall 04 Public Key Algorithms. Modular Arithmetic n Public key algorithms are based on modular arithmetic. n Modular addition. n Modular multiplication.
Ch1 - Algorithms with numbers Basic arithmetic Basic arithmetic Addition Addition Multiplication Multiplication Division Division Modular arithmetic Modular.
Modular Arithmetic and the RSA Cryptosystem Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 9Sept 27, 2005Carnegie.
Week 4 - Wednesday.  What did we talk about last time?  Finished DES  AES.
Lecture 3.1: Public Key Cryptography I CS 436/636/736 Spring 2015 Nitesh Saxena.
CSE 311: Foundations of Computing Fall 2013 Lecture 12: Primes, GCD, modular inverse.
Discrete Mathematics
CS 312: Algorithm Analysis Lecture #4: Primality Testing, GCD This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.Creative.
Great Theoretical Ideas in Computer Science.
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 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
RSA Cryptosystem Great Theoretical Ideas In Computer Science S. Rudich V. Adamchik CS Spring 2006 Lecture 8Feb. 09, 2006Carnegie Mellon University.
Lecture 5 Asymmetric Cryptography. Private-Key Cryptography Traditional private/secret/single key cryptography uses one key Shared by both sender and.
David Kauchak CS52 – Spring 2016
MA/CSSE 473 Day 06 Euclid's Algorithm.
Number Theory (Chapter 7)
Number Theory and Euclidean Algorithm
Discrete Math for CS CMPSC 360 LECTURE 12 Last time: Stable matching
Analysis of the RSA Encryption Algorithm
Presentation transcript:

CS Modular Division and RSA1 RSA Public Key Encryption To do RSA we need fast Modular Exponentiation and Primality generation which we have shown We also need Modular Division To do Modular Division we use the extended Euclid Algorithm which we will now build towards

CS Modular Division and RSA2 Euclid’s Rule for GCD How do you find the greatest common divisor of two integers – Largest integer that divides both – Could factor but that is exponential Back in ancient Greece Euclid discovered the rule: If x and y are positive integers with x ≥ y then gcd(x,y) = gcd(x mod y, y) As soon as x mod y is 0, then y is the gcd Must swap parameters each time to keep largest as 1 st parameter

CS Modular Division and RSA3 Euclid’s Algorithm This rule leads to the following algorithm Function Euclid (a,b) Input: Two integers a and b with a  b  0 (n-bit integers) Output: gcd(a,b) if b=0: return a else: return Euclid(b, a mod b) Examples Complexity?

CS Modular Division and RSA4 Euclid’s Algorithm This rule leads to the following algorithm Function Euclid (a,b) Input: Two integers a and b with a  b  0 (n-bit integers) Output: gcd(a,b) if b=0: return a else: return Euclid(b, a mod b) Examples Complexity? – Each call reduces the arguments by at least 1/2 – Thus O(n =log 2 (a)) calls each with an n 2 division – Complexity is O(n 3 )

CS Modular Division and RSA5 Extended Euclid’s Algorithm function extended-Euclid (a, b) Input: Two positive integers a and b with a  b  0 (n-bits) Output: Integers x, y, d such that d = gcd(a, b) and ax + by = d if b = 0: return (1, 0, a) (x', y', d) = extended-Euclid(b, a mod b) return (y', x' – floor(a/b)y', d) Exact same as Euclid except during stack unraveling This gives us the results we need for modular division We'll do an example in a minute

CS Modular Division and RSA6 Modular Division - Multiplicative Inverses Every real number a ≠ 0 has an inverse 1/a, (a·1/a = 1) Dividing by a is the same as multiplying by the inverse 1/a In modular arithmetic we say that x is the multiplicative inverse of a modulo N if ax = 1 (mod N) Multiplicative inverse of 3 mod 5 = ?

CS Modular Division and RSA7 Modular Division - Multiplicative Inverses Every real number a ≠ 0 has an inverse 1/a, (a·1/a = 1) Dividing by a is the same as multiplying by the inverse 1/a In modular arithmetic we say that x is the multiplicative inverse of a modulo N if ax = 1 (mod N) Multiplicative inverse of 3 mod 5 = 2 – We will also call 2, a -1 mod N in this case – If a multiplicative inverse exists, it is unique mod N Unlike regular arithmetic most numbers do not have a multiplicative inverse in modular arithmetic What is the multiplicative inverse of 2 mod 4? An Algorithm to find the inverse?

CS Modular Division and RSA8 Modular Division - Multiplicative Inverses In fact, the only time a has a multiplicative inverse mod N is when a and N are relatively prime Two numbers a and b are relatively prime if gcd(a,b) = 1 If a and N are relatively prime then we know the multiplicative inverse exists (e.g. 4 mod 7) Extended-Euclid(a,N) does it all for us: – Returns integers x, y, d such that d = gcd(a, b) and ax + by = d – First, must return d=1 as the gcd to confirm that a and N are relatively prime – If so, it finds the multiplicative inverse x of a mod N If a and N are relatively prime, then ax + Ny = 1 Ny = 0 (mod N) for all integers y Thus, ax  1 (mod N) Then x is the multiplicative inverse of a modulo N Modular N division can only be done for numbers relatively prime to N and the division is actually carried out by multiplying by the inverse

CS Modular Division and RSA9 Let's Try One What is multiplicative inverse of 20 Mod 79 – Are they relatively prime? – Euclid or extended-Euclid are the algorithms we use to find out (with the extension not needed). The extension only kicks in after the gcd has been found anyway. – returns integers x, y, d such that d = gcd(a, b) and ax + by = d – Remember to put the largest number first and if you have to switch at the beginning, then remember to switch x and y at the end

CS Modular Division and RSA10 Multiplicative Inverse of 20 Mod 79 abx'y'dret 1ret 2ret function extended-Euclid (a, b) if b = 0: return (1, 0, a) (x', y', d) = extended-Euclid(b, a mod b) return (y', x' – floor(a/b)y', d)

CS Modular Division and RSA11 Multiplicative Inverse of 20 Mod 79 abx'y'dret 1ret 2ret function extended-Euclid (a, b) if b = 0: return (1, 0, a) (x', y', d) = extended-Euclid(b, a mod b) return (y', x' – floor(a/b)y', d) ax + Ny = 1 = 79(-1) + 20(4) ax + Ny = 1 = 20(4) + 79(-1) Since we initially switched 20 and 79 Thus x = a -1 = 4Complexity?

CS Modular Division and RSA12 Multiplicative Inverse of 12 mod 15? abx'y'dret 1ret 2ret function extended-Euclid (a, b) if b = 0: return (1, 0, a) (x', y', d) = extended-Euclid(b, a mod b) return (y', x' – floor(a/b)y', d)

CS Modular Division and RSA13 Multiplicative Inverse of 12 mod 15? abx'y'dret 1ret 2ret function extended-Euclid (a, b) if b = 0: return (1, 0, a) (x', y', d) = extended-Euclid(b, a mod b) return (y', x' – floor(a/b)y', d) ax + Ny = 3 = 15(1) + 12(-1) However, there is no multiplicative inverse since the gcd = 3 and thus a and b are not relatively prime

CS Modular Division and RSA14 RSA Now we have all the algorithms/tools needed to do RSA RSA = Rivest, Shamir, and Adleman Common Public Key Encryption Approach Assume x is the initial message to be sent and e(x) encrypts x into y while d(y) decrypts y back to x Private key approaches - Alice and Bob both know e and d and can thus communicate with each other – but new/unknown people can't Public key - d is the inverse of e. Bob creates e and d and publishes e to everyone, but only he knows d. Alice can create her own pair and publish her own e, etc. e(x) = yd(y) = x encrypted y Alice Bob Eve

CS Modular Division and RSA15 RSA Encryption Messages are numbers modulo N Messages larger than N are segmented Encryption is a bijection (one-to-one and onto) from {0, 1,..., N-1} to {0, 1,..., N-1} – a permutation Decryption is its inverse

CS Modular Division and RSA16 RSA Overview Pick any two primes p and q and let N = p · q Choose a number e relatively prime to (p-1)(q-1) – e is often chosen as 3 – permits fast encoding Then the mapping x e mod N is a bijection onto {0, 1,..., N- 1} - Publish (e, N) as the public key for encryption Find d, the multiplicative inverse of e mod (p-1)(q-1) using extended-Euclid((p-1)(q-1), e) Then for all x  {0, 1,..., N-1} (x e ) d = x mod N – Proof on p. 34 based on Fermat's if p is prime, then a p-1  1 mod p Keep d private for decryption – Why can't they figure out d?

CS Modular Division and RSA17 Quick Example Let p = 5; q = 11 Then N = p·q = 55 Let e = 3 – Note that gcd((p-1)(q-1),e) = gcd(40,3) = Euclid(40,3) = 1 Thus, public key = (N, e) = (55, 3) Private key: d = 3 -1 mod 40 = 27 – found with extended-Euclid((p-1)(q-1),e) = extended-Euclid(40,3) which gives d = 27 Encryption of x: y = x 3 mod 55 – Encryption and decryption use modular exponentiation algorithm Decryption of y: x = y 27 mod 55 Let x = 13 y = 13 3 = 52 (mod 55) x = = 13 (mod 55)

CS Modular Division and RSA18 RSA Summary How could we break RSA - Could try factoring N into primes p and q - no known polynomial algorithm The crux of the security behind RSA – Efficient algorithms / Polynomial time computability for: Modular Exponentiation – modexp() GCD and modular division – extended-Euclid() Primality Testing and creation – primality2() – Absence of sub-exponential algorithms for Factoring The gulf between polynomial and exponential saves the day in this case