The RSA Public Key Cipher

Cryptography
Codes Lecture 6: Intro to Public Key
Cryptography via the RSA Cipher
Spring 2014
Morgan Schreffler
Office: POT 902
http://www.ms.uky.edu/~mschreffler
Intro to RSA
RSA Cryptosystem
The RSA Cipher is a public key cipher publicly discovered in the
1970s. The RSA cipher uses a form of multiplication for encryption
and is secure because factoring large numbers is (currently) very
difficult to do.
RSA stands for Rivest, Shamir, and Adleman, the people
responsible for first publicizing the RSA cipher.
The British and US governments may have known about RSA
prior to the 1970s, but did not announce their discovery.
Even though this is the basis for most modern cryptography,
there is current speculation that the US government
(specifically the NSA) has the ability to break this code.
Master Spy Training Program
Congratulations! You’ve been promoted to the highest rank in the
Spy Agency! It’s now time to learn about a modern and
sophisticated code. First, we’ll need to see if you can handle the
following questions:
Masterful Multiplication
How long does it take you to factor 2173 as a product of two
(prime) numbers 2173 = p · q?
How long does it take you to multiply 41 by 53?
If n is a big number, is it easy to factor? If p and q are big
numbers, is it easy to multiply them?
RSA Encryption
Bob wants to send a message to Alice, while keeping it secret from
Eve, who intercepts all their chatter. Here’s what happens:
Part 1 : What Alice Does to Prepare
1
Alice chooses two (large) prime numbers p and q, which she
keeps secret.
2
She then multiplies to find n = p · q. This can be done
quickly because multiplication is “easy”.
3
Alice also calculates a value m = (p − 1)(q − 1), which she
also keeps secret.
4
She selects a value e which is a unit mod m. In other words,
gcd(e, m) = 1. We call e the encryption exponent.
5
Alice sends Bob the numbers e and n. The pair (e, n) is called
the public key, since Eve (or anyone) may have intercepted it!
RSA Encryption
What Bob Does to Encrypt a Message for Alice
1
Bob converts letters (or blocks of letters) into numbers. We’ll
do this the usual way, but typically this is done by computer.
2
For plaintext letter(s) , Bob encrypts it using the rule
e (mod n) = .
3
Bob then sends the ciphertext to Alice.
Be Careful!
Alice made the key(s), but Bob is the one sending a message!
Be Even More Careful!
The plaintext may start as a letter (or block of letters), but RSA
ciphertext is always a number!
RSA Decryption
Reminder: Only Alice knows p, q, and m, while e and n are public.
What Alice Does to Decrypt Bob’s Message
1
Alice receives the ciphertext from Bob.
2
Next, she finds the number d that is the multiplicative inverse
to e (mod m). This is called the decryption exponent.
3
Alice decrypts using the rule
d (mod n) = .
We call (p, q, m, d) the private key, because if Eve knows
ANY of these numbers she can decrypt Bob’s message!
Why Are e and d the Right Exponents???
One of the MANY results called Euler’s theorem tells us (in so
many words) that if gcd(a, n) = 1 and x = 1 (mod m), then
ax = a (mod n). Particularly, (e )d = e·d = (mod n).
Which RSA Encryption/Decryption Exponents Work?
Theorem
For an RSA cipher that uses primes p and q with n = p · q and
m = (p − 1) · (q − 1), the encryption exponent e must be a unit
(mod m). In other words, gcd(e, m) = 1.
Why Must e Be a Unit Modulo m?
Again by Euler’s theorem, the encryption exponent e must have a
multiplicative inverse d (mod m) to guarantee that Alice can
decrypt Bob’s message.
Example (RSA Encryption/Decryption Exponents)
In an RSA cipher, if p = 43 and q = 67, is 11 a valid choice for e?
Note: m = (43 − 1)(67 − 1) = 2772 = 252 · 11. Since 11 is a factor
of 2772, gcd(11, 2772) = 11 6= 1, so e = 11 WON’T WORK.
5 and 13 are each valid choices though, since gcd(5, 2772) = 1 and
gcd(13, 2772) = 1. Can you name one that isn’t prime?
Master Spy Training Program
Now that you’ve seen RSA, can you work with it?
Example (Making an RSA Key)
If p = 71 and q = 59, find n = p · q.
If p = 71 and q = 59, find m = (p − 1) · (q − 1).
Example (Making Another RSA Key)
If p = 101 and q = 103, find n and m.
Example (Making Yet Another RSA Key)
If p = 521 and q = 641, find n and m. (Trust us, they’re prime!)
Example (Breaking an RSA Key)
If p = 7 and m = 132, find q and n.
Master Spy Training Program
Example (Sending a Message via RSA)
Agent J wants you to send her a message. She broadcasts public
key n = 85 and e = 5, expecting that they’ll be intercepted.
Is 5 a valid choice for e? Why or why not?
Use this RSA cipher to encrypt the letter “H” as a number.
Now encrypt “I.” Encrypt “J.”
The letters “H”, “I” and “J” are consecutive. Does RSA
encrypt these letters as consecutive numbers?
Encrypting letters 1-by-1, does RSA hides letter frequency?
Master Spy Training Program
Example
You need Agent J to send you a message. You decide on public key
n = 29 · 17 = 493, e = 5 and publish these to an open webpage.
Is 5 a valid choice for e? Why or why not?
What number will the letter “D” be encrypted as?
What number will the letter “E” be encrypted as?
Encrypt the number “0405”? Is this connected to the answers
above in any way?
Encrypting in blocks, does RSA hide letter frequency?
Master Spy Training Program
An enemy organization has caught on, and is now using RSA
against us! Luckily, we have a mole on the inside!
Example (Breaking RSA when a Private Key Goes Public)
The enemy uses the public key n = 143, e = 7.
At great personal risk, our mole found p = 11. Find q and m.
Based on the above, find the enemy’s decryption exponent d.
For your convenience, the list you will need for finding d is
121, 241, 361, 481, 601, 721, 841, 961, . . ..
The enemy received ciphertext 117, 115, 12, 47. Decrypt it!
(Helpful #’s: 11750 = 78 (mod 143), 11551 = 5 (mod 143),
122 = 1 (mod 143), and 4720 = 1 (mod 143).)
Code Summary
The summary below represents information about codes when
encrypting and decrypting English language plaintext.
Cipher
Caesar
Shift
Vigenère
Times
RSA
Encrypt
Key(s)
3
∆
∆1 ∆2 ∆3 . . .
F
n, e
Decrypt
Key(s)
23
∇
∇1 ∇2 ∇3 . . .
∗
m, d
Key
Secrecy
Private
Private
Private
Private
Public
Letter
Frequency
Normal
Normal
Less Predictable
Normal
Unpredictable
With RSA, private (encrypted) messages can be sent after keys are
publicly (open for interceptions) exchanged. This is what allows
you to shop or access your bank account online.