









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










EECS 588: Computer and Network Security January 11, 2011
Cipher Modes Building a Secure Channel Implementations (BREAK) Diffie‐Hellman Key Exchange RSARSA EncryptionEncryption andand SigningSigning Establishing Trust
How do we encryptyp more than one block? Some definitions: P (^) i – i‐ th plaintext block Ci – i‐ th ciphertext block E() – encryption function D()() – ddecryption i ff unctioni K – encryption key
“Electronic codebook” ((ECB) ) mode Ci := E( K , P (^) i ) for i = 1, …, n
Most “natural” construction Never use ECB
“Cipherp ‐Block Chaining”g ( (CBC) ) mode Ci := E( K , P (^) i C (^) i‐ 1 ) for i = 1, …, n P 1 P 2 P 3 …….
d
Random “Initialization Vector” IV C 1 C 2 C 3 ……. What if you reuse the IV? Bad.
“Counter” (CTR) mode
Stream cipher construction – like OTP Plaintext never passes through E
Ki := E( K , Nonce || i ) for i = 1, …, n Ci := P (^) i K (^) i
p g Don’t need to pad the message Allows parallelization and seeking Never reuse same K + Nonce (like OTP)
Session Key K Session Key K
// Initialization (Both Parties) KeySendEnc := HMAC‐SHA256( K , “Enc A‐to‐B”) KeyRecvEnc := HMAC‐SHA256( K , “Enc B‐to‐A”) KeySendAuth := HMAC‐SHA256( K , “Auth A‐to‐B”) K R A h HMAC SHA 6( K “A h B A”)
Session Key K Never reuse
Session Key K Never reuse
Separate keys for each f ti (^) KeyRecvAuth := HMAC‐SHA256( K , “Auth B‐to‐A”) if Bob then swap( KeySendEnc , KeyRecvEnc ) swap( KeySendAuth , KeyRecvAuth ) MsgCntSend := 0 MsgCntRecv := 0
function
// Sender MsgCntSend := MsgCntSend + 1 i := MsgCntSend a := HMAC‐SHA256( KeySendAuth , i || len( m ) || m )
// Receiver i || t := Receive() K := KeyRecvEnc // to length of t : i || len( m ) || m ) MsgKey := E( K i || 0) || E( K i || 1) || t := a || m K := KeySendEnc // to length of t : MsgKey := E( K , i || 0) || E( K , i || 1) || … Transmit( i || ( t MsgKey ))
MsgKey := E( K , i || 0) || E( K , i || 1) || … a || m := t MsgKey a' := HMAC‐SHA256( KeyRecvAuth , i || len( m ) || m ) Check( a ’ == a ) Check( i > MsgCntRecv ) MsgCntRecv := i
#include <openssl/hmac.h> #i#include l d << openssl/sha.h>l/ h h> #include <openssl/evp.h> unsigned char mac; mac = HMAC( EVP_sha256(), // use SHA‐ 256 hash function (unsigned char) key, ((unsigned i d l l ong ) k) k eyNumBytes,N B t (unsigned char*) data, (unsigned long ) dataNumBytes, NULL, NULL );
#include <openssl/evp.h> //void (^256) AesEncrypt(unsigned‐bit AES in CBC mode char with key[32], padding unsigned char iv[16]) { (^) unsigned char inData[16], outData[16]; Int inLen,EVP_CIPHER_CTX outLen; ctx; EVP_CIPHER_CTX_init(&ctx); EVP_EncryptInit_ex(&ctx, EVP_aes_256_cbc(), NULL, (unsigned char *)key, (unsigned char *)iv); whilehil (^) EVP_EncryptUpdate(&ctx, ((i((i nLen = ff read(inData,d(i (^) outData, 1, 16, stdin))&outLen,di )) > inData,0)) { { inLen); } fwrite(outData,^ 1,^ outLen,^ stdout); EVP_EncryptFinal_ex(&ctx,fwrite(outData, 1, outLen, outData, stdout); &outLen); } EVP_CIPHER_CTX_cleanup(&ctx);^ //^ zeroize the^ key
Install OpenSSLp or use tryy it on a cluster Sign and encrypt a message Compare the speed of various functions Think… How does the AES implementation compare to the speed of your Internet connection?connection? YourYour hardhard disk?disk? YourYour RAM?RAM? Use C, Python, or Perl and the OpenSSL library to implement our secure message passing protocol
Don’t use MD5;5; avoid hash function ppitfalls Don’t use DES; avoid ECB mode Don’t use rand() and its ilk
Problem: With symmetric ciphers, every sender‐receiver pair must share a secret key
Question: What if we could use differentdifferent keyskeys forfor encryptionencryption andand decryption?decryption?
Whitfield Diffie and Martin Hellman,, 197697
Eve
Lets Alice and Bob establish a shared secret even if Eve is listening in
Alice (^) Passive Eavesdropper Bob
Agree on a large prime p and primitive element g Alice (^) Bob
and primitive element g that generates the group ( p , g can be public) Chooses random x < p (secret) Chooses random y < p (secret)
^ * p
a := gx^ mod p y < p (secret) b := gy^ mod p Calculates k := bx^ mod p
Calculates k := a y^ mod p Why this works: bx^ = ( gy ) x^ = ( gx ) y^ = a y^ (mod p )
Diffie‐Hellman (DH) problem: Compute gxy^ given gx^ and gy^ (mod p )
Best known approach: Compute x from gx Called the discrete logarithm (DL) problem No known efficient algorithm
M d lModular exponentiationti ti b libelieved d tto bbe a one‐way function Easy to compute Hard to invert
p , q large random primes nn := pqpq modulusmodulus t := ( p ‐1)( q ‐1) ensures x t^ = 1 (mod n ) e := [small odd value] public exponent d := 1/ e mod t private exponent Public key: ( n , e ) Private key: any of p , q , t , d Encryption: c := m e^ mod n Decryption: m := cd^ mod n Why? ( m e ) d^ = m ed^ = m kt +1^ = ( m t ) km = 1 km = m (mod n )
Publish: ( n , e ) (^) directlyWhy^ don’t encrypt^ we theuse message?RSA^ to Store secretly: d Encryption of m Choose random k same size as n c := ke^ mod n
directly encrypt the message?
Send c , encrypt m with AES using k Decryption k := c d^ mod n ; decrypt m with AES using k
Publish: ( n , e ) Store secretly: d Signing m Seed a CPRNG with m and calculate pseudorandom string s same size as n σ := ss dd^ modmod nn Verifying a signature on m Recalculate s from m Check s = σe^ mod n
Chooses random x < p (secret) Chooses random y < p (secret)
a := gx^ mod p Sign Alice ( a )
b := gy^ mod p Sign Bob ( a , b )
Mallory
g p g (^) Bob ( , ) Verifies signature Calculates k := bx^ mod p
Verifies signature Calculates k := a y^ mod p