"bf-ecb" Cipher on Multiple Blocks

A tutorial example is provided to show you how multiple plaintext blocks are encrypted in ECB operation mode. Each plaintext block is encrypted independently. The corresponding ciphertext is same, no matter where the plaintext block is located in the plaintext stream.

Since ECB operation mode supports multiple plaintext blocks, let's run the "enc -bf-ecb" command with a 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-ecb -e \
   -K 00000000000000000000000000000000 -iv 0000000000000000 \
   -in 2-block.txt -out cipher.txt -nopad -p
   
salt=0200000000265601
key=00000000000000000000000000000000
iv =0000000000000000

C:\herong>perl -e "while (read(STDIN,$_,1)){print unpack('H*',$_);}" \
   < cipher.txt
   
4ef997456198dd78 4ef997456198dd78
---------------- ----------------
    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-ecb -e \
   -K 00000000000000000000000000000000 -iv 0000000000000000 \
   -in 3-block.txt -out cipher.txt -nopad -p
   
salt=0200000000264101
key=00000000000000000000000000000000
iv =0000000000000000

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

The output matches my expectation. In ECB operation mode, each plaintext block is encrypted independently. So identical plaintext blocks will have the same ciphertext block, no matter where the plaintext block is located in the 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

 What is OpenSSL

 Installing OpenSSL for Windows

 OpenSSL "enc" Blowfish Ciphers

 Ways to Control Secret Key and IV

 "bf-ecb" Cipher with Literal Key

"bf-ecb" Cipher on Multiple Blocks

 Secret Key Padding and Truncation

 "bf-ecb" Cipher with Salted Key

 Salted Key Generation Algorithm

 "bf-ecb" Cipher with Random Salt

 OpenSSL Default Padding - PKCS#5

 "enc -bf-ecb" Command Summary

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

 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