Cryptography and Cryptography and Network SecurityNetwork Security
Chapter 9Chapter 9
5th Edition5th Edition
by William Stallingsby William Stallings
Lecture slides by Lawrie BrownLecture slides by Lawrie Brown
Private-Key CryptographyPrivate-Key Cryptography
traditional traditional private/secret/single keyprivate/secret/single key cryptography uses cryptography uses oneone key key
shared by both sender and receiver shared by both sender and receiver if this key is disclosed communications are if this key is disclosed communications are
compromised compromised also is also is symmetricsymmetric, parties are equal , parties are equal hence does not protect sender from hence does not protect sender from
receiver forging a message & claiming is receiver forging a message & claiming is sent by sender sent by sender
Public-Key CryptographyPublic-Key Cryptography
probably most significant advance in the probably most significant advance in the 3000 year history of cryptography 3000 year history of cryptography
uses uses twotwo keys – a public & a private key keys – a public & a private key asymmetricasymmetric since parties are since parties are notnot equal equal uses clever application of number uses clever application of number
theoretic concepts to functiontheoretic concepts to function complements complements rather thanrather than replaces private replaces private
key cryptokey crypto
Why Public-Key Why Public-Key Cryptography?Cryptography?
developed to address two key issues:developed to address two key issues: key distributionkey distribution – how to have secure – how to have secure
communications in general without having to communications in general without having to trust a KDC with your keytrust a KDC with your key
digital signaturesdigital signatures – how to verify a message – how to verify a message comes intact from the claimed sendercomes intact from the claimed sender
public invention due to Whitfield Diffie & public invention due to Whitfield Diffie & Martin Hellman at Stanford Uni in 1976Martin Hellman at Stanford Uni in 1976 known earlier in classified communityknown earlier in classified community
Public-Key CryptographyPublic-Key Cryptography
public-key/two-key/asymmetricpublic-key/two-key/asymmetric cryptography cryptography involves the use of involves the use of twotwo keys: keys: a a public-keypublic-key, which may be known by anybody, and , which may be known by anybody, and
can be used to can be used to encrypt messagesencrypt messages, and , and verify verify signaturessignatures
a a private-keyprivate-key, known only to the recipient, used to , known only to the recipient, used to decrypt messagesdecrypt messages, and , and signsign (create) (create) signatures signatures
is is asymmetricasymmetric because because those who encrypt messages or verify signatures those who encrypt messages or verify signatures
cannotcannot decrypt messages or create signatures decrypt messages or create signatures
Public-Key ApplicationsPublic-Key Applications
can classify uses into 3 categories:can classify uses into 3 categories: encryption/decryptionencryption/decryption (provide secrecy) (provide secrecy) digital signaturesdigital signatures (provide authentication) (provide authentication) key exchangekey exchange (of session keys) (of session keys)
some algorithms are suitable for all uses, some algorithms are suitable for all uses, others are specific to oneothers are specific to one
Security of Public Key SchemesSecurity of Public Key Schemes like private key schemes brute force like private key schemes brute force exhaustive exhaustive
searchsearch attack is always theoretically possible attack is always theoretically possible but keys used are too large (>512bits) but keys used are too large (>512bits) security relies on a security relies on a large enoughlarge enough difference in difference in
difficulty between difficulty between easyeasy (en/decrypt) and (en/decrypt) and hardhard (cryptanalyse) problems(cryptanalyse) problems
more generally the more generally the hardhard problem is known, but problem is known, but is made hard enough to be impractical to break is made hard enough to be impractical to break
requires the use of requires the use of very large numbersvery large numbers hence is hence is slowslow compared to private key schemes compared to private key schemes
RSARSA
by Rivest, Shamir & Adleman of MIT in 1977 by Rivest, Shamir & Adleman of MIT in 1977 best known & widely used public-key scheme best known & widely used public-key scheme based on exponentiation in a finite (Galois) field based on exponentiation in a finite (Galois) field
over integers modulo a prime over integers modulo a prime nb. exponentiation takes O((log n)nb. exponentiation takes O((log n)33) operations (easy) ) operations (easy)
uses large integers (eg. 1024 bits)uses large integers (eg. 1024 bits) security due to cost of factoring large numbers security due to cost of factoring large numbers
nb. factorization takes O(e nb. factorization takes O(e log n log log nlog n log log n) operations (hard) ) operations (hard)
RSA Key SetupRSA Key Setup
each user generates a public/private key pair by: each user generates a public/private key pair by: selecting two large primes at random - selecting two large primes at random - p, qp, q computing their system modulus computing their system modulus n=p.qn=p.q
note note ø(n)=(p-1)(q-1)ø(n)=(p-1)(q-1) selecting at random the encryption key selecting at random the encryption key ee
• where 1<where 1<e<ø(n), gcd(e,ø(n))=1 e<ø(n), gcd(e,ø(n))=1
solve following equation to find decryption key solve following equation to find decryption key dd e.d=1 mod ø(n) and 0≤d≤ne.d=1 mod ø(n) and 0≤d≤n
publish their public encryption key: PU={e,n} publish their public encryption key: PU={e,n} keep secret private decryption key: PR={d,n} keep secret private decryption key: PR={d,n}
RSA UseRSA Use
to encrypt a message M the sender:to encrypt a message M the sender: obtains obtains public keypublic key of recipient of recipient PU={e,n}PU={e,n} computes: computes: C = MC = Mee mod n mod n, where , where 0≤M<n0≤M<n
to decrypt the ciphertext C the owner:to decrypt the ciphertext C the owner: uses their private key uses their private key PR={d,n}PR={d,n} computes: computes: M = CM = Cdd mod n mod n
note that the message M must be smaller note that the message M must be smaller than the modulus n (block if needed)than the modulus n (block if needed)
Why RSA WorksWhy RSA Works
because of Euler's Theorem:because of Euler's Theorem: aaø(n)ø(n)mod n = 1 mod n = 1 where where gcd(a,n)=1gcd(a,n)=1
in RSA have:in RSA have: n=p.qn=p.q ø(n)=(p-1)(q-1)ø(n)=(p-1)(q-1) carefully chose carefully chose ee & & dd to be inverses to be inverses mod ø(n)mod ø(n) hence hence e.d=1+k.ø(n)e.d=1+k.ø(n) for some for some kk
hence :hence :CCdd = M = Me.d e.d = M= M1+k.ø(n)1+k.ø(n) = M = M11.(M.(Mø(n)ø(n)))kk = M= M11.(1).(1)kk = M = M11 = M mod n = M mod n
RSA Example - Key SetupRSA Example - Key Setup
1.1. Select primes: Select primes: pp=17 & =17 & qq=11=112.2. ComputeCompute n n = = pq pq =17=17 x x 11=18711=1873.3. ComputeCompute ø( ø(nn)=()=(p–p–1)(1)(q-q-1)=161)=16 x x 10=16010=1604.4. Select Select ee:: gcd(e,160)=1; gcd(e,160)=1; choose choose ee=7=75.5. Determine Determine dd:: de=de=1 mod 1601 mod 160 and and d d < 160< 160
Value is Value is d=23d=23 since since 2323xx7=161= 107=161= 10xx160+1160+16.6. Publish public key Publish public key PU={7,187}PU={7,187}7.7. Keep secret private key Keep secret private key PR={23,PR={23,187}187}
RSA Example - En/DecryptionRSA Example - En/Decryption
sample RSA encryption/decryption is: sample RSA encryption/decryption is: given message given message M = 88M = 88 (nb. (nb. 88<18788<187)) encryption:encryption:
C = 88C = 8877 mod 187 = 11 mod 187 = 11 decryption:decryption:
M = 11M = 112323 mod 187 = 88 mod 187 = 88
ExponentiationExponentiation
can use the Square and Multiply Algorithmcan use the Square and Multiply Algorithm a fast, efficient algorithm for exponentiation a fast, efficient algorithm for exponentiation concept is based on repeatedly squaring base concept is based on repeatedly squaring base and multiplying in the ones that are needed to and multiplying in the ones that are needed to
compute the result compute the result look at binary representation of exponent look at binary representation of exponent only takes O(logonly takes O(log22 n) multiples for number n n) multiples for number n
eg. eg. 7755 = 7 = 744.7.711 = 3.7 = 10 mod 11 = 3.7 = 10 mod 11 eg. eg. 33129129 = 3 = 3128128.3.311 = 5.3 = 4 mod 11 = 5.3 = 4 mod 11
ExponentiationExponentiation
c = 0; f = 1c = 0; f = 1for i = k downto 0 for i = k downto 0 do c = 2 x cdo c = 2 x c f = (f x f) mod nf = (f x f) mod n
if bif bii == 1 == 1 then then c = c + 1c = c + 1 f = (f x a) mod n f = (f x a) mod n return freturn f
Efficient EncryptionEfficient Encryption
encryption uses exponentiation to power eencryption uses exponentiation to power e hence if e small, this will be fasterhence if e small, this will be faster
often choose e=65537 (2often choose e=65537 (21616-1)-1) also see choices of e=3 or e=17also see choices of e=3 or e=17
but if e too small (eg e=3) can attackbut if e too small (eg e=3) can attack using Chinese remainder theorem & 3 using Chinese remainder theorem & 3
messages with different moduliimessages with different modulii if e fixed must ensure if e fixed must ensure gcd(e,ø(n))=1gcd(e,ø(n))=1
ie reject any p or q not relatively prime to eie reject any p or q not relatively prime to e
Efficient DecryptionEfficient Decryption
decryption uses exponentiation to power ddecryption uses exponentiation to power d this is likely large, insecure if notthis is likely large, insecure if not
can use the Chinese Remainder Theorem can use the Chinese Remainder Theorem (CRT) to compute mod p & q separately. (CRT) to compute mod p & q separately. then combine to get desired answerthen combine to get desired answer approx 4 times faster than doing directlyapprox 4 times faster than doing directly
only owner of private key who knows only owner of private key who knows values of p & q can use this technique values of p & q can use this technique
RSA Key GenerationRSA Key Generation
users of RSA must:users of RSA must: determine two primes determine two primes at random - at random - p, qp, q select either select either ee or or dd and compute the other and compute the other
primes primes p,qp,q must not be easily derived must not be easily derived from modulus from modulus n=p.qn=p.q means must be sufficiently largemeans must be sufficiently large typically guess and use probabilistic testtypically guess and use probabilistic test
exponents exponents ee, , dd are inverses, so use are inverses, so use Inverse algorithm to compute the otherInverse algorithm to compute the other
RSA SecurityRSA Security
possible approaches to attacking RSA are:possible approaches to attacking RSA are: brute force key search (infeasible given size brute force key search (infeasible given size
of numbers)of numbers) mathematical attacks (based on difficulty of mathematical attacks (based on difficulty of
computing ø(n), by factoring modulus n)computing ø(n), by factoring modulus n) timing attacks (on running of decryption)timing attacks (on running of decryption) chosen ciphertext attacks (given properties of chosen ciphertext attacks (given properties of
RSA)RSA)
Factoring ProblemFactoring Problem
mathematical approach takes 3 forms:mathematical approach takes 3 forms: factor factor n=p.qn=p.q, hence compute , hence compute ø(n)ø(n) and then d and then d determine determine ø(n)ø(n) directly and directly and compute compute dd find d directlyfind d directly
currently believe all equivalent to factoringcurrently believe all equivalent to factoring have seen slow improvements over the years have seen slow improvements over the years
• as of May-05 best is 200 decimal digits (663) bit with LS as of May-05 best is 200 decimal digits (663) bit with LS biggest improvement comes from improved algorithmbiggest improvement comes from improved algorithm
• cf QS to GHFS to LScf QS to GHFS to LS currently assume 1024-2048 bit RSA is securecurrently assume 1024-2048 bit RSA is secure
• ensure p, q of similar size and matching other constraintsensure p, q of similar size and matching other constraints
Timing AttacksTiming Attacks
developed by Paul Kocher in mid-1990’sdeveloped by Paul Kocher in mid-1990’s exploit timing variations in operationsexploit timing variations in operations
eg. multiplying by small vs large number eg. multiplying by small vs large number or IF's varying which instructions executedor IF's varying which instructions executed
infer operand size based on time taken infer operand size based on time taken RSA exploits time taken in exponentiationRSA exploits time taken in exponentiation countermeasurescountermeasures
use constant exponentiation timeuse constant exponentiation time add random delaysadd random delays blind values used in calculationsblind values used in calculations
Chosen Ciphertext AttacksChosen Ciphertext Attacks
• RSA is vulnerable to a Chosen Ciphertext RSA is vulnerable to a Chosen Ciphertext Attack (CCA)Attack (CCA)
• attackers chooses ciphertexts & gets attackers chooses ciphertexts & gets decrypted plaintext backdecrypted plaintext back
• choose ciphertext to exploit properties of choose ciphertext to exploit properties of RSA to provide info to help cryptanalysisRSA to provide info to help cryptanalysis
• can counter with random pad of plaintextcan counter with random pad of plaintext• or use Optimal Asymmetric Encryption or use Optimal Asymmetric Encryption
Padding (OASP)Padding (OASP)