"bf-cfb" 2-Block Test Vectors

A tutorial example is provided to show how to build a table of test vectors for Blowfish algorithm in CFB mode on 2-block (16-byte) plaintext messages using OpenSSL 'enc -bf-cfb' command.

Since there are not enough test vectors published on the Internet for Blowfish algorithm in CFB 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-cfb" command:

```#- OpenSSL-bf-cfb-2-Block-Test-Vector.pl
#-
@tests = split(/\n/, getInput());
print("Blowfish CFB 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-cfb -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 E1C030E74C14D2614EF997456198DD78
3  3000000000000000 1000000000000001 C170D6977BAF4AFF7D856F9A613063F2
4  1111111111111111 1111111111111111 695CFFB69DC5B0BA2466DD878B963C9D
5  0123456789ABCDEF 1111111111111111 354D26A3D1C5D03161F9C3802281B096
6  1111111111111111 0123456789ABCDEF 3F389598F060D6C67D0CC630AFDA1EC7
7  FEDCBA9876543210 0123456789ABCDEF 52BA6077910130BB0ACEAB0FC6A0A28D
8  7CA110454A1A6E57 01A1D6D039776742 8E1482495AAE778259C68245EB05282B
9  0131D9619DC1376E 5CD54CA83DEF57DA 278EC4570AFBA00BB1B8CC0B250F09A0
10 07A1133E4A0B2686 0248D43806F67172 A721AF5F8FE286E61730E5778BEA1DA4
11 3849674C2602319E 51454B582DDF440A 41B5844B528DEBCBA25E7856CF2651EB
12 04B915BA43FEB5B6 42FD443059577FA2 C7E83F0896578AB9353882B109CE8F1A
13 0113B970FD34F2CE 059B5E0851CF143A 574315272A39D84448F4D0884C379918
14 0170F175468FB5E6 0756D8E0774761D2 5968C3C90812BE01432193B78951FC98
16 07A7137045DA2A16 3BDD119049372802 49DB91A767ED20BE2EEDDA93FFD39C79
17 04689104C2FD3B2F 26955F6835AF609A 19FF040A73E6FC0CD887E0393C2DA6E3
18 37D06BB516CB7546 164D5E404F275232 7B6A20E27D9800955F99D04F5B163969
19 1F08260D1AC2465E 6B056E18759F5CCA DE229E1EBD41B5B84A057A3B24D3977B
21 025816164629B007 480D39006EE762F2 FEBD1D7E17CBCA417555AE39F59B87BD
23 4FB05E1515AB73A7 072D43A077075292 395B6287FC04BF007A8E7BFA937E89A3
25 018310DC409B26D6 1D9D5C5018F728C2 A97AC0003948A6AFD1ABB290658BC778
26 1C587F1C13924FEF 305532286D6F295A B04625239644223755CB3774D13EF201
28 1F1F1F1F0E0E0E0E 0123456789ABCDEF 91E789440185282EA790795108EA3CAE
29 E0FEE0FEF1FEF1FE 0123456789ABCDEF B37736664428E3FAC39E072D9FAC631D
30 0000000000000000 FFFFFFFFFFFFFFFF FFDA124B8354E2BD014933E0CDAFF6E4
31 FFFFFFFFFFFFFFFF 0000000000000000 5BC51F22E32C2CE8F21E9A77B71C49BC
32 0123456789ABCDEF 0000000000000000 BFAF44BDD441F9F6245946885754369A
33 FEDCBA9876543210 FFFFFFFFFFFFFFFF BDC6CD6E802DE0976B5C5A9C5D9E0A5A
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 CFB 2-Block Test Vectors in Hex:
1 - Secret Key: 0000000000000000 + IV: 0000000000000000
Plaintext: E1C030E74C14D2614EF997456198DD78
Ciphertext: af39a7a22d8c0f19ce94e96f7a22ac91
2 - Secret Key: FFFFFFFFFFFFFFFF + IV: FFFFFFFFFFFFFFFF
Ciphertext: eb0c567cf9cd664bef9f89b304c266fd
3 - Secret Key: 3000000000000000 + IV: 1000000000000001
Plaintext: C170D6977BAF4AFF7D856F9A613063F2
4 - Secret Key: 1111111111111111 + IV: 1111111111111111
Plaintext: 695CFFB69DC5B0BA2466DD878B963C9D
Ciphertext: 4d3a223116538c272762b93f7c3b7f77
5 - Secret Key: 0123456789ABCDEF + IV: 1111111111111111
Plaintext: 354D26A3D1C5D03161F9C3802281B096
Ciphertext: 54b4e523f34460a7321534046446d996
6 - Secret Key: 1111111111111111 + IV: 0123456789ABCDEF
Plaintext: 3F389598F060D6C67D0CC630AFDA1EC7
Ciphertext: 423453a85fbac8010f70e4e2912ca1d5
7 - Secret Key: FEDCBA9876543210 + IV: 0123456789ABCDEF
Plaintext: 52BA6077910130BB0ACEAB0FC6A0A28D
Ciphertext: 5874cb7857a19236f7a8b373399a0db5
8 - Secret Key: 7CA110454A1A6E57 + IV: 01A1D6D039776742
Plaintext: 8E1482495AAE778259C68245EB05282B
Ciphertext: d7d2000cb1ab5fa9b0280e9c2830d2bd
9 - Secret Key: 0131D9619DC1376E + IV: 5CD54CA83DEF57DA
Plaintext: 278EC4570AFBA00BB1B8CC0B250F09A0
Ciphertext: 9636085c2ff4a9abf6859c11e4552770
10 - Secret Key: 07A1133E4A0B2686 + IV: 0248D43806F67172
Plaintext: A721AF5F8FE286E61730E5778BEA1DA4
Ciphertext: b0114a2804089b42f8f5835153d678d4
11 - Secret Key: 3849674C2602319E + IV: 51454B582DDF440A
Plaintext: 41B5844B528DEBCBA25E7856CF2651EB
Ciphertext: e3ebfc1d9dabba205fa8e74c712e13ed
12 - Secret Key: 04B915BA43FEB5B6 + IV: 42FD443059577FA2
Plaintext: C7E83F0896578AB9353882B109CE8F1A
Ciphertext: f2d0bdb99f9905a31dcf228b97495033
13 - Secret Key: 0113B970FD34F2CE + IV: 059B5E0851CF143A
Plaintext: 574315272A39D84448F4D0884C379918
Ciphertext: 1fb7c5af660e415ce6743ba07583c82e
14 - Secret Key: 0170F175468FB5E6 + IV: 0756D8E0774761D2
Plaintext: 5968C3C90812BE01432193B78951FC98
Ciphertext: 1a49507e81434299be9f12d5253ed684
15 - Secret Key: 43297FAD38E373FE + IV: 762514B829BF486A
Plaintext: 9229B7E3B6B1776813F04154D69D1AE5
Ciphertext: 81d9f6b7602c6d8d81aa419c055a362c
16 - Secret Key: 07A7137045DA2A16 + IV: 3BDD119049372802
Plaintext: 49DB91A767ED20BE2EEDDA93FFD39C79
Ciphertext: 67364b34983ebcc7af8132c2821d389c
17 - Secret Key: 04689104C2FD3B2F + IV: 26955F6835AF609A
Plaintext: 19FF040A73E6FC0CD887E0393C2DA6E3
Ciphertext: c178e4334fcb5aef16cb8114a292e1b9
18 - Secret Key: 37D06BB516CB7546 + IV: 164D5E404F275232
Plaintext: 7B6A20E27D9800955F99D04F5B163969
19 - Secret Key: 1F08260D1AC2465E + IV: 6B056E18759F5CCA
Plaintext: DE229E1EBD41B5B84A057A3B24D3977B
Ciphertext: 9427e425999222c3f01532b1924dc4c5
20 - Secret Key: 584023641ABA6176 + IV: 004BD6EF09176062
Ciphertext: 4afdefdb6ea1597e5ed9c7183216372e
21 - Secret Key: 025816164629B007 + IV: 480D39006EE762F2
Plaintext: FEBD1D7E17CBCA417555AE39F59B87BD
Ciphertext: 8be8b347e2504dfc1e86b3534b818f8f
22 - Secret Key: 49793EBC79B3258F + IV: 437540C8698F3CFA
Ciphertext: f42820d80c2d11b47ecd4f4e585cdf6d
23 - Secret Key: 4FB05E1515AB73A7 + IV: 072D43A077075292
Plaintext: 395B6287FC04BF007A8E7BFA937E89A3
Ciphertext: 43d5197d6f7a36a3c350bf27f3874223
24 - Secret Key: 49E95D6D4CA229BF + IV: 02FE55778117F12A
Ciphertext: 6c4909f5747fdb0b8c209f9720d9279a
25 - Secret Key: 018310DC409B26D6 + IV: 1D9D5C5018F728C2
Plaintext: A97AC0003948A6AFD1ABB290658BC778
Ciphertext: 78d172905cc361d793fd695e7b4b68d0
26 - Secret Key: 1C587F1C13924FEF + IV: 305532286D6F295A
Plaintext: B04625239644223755CB3774D13EF201
27 - Secret Key: 0101010101010101 + IV: 0123456789ABCDEF
Ciphertext: 9af156e5a77bab51012b3daf6d6774a7
28 - Secret Key: 1F1F1F1F0E0E0E0E + IV: 0123456789ABCDEF
Plaintext: 91E789440185282EA790795108EA3CAE
Ciphertext: 3677f015096f1480e67d2e1a4cdc57a8
29 - Secret Key: E0FEE0FEF1FEF1FE + IV: 0123456789ABCDEF
Plaintext: B37736664428E3FAC39E072D9FAC631D
Ciphertext: 70e9314bdb8480e77f60277940b8775f
30 - Secret Key: 0000000000000000 + IV: FFFFFFFFFFFFFFFF
Plaintext: FFDA124B8354E2BD014933E0CDAFF6E4
Ciphertext: fe9321ab4efb1459d4dc31b8ab277c0a
31 - Secret Key: FFFFFFFFFFFFFFFF + IV: 0000000000000000
Plaintext: 5BC51F22E32C2CE8F21E9A77B71C49BC
Ciphertext: a9db855554306554d08de5451f1542e6
32 - Secret Key: 0123456789ABCDEF + IV: 0000000000000000
Plaintext: BFAF44BDD441F9F6245946885754369A
Ciphertext: 9bf602358315cf6c761422105a26f784
33 - Secret Key: FEDCBA9876543210 + IV: FFFFFFFFFFFFFFFF
Plaintext: BDC6CD6E802DE0976B5C5A9C5D9E0A5A
Ciphertext: d69a97f2ddb3eacdef40204c50c98032
```

Last update: 2015.