Blowfish CBC 2-Block Test Vectors

A tutorial Perl example is provided to show how to build a table of test vectors for Blowfish algorithm in CBC mode on 2-block (16-byte) plaintext messages.

Since there are not enough test vectors published on the Internet for Blowfish algorithm in CBC operation mode, let's build a test vector table with 2-block plaintext messages.

Here is my Perl script, which takes a list of secret keys, IV and plaintext, then encrypts them one by one:

#- Crypt-CBC-2-Block-Test-Vector.pl
#- Copyright (c) 2015 HerongYang.com, All Rights Reserved.
#- 
   use Crypt::CBC;
   use Crypt::Blowfish;

   @tests = split(/\n/, getInput());
   print("Blowfish CBC 2-Block Test Vectors in Hex:\n");
   foreach (@tests) {
      ($i, $keyHex, $ivHex, $plainHex) = split(/ +/,$_);
      $keyStr = pack("H*", $keyHex);
      $ivStr = pack("H*", $ivHex);
      $plainStr = pack("H*", $plainHex);
      $blowfish = new Crypt::Blowfish($keyStr);
      $cipher = Crypt::CBC->new( 
         -cipher => $blowfish,
         -iv => $ivStr,
         -header => 'none',
         -padding => 'none'
         );
      $cipherStr = $cipher->encrypt($plainStr);
      $cipherHex = unpack("H*", $cipherStr);
      print("$i - Secret Key: $keyHex + IV: $ivHex\n");
      print("   Plaintext: $plainHex\n");
      print("   Ciphertext: $cipherHex\n");
   }

sub getInput {
   return $input = << 'EOD';
1  0000000000000000 0000000000000000 4EF997456198DD78E1C030E74C14D261
2  FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF 51866FD5B85ECB8ABA8A39A94193ADC1
3  3000000000000000 1000000000000001 7D856F9A613063F2C170D6977BAF4AFF
4  1111111111111111 1111111111111111 2466DD878B963C9D695CFFB69DC5B0BA
5  0123456789ABCDEF 1111111111111111 61F9C3802281B096354D26A3D1C5D031
6  1111111111111111 0123456789ABCDEF 7D0CC630AFDA1EC73F389598F060D6C6
7  FEDCBA9876543210 0123456789ABCDEF 0ACEAB0FC6A0A28D52BA6077910130BB
8  7CA110454A1A6E57 01A1D6D039776742 59C68245EB05282B8E1482495AAE7782
9  0131D9619DC1376E 5CD54CA83DEF57DA B1B8CC0B250F09A0278EC4570AFBA00B
10 07A1133E4A0B2686 0248D43806F67172 1730E5778BEA1DA4A721AF5F8FE286E6
11 3849674C2602319E 51454B582DDF440A A25E7856CF2651EB41B5844B528DEBCB
12 04B915BA43FEB5B6 42FD443059577FA2 353882B109CE8F1AC7E83F0896578AB9
13 0113B970FD34F2CE 059B5E0851CF143A 48F4D0884C379918574315272A39D844
14 0170F175468FB5E6 0756D8E0774761D2 432193B78951FC985968C3C90812BE01
15 43297FAD38E373FE 762514B829BF486A 13F04154D69D1AE59229B7E3B6B17768
16 07A7137045DA2A16 3BDD119049372802 2EEDDA93FFD39C7949DB91A767ED20BE
17 04689104C2FD3B2F 26955F6835AF609A D887E0393C2DA6E319FF040A73E6FC0C
18 37D06BB516CB7546 164D5E404F275232 5F99D04F5B1639697B6A20E27D980095
19 1F08260D1AC2465E 6B056E18759F5CCA 4A057A3B24D3977BDE229E1EBD41B5B8
20 584023641ABA6176 004BD6EF09176062 452031C1E4FADA8E0FDDDE1A8A5B83F0
21 025816164629B007 480D39006EE762F2 7555AE39F59B87BDFEBD1D7E17CBCA41
22 49793EBC79B3258F 437540C8698F3CFA 53C55F9CB49FC019A7ED7F44B8B2D1AD
23 4FB05E1515AB73A7 072D43A077075292 7A8E7BFA937E89A3395B6287FC04BF00
24 49E95D6D4CA229BF 02FE55778117F12A CF9C5D7A4986ADB5A3D5548F3DF976BE
25 018310DC409B26D6 1D9D5C5018F728C2 D1ABB290658BC778A97AC0003948A6AF
26 1C587F1C13924FEF 305532286D6F295A 55CB3774D13EF201B046252396442237
27 0101010101010101 0123456789ABCDEF FA34EC4847B268B260C5BAADE0C9C3E3
28 1F1F1F1F0E0E0E0E 0123456789ABCDEF A790795108EA3CAE91E789440185282E
29 E0FEE0FEF1FEF1FE 0123456789ABCDEF C39E072D9FAC631DB37736664428E3FA
30 0000000000000000 FFFFFFFFFFFFFFFF 014933E0CDAFF6E4FFDA124B8354E2BD
31 FFFFFFFFFFFFFFFF 0000000000000000 F21E9A77B71C49BC5BC51F22E32C2CE8
32 0123456789ABCDEF 0000000000000000 245946885754369ABFAF44BDD441F9F6
33 FEDCBA9876543210 FFFFFFFFFFFFFFFF 6B5C5A9C5D9E0A5ABDC6CD6E802DE097
EOD
}

Run the example script, you will get a nice looking Blowfish CBC mode test vectors with 2-block plaintext messages:

C:\herong>perl Crypt-CBC-2-Block-Test-Vector.pl

Blowfish CBC 2-Block Test Vectors in Hex:
1 - Secret Key: 0000000000000000 + IV: 0000000000000000
   Plaintext: 4EF997456198DD78E1C030E74C14D261
   Ciphertext: e1c030e74c14d2614ef997456198dd78
2 - Secret Key: FFFFFFFFFFFFFFFF + IV: FFFFFFFFFFFFFFFF
   Plaintext: 51866FD5B85ECB8ABA8A39A94193ADC1
   Ciphertext: 5e299e3f053d25d8e89abe02b6524a8e
3 - Secret Key: 3000000000000000 + IV: 1000000000000001
   Plaintext: 7D856F9A613063F2C170D6977BAF4AFF
   Ciphertext: 6375951e1d2076b9cc9f9cb5415cd218
4 - Secret Key: 1111111111111111 + IV: 1111111111111111
   Plaintext: 2466DD878B963C9D695CFFB69DC5B0BA
   Ciphertext: 820d658282b33ceaf628031f8c1ed14c
5 - Secret Key: 0123456789ABCDEF + IV: 1111111111111111
   Plaintext: 61F9C3802281B096354D26A3D1C5D031
   Ciphertext: 61c95580cd594fbfaa53b1a167b81d8c
6 - Secret Key: 1111111111111111 + IV: 0123456789ABCDEF
   Plaintext: 7D0CC630AFDA1EC73F389598F060D6C6
   Ciphertext: 999f866212275cc833321a5b7db1ea71
7 - Secret Key: FEDCBA9876543210 + IV: 0123456789ABCDEF
   Plaintext: 0ACEAB0FC6A0A28D52BA6077910130BB
   Ciphertext: d1921d4d06fd895d5c0455e5a925ce3c
8 - Secret Key: 7CA110454A1A6E57 + IV: 01A1D6D039776742
   Plaintext: 59C68245EB05282B8E1482495AAE7782
   Ciphertext: a3bf975dbfe089f41fd545dcb81a5284
9 - Secret Key: 0131D9619DC1376E + IV: 5CD54CA83DEF57DA
   Plaintext: B1B8CC0B250F09A0278EC4570AFBA00B
   Ciphertext: 006b28f8a23378a37fe324f984059671
10 - Secret Key: 07A1133E4A0B2686 + IV: 0248D43806F67172
   Plaintext: 1730E5778BEA1DA4A721AF5F8FE286E6
   Ciphertext: d0b5cbf4392248335c0b8d76beab2792
11 - Secret Key: 3849674C2602319E + IV: 51454B582DDF440A
   Plaintext: A25E7856CF2651EB41B5844B528DEBCB
   Ciphertext: 9ad0530768ee9f10778bf9bdc1d27fc8
12 - Secret Key: 04B915BA43FEB5B6 + IV: 42FD443059577FA2
   Plaintext: 353882B109CE8F1AC7E83F0896578AB9
   Ciphertext: 327422e645d6c1be18281ad078afe438
13 - Secret Key: 0113B970FD34F2CE + IV: 059B5E0851CF143A
   Plaintext: 48F4D0884C379918574315272A39D844
   Ciphertext: 09fe127c53b89f48ff2ae61d4bc53e27
14 - Secret Key: 0170F175468FB5E6 + IV: 0756D8E0774761D2
   Plaintext: 432193B78951FC985968C3C90812BE01
   Ciphertext: 23aac9747cb314e8426c8e281aaeb0ef
15 - Secret Key: 43297FAD38E373FE + IV: 762514B829BF486A
   Plaintext: 13F04154D69D1AE59229B7E3B6B17768
   Ciphertext: 41eab3083fa7a9975bf61be7b0b7a5dc
16 - Secret Key: 07A7137045DA2A16 + IV: 3BDD119049372802
   Plaintext: 2EEDDA93FFD39C7949DB91A767ED20BE
   Ciphertext: 1c9779ce92d8874c10f2fa8ab67d4b87
17 - Secret Key: 04689104C2FD3B2F + IV: 26955F6835AF609A
   Plaintext: D887E0393C2DA6E319FF040A73E6FC0C
   Ciphertext: 90fc1c4171ba4253bf6628c36e133cab
18 - Secret Key: 37D06BB516CB7546 + IV: 164D5E404F275232
   Plaintext: 5F99D04F5B1639697B6A20E27D980095
   Ciphertext: e895d38177ed40aed3d04998ced3bd5d
19 - Secret Key: 1F08260D1AC2465E + IV: 6B056E18759F5CCA
   Plaintext: 4A057A3B24D3977BDE229E1EBD41B5B8
   Ciphertext: cc9cf1222b52ca5b859e62ca52e9260c
20 - Secret Key: 584023641ABA6176 + IV: 004BD6EF09176062
   Plaintext: 452031C1E4FADA8E0FDDDE1A8A5B83F0
   Ciphertext: 7d9d0f14f0177e6235e32f0c97b37a5f
21 - Secret Key: 025816164629B007 + IV: 480D39006EE762F2
   Plaintext: 7555AE39F59B87BDFEBD1D7E17CBCA41
   Ciphertext: 73e184b02df518aad1df9a37054586ad
22 - Secret Key: 49793EBC79B3258F + IV: 437540C8698F3CFA
   Plaintext: 53C55F9CB49FC019A7ED7F44B8B2D1AD
   Ciphertext: 72a32841e9bd74b66c651f91fc21ced3
23 - Secret Key: 4FB05E1515AB73A7 + IV: 072D43A077075292
   Plaintext: 7A8E7BFA937E89A3395B6287FC04BF00
   Ciphertext: 16e023d99810f31c0eb84aa23d8ceafb
24 - Secret Key: 49E95D6D4CA229BF + IV: 02FE55778117F12A
   Plaintext: CF9C5D7A4986ADB5A3D5548F3DF976BE
   Ciphertext: e94c65ef2d3629e4b6f0fd03b71546c0
25 - Secret Key: 018310DC409B26D6 + IV: 1D9D5C5018F728C2
   Plaintext: D1ABB290658BC778A97AC0003948A6AF
   Ciphertext: 3ca14db00ceba84873c793610780a5ec
26 - Secret Key: 1C587F1C13924FEF + IV: 305532286D6F295A
   Plaintext: 55CB3774D13EF201B046252396442237
   Ciphertext: f19c6e6c9f34fa702c28f97ebd14aca4
27 - Secret Key: 0101010101010101 + IV: 0123456789ABCDEF
   Plaintext: FA34EC4847B268B260C5BAADE0C9C3E3
   Ciphertext: 99a33d87edc03cb54e0d74c9fe5e6934
28 - Secret Key: 1F1F1F1F0E0E0E0E + IV: 0123456789ABCDEF
   Plaintext: A790795108EA3CAE91E789440185282E
   Ciphertext: bdee734fec4b296ad2d2b67d383837d5
29 - Secret Key: E0FEE0FEF1FEF1FE + IV: 0123456789ABCDEF
   Plaintext: C39E072D9FAC631DB37736664428E3FA
   Ciphertext: 8d7f40c04796eb2264b49e634c7a3df5
30 - Secret Key: 0000000000000000 + IV: FFFFFFFFFFFFFFFF
   Plaintext: 014933E0CDAFF6E4FFDA124B8354E2BD
   Ciphertext: cb173d866b305e4d8ef14ae445a5cb8c
31 - Secret Key: FFFFFFFFFFFFFFFF + IV: 0000000000000000
   Plaintext: F21E9A77B71C49BC5BC51F22E32C2CE8
   Ciphertext: 92fad911711bd626c4ac803d095ec0b7
32 - Secret Key: 0123456789ABCDEF + IV: 0000000000000000
   Plaintext: 245946885754369ABFAF44BDD441F9F6
   Ciphertext: e74f215b96c7b86db0768f330ea2e702
33 - Secret Key: FEDCBA9876543210 + IV: FFFFFFFFFFFFFFFF
   Plaintext: 6B5C5A9C5D9E0A5ABDC6CD6E802DE097
   Ciphertext: 064a8418e8afd117b7146b9f8f26b7d9

Last update: 2018.

Table of Contents

 About This Book

 Blowfish Cipher Algorithm

 Perl Crypt::Blowfish Module

 Perl Crypt::ECB Perl Module

Perl Crypt::CBC Module

 What is Crypt::CBC

 Installing Crypt::CBC 2.33 with ActivePerl

 Crypt::CBC Encryption with Literal Keys

 Crypt::CBC Literal Key Error Cases

 Crypt::CBC Encryption with Crypt::Blowfish Objects

 Crypt::CBC Operation Simulation

 Crypt::CBC Encryption Verification

Blowfish CBC 2-Block Test Vectors

 Crypt::CBC Prepending IV to Ciphertext

 Crypt::CBC Encryption with Salted Keys

 Crypt::CBC Salted Key Test Cases

 Crypt::CBC Secret Key and IV Algorithm

 Crypt::CBC Encryption with Random Salt

 Crypt::CBC Padding Options

 Crypt::CBC Padding Option Tests

 Crypt::CBC Blowfish Encryption Summary

 Perl Crypt::CFB Perl Module

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

 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