Lecture 21 22 23 24
Lecture 21 22 23 24
Instructor:
Dr Mohammad Wazid
Associate Professor, Department of CSE
Graphic Era (Deemed to be University), Dehradun, India
Email: [email protected]
Homepage: https://sites.google.com/site/mwazidiiith/home
Public-Key Cryptography
• Probably most significant advancement in the 3000 year
history of cryptography
• Uses two keys – a public & a private key
• Asymmetric since parties are not equal
• Uses the number theoretic concepts to the
encryption/decryption function
• Complements rather than replaces private key cryptosystem
Why Public-Key Cryptography?
• Developed to address two key issues:
• key distribution – how to have secure
communications in general without having to trust a
KDC with your key
• digital signatures – how to verify a message comes
intact from the claimed sender
• Public invention due to Whitfield Diffie & Martin
Hellman at Stanford University in 1976
Public-Key Cryptography
• Public-key/two-key/asymmetric cryptography involves the
use of two keys:
• a public-key, which may be known to anybody, and can be
used to encrypt messages, and verify signatures
• a related private-key, known only to the recipient, used to
decrypt messages, and sign (create) signatures
• Infeasible to determine private key from public key
• Is asymmetric because
• those who encrypt messages or verify signatures cannot
decrypt messages or create signatures
Public-Key Cryptography
Symmetric vs Public-Key
Public-Key Cryptosystems
Here, we’ll
achieve both
properties
secrecy
(confidentiality)
as well as
authenticity of
messages
Public-Key Applications
• Can be classified into 3 categories:
• encryption/decryption (provide secrecy)
• digital signatures (provide authentication)
• key exchange (of session keys)
• Some algorithms are suitable for all uses, others are specific to
one
Public-Key Requirements
• Public-Key algorithms rely on two keys where:
• It is computationally infeasible to find decryption key
knowing only algorithm & encryption key.
• It is computationally easy to en/decrypt messages
when the relevant (en/decrypt) key is known.
• Either of the two related keys can be used for
encryption, with the other used for decryption (for
some algorithms).
• These are essential requirements which only a few
algorithms have satisfied.
Security of Public Key Schemes
Like private key schemes brute force exhaustive search attack is
always theoretically possible.
But keys used are too large (>512bits).
Security relies on a large enough difference in difficulty between
easy (en/decrypt) and hard (cryptanalyse) problems.
More generally the hard problem is known, but is made hard
enough to be impractical to break.
Requires the use of very large numbers.
Hence, these algorithms are slow as compared to private key
schemes.
RSA Algorithm
• The RSA algorithm is named after Ron Rivest, Adi Shamir
and Len Adleman, who invented it in 1977.
• The RSA cryptosystem is the most widely-used public key
cryptography algorithm in the world.
• It can be used to encrypt a message without the need to
exchange a secret key separately.
• The RSA algorithm can be used for both public key
encryption and digital signatures.
RSA Algorithm
• Its security is based on the difficulty of factoring large
integers.
• Party A can send an encrypted message to party B without
any prior exchange of secret keys.
• A just uses B's public key to encrypt the message and B
decrypts it using the private key, which only he knows.
• RSA can also be used to sign a message, so A can sign a
message using his/her private key and B can verify it using
A's public key.
RSA Algorithm
• Key Generation Algorithm
• Generate two large random primes, p and q, of
approximately equal size such that their product n=p*q is of
the required bit length, e.g. 1024 bits.
• Compute n=p*q and ϕ(n)=(p-1)(q-1). Here ϕ(n) is euler’s
totient function
• Choose an integer e, 1<e<ϕ(n), such that gcd(e, ϕ(n))=1.
• Compute the secret exponent d, 1<d<ϕ(n), such that ed≡1
mod ϕ(n).
• The public key is (e, n) and the private key (d, n).
Use euclidean algorithm to compute gcd
• In order to find the largest common divisor, we can prime
factorize both numbers and examine which prime factors that
appear in both numbers, that is, the largest common divisor will
be the intersection of the sets of prime factors for both numbers.
• However, the procedure of prime factorizing numbers is very
tedious.
• Start by dividing the larger number m with the smaller n. This
gives a remainder r1.
• Then divide the smaller number n with the obtained remainder
r1.
Use euclidean algorithm to compute gcd
• This gives a new remainder r2. Now divide the remainder r1
with the remainder r2.
• This gives yet another remainder r3.
• Repeat the procedure until the remainder becomes zero.
• The last non-zero remainder is equal to the largest common
divisor.
Use euclidean algorithm to compute gcd
• Example:
• gcd(100,44)?
• In case if we get 0 in the
reminder then previous
reminder is the gcd.
Use euclidean algorithm to compute gcd
• Other case:
• Example:
• gcd(9,7)?
• 9=7x1+2
• 7=2x3+1
• Note: In the reminder if get 1 then 1 will be the gcd.
Use euclidean algorithm to compute gcd
• Another example:
• gcd(15,13)?
• 15=13x1+2
• 13=2x6+1
• Therefore gcd will be 1.
• Note: greatest common factor (G.C.F)or highest common
factor (H.C.F) or greatest common divisor (G.C.D), we know
that there is no difference between them.
Extended Euclidean algorithm to compute
inverse modulo
• Compute 7-1 (mod 20)
• To compute this first apply the steps of Euclidean algorithm
• 20=7*2+6 ---(eq. 1)
• 7=6*1+1 ---(eq. 2)
• If we get reminder as a 1 then inverse modulo is possible
otherwise not.
• Eq. 1 and 2 can also be written as
• 20=7*2+6 ---(eq. 1) or 6=20-7*2
• 7=6*1+1 ---(eq. 2) or 1=7-6*1
Extended Euclidean algorithm to compute
inverse modulo
• 6=20-7*2 --- (eq. 3)
• 1=7-6*1--- (eq. 4)
• Substitute the value of 6 from eq. 3 to eq. 4
• 1=7-1*(20-7*2)
• 1=7-1*20+7*2
• 1=7*1-1*20+7*2
• 1=7*3-1*20 (whatever we’ll have in the multiplication of 7 will
be the modulo inverse.
• Therefore, 7-1 (mod 20) will be 3.
RSA Algorithm
Encryption
• Sender A does the following:
• Obtains the recipient B's public key (e,n).
• Represents the plaintext message as a positive integer m with 1<m<n
• Computes the ciphertext c=m^e mod n.
• Sends the ciphertext c to recipient B.
Decryption
• Recipient B does the following:
• Uses his private key (d,n) to compute m=c^d mod n.
• Extracts the plaintext m from the received message c.
Example of RSA encryption and decryption using the
key pair established:
• public key: (9, 1189) and private key: (249,1189)
• Suppose someone wants to encrypt the plaintext 19. We
• Step 3:
thus have to calculate: • C ≡ (19^8)(19^1) mod 1189
• C ≡ 19^9 mod 1189.
• ≡ (1185)(19) mod 1189
• This is most efficiently calculated using the Repeated
Squares Algorithm: • ≡ 22515 mod 1189
• Step 1:
• ≡ 1113 mod 1189
• C ≡ {19^(8+1)} mod 1189
• C ≡ {(19^8)(19^1)} mod 1189 • So the ciphertext C is 1113.
• Step 2:
• 19^1 ≡ 19 mod 1189
• 19^2 ≡ 19^2 = 361 mod 1189
• 19^4 = (19^2)^2 ≡ (361)^2 = 130321 ≡ 720 mod 1189
• 19^8 = (19^4)^2 ≡ (720)^2 = 518400 ≡ 1185 mod 1189
Example of RSA encryption and decryption using the
key pair established:
• RSA Decryption • Step 2:
• Suppose we now receive this ciphertext • 1113^1 ≡ 1113 mod 1189
C=1113. To decrypt it we have to calculate:
• 1113^2 ≡ 11132 = 1238769 ≡ 1020 mod
• M ≡ {1113^249} mod 1189. 1189
• This is most efficiently calculated using the • 1113^4 = (1113^2)^2 ≡ (1020)^2 =
Repeated Squares Algorithm:
1040400 ≡ 25 mod 1189
• Step 1:
• 1113^8 = (1113^4)^2 ≡ (25)^2 = 625
• M ≡ 1113^249 mod 1189 mod 1189
• M ≡ {1113^(128+64+32+16+8+1)} mod 1189
• M≡
{(1113^128)(1113^64)(1113^32)(1113^16)(1
113^8)(1113^1)} mod 1189
Example of RSA encryption and decryption using the
key pair established:
• 1113^16 = (1113^8)^2 ≡ (625)^2 = 390625 ≡ (256)(16)(1185)(633)(625)(1113) mod 1189
≡ 633 mod 1189 ≡ (256)(16)(1185)(633){(625)(1113) mod 1189}
• 1113^32 = (1113^16)^2 ≡ (633)^2 = 400689 ≡ (256)(16)(1185)(633)(60) mod 1189
≡ 1185 mod 1189 ≡ (256)(16)(60){(1185)(633) mod 1189}
• 1113^64 = (1113^32)^2 ≡ (1185)^2 = ≡ (256)(16)(60)(1035) mod 1189
1404225 ≡ 16 mod 1189 ≡ (16)(60){(256)(1035) mod 1189}
≡(16)(60)(1002) mod 1189
• 1113^128 = (1113^64)^2 ≡ (16)^2 = 256
mod 1189 ≡961920 mod 1189
≡ 19 mod 1189.
• Step 3: • So the plaintext M is 19. Cross verified.
• M≡
(1113^128)(1113^64)(1113^32)(1113^16)(11
13^8)(1113^1) mod 1189
Correctness proof of RSA Algorithm
Diffie-Hellman Key Exchange
• First published public-key algorithm (in 1976).