The idea
Symmetric encryption has a chicken-and-egg problem. To send a secret message you first need a shared secret, and to share a secret you need a secure channel.
Public-key encryption breaks the loop with two keys. Bob publishes one and keeps the other. Anyone can use the published key to lock a message for Bob, but only Bob’s private key opens it. Alice and Bob never have to meet. The price is speed, which is why the lecture lists a set of cons next to the pros.
How it works
Two keys instead of one
The lecture states the idea directly.
- No key sharing is needed.
- There are two separate keys: one private and one public.
- The public key, exposed to the public domain, is used for encryption.
- The private key, private to the user, is used for decryption.
- The public key locks the message and the private key opens it.
The figure on the confidentiality slide did not extract. The text above is all the lecture’s wording that survives.
Pros
- No need for secret key sharing.
- It is computationally infeasible to compute the private key given the cryptographic algorithm and the public key.
- Used for authentication, digital signatures and secret-key exchanges.
Cons
- Relatively long mathematical calculations using relatively long keys.
- Much slower than symmetric-key encryption.
- Inefficient for long messages.
- The public key must be distributed via a trusted third party.
How it works
RSA: the algorithm in outline
RSA is named for Rivest, Shamir and Adleman and was developed in 1978 at MIT. The lecture calls it the de-facto standard for data transmission on the Internet. It uses two exponents, e and d, where e is public and d is private. If P is the plaintext and C the ciphertext, Alice uses C = P^e mod n to encrypt and Bob uses P = C^d mod n to recover the plaintext. The modulus n, a very large number, is created during key generation.
Before any of that, the lecture notes a message is just a bit pattern, and a bit pattern is uniquely a number. For example m = 10010001 is 2^7 + 2^4 + 2^0 = 128 + 16 + 1 = 145. Encrypting the message means encrypting that number, which gives a new number, the ciphertext.
How it works
RSA: creating a public and private key pair
- Choose two large prime numbers
pandq, for example 1024 bits each. - Compute
n = pqandz = (p-1)(q-1). - Choose
ewithe < nthat has no common factors withz. That is,eandzare relatively prime. - Choose
dsuch thated - 1is exactly divisible byz. In other wordsed mod z = 1. - The public key is
(n, e)and the private key is(n, d).
- p, q
- Two large primes
- n
- Modulus, pq
- z
- (p-1)(q-1)
- e
- Public exponent, no common factor with z
- d
- Private exponent, ed mod z = 1
How it works
RSA: encryption and decryption
Given (n, e) and (n, d) as above, with the message as a number m < n:
- To encrypt, compute
c = m^e mod n. - To decrypt the received bit pattern
c, computem = c^d mod n.
- m
- Message as a number, less than n
- c
- Ciphertext as a number
How it works
The lecture's worked example
Worked example
Bob chooses p = 5 and q = 7, encrypting the 8-bit message 00001100
Modulus:
n = pq=5 x 7=35.z:
(5-1)(7-1)=4 x 6=24.Choose e: the lecture takes
e = 5. The factors of5are1and5, and the factors of24include2,3,4,6,8,12. The only common factor is1, soeandzare relatively prime, and5 < 35.Choose d: the lecture takes
d = 29. Check:e x d=5 x 29=145, and145 - 1=144=6 x 24. Soed - 1is exactly divisible byz, anded mod 24=1.Keys: public
(35, 5), private(35, 29).Message:
00001100in binary is8 + 4=12, som = 12, and12 < 35.Encrypt:
c = 12^5 mod 35. Directly,12^5=248832. Since35 x 7109=248815, the remainder is248832 - 248815=17. By reducing at each stage:12^2=144,144 mod 35=4. Then12^4=4^2=16. Then12^5=16 x 12=192, and192 mod 35=17. Soc = 17.Decrypt:
m = 17^29 mod 35. Using repeated squaring:17^2=289,289 mod 35=9.17^4=9^2=81,81 mod 35=11.17^8=11^2=121,121 mod 35=16.17^16=16^2=256,256 mod 35=11. Since29 = 16 + 8 + 4 + 1, multiply17^16 x 17^8 x 17^4 x 17^1mod 35:11 x 16=176,176 mod 35=1. Then1 x 11=11. Then11 x 17=187,187 mod 35=12. Som = 12.
AnswerPublic key (35, 5), private key (35, 29). The message 12 encrypts to 17 and decrypts back to 12.
The slide prints m^e as 24832 and c^d as 481968572106750915091411825223071697. The second number is exactly 17^29. The first is one digit short, since 12^5 is 248832. The ciphertext 17 and the recovered message 12 are both right, so the slide’s printed value is a typo and the answers stand.
How it works
Another important property
The lecture states that encrypting then decrypting, in either order, returns the message.
K_B^-(K_B^+(m)) = m = K_B^+(K_B^-(m))
Using the public key first and then the private key gives m. Using the private key first and then the public key also gives m. The result is the same.
This matters in the signature topic, where the private key is applied first on purpose. The lecture says the property “will be very useful later”.
How it works
Why is RSA secure?
Suppose you know Bob’s public key (n, e). To determine d you essentially need to find the factors of n without knowing the two factors p and q. The lecture’s fact is that factoring a big number is hard.
With the toy numbers, n = 35 factors by inspection as 5 x 7, so the example is not secure. Real keys use primes of around 1024 bits each.
Where marks get lost
The public key does not decrypt
In confidentiality the public key encrypts and the private key decrypts. Mixing them up is the commonest slip. In the signature topic the roles reverse, with the private key applied first, which is why the commutative property is stated.
In the exam
- Be able to carry out the five key-generation steps for small
pandq, showingn,z, a valide, and a check ofed mod z = 1. - Encrypt with
m^e mod n, reducing at each stage, and decrypt withc^d mod n. - The lecture’s numbers:
p = 5,q = 7,n = 35,z = 24,e = 5,d = 29,m = 12,c = 17. - Know all four pros and cons.
- The security argument is the difficulty of factoring
n.
Aside
Flagged: the printed power
The lecture slide shows 12^5 as 24832. The correct value is 248832. The slide’s ciphertext 17 is right regardless, and that is the answer the exam marks.
Check yourself
- Public key encrypts, private key decrypts. Nothing secret is shared in advance.
- The cost is speed, so RSA suits short messages such as keys.
n = pq,z = (p-1)(q-1),erelatively prime toz,ed mod z = 1.c = m^e mod nandm = c^d mod n. With the lecture’s keys, 12 becomes 17 and back.- RSA is secure because factoring
nis hard.