Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Unit 4_Public Key cryptography

Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

Cryptography

Unit 4 – Public Key Cryptography

Dr. M. V. Mandi
Professor, Dept. of ECE, Dr. AIT, Bangalore
Private-Key Cryptography

• traditional private/secret/single key cryptography


uses one key
• shared by both sender and receiver
• if this key is disclosed communications are
compromised
• does not protect sender from receiver forging a
message & claiming is sent by sender
Public-Key Cryptography

• probably most significant advance in the 3000 year


history of cryptography
• uses two keys – a public & a private key
• asymmetric since parties are not equal
• uses clever application of number theoretic
concepts to function
• complements rather than replaces private key
crypto
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
• known earlier in classified community
Public-Key Cryptography

• public-key/two-key/asymmetric cryptography
involves the use of two keys:
• a public-key, which may be known by anybody, and can
be used to encrypt messages, and verify signatures
• a private-key, known only to the recipient, used to
decrypt messages, and sign (create) signatures
• is asymmetric because
• those who encrypt messages or verify signatures cannot
decrypt messages or create signatures
Public-Key Cryptography
Public-Key Characteristics

• 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 encrypt/decrypt messages
when the relevant (encrypt/decrypt) key is known
• either of the two related keys can be used for encryption,
with the other used for decryption (for some algorithms)
Public-Key Cryptosystems

Above method provides both authentication and confidentiality


If keys are generated at destination then it provides only confidentiality
If keys are generated at source then it provides only authentication
Public-Key Applications
• can classify uses 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
Sl. No Algorithm E/D Digital Key
Signature exchange
1 RSA Yes Yes Yes
2 Diffie-Hellman No No Yes
3 Digital Signature No Yes No
Standard
4 Elliptic Curve Yes Yes Yes
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 (encrypt/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 is slow compared to private key schemes
RSA Algorithm
• by Rivest, Shamir & Adleman of MIT in 1977
• best known & widely used public-key scheme
• based on exponentiation in a finite (Galois) field over
integers modulo a prime
• Note: exponentiation takes O((log n)3) operations (easy)
• uses large integers (eg: 1024 bits)
• security due to cost of factoring large numbers
• Note: factorization takes O(e log n log log n) operations (very hard)
RSA Key Setup
• each user generates a public/private key pair by:
• selecting two large primes at random: p,q
• computing their system modulus n=p.q
• note ø(n)=(p-1)(q-1)
• selecting at random the encryption key e
• where 1<e<ø(n), gcd(e, ø(n))=1
• solve following equation to find decryption key d
• e.d ≡ 1 mod ø(n) and 0≤d≤n
• publish their public encryption key: PU={e,n}
• keep secret private decryption key: PR={d,n}
RSA Use
• to encrypt a message M the sender:
• obtains public key of recipient PU={e, n}
• computes: C = Me mod n, where 0≤M<n
• to decrypt the ciphertext C the owner:
• uses their private key PR={d, n}
• computes: M = Cd mod n
• note that the message M must be smaller than the
modulus n (block if needed)
RSA algorithm
I Key Generation
1. Select p, q p, q are both prime nos. (pǂq)
2. Calculate n = p.q
3. Calculate ø(n)=(p-1)(q-1)
4. Select integer, e gcd(ø(n), e) = 1
5. Calculate d such that d ≡ e -1 mod ø(n)
6. Public key KU = {e, n}
7. Private key KR = {d, n}
II Encryption
Plain text: M < n
Cipher Text: C = Me (mod n)
III Decryption
Cipher text: C
Plain Text: M = Cd (mod n)
RSA Example - Key Setup
1. Select primes: p=17 & q=11
2. Compute n = p.q =17 x 11=187
3. Compute ø(n)=(p–1)(q-1)=16 x
10=160
4. Select e: gcd(e,160)=1; choose e = 7
5. Determine d: de ≡ 1 mod 160 and d < 160
or d ≡ e -1 mod ø(n), find 7-1 in Z160
Value is d=23 since 23x7=161= 10x160+1
1. Publish public key PU={7,187}
2. Keep secret private key PR={23,187}
RSA Example - Encryption/Decryption
• sample RSA encryption/decryption is:
• given message M = 88 (note: 88<187)
• encryption:
C = 887 mod 187 = 11
• decryption:
M = 1123 mod 187 = 88
To find 7-1 in Z160 using Extended Euclid’s algorithm

q r1 r2 r t1 t2 t
22 160 7 6 0 1 -22
1 7 6 1 1 -22 23
6 6 1 0 -22 23 -160
1 0 23 -160

Here t = t1 – q x t2
Since gcd(7, 160) = 1, multiplicative inverse of 7 is 23
Ex 2: RSA
1. Select primes: p=7 & q=11
2. Compute n = p.q =7 x 11= 77
3. Compute ø(n)=(p–1)(q-1)=6 x 10=60
4. Select e: gcd(e,60)=1; choose e = 13
5. Determine d: de ≡ 1 mod 60 and d < 60
or d ≡ e -1 mod ø(n), find 7-1 in Z60
Value is d=43 since 43x7=301 ≡ 1 mod 60
1. Publish public key PU={7,77}
2. Keep secret private key PR={43,77}
RSA Example - Encryption/Decryption
• sample RSA encryption/decryption is:
• given message M = 10 (note: 10<77)
• encryption:
C = 107 mod 77= 10
• decryption:
M = 1043 mod 77= 10
To find 7-1 in Z60 using Extended Euclid’s algorithm

q r1 r2 r t1 t2 t
8 60 7 4 0 1 -8
1 7 4 3 1 -8 9
1 4 3 1 -8 9 -17
3 3 1 0 9 -17 60
1 0 -17 60

Here t = t1 – q x t2
Since gcd(7, 60) = 1, multiplicative inverse of 7 is 43
-17 mod 60 = 43
Problems on RSA
1.p=3 and q = 11. Take e = 3 and M = 23
Ans: Ref. Notes
2.P=17 and q=11. Take e = 3 and M = 88
Ans: Ref Notes

3. p=5 and q=19 Take e=5 and M=45


Exponentiation
• can use the Square and Multiply Algorithm
• a fast, efficient algorithm for exponentiation
• concept is based on repeatedly squaring base
and multiplying in the ones that are needed to
compute the result
• only takes O(log2 n) multiples for number n
• eg. 75 = 74.71 = 3.7 = 10 mod 11
• eg. 3129 = 3128.31 = 5.3 = 4 mod 11
RSA Key Generation
• users of RSA must:
• determine two primes at random: p, q (large)
• select either e or d and compute the other
• primes p, q must not be easily derived from
modulus n = p.q
• means must be sufficiently large
• typically guess and use probabilistic test
• exponents e, d are inverses, so use Inverse
algorithm to compute the other
• Use Extended Euclid’s algorithm to find multiplicative
inverse
RSA Security
• possible approaches to attacking RSA are:
• brute force key search (infeasible given size of numbers)
• mathematical attacks (based on difficulty of computing
ø(n), by factoring modulus n)
• timing attacks (on running of decryption)
• chosen ciphertext attacks (given properties of RSA)
Factoring Problem
• mathematical approach takes 3 forms:
• factor n=p.q, hence compute ø(n) and then d
• determine ø(n) directly and compute d
• find d directly
• currently believe all equivalent to factoring
• currently assume 1024-2048 bit RSA is secure
• ensure p, q of similar size and matching other constraints
Timing Attacks
• developed by Paul Kocher in mid-1990’s
• exploit timing variations in operations
• e.g., multiplying by small vs large number
• infer operand size based on time taken
• RSA exploits time taken in exponentiation
• countermeasures
• use constant exponentiation time
• add random delays
• blind values used in calculations
Chosen Ciphertext Attacks

RSA is vulnerable to a Chosen Ciphertext Attack (CCA),


attackers chooses ciphertexts & gets decrypted plaintext
back

choose ciphertext to exploit properties of RSA to provide


info to help cryptanalysis

can counter with random pad of plaintext


Key Management
• public-key encryption helps address key distribution
problems
• have two aspects of this:
• distribution of public keys
• use of public-key encryption to distribute secret (private)
keys
Distribution of Public Keys

•can be considered as using one of:


1. public announcement
2. publicly available directory
3. public-key authority
4. public-key certificates
1. Public Announcement

• users distribute public keys to recipients or


broadcast to community at large
• eg. append PGP keys to email messages or post to news
groups or email list
• major weakness is forgery
• anyone can create a key claiming to be someone else and
broadcast it
• until forgery is discovered can masquerade (impersonate)
as claimed user
2. Publicly Available Directory

• can obtain greater security by registering keys with


a public directory
• directory must be trusted with properties:
• contains {name, public-key} entries
• participants register securely with directory
• participants can replace key at any time
• directory is periodically published
• directory can be accessed electronically
• still vulnerable to tampering or forgery
3. Public-Key Authority
• improve security by tightening control over
distribution of keys from directory
• has properties of directory
• and requires users to know public key for the
directory
• then users interact with directory to obtain any
desired public key securely
• does require real-time access to directory when keys are
needed
Public-Key Authority (Cont…)
4. Public-Key Certificates
• certificates allow key exchange without real-time
access to public-key authority
• a certificate binds identity to public key
• usually with other info such as period of validity, rights of
use etc.
• with all contents signed by a trusted Public-Key or
Certificate Authority (CA)
• can be verified by anyone who knows the public-key
authorities public-key
Public-Key Certificates (Cont…)
Public-Key distribution of Secret Keys
• use previous methods to obtain public-key
• can use for secrecy or authentication
• but public-key algorithms are slow
• so usually want to use private-key encryption to
protect message contents
• hence need a session key
• have several alternatives for negotiating a suitable
session
Distribution of Public Keys
•can be considered as using one of:

1. Simple Secret key Distribution


2. Public key distribution of secret keys
3. Hybrid key distribution
1. Simple Secret Key Distribution
• proposed by Merkle in 1979
• ‘A’ generates a new temporary public key pair
• ‘A’ sends ‘B’ the public key and their identity
• ‘B’ generates a session key ‘K’ sends it to ‘A’ encrypted
using the supplied public key
• ‘A’ decrypts the session key and both use
• problem is that an opponent can intercept and
impersonate both halves of protocol
Simple Secret Key Distribution - disadvantage
2. Public-Key Distribution of Secret Keys
3. Hybrid Key Distribution
• retain use of private-key KDC (key distribution
centre)
• shares secret master key with each user
• distributes session key using master key
• public-key used to distribute master keys
• especially useful with widely distributed users
Diffie-Hellman Key Exchange
• first public-key type scheme proposed
• by Diffie & Hellman in 1976 along with the
exposition of public key concepts
• note: concept was previously described by Williamson
(UK) in 1970
• is a practical method for public exchange of a secret
key
• used in a number of commercial products
Diffie-Hellman Key Exchange
• a public-key distribution scheme
• cannot be used to exchange an arbitrary message
• rather it can establish a common key
• known only to the two participants
• value of key depends on the participants (and their
private and public key information)
• based on exponentiation in a finite (Galois) field
(modulo a prime or a polynomial) - easy
• security relies on the difficulty of computing
discrete logarithms (similar to factoring) – very hard
Diffie-Hellman Setup
• all users agree on global parameters:
• large prime integer or polynomial q
• α being a primitive root mod q
• each user (eg. A) generates their key
• A chooses a secret key (number): xA < q
• compute A’s public key: y A=αxA mod q
• user A makes that public key yA
• Similarly, B chooses: xB < q
x
• compute their public key: y B=α B mod q
• user A makes that public key yB
Diffie-Hellman Key Exchange
• shared session key for users A & B is KAB:
x x
• KAB = α A. B mod q
xB
= yA mod q (which B can compute)
xA
= yB mod q (which A can compute)
• KAB is used as session key in private-key encryption
scheme between Alice and Bob
• if Alice and Bob subsequently communicate, they
will have the same key as before, unless they
choose new public-keys
• attacker needs an x, must solve discrete log
Diffie-Hellman Algorithm

Global Public Elements


q Prime number
α α < q (a primitive root mod q)
User A key generation
A chooses a secret key: xA < q
compute A’s public key: y A=αxA mod q
User B key generation
A chooses a secret key: xB < q
compute A’s public key: y B=αxB mod q
Generation of Secret key User A
K= yBxA mod q
Generation of Secret key User B
K=yAxB mod q
Diffie-Hellman Example
• users Alice & Bob who wish to swap keys:
• agree on prime q=353 and α=3
• select random secret keys:
• A chooses xA=97, B chooses xB=233
• compute respective public keys:
• yA=397 mod 353 = 40 (Alice)
233
• yB=3 mod 353 = 248 (Bob)
• compute shared session key as:
• KAB= yBxA mod 353 = 24897 = 160 (Alice)
xB 233
• KAB= yA mod 353 = 40 = 160 (Bob)
Diffie-Hellman Example
Summary

Have considered
Public Key cryptography
RSA,
Diffie-Hellman Key exchange algorithm

You might also like