Blowfish Cipher Tutorials - Herong's Tutorial Examples - v2.04, by Herong Yang
"ncfb/nofb" for Block Chaining Ciphers
This section provides a tutorial example on how to use 'ncfb' and 'nofb' mode codes to perform standard block chaining cipher operations using the PHP Mcrypt mcrypt_encrypt() function with Blowfish algorithm.
After reading again the PHP Mcrypt documentation at http://php.net/manual/en/intro.mcrypt.php, I noticed that this "CFB/OFB are 8bit by default." statement in the introduction paragraph.
This tells me that both "cfb" and "ofb" mode codes in the Mcrypt extension represent a byte (8-bit) chaining cipher operation, not the standard block chaining cipher operation.
If you want standard block chaining cipher operations in CFB and OFB modes, you need to use "ncfb" and "nofb" codes.
Test 1: Re-run a CFB 2-block test vector with "ncfb" mode code. The result should match the expected ciphertext:
C:\herong>php Blowfish-Block-Chaining-Cipher.php \ 0000000000000000 E1C030E74C14D2614EF997456198DD78 ncfb \ 0000000000000000 af39a7a22d8c0f19ce94e96f7a22ac91 Secret Key: 0000000000000000 + IV: 0000000000000000 Plaintext: e1c030e74c14d2614ef997456198dd78 Oper. Mode: ncfb Ciphertext: af39a7a22d8c0f19ce94e96f7a22ac91 PHP Result: af39a7a22d8c0f19ce94e96f7a22ac91 Validation: 1
Test 2: Re-run an OFB 2-block test vector with "ncfb" mode code. The result should match the expected ciphertext:
C:\herong>php Blowfish-Block-Chaining-Cipher.php \ 0000000000000000 E1C030E74C14D2614EF997456198DD78 nofb \ 0000000000000000 af39a7a22d8c0f19af39a7a22d8c0f19 Secret Key: 0000000000000000 + IV: 0000000000000000 Plaintext: e1c030e74c14d2614ef997456198dd78 Oper. Mode: nofb Ciphertext: af39a7a22d8c0f19af39a7a22d8c0f19 PHP Result: af39a7a22d8c0f19af39a7a22d8c0f19 Validation: 1
Conclusion: the PHP Mcrypt extension uses "cfb" and "ofb" mode codes for byte chaining cipher operations, and "ncfb" and "nofb" mode codes for block chaining cipher operations. PHP Mcrypt Web page does a poor job to explain these differences.
Table of Contents
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
PHP Mcrypt Blowfish Block Cipher
Mycrypt Blowfish Block Chaining Cipher
►"ncfb/nofb" for Block Chaining Ciphers
Performing CFB Operation Manually