CS 155 Spring 2008 Cryptography Overview John Mitchell

  • Slides: 52
Download presentation
CS 155 Spring 2008 Cryptography Overview John Mitchell

CS 155 Spring 2008 Cryptography Overview John Mitchell

Announcement: Homework 1 Posted on web n Five problems Due April 29

Announcement: Homework 1 Posted on web n Five problems Due April 29

Cryptography Is n n A tremendous tool The basis for many security mechanisms Is

Cryptography Is n n A tremendous tool The basis for many security mechanisms Is not n n The solution to all security problems Reliable unless implemented properly Reliable unless used properly Something you should try to invent yourself unless w you spend a lot of time becoming an expert w you subject your design to outside review

Basic Cryptographic Concepts Encryption scheme: n n functions to encrypt, decrypt data key generation

Basic Cryptographic Concepts Encryption scheme: n n functions to encrypt, decrypt data key generation algorithm Symmetric key vs. public key n n Public key: publishing key does not reveal key-1 Secret key: more efficient, generally key = key-1 Hash function, MAC n n Map any input to short hash; ideally, no collisions MAC (keyed hash) used for message integrity Signature scheme n Functions to sign data, verify signature

Five-Minute University Father Guido Sarducci Everything you might remember, five years after taking CS

Five-Minute University Father Guido Sarducci Everything you might remember, five years after taking CS 255 … ? This lecture describes basic functions and example constructions. Constructions not needed for CS 155.

Example: network transactions Assume attackers can control the network n n We will talk

Example: network transactions Assume attackers can control the network n n We will talk about how they do this in a few weeks Attackers can intercept your packets, tamper with or suppress them, and inject arbitrary packets

Secure communication n Based on n n Cryptographic methods Key management protocols

Secure communication n Based on n n Cryptographic methods Key management protocols

Secure Sockets Layer / TLS Standard for Internet security n n Originally designed by

Secure Sockets Layer / TLS Standard for Internet security n n Originally designed by Netscape Goal: “. . . provide privacy and reliability between two communicating applications” Two main parts n Handshake Protocol w Establish shared secret key using public-key cryptography w Signed certificates for authentication n Record Layer w Transmit data using negotiated key, encryption function

SSL/TLS Cryptography Public-key encryption n n Key chosen secretly (handshake protocol) Key material sent

SSL/TLS Cryptography Public-key encryption n n Key chosen secretly (handshake protocol) Key material sent encrypted with public key Symmetric encryption n Shared (secret) key encryption of data packets Signature-based authentication n n Client can check signed server certificate And vice-versa, in principal Hash for integrity n n Client, server check hash of sequence of messages MAC used in data packets (record protocol)

Example cryptosystems One-time pad n “Theoretical idea, ” but leads to stream cipher Feistel

Example cryptosystems One-time pad n “Theoretical idea, ” but leads to stream cipher Feistel construction for symmetric key crypto n n n Iterate a “scrambling function” Examples: DES, Lucifer, FREAL, Khufu, Khafre, LOKI, GOST, CAST, Blowfish, … AES (Rijndael) is also block cipher, but different … Complexity-based public-key cryptography n n Modular exponentiation is a “one-way” function Examples: RSA, El Gamal, elliptic curve systems, . . .

Symmetric Encryption keeps communication secret Encryption algorithm has two functions: E and D n

Symmetric Encryption keeps communication secret Encryption algorithm has two functions: E and D n To communicate secretly, parties share secret key K Given a message M, and a key K: n n M is known as the plaintext E(K, M) → C (C known as the ciphertext) D(K, C) → M Attacker cannot efficiently derive M from C without K Note E and D use same key K n Reason for the name “symmetric encryption”

One-time pad Share a random key K Encrypt plaintext by xor with sequence of

One-time pad Share a random key K Encrypt plaintext by xor with sequence of bits n encrypt(key, text) = key text (bit-by-bit) Decrypt ciphertext by xor with same bits n decrypt(key, text) = key text (bit-by-bit) Advantages n n Easy to compute encrypt, decrypt from key, text This is an information-theoretically secure cipher Disadvantage n Key is as long as the plaintext w How does sender get key to receiver securely? Idea for stream cipher: use pseudo-random generators for key …

Types of symmetric encryption Stream ciphers – pseudo-random pad n n n Generate pseudo-random

Types of symmetric encryption Stream ciphers – pseudo-random pad n n n Generate pseudo-random stream of bits from short key Encrypt/decrypt by XORing as with one-time pad But NOT one-time PAD! (People who claim so are frauds!) Block cipher n n n Operates on fixed-size blocks (e. g. , 64 or 128 bits) Maps plaintext blocks to same size ciphertext blocks Today use AES; other algorithms: DES, Blowfish, . . .

Feistel network: One Round Divide n-bit input in half and repeat L i-1 Scheme

Feistel network: One Round Divide n-bit input in half and repeat L i-1 Scheme requires R i-1 n f Ki n Function f(Ri-1 , Ki) Computation for Ki w e. g. , permutation of key K Advantage n w Easy if f is table, etc. n Li Ri Systematic calculation Invertible if Ki known w Get Ri-1 from Li w Compute f(R i-1 , Ki) w Compute Li-1 by

Data Encryption Standard Developed at IBM, Feistel structure n n n some input from

Data Encryption Standard Developed at IBM, Feistel structure n n n some input from NSA, Permute input bits Repeat application of a S-box function Apply inverse permutation to produce output Worked well in practice n n (but brute-force attacks now) Efficient to encrypt, decrypt Not provably secure Improvements n widely used Triple DES, AES (Rijndael)

Block cipher modes (for DES, AES, …) ECB – Electronic Code Book mode n

Block cipher modes (for DES, AES, …) ECB – Electronic Code Book mode n n Divide plaintext into blocks Encrypt each block independently, with same key CBC – Cipher Block Chaining n n XOR each block with encryption of previous block Use initialization vector IV for first block OFB – Output Feedback Mode n Iterate encryption of IV to produce stream cipher CFB – Cipher Feedback Mode n Output block yi = input xi encyrpt. K(yi-1)

Electronic Code Book (ECB) Plain Block Cipher Ciphe Text Block Cipher r Tex Plain

Electronic Code Book (ECB) Plain Block Cipher Ciphe Text Block Cipher r Tex Plain Block Cipher t Cip Text Block Cipher T Problem: Identical blocks encrypted identically

Cipher Block Chaining (CBC) Plain Text IV Block Cipher Ciphe Block Cipher r Tex

Cipher Block Chaining (CBC) Plain Text IV Block Cipher Ciphe Block Cipher r Tex Block Cipher t Cip Block Cipher T Advantages: Identical blocks encrypted differently Last ciphertext block depends on entire input

Comparison (for AES, by Bart Preneel) Similar plaintext blocks produce similar ciphertext (see outline

Comparison (for AES, by Bart Preneel) Similar plaintext blocks produce similar ciphertext (see outline of head) No apparent pattern

RC 4 stream cipher – “Ron’s Code” Design goals (Ron Rivest, 1987): n n

RC 4 stream cipher – “Ron’s Code” Design goals (Ron Rivest, 1987): n n n speed support of 8 -bit architecture simplicity (circumvent export regulations) Widely used n n SSL/TLS Windows, Lotus Notes, Oracle, etc. Cellular Digital Packet Data Open. BSD pseudo-random number generator

RSA Trade Secret History n n 1994 1995 1996 1997 – – leaked to

RSA Trade Secret History n n 1994 1995 1996 1997 – – leaked to cypherpunks mailing list first weakness (USENET post) appeared in Applied Crypto as “alleged RC 4” first published analysis Weakness is predictability of first bits; best to discard them

Encryption/Decryption key state 0001111010101 plain text = cipher text cipher t Stream cipher: one-time

Encryption/Decryption key state 0001111010101 plain text = cipher text cipher t Stream cipher: one-time pad based on pseudo-random generator

Security Goal: indistinguishable from random sequence n given part of the output stream, it

Security Goal: indistinguishable from random sequence n given part of the output stream, it is impossible to distinguish it from a random string Problems n Second byte [MS 01] w Second byte of RC 4 is 0 with twice expected probability n Related key attack [FMS 01] w Bad to use many related keys (see WEP 802. 11 b) Recommendation n Discard the first 256 bytes of RC 4 output [RSA, MS]

Complete Algorithm for i : = 0 to 255 S[i] : = i j

Complete Algorithm for i : = 0 to 255 S[i] : = i j : = 0 for i : = 0 to 255 j : = j + S[i] + key[i] swap (S[i], S[j]) i, j : = 0 repeat i : = i + 1 j : = j + S[i] swap (S[i], S[j]) output (S[ S[i] + S[j] ]) (all arithmetic mod 256) Key scheduling 0 1 2 3 4 5 6 … Permutation of 256 bytes, depending on key 2 123 134 24 1 218 53 … Random generator 2 123 134 24 9 218 53 i j +24 …

Example use of stream cipher? Share secret s with web vendor Exchange payment information

Example use of stream cipher? Share secret s with web vendor Exchange payment information as follows n n Send: E(s, “Visa card #3273. . . ”) Receive: E(s, “Order confirmed, have a nice day”) Now eavesdropper can’t get out your Visa #

Wrong! Suppose attacker overhears n n c 1 = Encrypt(s, “Visa card #3273. .

Wrong! Suppose attacker overhears n n c 1 = Encrypt(s, “Visa card #3273. . . ”) c 2 = Encrypt(s, “Order confirmed, have a nice day”) Now compute n m ← c 1 ⊕ c 2 ⊕ “Order confirmed, have a nice day” Lesson: Never re-use keys with a stream cipher n n Basic problem with one-time pads This is why they’re called one-time pads

Public-key Cryptosystem Trapdoor function to encrypt and decrypt n encrypt(key, message) key pair n

Public-key Cryptosystem Trapdoor function to encrypt and decrypt n encrypt(key, message) key pair n decrypt(key -1, encrypt(key, message)) = message Resists attack n Cannot compute m from encrypt(key, m) and key, unless you have key-1

Complexity Classes hard PSpace NP BPP P easy Answer in polynomial space may need

Complexity Classes hard PSpace NP BPP P easy Answer in polynomial space may need exhaustive search If yes, can guess and check in polynomial time Answer in polynomial time, with high probability Answer in polynomial time compute answer directly

Example: RSA Arithmetic modulo pq n n n Generate secret primes p, q Generate

Example: RSA Arithmetic modulo pq n n n Generate secret primes p, q Generate secret numbers a, b with xab x mod pq Public encryption key n, a n Encrypt( n, a , x) = xa mod n Private decryption key n, b n Decrypt( n, b , y) = yb mod n Main properties n n This appears to be a “trapdoor permutation” Cannot compute b from n, a w Apparently, need to factor n = pq

Why RSA works (quick sketch) Let p, q be two distinct primes and let

Why RSA works (quick sketch) Let p, q be two distinct primes and let n=p*q n n Encryption, decryption based on group Zn* For n=p*q, order (n) = (p-1)*(q-1) w Proof: (p-1)*(q-1) = p*q - p - q + 1 Key pair: a, b with ab 1 mod (n) n n n Encrypt(x) = xa mod n Decrypt(y) = yb mod n Since ab 1 mod (n), have xab x mod n w Proof: if gcd(x, n) = 1, then by general group theory, otherwise use “Chinese remainder theorem”.

Textbook RSA is insecure What if message is from a small set (yes/no)? n

Textbook RSA is insecure What if message is from a small set (yes/no)? n Can build table What if I want to outbid you in secret auction? n I take your encrypted bid c and submit c (101/100)e mod n What if there’s some protocol in which I can learn other message decryptions?

OAEP [BR 94, Shoup ’ 01] Preprocess message for RSA Message Check pad on

OAEP [BR 94, Shoup ’ 01] Preprocess message for RSA Message Check pad on decryption. Reject CT if invalid. 01 00. . 0 + rand. H G Plaintext to encrypt + with RSA {0, 1}n-1 If RSA is trapdoor permutation, then this is chosen-ciphertext secure (if H, G “random oracles”) In practice: use SHA-1 or MD 5 for H and G

Problem: Integrity Encryption does not guarantee integrity! An attacker could n Intercept message containing

Problem: Integrity Encryption does not guarantee integrity! An attacker could n Intercept message containing w … I authorize you to withdraw $1 from my account n and change this to w … I authorize you to withdraw $1 B from my account n without breaking encryption!

Cryptographic hash functions Length-reducing function h n Map arbitrary strings to strings of fixed

Cryptographic hash functions Length-reducing function h n Map arbitrary strings to strings of fixed length One way (“preimage resistance”) n Given y, hard to find x with h(x)=y Collision resistant n Hard to find any distinct m, m’ with h(m)=h(m’) Also useful: 2 nd preimage resistance n n Given x, hard to find x’ x with h(x’)=h(x) Collision resistance 2 nd preimage resistance

Applications of one-way hash Password files Digital signatures n (one way) (collision resistant) Sign

Applications of one-way hash Password files Digital signatures n (one way) (collision resistant) Sign hash of message instead of entire message Data integrity n n Compute and store hash of some data Check later by recomputing hash and comparing Keyed hash for message authentication n MAC – Message Authentication Code

Iterated hash functions Repeat use of block cipher or custom function n n Pad

Iterated hash functions Repeat use of block cipher or custom function n n Pad input to some multiple of block length Iterate a length-reducing function f w f : 22 k -> 2 k reduces bits by 2 w Repeat h 0= some seed hi+1 = f(hi, xi) n Some final function g completes calculation x Pad to x=x 1 x 2 …xk xi f(xi-1) f g

MAC: Message Authentication Code General pattern of use n n n Sender sends Message

MAC: Message Authentication Code General pattern of use n n n Sender sends Message and M 1 = MAC(Message) Receiver receives both parts Receiver computes M 2 = MAC(Message) w If M 2 == M 1, data is valid w If M 2 != M 1, data has been corrupted This requires a shared secret key n n n Suppose an attacker can compute MAC(x) Intercept M and MAC(M), resend as M' and MAC(M') Receiver cannot detect that message has been altered

Basic CBC-MAC Plain Text IV=0 Block Cipher CBC block cipher, discarding all but last

Basic CBC-MAC Plain Text IV=0 Block Cipher CBC block cipher, discarding all but last output block Additional post-processing (e. g, encrypt with second key) can improve output

HMAC: Keyed Hash-Based MAC Internet standard RFC 2104 Uses hash of key, message: HMACK(M)

HMAC: Keyed Hash-Based MAC Internet standard RFC 2104 Uses hash of key, message: HMACK(M) = Hash[ (K+ XOR opad) || Hash[(K+ XOR ipad)||M)] ] Low overhead n opad, ipad are constants Any of MD 5, SHA-1, … can be used K+ is the key padded out to size

Order of Encryption and MACs Should you Encrypt then MAC, or vice versa? MACing

Order of Encryption and MACs Should you Encrypt then MAC, or vice versa? MACing encrypted data is always secure Encrypting {Data+MAC} may not be secure!

Digital Signatures Public-key encryption n Alice publishes encryption key Anyone can send encrypted message

Digital Signatures Public-key encryption n Alice publishes encryption key Anyone can send encrypted message Only Alice can decrypt messages with this key Digital signature scheme n n n Alice publishes key for verifying signatures Anyone can check a message signed by Alice Only Alice can send signed messages

Properties of signatures Functions to sign and verify n n Sign(Key-1, message) Verify(Key, x,

Properties of signatures Functions to sign and verify n n Sign(Key-1, message) Verify(Key, x, m) = Resists forgery n n true if x = Sign(Key-1, m) false otherwise Cannot compute Sign(Key-1, m) from m and Key Resists existential forgery: given Key, cannot produce Sign(Key-1, m) for any random or arbitrary m

RSA Signature Scheme Publish decryption instead of encryption key n n n Alice publishes

RSA Signature Scheme Publish decryption instead of encryption key n n n Alice publishes decryption key Anyone can decrypt a message encrypted by Alice Only Alice can send encrypt messages In more detail, n n Alice generates primes p, q and key pair a, b Sign(x) = xa mod n Verify(y) = yb mod n Since ab 1 mod (n), have xab x mod n Generally, sign hash of message instead of full plaintext

Public-Key Infrastructure (PKI) Anyone can send Bob a secret message n Provided they know

Public-Key Infrastructure (PKI) Anyone can send Bob a secret message n Provided they know Bob’s public key How do we know a key belongs to Bob? n If imposter substitutes another key, can read Bob’s mail One solution: PKI n Trusted root authority (Veri. Sign, IBM, United Nations) w Everyone must know the verification key of root authority w Check your browser; there are hundreds!! n n n Root authority can sign certificates Certificates identify others, including other authorities Leads to certificate chains

Public-Key Infrastructure Known public signature verification key Ka Ka Client Certificate Authority Sign(Ka-1, Ks),

Public-Key Infrastructure Known public signature verification key Ka Ka Client Certificate Authority Sign(Ka-1, Ks), Sign(Ks, msg) Certificate Sign(Ka-1, Ks) Ks Server certificate can be verified by any client that has CA key Ka Certificate authority is “off line”

Back to SSL/TLS Version, Crypto choice, nonce Version, Choice, nonce, Signed certificate containing server’s

Back to SSL/TLS Version, Crypto choice, nonce Version, Choice, nonce, Signed certificate containing server’s public key Ks C S Secret key K encrypted with server’s key Ks switch to negotiated cipher Hash of sequence of messages

Crypto Summary Encryption scheme: encrypt(key, plaintext) -1 decrypt(key , ciphertext) Symmetric vs. public key

Crypto Summary Encryption scheme: encrypt(key, plaintext) -1 decrypt(key , ciphertext) Symmetric vs. public key n n Public key: publishing key does not reveal key -1 Secret key: more efficient, but key = key -1 Hash function n n Map long text to short hash; ideally, no collisions Keyed hash (MAC) for message authentication Signature scheme n Private key -1 and public key provide authentication

Limitations of cryptography Most security problems are not crypto problems n This is good

Limitations of cryptography Most security problems are not crypto problems n This is good w Cryptography works! n This is bad w People make other mistakes; crypto doesn’t solve them

How well does RSA work? Can generate modulus, keys fairly efficiently n Efficient rand

How well does RSA work? Can generate modulus, keys fairly efficiently n Efficient rand algorithms for generating primes p, q w May fail, but with low probability n n n Given primes p, q easy to compute n=p*q and (n) Choose a randomly with gcd(a, (n))=1 Compute b = a-1 mod (n) by Euclidean alg Public key n, a does not reveal b n This is not proven, but believed But if n can be factored, all is lost. . . Public-key crypto is significantly slower than symmetric key crypto

Message integrity RSA as stated does not provide integrity n n encrypt(k*m) = (k*m)e

Message integrity RSA as stated does not provide integrity n n encrypt(k*m) = (k*m)e = ke * me = encrypt(k)*encrypt(m) This leads to “chosen ciphertext” form of attack w If someone will decrypt new messages, then can trick them into decrypting m by asking for decrypt(ke *m) Implementations reflect this problem n “The PKCS#1 … RSA encryption is intended primarily to provide confidentiality. … It is not intended to provide integrity. ” RSA Lab. Bulletin Additional mechanisms provide integrity