#50082 [Opn->Csd]: Incorrect test vector CFB/OFB results for Blowfish encryption

From: Date: Fri, 13 Nov 2009 16:57:50 +0000
Subject: #50082 [Opn->Csd]: Incorrect test vector CFB/OFB results for Blowfish encryption
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-3102@lists.php.net to get a copy of this message
ID: 50082 Updated by: vrana@php.net Reported By: gslin at pixnet dot tw -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: FreeBSD 7.2-RELEASE i386 PHP Version: 5.2.11 New Comment: This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "CFB/OFB are 8bit by default." Previous Comments: ------------------------------------------------------------------------ [2009-11-13 16:57:42] svn@php.net Automatic comment from SVN on behalf of vrana Revision: http://svn.php.net/viewvc/?view=revision&revision=290675 Log: CFB/OFB 8bit (bug #50082) ------------------------------------------------------------------------ [2009-11-11 01:56:38] fa@php.net Actually this should be documented properly to avoid further RTFM and mcrypt is badly documented anyway. ------------------------------------------------------------------------ [2009-11-11 01:53:52] fa@php.net Hello, this is not a bug in PHP. cfb/ofb in mcrypt is 8bit by default (see http://mcrypt.hellug.gr/lib/mcrypt.3.html) the data given on your link (http://www.schneier.com/code/vectors.txt) clearly states 64bit cfb/ofb. Another version of your test script: <?php $iv = pack('H*', 'FEDCBA9876543210'); printf("iv: %s\n", bin2hex($iv)); $k = pack('H*', '0123456789ABCDEFF0E1D2C3B4A59687'); printf("key: %s\n", bin2hex($k)); $data = pack('H*', '37363534333231204E6F77206973207468652074696D6520666F722000'); printf("data:(%d) '%s'\n", strlen($data), $data); printf("data:(%d) '%s'\n", strlen(bin2hex($data)), bin2hex($data)); $cbc = mcrypt_cbc('blowfish', $k, $data, MCRYPT_ENCRYPT, $iv); printf("cbc: %s\n", bin2hex($cbc)); $cfb = mcrypt_cfb('blowfish', $k, $data, MCRYPT_ENCRYPT, $iv); printf("cfb: %s\n", bin2hex($cfb)); $ofb = mcrypt_ofb('blowfish', $k, $data, MCRYPT_ENCRYPT, $iv); printf("ofb: %s\n", bin2hex($ofb)); $td = mcrypt_module_open('blowfish', '', 'ncfb', ''); mcrypt_generic_init($td, $k, $iv); $x = mcrypt_generic($td, $data); printf("ncfb: %s\n", bin2hex($x)); $td = mcrypt_module_open('blowfish', '', 'nofb', ''); mcrypt_generic_init($td, $k, $iv); $x = mcrypt_generic($td, $data); printf("nofb: %s\n", bin2hex($x)); and the output: iv: fedcba9876543210 key: 0123456789abcdeff0e1d2c3b4a59687 data:(29) '7654321 Now is the time for ' data:(58) '37363534333231204e6f77206973207468652074696d6520666f722000' cbc: 6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc cfb: e7bb1fc3073eb8314b378689fab0b1160244415d4d017fce0d9b4cb2fa ofb: e7e246a97576bf3da1236575443e0c46bcdb2638fe825603f561ffe6aa ncfb: e73214a2822139caf26ecf6d2eb9e76e3da3de04d1517200519d57a6c3 nofb: e73214a2822139ca62b343cc5b65587310dd908d0c241b2263c2cf80da ------------------------------------------------------------------------ [2009-11-04 23:10:21] gslin at pixnet dot tw Description: ------------ Incorrect results for CFB/OFB Blowfish test vectors (http://www.schneier.com/code/vectors.txt). Reproduce code: --------------- <?php $iv = pack('H*', 'FEDCBA9876543210'); printf("iv: %s\n", bin2hex($iv)); $k = pack('H*', '0123456789ABCDEFF0E1D2C3B4A59687'); printf("key: %s\n", bin2hex($k)); $data = pack('H*', '37363534333231204E6F77206973207468652074696D6520666F722000'); printf("data: %s\n", bin2hex($data)); $cbc = mcrypt_cbc('blowfish', $k, $data, MCRYPT_ENCRYPT, $iv); printf("cbc: %s\n", bin2hex($cbc)); $cfb = mcrypt_cfb('blowfish', $k, $data, MCRYPT_ENCRYPT, $iv); printf("cfb: %s\n", bin2hex($cfb)); $ofb = mcrypt_cfb('blowfish', $k, $data, MCRYPT_ENCRYPT, $iv); printf("ofb: %s\n", bin2hex($ofb)); Expected result: ---------------- iv: fedcba9876543210 key: 0123456789abcdeff0e1d2c3b4a59687 data: 37363534333231204e6f77206973207468652074696d6520666f722000 cbc: 6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc cfb: e73214a2822139caf26ecf6d2eb9e76e3da3de04d1517200519d57a6c3 ofb: e73214a2822139ca62b343cc5b65587310dd908d0c241b2263c2cf80da Actual result: -------------- iv: fedcba9876543210 key: 0123456789abcdeff0e1d2c3b4a59687 data: 37363534333231204e6f77206973207468652074696d6520666f722000 cbc: 6b77b4d63006dee605b156e27403979358deb9e7154616d959f1652bd5ff92cc cfb: e7bb1fc3073eb8314b378689fab0b1160244415d4d017fce0d9b4cb2fa ofb: e7bb1fc3073eb8314b378689fab0b1160244415d4d017fce0d9b4cb2fa ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50082&edit=1

« previous php.doc.bugs (#3102) next »