Cipher block modes
Upcoming SlideShare
Loading in...5
×
 

Cipher block modes

on

  • 2,464 views

http://www.adayinthelifeof.nl/2010/12/08/encryption-operating-modes-ecb-vs-cbc/

http://www.adayinthelifeof.nl/2010/12/08/encryption-operating-modes-ecb-vs-cbc/

Statistics

Views

Total Views
2,464
Views on SlideShare
2,464
Embed Views
0

Actions

Likes
0
Downloads
59
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

Cipher block modes Cipher block modes Presentation Transcript

  • Block cipher modes or:what the heck are those MCRYPT_MODE_ECB, MCRYPT_MODE_CBC constants?
  • What are block cipher modes‣ Modes to handle “blocks” during block cipher encryption / decryption.‣ Work on blocks of data (8-256 byte mostly) instead of a continuous stream.‣ Each block is en/decrypted separately.‣ mcrypt_*() functions in PHP‣ FOOTER TEXT
  • What are block cipher modes ‣ ECB - electronic cookbook ‣ CBC - cipher block chaining ‣ CFB - cipher feedback ‣ (N)OFB - Output feedback
  • Electronic Cookbook (ECB)http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation
  • Electronic Cookbook (ECB) <?php // The key size does not matter $key = "1234567890"; // Message is 10x the string HELLOYOU. Since each string is // 64bit, this will result in every HELLOYOU be encrypted // separately. $message = str_repeat("HELLOYOU", 10); // Blowfish is an encryption that uses 64bit blocks $crypted = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $message, MCRYPT_MODE_ECB); // Display the result in hex for ($i=0; $i!=strlen($crypted); $i++) { printf ("%02X ", ord($crypted[$i])); if ($i % 8 == 7) print "n"; }‣ ENCRYPT 10 EQUAL BLOCKS OF DATA
  • Electronic Cookbook (ECB) 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD 3F 89 AD 58 3C C8 21 CD‣ RESULT IS DETERMINISTIC
  • Electronic Cookbook (ECB) <?php // The key size does not matter $key = "1234567890"; // again: all padded to the blocksize $message = "1111111122222222333333334444444455555555666666667777777788888888"; // Blowfish is an encryption that uses 64bit blocks $crypted = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $message, MCRYPT_MODE_ECB); // Lets "corrupt" a byte in the second block $crypted[10] = "A"; // Decrypt, and see the results: $plaintext = mcrypt_decrypt(MCRYPT_BLOWFISH, $key, $crypted, MCRYPT_MODE_ECB); print $plaintext."n";‣ CREATE A CORRUPT ENCRYPTED BLOCK
  • Electronic Cookbook (ECB) 11111111T#####zO333333334444444455555555666666667777777788888888‣ ERRORS ARE ISOLATED IN ONE BLOCK
  • Electronic Cookbook (ECB) Thread 1 Thread 2 Thread 3 Block 1 Block 6 Block 8 Block 2 Block 5 Block 7 Block 3 Block 4 Block 9 assemble = Block 1 Block 2 Block 3 Block 4 Block 5 Block 6 Block 7 Block 8 Block 9‣ PARALLEL ENCRYPTION AND DECRYPTION IS POSSIBLE
  • Cipher Block Chaining (CBC)http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation
  • Cipher Block Chaining (CBC) <?php // The key size does not matter $key = "1234567890"; // The IV MUST be equal to the block size of the encryption method $iv = "IAMWEASL"; // Message is 10x the string HELLOYOU. Since each string is // 64bit, this will result in every HELLOYOU be encrypted // separately. $message = str_repeat("HELLOYOU", 10); // Blowfish is an encryption that uses 64bit blocks $crypted = mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $message, MCRYPT_MODE_CBC, $iv); // Display the result in hex for ($i=0; $i!=strlen($crypted); $i++) { printf ("%02X ", ord($crypted[$i])); if ($i % 8 == 7) print "n"; }‣ ENCRYPT 10 EQUAL BLOCKS OF DATA
  • Cipher Block Chaining (CBC) 02 67 2E AA 4A EB E1 C1 F8 DB A6 2A 66 47 22 A7 5A 5B 7B 46 7D 68 8E E4 B4 BE 7D F7 00 73 B0 DD 72 71 4D 32 A9 A2 36 73 BB 8E 42 25 49 1D 65 B6 D9 36 F2 43 6A A9 E2 85 E4 C0 56 CC 24 05 73 22 52 A3 BA 85 88 5C A3 0D 98 29 3F 87 15 76 2E 98‣ RESULT IS NON-DETERMINISTIC
  • Cipher Block Chaining (CBC) Limited error propagation. 11111111?Թ~*IU33&333334444444455555555666666667777777788888888‣ ERRORS ARE ISOLATED IN ONE BLOCK PLUS THE NEXT
  • Cipher Block Chaining (CBC) +%,#&=#322222222333333334444444455555555666666667777777788888888‣ INCORRECT IV ONLY RESULTS IN FIRST BLOCK FAILURE
  • Cipher Block Chaining (CBC) ‣ IV is not a additional secret key! ‣ non-deterministic, since we’re chaining each block ‣ Change IV for each message for optimal security for non- deterministic messages.
  • Cipher feedback (CFB)http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation
  • Cipher feedback (CFB) ‣ Only needs “encryption” ‣ Effectively convert a block cipher into a stream cipher. ‣ No padding is needed (can be used on non-matching block lenghts)
  • Output feedback (OFB)http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation
  • Output feedback (OFB) ‣ Don’t use MCRYPT_MODE_OFB (8bit) ‣ Use MCRYPT_MODE_NOFB ‣ Cipher text is fed back instead of the output.
  • Conclusion ‣ You should use MCRYPT_MODE_CBC. ‣ Use randomize IV’s for each message (mcrypt_create_iv()) ‣ You should use the correct cipher algorithm (DES vs AES)