ENCRYPTION TAKE 2: PRACTICAL DETAILS David Kauchak CS52 – Spring 2015.

Slides:



Advertisements
Similar presentations
RSA.
Advertisements

RSA COSC 201 ST. MARY’S COLLEGE OF MARYLAND FALL 2012 RSA.
CSE331: Introduction to Networks and Security Lecture 19 Fall 2002.
MS 101: Algorithms Instructor Neelima Gupta
Primality Testing Patrick Lee 12 July 2003 (updated on 13 July 2003)
Public Key Cryptosystems - RSA Receiver Sender Eavesdroppe r p q p q p q p and q prime.
22C:19 Discrete Structures Integers and Modular Arithmetic
Primality Testing By Ho, Ching Hei Cheung, Wai Kwok.
22C:19 Discrete Math Integers and Modular Arithmetic Fall 2010 Sukumar Ghosh.
Lecture 3.3: Public Key Cryptography III CS 436/636/736 Spring 2012 Nitesh Saxena.
CNS2010handout 10 :: digital signatures1 computer and network security matt barrie.
Cryptography Lecture 11: Oct 12. Cryptography AliceBob Cryptography is the study of methods for sending and receiving secret messages. adversary Goal:
Announcements: 1. Congrats on reaching the halfway point once again! 2. Reminder: HW5 due tomorrow, HW6 due Tuesday after break 3. Term project groups.
1 Lecture #10 Public Key Algorithms HAIT Summer 2005 Shimrit Tzur-David.
Public Key Cryptography
WS Algorithmentheorie 03 – Randomized Algorithms (Public Key Cryptosystems) Prof. Dr. Th. Ottmann.
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.
Chapter 3 Encryption Algorithms & Systems (Part C)
Public Key Algorithms 4/17/2017 M. Chatterjee.
CSE 321 Discrete Structures Winter 2008 Lecture 10 Number Theory: Primality.
Andreas Steffen, , 4-PublicKey.pptx 1 Internet Security 1 (IntSi1) Prof. Dr. Andreas Steffen Institute for Internet Technologies and Applications.
The RSA Algorithm Rocky K. C. Chang, March
Lecture 15 Lecture’s outline Public algorithms (usually) that are each other’s inverse.
MATH 224 – Discrete Mathematics
Great Theoretical Ideas in Computer Science.
1 Applications of Number Theory CS 202 Epp section 10.4 Aaron Bloomfield.
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.
The Complexity of Primality Testing. What is Primality Testing? Testing whether an integer is prime or not. – An integer p is prime if the only integers.
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.
Public-Key Cryptography CS110 Fall Conventional Encryption.
MA/CSSE 473 Day 11 Primality testing summary Data Encryption RSA.
Implementing RSA Encryption in Java
Cryptography Lecture 7: RSA Primality Testing Piotr Faliszewski.
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.
A Method for Obtaining Digital Signatures and Public-key Cryptosystems
MA/CSSE 473 Day 10 Primality testing summary Data Encryption RSA.
Algebra of RSA codes Yinduo Ma Tong Li. Ron Rivest, Adi Shamir and Leonard Adleman.
The RSA Algorithm. Content Review of Encryption RSA An RSA example.
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.
CRYPTOGRAPHY. WHAT IS PUBLIC-KEY ENCRYPTION? Encryption is the key to information security The main idea- by using only public information, a sender can.
22C:19 Discrete Structures Integers and Modular Arithmetic Fall 2014 Sukumar Ghosh.
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.
David Kauchak CS52 – Spring 2015
1 Section Congruences In short, a congruence relation is an equivalence relation on the carrier of an algebra such that the operations of the algebra.
CS Modular Division and RSA1 RSA Public Key Encryption To do RSA we need fast Modular Exponentiation and Primality generation which we have shown.
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.
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),
Introduction to Cryptography Lecture 9. Public – Key Cryptosystems Each participant has a public key and a private key. It should be infeasible to determine.
1 Applications of Number Theory CS/APMA 202 Rosen section 2.6 Aaron Bloomfield.
Week 4 - Wednesday.  What did we talk about last time?  Finished DES  AES.
Primality Testing. Introduction The primality test provides the probability of whether or not a large number is prime. Several theorems including Fermat’s.
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.
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.
Breaking Cryptosystems Joshua Langford University of Texas at Tyler Fall 2007 Advisor: Dr. Ramona Ranalli Alger.
Information and Computer Security CPIS 312 Lab 8 1 Asymmetric Key Algorithms RSA Algorithm TRIGUI Mohamed Salim.
1 The RSA Algorithm Rocky K. C. Chang February 23, 2007.
MA/CSSE 473 Day 9 Primality Testing Encryption Intro.
Revision. Cryptography depends on some properties of prime numbers. One of these is that it is rather easy to generate large prime numbers, but much harder.
Encryption Take 2: Practical details
David Kauchak CS52 – Spring 2016
Public Key Cryptosystems - RSA
Oblivious Transfer.
Presentation transcript:

ENCRYPTION TAKE 2: PRACTICAL DETAILS David Kauchak CS52 – Spring 2015

Admin Assignment 6 4 more assignments:  Assignment 7 (posted), due 11/13 5pm  Assignment 8, due 11/20 5pm  Assignments 9 & 10, due 12/9 11:59pm Midterm reviews Tue & Wed 7-8pm No office hours Thursday

Courses next spring

Public key encryption I like bananas encrypt message send encrypted message decrypt message I like bananas

RSA public key encryption 1. Choose a bit-length k 2. Choose two primes p and q which can be represented with at most k bits 3. Let n = pq and ϕ (n) = (p-1)(q-1) 4. Find d such that 0 < d < n and gcd(d, ϕ (n)) = 1 5. Find e such that de mod ϕ (n) = 1 6. private key = (d,n) and public key = (e, n) 7. encrypt(m) = m e mod n decrypt(z) = z d mod n

Cracking RSA 1. Choose a bit-length k 2. Choose two primes p and q which can be represented with at most k bits 3. Let n = pq and ϕ (n) = (p-1)(q-1) 4. Find d such that 0 < d < n and gcd(d, ϕ (n)) = 1 5. Find e such that de mod ϕ (n) = 1 6. private key = (d,n) and public key = (e, n) 7. encrypt(m) = m e mod n decrypt(z) = z d mod n Say I maliciously intercept an encrypted message. How could I decrypt it? (Note, you can also assume that we have the public key (e, n).)

Cracking RSA encrypt(m) = m e mod n Idea 1: undo the mod operation, i.e. mod -1 function If we knew m e and e, we could figure out m Do you think this is possible?

Cracking RSA encrypt(m) = m e mod n Idea 1: undo the mod operation, i.e. mod -1 function If we knew m e and e, we could figure out m Generally, no, if we don’t know anything about the message. The challenge is that the mod operator maps many, many numbers to a single value.

Security of RSA p: prime number q: prime number n = pq ϕ (n) = (p-1)(q-1) d: 0 < d < n and gcd(d, ϕ (n)) = 1 e: de mod ϕ (n) = 1 private key public key (d, n) (e, n) Assuming you can’t break the encryption itself (i.e. you cannot decrypt an encrypted message without the private key) How else might you try and figure out the encrypted message?

Security of RSA p: prime number q: prime number n = pq ϕ (n) = (p-1)(q-1) d: 0 < d < n and gcd(d, ϕ (n)) = 1 e: de mod ϕ (n) = 1 private key public key (d, n) (e, n) Assuming you can’t break the encryption itself (i.e. you cannot decrypt an encrypted message without the private key) Idea 2: Try and figure out the private key! How would you do this?

Security of RSA p: prime number q: prime number n = pq ϕ (n) = (p-1)(q-1) d: 0 < d < n and gcd(d, ϕ (n)) = 1 e: de mod ϕ (n) = 1 private key public key (d, n) (e, n) Already know e and n. If we could figure out p and q, then we could figure out the rest (i.e. d)!

Security of RSA p: prime number q: prime number n = pq ϕ (n) = (p-1)(q-1) d: 0 < d < n and gcd(d, ϕ (n)) = 1 e: de mod ϕ (n) = 1 private key public key (d, n) (e, n) How would you do figure out p and q?

Security of RSA p: prime number q: prime number n = pq ϕ (n) = (p-1)(q-1) d: 0 < d < n and gcd(d, ϕ (n)) = 1 e: de mod ϕ (n) = 1 private key public key (d, n) (e, n) For every prime p (2, 3, 5, 7 …): -If n divides p evenly then q = n / p Why do we know that this must be p and q?

Security of RSA p: prime number q: prime number n = pq ϕ (n) = (p-1)(q-1) d: 0 < d < n and gcd(d, ϕ (n)) = 1 e: de mod ϕ (n) = 1 private key public key (d, n) (e, n) For every prime p (2, 3, 5, 7 …): -If n divides p evenly then q = n / p Since p and q are both prime, there are no other numbers that divide them evenly, therefore no other numbers divide n evenly

Security of RSA p: prime number q: prime number n = pq ϕ (n) = (p-1)(q-1) d: 0 < d < n and gcd(d, ϕ (n)) = 1 e: de mod ϕ (n) = 1 private key public key (d, n) (e, n) For every number p (2, 3, 4, 5, 6, 7 …): -If n divides p evenly then q = n / p Currently, there are no known “efficient” methods for factoring a number into it’s primes. This is the key to why RSA works!

Implementing RSA 1. Choose a bit-length k For generating the keys, this is the only input the algorithm has

Implementing RSA 2. Choose two primes p and q which can be represented with at most k bits Ideas?

Finding primes 2. Choose two primes p and q which can be represented with at most k bits Idea: pick a random number and see if it’s prime How do we check if a number is prime?

Finding primes 2. Choose two primes p and q which can be represented with at most k bits Idea: pick a random number and see if it’s prime isPrime(num): for i = 1 … sqrt(num): if num % i == 0: return false return true If the number is k bits, how many numbers (worst case) might we need to examine?

Finding primes 2. Choose two primes p and q which can be represented with at most k bits Idea: pick a random number and see if it’s prime -With k bits we can represent numbers up to 2 k -We’re counting up to sqrt = (2 k ) 1/2 -Which is still 2 k/2 -For large k (e.g. 1024) this is a very big number!

Finding primes Primality test for num: - pick a random number a - perform test(num, a) - if test fails, num is not prime - if test passes, 1/2 chance that num is prime Does this help us?

Finding primes Primality test for num: - pick a random number a - perform test(num, a) - if test fails: return false - if test passes: return true If num is not prime, what are the chances that we incorrectly say num is a prime?

Finding primes Primality test for num: - pick a random number a - perform test(num, a) - if test fails: return false - if test passes: return true 0.5 (50%) Can we do any better?

Finding primes If num is not prime, what are the chances that we incorrectly say num is a prime? Primality test for num: - Repeat 2 times: - pick a random number a - perform test(num, a) - if test fails: return false - return true

Finding primes Primality test for num: - pick a random number a - perform test(num, a) - if test fails: return false - if test passes: return true p(0.25) Half the time we catch it on the first test Of the remaining half, again, half (i.e. a quarter total) we catch it on the second test ¼ we don’t catch it

Finding primes If num is not prime, what are the chances that we incorrectly say num is a prime? Primality test for num: - Repeat 3 times: - pick a random number a - perform test(num, a) - if test fails: return false - return true

Finding primes Primality test for num: - Repeat 3 times: - pick a random number a - perform test(num, a) - if test fails: return false - return true p(1/8)

Finding primes If num is not prime, what are the chances that we incorrectly say num is a prime? Primality test for num: - Repeat m times: - pick a random number a - perform test(num, a) - if test fails: return false - return true

Finding primes Primality test for num: - Repeat m times: - pick a random number a - perform test(num, a) - if test fails: return false - return true p(1/2 m ) For example, m = 20: p(1/2 20 ) = p(1/1,000,000)

Finding primes Primality test for num: - Repeat m times: - pick a random number a - perform test(num, a) - if test fails: return false - return true Fermat’s little theorem: If p is a prime number, then for all integers a: a a p (mod p) How does this help us?

Finding primes Fermat’s little theorem: If p is a prime number, then for all integers a: a a p (mod p) test(num,a): -generate a random number a < p -check if a p mod p = a

Implementing RSA 1. Choose a bit-length k 2. Choose two primes p and q which can be represented with at most k bits 3. Let n = pq and ϕ (n) = (p-1)(q-1) How do we do this?

Implementing RSA 4. Find d such that 0 < d < n and gcd(d, ϕ (n)) = 1 5. Find e such that de mod ϕ (n) = 1 How do we do these steps?

Greatest Common Divisor A useful property: If two numbers are relatively prime (i.e. gcd(a,b) = 1), then there exists a c such that a*c mod b = 1

Greatest Common Divisor A more useful property: two numbers are relatively prime (i.e. gcd(a,b) = 1) iff there exists a c such that a*c mod b = 1 What does iff mean?

Greatest Common Divisor A more useful property: 1. If two numbers are relatively prime (i.e. gcd(a,b) = 1), then there exists a c such that a*c mod b = 1 2. If there exists a c such that a*c mod b = 1, then the two numbers are relatively prime (i.e. gcd(a,b) = 1) We’re going to leverage this second part

Implementing RSA 4. Find d such that 0 < d < n and gcd(d, ϕ (n)) = 1 5. Find e such that de mod ϕ (n) = 1 If there exists a c such that a*c mod b = 1, then the two numbers are relatively prime (i.e. gcd(a,b) = 1) To find d and e: -pick a random d, 0 < d < n -try and find and e such that de mod ϕ (n) = 1 -if none exists, try another d -if one exists, we’re done!

Known problem with known solutions For the assignment, I’ve provided you with a function: inversemod

inversemod

Option type Look at option.sml /examples/option.sml option type has two constructors: - NONE (representing no value) - SOME v (representing the value v)

case statement case _______ of pattern1 => value | pattern2 => value | pattern3 => value …

inversemod

Signing documents encrypt message I like bananas If a message is encrypted with the private key how can it be decrypted? Hint: -(m e ) d = m ed = m (mod n) -encrypt(m, (e, n)) = m e mod n -decrypt(z, (d, n)) = z d mod n

Signing documents -(m e ) d = m ed = m (mod n) -encrypt(m, (e, n)) = m e mod n -decrypt(z, (d, n)) = z d mod n encrypt(m, (d,n)) = m d mod n decrypt( m d mod n, (e, n)) =(m d ) e mod n = m de mod n = m ed mod n = m (if m < n)

Signing documents encrypt message I like bananas What does this do for us?

Signing documents encrypt message I like bananas If the message can be decrypted with the public key then the sender must have had the private key This is a way to digitally sign a document!

Signing documents I like bananas decrypt message send signed message encrypt message I like bananas Confirmed: batman likes bananas

Signing documents I like bananas decrypt message send signed message encrypt message I like bananas Confirmed: batman likes bananas

Public key encryption Share your public key with everyone How does this happen? Anything we have to be careful of?

What next… More implementation details  characters to integers  splitting up the numbers  finding prime numbers  helper functions  option type Key distribution “signing” documents