Public Key Cryptography and RSA
Public Key Cryptography and RSA
Public Key Cryptography and RSA
Lecture#06
Public Key Cryptography and
RSA
Course: Cryptography & Network Security (CE-408)
Course Teacher: Ms. Rukaiya
Contact Info:
Email: [email protected]
1
Secret/ Symmetric Key Encryption
Problems
2
Public-Key Cryptography
• Public-key encryption involves usage of two keys
Public-key
It is known to anybody
It can be used to encrypt messages and verify signatures
Private-key
It is known to the recipient
It can be used to decrypt messages and create digital
signature
3
Conventional And Public Key Encryption
Conventional Encryption Public-Key Encryption
Needed to Work: Needed to Work:
1. The same algorithm with the 1. One algorithm is used for encryption
same key is used for encryption and a related algorithm for
and decryption. decryption with a pair of keys, one
for encryption and one for
2. The sender and receiver must decryption.
share the algorithm and the key.
2. The sender and receiver must each
Needed for Security: have one of the matched pair of keys
(not the same one).
1. The key must be kept secret.
Needed for Security:
2. It must be impossible or at least
impractical to decipher a 1. One of the two keys must be kept
message if the key is kept secret. secret.
Distinct
Secret Key Public Key
Features
No. of keys Single key Pair of keys
Types of Keys Key is secret One is public,
one is private
Size of keys 50 – 250 bits 500 – 2500 bits
Relative Faster Slower
Speeds
5
Terminologies Related to Asymmetric
Encryption
Table 9.1 Terminology Related to Asymmetric Encryption
Asymmetric Keys
Two related keys, a public key and a private key that are used to perform complementary
operations, such as encryption and decryption or signature generation and signature verification.
6
Misconceptions Concerning Public-Key
Encryption
7
Principles of Public-Key Cryptosystems
• The concept of public-key cryptography evolved from an attempt
to attack two of the most difficult problems associated with
symmetric encryption:
Key
distribution
• How to have secure communications in general without
having to trust a KDC with your key
Digital
signatures
• How to verify that a message comes intact from the
claimed sender
Encryption Decryption
Plaintext Public key Private key Ciphertext
algorithm algorithm
The Accepts
readable the
The
message Performs ciphertext
Used for Used for scrambl
or data various and the
encryptio encrypti ed
that is transform matching
n or on or message
fed into ations on key and
decryptio decrypti produce
the the produces
n on d as
algorith plaintext the
output
m as original
input plaintext
9
Encryption with Public Key
Bobs's
public key
ring
Joy
Ted
Mike Alice
Transmitted X=
X ciphertext D[PRa, Y]
Y = E[PUa, X]
Plaintext Plaintext
Encryption algorithm Decryption algorithm
input output
(e.g., RSA)
10
Plaintext Plaintext
Encryption algorithm Decryption algorithm
input output
(e.g., RSA)
Encryption with Private Key
Bob (a) Encryption with public key Alice
Alice's
public key
ring
Joy
Ted
Mike Bob
X=
X Transmitted D[PUb, Y]
ciphertext
Y = E[PRb, X]
Plaintext Plaintext
Encryption algorithm Decryption algorithm
input output
(e.g., RSA)
11
Public-key Cryptosystem: Confidentiality
^
X
Cryptanalyst
^
PRb
Source A Destination B
PUb PRb
Key Pair
Source
13
Public-key Cryptosystem: Authentication
and Secrecy
14
Applications for Public-Key Cryptosystems
15
Applications for Public-Key Cryptosystems
• Public-key cryptosystems can be classified into
three categories:
18
Public-Key Cryptanalysis
• A public-key encryption scheme is vulnerable to a brute-force
attack
Countermeasure: use large keys
Key size must be small enough for practical encryption and
decryption
Key sizes that have been proposed result in encryption/decryption speeds
that are too slow for general-purpose use
Public-key encryption is currently confined to key management
and signature applications
Another form of attack is to find some way to compute the private key
given the public key
To date it has not been mathematically proven that this form of
attack is infeasible for a particular public-key algorithm
19
Rivest-Shamir-Adleman (RSA)
Algorithm
• Developed in 1977 at MIT by Ron Rivest, Adi
Shamir & Len Adleman
20
RSA Algorithm
• RSA makes use of an expression with exponentials
• Plaintext is encrypted in blocks with each block having a
binary value less than some number n
• Encryption and decryption are of the following form, for
some plaintext block M and ciphertext block C
C = Me mod n
M = Cd mod n = (Me)d mod n = Med mod n
• Both sender and receiver must know the value of n
• The sender knows the value of e, and only the receiver
knows the value of d
• This is a public-key encryption algorithm with a public key
of PU={e,n} and a private key of PR={d,n}
21
Algorithm Requirements
• For this algorithm to be satisfactory for public-
key encryption, the following requirements
must be met:
1. It is possible to find values of e, d, n
such that Med mod n = M for all M < n
2. It is relatively easy to calculate Me mod n
and Cd mod n for all values of M < n
3. It is infeasible to determine d given e
and n
22
Key Generation by Alice
Calculate n = p ´ q
Plaintext: M<n
Ciphertext: C = Me mod n
Ciphertext: C
Plaintext: M = Cd mod n
Key Generation
1. First choose two prime numbers p and q (large) and find
the product n, where n= p x q
25
DIGITAL CERTIFICATE
• It can be considered as the ID card issued to the person. People use
ID cards such as a driver's license, passport to prove their identity.
• These are not only issued to people, but they can be issued to
computers, software packages or anything else that need to prove the
identity in the electronic world.
• These are based on the ITU standard X.509 which defines a standard
certificate format for public key certificates and certification validation.
Hence digital certificates are sometimes also referred to as X.509
certificates.
• Anyone who needs the assurance about the public key and
associated information of client, he carries out the signature validation
process using CA’s public key. Successful validation assures that the
public key given in the certificate belongs to the person whose details
are given in the certificate. 26
RSA-Key Generation
27
Example of RSA Algorithm
• p = 3, q =11. n=p* q = 3* 11 = 33
• Calculate ø(n) = (p-1) (q-1) = (3-1) (11-1) = 2 * 10 = 20
There are 20 relative numbers to 33, what are they??
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
d=7 (7 and 20 have no common factor but 1)
7 e = 1 mod 20
Find ‘e’ using Extended Euclidean algorithm, as e is
multiplicative inverse of d
e =3 Decryption
Encryption Decryption
ciphertext
plaintext plaintext
7 11 23
88 88 mod 187 = 11 11 mod 187 = 88 88
31
Sender
3
Plaintext P
Decimal string
4
Blocks of numbers
P1, P2,
5
Ciphertext C
2
Public key C1 = P1e mod n
e, n C2 = P2e mod n
RSA Processing of n = pq
Multiple Blocks
11
Transmit
6 7
Private key Recovered
d, n decimal text
P1 = C1d mod n
d= mod f(n)
e–1 P2 = C2d mod n 5
f(n) = (p – 1)(q – 1) 1
1 n = pq 1 1
e, p, q
p
Decimal string 33 14 22 62 00 17 04 62 24 14 20 66
4 4
Blocks of numbers P1 = 3314 P2 = 2262 P3 = 0017
P1, P2, P4 = 0462 P5 = 2414 P6 = 2066
5 5
Ciphertext C C1 = 3314 11 mod 11023 = 10260
2 2 C2 = 2262 11 mod 11023 = 9489
Public key C1 = P1e mod n e = 11 C3 = 17 11 mod 11023 = 1782
e, n C2 = P2e mod n n = 11023
RSA Processing of
C4 = 462 11 mod 11023 = 727
C5 = 2414 11 mod 11023 = 10032
C6 = 2066 11 mod 11023 = 2253
Multiple Blocks
n = pq
Transmit
11023 = 73 151
Transmit
6 7 6 7
Private key Recovered d = 5891
P1 = 10260 5891 mod 11023 = 3314
d, n decimal text n = 11023
P2 = 9489 5891 mod 11023 = 2262
P1 = C1d mod n P3 = 1782 5891 mod 11023 = 0017
d= mod f(n)
e–1 P2 = C2d mod n 5891 = 11–1 mod 10800 P4 = 7275891 mod 11023 = 0462
f(n) = (p – 1)(q – 1) 10800 = (73 – 1)(151 – 1) P5 = 10032 5891 mod 11023 = 2414
1 n = pq 1 11023 = 73 51 P6 = 2253 5891 mod 11023 = 2066
e = 11
e, p, q
p = 73, q = 151
34
Efficient Operation Using the Public
Key
• Decryption uses exponentiation to power d
A small value of d is vulnerable to a brute-force
attack and to other forms of cryptanalysis
35
Key Generation
36
The Security of RSA
Brute force
•Involves Mathematical
Chosen ciphertext trying all attacks
attacks possible •There are several
•This type of private keys approaches, all
attack exploits equivalent in effort
properties of the to factoring the
RSA algorithm product of two
primes
Five
possible
approaches
to
Hardware fault- attacking
based attack RSA are:
Timing attacks
•This involves
inducing hardware •These depend on
faults in the the running time
processor that is of the decryption
generating digital algorithm
signatures
37
Factoring Problem
• We can identify three approaches to attacking
RSA mathematically:
Factor n into its two prime factors. This enables
calculation of ø(n) = (p – 1) x (q – 1), which in turn
enables determination of d = e-1 (mod ø(n))
38
Timing Attack
• Paul Kocher, a cryptographic consultant,
demonstrated that a snooper can determine a
private key by keeping track of how long a
computer takes to decipher messages
• Are applicable not just to RSA but to other
public-key cryptography systems
• Are alarming for two reasons:
It comes from a completely unexpected
direction
It is a ciphertext-only attack
39
Countermeasures
40
Fault-Based Attack
• An attack on a processor that is generating RSA
digital signatures
Induces faults in the signature computation by
reducing the power to the processor
The faults cause the software to produce invalid
signatures which can then be analyzed by the
attacker to recover the private key
42
P
seed M
H(P)
padding
DB
MGF
maskedDB
MGF
maskedseed
EM