"bf-cbc" 2-Block Test Vectors

A tutorial 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 using OpenSSL 'enc -bf-cbc' command.

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 by calling the OpenSSL "enc -bf-cbc" command:

```#- OpenSSL-bf-cbc-2-Block-Test-Vector.pl
#-
@tests = split(/\n/, getInput());
print("Blowfish CBC 2-Block Test Vectors in Hex:\n");
foreach (@tests) {
(\$i, \$keyHex, \$ivHex, \$plainHex) = split(/ +/,\$_);
open(OUT, "> plain.txt");
binmode(OUT);
print OUT pack('H*',\$plainHex);
close(OUT);

\$cmd = "\\local\\gnuwin32\\bin\\openssl enc -bf-cbc -e "
. "-K \$keyHex\$keyHex -iv \$ivHex "
. "-in plain.txt -out cipher.txt -nopad";
system(\$cmd);

open(IN, "< cipher.txt");
binmode(IN);
\$cipherHex = unpack('H*',\$cipherStr);
close(IN);

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
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
16 07A7137045DA2A16 3BDD119049372802 2EEDDA93FFD39C7949DB91A767ED20BE
17 04689104C2FD3B2F 26955F6835AF609A D887E0393C2DA6E319FF040A73E6FC0C
18 37D06BB516CB7546 164D5E404F275232 5F99D04F5B1639697B6A20E27D980095
19 1F08260D1AC2465E 6B056E18759F5CCA 4A057A3B24D3977BDE229E1EBD41B5B8
21 025816164629B007 480D39006EE762F2 7555AE39F59B87BDFEBD1D7E17CBCA41
23 4FB05E1515AB73A7 072D43A077075292 7A8E7BFA937E89A3395B6287FC04BF00
25 018310DC409B26D6 1D9D5C5018F728C2 D1ABB290658BC778A97AC0003948A6AF
26 1C587F1C13924FEF 305532286D6F295A 55CB3774D13EF201B046252396442237
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
}
```

Note that we have to binary mode when writing and reading data to and from files. Also note that we have to use the secret key twice, "-K \$keyHex\$keyHex", to avoid OpenSSL padding it with 0x00, because it has only 8 bytes.

When running the example script, I got the following:

```Blowfish CBC 2-Block Test Vectors in Hex:
1 - Secret Key: 0000000000000000 + IV: 0000000000000000
Plaintext: 4EF997456198DD78E1C030E74C14D261
Ciphertext: e1c030e74c14d2614ef997456198dd78
2 - Secret Key: FFFFFFFFFFFFFFFF + IV: FFFFFFFFFFFFFFFF
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
12 - Secret Key: 04B915BA43FEB5B6 + IV: 42FD443059577FA2
Plaintext: 353882B109CE8F1AC7E83F0896578AB9
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
Ciphertext: 7d9d0f14f0177e6235e32f0c97b37a5f
21 - Secret Key: 025816164629B007 + IV: 480D39006EE762F2
Plaintext: 7555AE39F59B87BDFEBD1D7E17CBCA41
22 - Secret Key: 49793EBC79B3258F + IV: 437540C8698F3CFA
Ciphertext: 72a32841e9bd74b66c651f91fc21ced3
23 - Secret Key: 4FB05E1515AB73A7 + IV: 072D43A077075292
Plaintext: 7A8E7BFA937E89A3395B6287FC04BF00
Ciphertext: 16e023d99810f31c0eb84aa23d8ceafb
24 - Secret Key: 49E95D6D4CA229BF + IV: 02FE55778117F12A
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
Ciphertext: 99a33d87edc03cb54e0d74c9fe5e6934
28 - Secret Key: 1F1F1F1F0E0E0E0E + IV: 0123456789ABCDEF
Plaintext: A790795108EA3CAE91E789440185282E
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