"bf-cbc" Cipher on Multiple Blocks

A tutorial example is provided to show you how multiple plaintext blocks are encrypted in CBC operation mode. The encryption of each plaintext block is impacted by the encryption of the previous block.

Since CBC operation mode supports multiple plaintext blocks, let's run the "enc -bf-CBC" command with longer plaintext:

C:\herong> \
   perl -e "binmode(STDOUT); print pack('H*', '0000000000000000')" \
   > 2-block.txt

C:\herong> \
   perl -e "binmode(STDOUT); print pack('H*', '0000000000000000')" \
   >> 2-block.txt

C:\herong>\local\gnuwin32\bin\openssl enc -bf-cbc -e \
   -K 00000000000000000000000000000000 -iv 0000000000000000 \
   -in 2-block.txt -out cipher.txt -nopad -p
   
salt=0200000000265301
key=00000000000000000000000000000000
iv =0000000000000000

C:\herong>perl -e "while (read(STDIN,$_,1)){print unpack('H*',$_);}" \
   < cipher.txt
   
4ef997456198dd78 e1c030e74c14d261
---------------- ----------------
    block 1           block 2
    

C:\herong> \
   perl -e "binmode(STDOUT); print pack('H*', '0000000000000000')" \
   > 3-block.txt

C:\herong> \
   perl -e "binmode(STDOUT); print pack('H*', '0000000000000000')" \
   >> 3-block.txt

C:\herong> \
   perl -e "binmode(STDOUT); print pack('H*', '0000000000000000')" \
   >> 3-block.txt

C:\herong>\local\gnuwin32\bin\openssl enc -bf-cbc -e \
   -K 00000000000000000000000000000000 -iv 0000000000000000 \
   -in 3-block.txt -out cipher.txt -nopad -p
   
salt=0200000000265E01
key=00000000000000000000000000000000
iv =0000000000000000

C:\herong>perl -e "while (read(STDIN,$_,1)){print unpack('H*',$_);}" \
   < cipher.txt
   
4ef997456198dd78 e1c030e74c14d261 53e3b2a5a3bc297f
---------------- ---------------- ----------------
    block 1           block 2          block 3

The output matches my expectation. In CBC operation mode, the encryption of each plaintext block is impacted by the encryption of the previous block. This behavior definitely improves the strength of the encryption of the entire plaintext stream.

Table of Contents

 About This Book

 Blowfish Cipher Algorithm

 Perl Crypt::Blowfish Module

 Perl Crypt::ECB Perl Module

 Perl Crypt::CBC Module

 Perl Crypt::CFB Perl Module

 OpenSSL "enc -bf-ecb" for Blowfish/ECB Encryption

OpenSSL "enc -bf-cbc" for Blowfish/CBC Encryption

 "bf-cbc" Cipher with Literal Key

"bf-cbc" Cipher on Multiple Blocks

 "bf-cbc" Encryption Verification

 "bf-cbc" 2-Block Test Vectors

 "bf-cbc" Cipher with Salted Key

 "bf-cbc" Cipher with Random Salt

 "enc -bf-cbc" Command Summary

 OpenSSL "enc -bf-cfb" for Blowfish/CFB Encryption

 OpenSSL "enc -bf-ofb" for Blowfish/OFB Encryption

 PHP Mcrypt Extension for Blowfish

 Blowfish 8-Bit Cipher in PHP

 References

 Full Version in PDF/EPUB