Lecture 4 - PKE - Notes
Lecture 4 - PKE - Notes
1
Reminder of previous lecture
• Number theory
– Basic number theory for cryptography
– Familiar with terminology
– Need to have functional knowledge
2
Today’s Lecture
• Asymmetric encryption
– Difference between symmetric and asymmetric
– RSA and El-Gamal
3
Symmetric Key Management
• Each pair of communicating entities needs a shared key
• For an n-party system, there are n(n-1)/2 distinct keys in the system and
each party needs to maintain n-1 distinct keys.
• How to reduce the number of shared keys in the system
1. Centralized key management
2. Public keys
• How to set up shared keys
K1 K4
K2 K3
K5
K6
K8
K7
K9
K10
4
Study
4
Centralized Key Management
Online Key Distribution Server
K1 K2
session key
Alice Bob
• Only n long-term secret keys, instead of n(n-1)/2 in the system.
• Each user shares one long-term secret key with the Server.
• The Server may become the single-point-of-failure and the
performance bottleneck.
• Secret keys are used only for the secure delivery of session keys.
• Real data are encrypted under session keys.
5
Study
5
Public key Encryption
• Receiver Bob has a key pair: public and private
• publish the public key such that the key is publicly known
• Bob keeps the private key secret
• Other people use Bob’s public key to encrypt messages for Bob
• Bob uses his private key to decrypt
Its more common use is to encrypt a session key that the parties
can subsequently use for symmetric encryption, etc.
In public key crypto the key has two components – one is known to
everyone (publick key) and the other is only known to one person
(private key). This allows anyone to encrypt a message, but only the
receiver can decrypt.
6
Motivation of Public Key Cryptography (Summary)
• One problem with symmetric key algorithms is that the sender needs
a secure method for telling the receiver about the encryption key.
• Plus, you need a separate key for everyone you might communicate
with (scalability issue).
7
What is public key crypto based on?
• Public key crypto is based on mathematical one way functions
– Easy to compute output given the inputs
– Difficult to compute input given the output
• Factorisation problem
– Multiplying two prime numbers
– Given prime x and y it is easy to compute x.y = z
– Given z it is not easy to compute x and y
Study
8
Rivest, Shamir, and Adleman (RSA)
• Encryption: C = Me mod n
• Decryption: M = Cd mod n
Study – RSA is one of most well know algorithms. You need to know
and memorise the algorithm.
9
Alan Turing has a rich history in cryptography. Public key crypto is seen as
great CS achievement.
ACM Turing Award 2015 (Whit Diffie, Martin Hellman – look at their main
protocol idea later)
ACM Turing Award jointly for Adleman, Rivest and Shamir (2002) based
on RSA work published in 1977.
The three Turing Award recipients were not aware that a similar method
had been developed years before by British mathematician Clifford Cocks,
who extended the even earlier work of James H. Ellis. Cocks was doing his
encryption work at the British Government Communications Headquarters
(GCHQ), so it was classified as secret and not released until 1997, twenty
years after Rivest, Adleman, and Shamir had published their independent
discovery.
9
10
10
Your turn
• Given p=13, q=11 and choosing e=7. Use RSA to encrypt M=10
11
11
Example of RSA Encryption and Decryption
• Choose two primes p=47 and q=71 n = pq = 3337.
• Choose e such that it is relatively prime to (n) = 46x70 = 3220.
• e.g. e = 79.
• Compute d = e-1 mod (n) using extended Euclidean algorithm.
• d 79-1 (mod 3220) = 1019
• Public key PK = (n, e) = (3337,79)
• Private key SK = d = 1019
12
This is a complex example, use this and the simple example to test
your understanding of RSA
12
Security of RSA
• Remember Factorization Problem (FACTORING) : Given a positive integer n,
find its prime factorization; that is, write n = p1e1 p2e2… pkek where the pi are
primes and each ei 1.
• E.g. 72 = 23 ∙ 32
• RSA Problem (RSAP) : Given
• a positive integer n that is a product of two distinct equal-length primes p and q,
• a positive integer e such that gcd(e, (p-1)(q-1)) = 1, and
• an integer c chosen randomly from Zn*
find an integer m such that me c (mod n). Note: p and q are not given.
• The intractability of the RSAP forms the basis for the security of the RSA
public-key cryptosystem.
• RSAP is closely related to the Factorization Problem but not known to be
equivalent.
• If one can solve FACTORING, then one can solve RSAP.
• Is FACTORING P RSAP?
• It is widely believed that it is true, although no proof of this is known
13
What you need to know from slides 13-17 is what the security of
RSA is based on. What is the hard problem that an attacker needs
to solve? Problem is most directly related to the factoring (need to
factor n if you want to calculate d from public key e).
13
Public Key Encryption
( )
exp (ln n ) 3 (ln ln n )
1
14
Reference
These days 3072 key size is starting to be seen to be better, 2048 should be OK for
another approximately 6 years.
You only need to know from this slide the RSA key size compared to
size symmetric encryption keys, which is said to give roughly
equivalent security.
16
ElGamal Encryption Scheme
• Let p be a large prime.
• Let Zp* = { 1, 2, 3, …, p-1 }
• Let Zp-1 = { 0, 1, 2, …, p-2 }
• a R S means that a is randomly chosen from the set S
• Let g Zp* such that none of g1 mod p, g2 mod p, …, gp-2 mod p is equal to 1.
Encryption:
1. r R Zp-1
2. A = gr mod p
3. B = Myr mod p where M Zp* is the message.
Ciphertext C = (A, B).
Decryption:
1. K = Ax mod p
2. M = B K-1 mod p
17
RSA is the most well known but not the only scheme.
If we have two plaintext messages P_1 and P_2 (which are the same
P_1 = P_2). If we encrypt these with RSA and we encrypt these
with El-Gamal, what is relationship between C_1 and C_2?
For RSA C_1 is equal to C_2, for ElGamal C_1 it not equal to C_2
because of the random number r chosen for each encryption.
17
Your turn
• Let p =23, g =11 and x =6. Encrypt M =10 with r being 3
• Encrypt
• C1 = 113 mod 23 = 20
• C2 = 10x93 mod 23 = 10x16 mod 23 = 22
• Decrypt
• K = 206 mod 23 = 16
• M = 22x 16-1 mod 23 = 22x13 mod 23 = 10
18
Apart from having to do some modular maths the most tricky thing
here is the modular inverse calculation.
Remember that you can use the Euclidean and Extended Euclidean
algorithms – here is the example above:
1 = 7 – 3x2 mod 23
1 = 7 – 3x(16-2x7) = -3x16 +7x7 mod 23
1= -3x16 +7x(23-16) = -10x16 +7x23 mod 23
1= (-10 mod 23)x16 mod 23
18
1= 13x16 mod 23, therefore 13 is modular inverse of 16 mode 23
18
Example of ElGamal Encryption and Decryption
• Let p =2357
g=2
Private key: x = 1751
Public key: y = gx = 21751 = 1185 (mod 2357)
• Encryption:
– say M = 2035
1. Pick a random number r = 1520
2. Computes A,B and C
A = gr 21520 1430 (mod 2357)
B = Myr 2035 x 11851520 697 (mod 2357)
The ciphertext C = (A, B) = (1430, 697)
• Decryption:
1. Computes K Ax 14301751 2084 (mod 2357)
2. M B K-1 697 x 2084-1 2035 (mod 2357)
19
19
Security of ElGamal Encryption Scheme
Encryption:
1. r R Zp-1
2. A = gr mod p
3. B = Myr mod p where M Zp* is the message.
Ciphertext C = (A, B).
1. If adversary can get r from A=gr mod p, then the scheme is broken.
2. If adversary can get x from y=gx mod p, then the scheme is broken.
3. From A=gr mod p and y=gx mod p, if adversary can compute grx mod p,
then the scheme is broken.
20
20
Discrete Logarithm Problem (DLP)
• Let p be a prime number. Given two integers: g, y
– g and y are integers chosen randomly in Zp*.
• Find a such that ga mod p = y
• a is called the discrete log of y to the base g mod p.
Factoring (revisit)
• Given p and q, compute n = pq is EASY
• However, given n, compute the prime factors p and q is HARD
DLP Example:
• For p=97, g = 5 and y= 35, compute a such that ga mod p = 35.
– We need to try all possibilities (from 1 to 96) to obtain such a
21
21
Diffie-Hellman Problem
22
References
22
Diffie-Hellman Key Exchange
ga mod p
gb mod p
Alice, a Bob, b
❑ Alice computes (gb)a = gba = gab mod p
❑ Bob computes (ga)b = gab mod p
❑ Could use K = gab mod p as symmetric key
23
For slides 23 and 24. You must be able to explain and do an example
of a Diffie-Hellman key exchange. You must also understand how a
third party can execute the man-in-the-middle attack.
23
Man-in-the-Middle Attack (MITM)
ga mod p gt mod p
gt mod p gb mod p
24
24
Public key vs. Symmetric key
Symmetric key Public key
Two parties MUST trust each other Two parties DO NOT need to trust each other
Both share the same key (or one key is Two separate keys: a public and a private key
computable from the other)
Attack approach: bruteforce Attack approach: solving mathematical
problems (e.g. factorization, discrete log
problem)
Faster Slower (100-1000 times slower)
Smaller key size Larger key size
Examples: DES, 3DES, DESX, RC6, AES, … Examples: RSA, ElGamal, ECC,…
25
Reference
25
Post-Quantum Crypto
26
26
The end!
?
Any questions…
27
27