#50082 [Opn->Bgs]: Incorrect test vector CFB/OFB results for Blowfish encryption
| From: | fa@php.net | Date: | Wed, 11 Nov 2009 01:53:53 +0000 |
| Subject: | #50082 [Opn->Bgs]: Incorrect test vector CFB/OFB results for Blowfish encryption | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-144436@lists.php.net to get a copy of this message | ||
ID: 50082
Updated by: fa@php.net
Reported By: gslin at pixnet dot tw
-Status: Open
+Status: Bogus
Bug Type: mcrypt related
Operating System: FreeBSD 7.2-RELEASE i386
PHP Version: 5.2.11
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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