SlideShare a Scribd company logo
1 of 20
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)

More Related Content

Viewers also liked

Puppet for dummies - PHPBenelux UG edition
Puppet for dummies - PHPBenelux UG editionPuppet for dummies - PHPBenelux UG edition
Puppet for dummies - PHPBenelux UG edition
Joshua Thijssen
 
Deploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APTDeploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APT
Joshua Thijssen
 
Alice & bob public key cryptography 101 - uncon dpc
Alice & bob  public key cryptography 101 - uncon dpcAlice & bob  public key cryptography 101 - uncon dpc
Alice & bob public key cryptography 101 - uncon dpc
Joshua Thijssen
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
Joshua Thijssen
 
Alice & bob public key cryptography 101
Alice & bob  public key cryptography 101Alice & bob  public key cryptography 101
Alice & bob public key cryptography 101
Joshua Thijssen
 
international data encryption Algoritm (IDEA) and RC-4
international data encryption Algoritm (IDEA) and RC-4international data encryption Algoritm (IDEA) and RC-4
international data encryption Algoritm (IDEA) and RC-4
sikindir
 
Unit V network management and security
Unit V network management and securityUnit V network management and security
Unit V network management and security
sangusajjan
 
Alice & bob public key cryptography 101
Alice & bob  public key cryptography 101Alice & bob  public key cryptography 101
Alice & bob public key cryptography 101
Joshua Thijssen
 
euclids division lemma
euclids division lemmaeuclids division lemma
euclids division lemma
Jashan Kainth
 

Viewers also liked (20)

Puppet for dummies - PHPBenelux UG edition
Puppet for dummies - PHPBenelux UG editionPuppet for dummies - PHPBenelux UG edition
Puppet for dummies - PHPBenelux UG edition
 
Moved 301
Moved 301Moved 301
Moved 301
 
Workshop unittesting
Workshop unittestingWorkshop unittesting
Workshop unittesting
 
Representation state transfer and some other important stuff
Representation state transfer and some other important stuffRepresentation state transfer and some other important stuff
Representation state transfer and some other important stuff
 
Deploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APTDeploying and maintaining your software with RPM/APT
Deploying and maintaining your software with RPM/APT
 
15 protips for mysql users
15 protips for mysql users15 protips for mysql users
15 protips for mysql users
 
Alice & bob public key cryptography 101 - uncon dpc
Alice & bob  public key cryptography 101 - uncon dpcAlice & bob  public key cryptography 101 - uncon dpc
Alice & bob public key cryptography 101 - uncon dpc
 
PFZ WorkshopDay Linux - Advanced
PFZ WorkshopDay Linux - AdvancedPFZ WorkshopDay Linux - Advanced
PFZ WorkshopDay Linux - Advanced
 
PFZ WorkshopDay Linux - Basic
PFZ WorkshopDay Linux - BasicPFZ WorkshopDay Linux - Basic
PFZ WorkshopDay Linux - Basic
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Alice & bob public key cryptography 101
Alice & bob  public key cryptography 101Alice & bob  public key cryptography 101
Alice & bob public key cryptography 101
 
international data encryption Algoritm (IDEA) and RC-4
international data encryption Algoritm (IDEA) and RC-4international data encryption Algoritm (IDEA) and RC-4
international data encryption Algoritm (IDEA) and RC-4
 
Czzawk
CzzawkCzzawk
Czzawk
 
Awk programming
Awk programming Awk programming
Awk programming
 
Unit V network management and security
Unit V network management and securityUnit V network management and security
Unit V network management and security
 
Alice & bob public key cryptography 101
Alice & bob  public key cryptography 101Alice & bob  public key cryptography 101
Alice & bob public key cryptography 101
 
Byte Rotation Algorithm
Byte Rotation AlgorithmByte Rotation Algorithm
Byte Rotation Algorithm
 
euclids division lemma
euclids division lemmaeuclids division lemma
euclids division lemma
 
Idea (international data encryption algorithm)
Idea (international data encryption algorithm)Idea (international data encryption algorithm)
Idea (international data encryption algorithm)
 
Naive Bayes
Naive Bayes Naive Bayes
Naive Bayes
 

Similar to Cipher block modes

Windows kernel debugging workshop in florida
Windows kernel debugging   workshop in floridaWindows kernel debugging   workshop in florida
Windows kernel debugging workshop in florida
Sisimon Soman
 
Kernelvm 201312-dlmopen
Kernelvm 201312-dlmopenKernelvm 201312-dlmopen
Kernelvm 201312-dlmopen
Hajime Tazaki
 
MicroLab2 2011.pptx
MicroLab2 2011.pptxMicroLab2 2011.pptx
MicroLab2 2011.pptx
HebaEng
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
Béo Tú
 

Similar to Cipher block modes (20)

BlueHat v18 || A mitigation for kernel toctou vulnerabilities
BlueHat v18 || A mitigation for kernel toctou vulnerabilitiesBlueHat v18 || A mitigation for kernel toctou vulnerabilities
BlueHat v18 || A mitigation for kernel toctou vulnerabilities
 
Windows kernel debugging workshop in florida
Windows kernel debugging   workshop in floridaWindows kernel debugging   workshop in florida
Windows kernel debugging workshop in florida
 
Writing Metasploit Plugins
Writing Metasploit PluginsWriting Metasploit Plugins
Writing Metasploit Plugins
 
Linux kernel debugging(PDF format)
Linux kernel debugging(PDF format)Linux kernel debugging(PDF format)
Linux kernel debugging(PDF format)
 
Linux kernel debugging(ODP format)
Linux kernel debugging(ODP format)Linux kernel debugging(ODP format)
Linux kernel debugging(ODP format)
 
Defcon CTF quals
Defcon CTF qualsDefcon CTF quals
Defcon CTF quals
 
Davide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruptionDavide Berardi - Linux hardening and security measures against Memory corruption
Davide Berardi - Linux hardening and security measures against Memory corruption
 
Kernelvm 201312-dlmopen
Kernelvm 201312-dlmopenKernelvm 201312-dlmopen
Kernelvm 201312-dlmopen
 
MicroLab2 2011.pptx
MicroLab2 2011.pptxMicroLab2 2011.pptx
MicroLab2 2011.pptx
 
Java bytecode Malware Analysis
Java bytecode Malware AnalysisJava bytecode Malware Analysis
Java bytecode Malware Analysis
 
NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016NYU hacknight, april 6, 2016
NYU hacknight, april 6, 2016
 
Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops
Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loopsMultiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops
Multiple Choice Questions on JAVA (object oriented programming) bank 4 -- loops
 
The propeller
The propellerThe propeller
The propeller
 
CSS architecture: How To Write Clean & Scalable Code
CSS architecture: How To Write Clean & Scalable CodeCSS architecture: How To Write Clean & Scalable Code
CSS architecture: How To Write Clean & Scalable Code
 
Technical Overview of QUIC
Technical  Overview of QUICTechnical  Overview of QUIC
Technical Overview of QUIC
 
Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014Verilog Lecture3 hust 2014
Verilog Lecture3 hust 2014
 
Verilog Lecture2 thhts
Verilog Lecture2 thhtsVerilog Lecture2 thhts
Verilog Lecture2 thhts
 
[CB20] DeClang: Anti-hacking compiler by Mengyuan Wan
[CB20] DeClang: Anti-hacking compiler by Mengyuan Wan[CB20] DeClang: Anti-hacking compiler by Mengyuan Wan
[CB20] DeClang: Anti-hacking compiler by Mengyuan Wan
 
Hacklu11 Writeup
Hacklu11 WriteupHacklu11 Writeup
Hacklu11 Writeup
 
Meltdown & Spectre
Meltdown & Spectre Meltdown & Spectre
Meltdown & Spectre
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 

Cipher block modes

  • 1. Block cipher modes or: what the heck are those MCRYPT_MODE_ECB, MCRYPT_MODE_CBC constants?
  • 2. 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
  • 3. What are block cipher modes ‣ ECB - electronic cookbook ‣ CBC - cipher block chaining ‣ CFB - cipher feedback ‣ (N)OFB - Output feedback
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. Electronic Cookbook (ECB) 11111111T#####zO333333334444444455555555666666667777777788888888 ‣ ERRORS ARE ISOLATED IN ONE BLOCK
  • 9. 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
  • 10. Cipher Block Chaining (CBC) http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation
  • 11. 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
  • 12. 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
  • 13. Cipher Block Chaining (CBC) Limited error propagation. 11111111?Թ~*IU33&333334444444455555555666666667777777788888888 ‣ ERRORS ARE ISOLATED IN ONE BLOCK PLUS THE NEXT
  • 14. Cipher Block Chaining (CBC) +%,#&=#322222222333333334444444455555555666666667777777788888888 ‣ INCORRECT IV ONLY RESULTS IN FIRST BLOCK FAILURE
  • 15. 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.
  • 17. 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)
  • 19. Output feedback (OFB) ‣ Don’t use MCRYPT_MODE_OFB (8bit) ‣ Use MCRYPT_MODE_NOFB ‣ Cipher text is fed back instead of the output.
  • 20. 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)

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n