Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.1.0RC2

Bug #12906 Algorithm does not pass standard Blowfish test
Submitted: 2008-01-14 22:26 UTC
From: greezybacon Assigned:
Status: No Feedback Package: Crypt_Blowfish (version 1.1.0RC1)
PHP Version: 5.2.1 OS: Solaris 8 / SPARC
Roadmaps: (Not assigned)    
Subscription  
Comments Add Comment Add patch


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 8 - 6 = ?

 
 [2008-01-14 22:26 UTC] greezybacon (Jared Hancock)
Description: ------------ Using test vectors from http://www.schneier.com/blowfish.html, this implementation does not generate expected values. One could also consider the results between the MCrypt implementation and the pure PHP, as this setup can use either. Test script: --------------- # # NOTE: Assume hex2bin and bin2hex functions # exist that convert hexadecimal strings # (base16) to/from binary strings (base256) # $B=new Crypt_Blowfish(hex2bin('0123456789ABCDEF')) echo bin2hex($B->encrypt('1111111111111111')) Expected result: ---------------- 61F9C3802281B096 Actual result: -------------- 2E38367FA01A330E

Comments

 [2008-01-15 13:41 UTC] greezybacon (Jared Hancock)
Never created a patch file before, so I just post the fixed code here. The only changes were the addititions of a floating modulus of 2^32 operation after the addition of the S0 and S1 parts and after the addition of the S3 parts as per the blowfish specification found at http://www.schneier.com/paper-blowfish-fse.html. Changes were made to the _encipher() and _decipher() methods of the Crypt_Blowfish_PHP class. The server being used for this bug is 64-bit. I have no idea, but wonder if this issue is specific to 64-bit platforms. /** * Enciphers a single 64-bit block * * @param int &$Xl * @param int &$Xr * @access protected */ function _encipher(&$Xl, &$Xr) { if ($Xl < 0) { $Xl += 4294967296; } if ($Xr < 0) { $Xr += 4294967296; } for ($i = 0; $i < 16; $i++) { $temp = $Xl ^ $this->_P[$i]; if ($temp < 0) { $temp += 4294967296; } $Xl = fmod(((fmod(($this->_S[0][($temp >> 24) & 255] + $this->_S[1][($temp >> 16) & 255] ),4294967296) ^ $this->_S[2][($temp >> 8) & 255] ) + $this->_S[3][$temp & 255] ),4294967296) ^ $Xr; $Xr = $temp; } $Xr = $this->_binxor($Xl, $this->_P[16]); $Xl = $this->_binxor($temp, $this->_P[17]); } /** * Deciphers a single 64-bit block * * @param int &$Xl * @param int &$Xr * @access protected */ function _decipher(&$Xl, &$Xr) { if ($Xl < 0) { $Xl += 4294967296; } if ($Xr < 0) { $Xr += 4294967296; } for ($i = 17; $i > 1; $i--) { $temp = $Xl ^ $this->_P[$i]; if ($temp < 0) { $temp += 4294967296; } $Xl = fmod(((fmod(($this->_S[0][($temp >> 24) & 255] + $this->_S[1][($temp >> 16) & 255] ),4294967296) ^ $this->_S[2][($temp >> 8) & 255] ) + $this->_S[3][$temp & 255] ),4294967296) ^ $Xr; $Xr = $temp; } $Xr = $this->_binxor($Xl, $this->_P[1]); $Xl = $this->_binxor($temp, $this->_P[0]); }
 [2008-08-31 15:00 UTC] jausions (Philippe Jausions)
Thank you for taking the time to report a problem with the package. Unfortunately you are not using a current version of the package -- the problem might already be fixed. Please download a new version from http://pear.php.net/packages.php If you are able to reproduce the bug with one of the latest versions, please change the package version on this bug report to the version you tested and change the status back to "Open". Again, thank you for your continued support of PEAR. Thank you for taking the time to report a problem with the package. Unfortunately you are not using a current version of the package -- the problem might already be fixed. Please download a new version from http://pear.php.net/packages.php If you are able to reproduce the bug with one of the latest versions, please change the package version on this bug report to the version you tested and change the status back to "Open". Again, thank you for your continued support of PEAR.