Bug #10162 [Fbk->NoF]: Algorithm does not work correctly on a Linux server

From: Date: Mon, 23 Mar 2009 17:05:30 +0000
Subject: Bug #10162 [Fbk->NoF]: Algorithm does not work correctly on a Linux server
References: 1  Groups: php.pear.bugs 
Request: Send a blank email to pear-bugs+get-244@lists.php.net to get a copy of this message
Edit report at http://pear.php.net/bugs/bug.php?id=10162&edit=1 ID: 10162 Updated by: daniel.oconnor@gmail.com Reported By: jausions at php dot net Summary: Algorithm does not work correctly on a Linux server -Status: Feedback +Status: No Feedback Type: Bug Package: Crypt_Blowfish Operating System: Linux 2.4.32 Package Version: 1.1.0RC1 PHP Version: 4.3.10 Roadmap Versions: New Comment: -Status: Feedback +Status: No Feedback Previous Comments: ------------------------------------------------------------------------ [2008-08-31 11:00:39] 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. ------------------------------------------------------------------------ [2007-02-23 15:20:02] cynic at poczta dot onet dot pl Another thing: for my changes to work correctly, you need a version of the Crypt_Blowfish_DefaultKey class with the internal array elements initialized with signed decimal literals (so that they are all of the integer datatype), not unsigned hexadecimal. ------------------------------------------------------------------------ [2007-02-23 14:54:04] cynic at poczta dot onet dot pl Also, in the heat of the moment I missed the "If you are able to reproduce the bug with the latest CVS, please change the status back to "Open". " fragment in one of the comments in #6159. I'm sorry for that. ------------------------------------------------------------------------ [2007-02-23 14:51:25] cynic at poczta dot onet dot pl On this particular server, XOR operator ("^") and some type conversions work correctly only with signed 32-bit integers. The solution that works for me - on this particular server, my 32-bit Windows XP development machine with PHP 5.2 and another Linux shared hosting server with PHP 4.4 (on which 1.1.0RC1 worked fine but 1.0 did not) - is to do as much internal algorithm operations on 32-bit signed integer as possible. There are following changes to the 1.1.0RC1 code: In class Crypt_Blowfish_PHP: Replaced methods: function _binxor($l, $r) { while ($l > 2147483647) { $l -= 4294967296; } while ($l < -2147483648) { $l += 4294967296; } $l = (int) $l; while ($r > 2147483647) { $r = $r - 4294967296; } while ($r < -2147483648) { $r += 4294967296; } $r = (int) $r; return $l ^ $r; } function _encipher(&$Xl, &$Xr) { for ($i = 0; $i < 16; $i++) { $temp = $this->_binxor($Xl, $this->_P[$i]); $Xl = $this->_binxor( $this->_binxor( $this->_S[0][($temp >> 24) & 255] + $this->_S[1][($temp >> 16) & 255], $this->_S[2][($temp >> 8) & 255] ) + $this->_S[3][$temp & 255], $Xr); $Xr = $temp; } $Xr = $this->_binxor($Xl, $this->_P[16]); $Xl = $this->_binxor($temp, $this->_P[17]); } function _decipher(&$Xl, &$Xr) { for ($i = 17; $i > 1; $i--) { $temp = $this->_binxor($Xl, $this->_P[$i]); $Xl = $this->_binxor( $this->_binxor( ($this->_S[0][($temp >> 24) & 255] + $this->_S[1][($temp >> 16) & 255]), $this->_S[2][($temp >> 8) & 255] ) + $this->_S[3][$temp & 255], $Xr); $Xr = $temp; } $Xr = $this->_binxor($Xl, $this->_P[1]); $Xl = $this->_binxor($temp, $this->_P[0]); } In method setKey: Replaced line: $this->_P[$i] ^= $data; with: $this->_P[$i] = $this->_binxor($this->_P[$i], $data); ------------------------------------------------------------------------ [2007-02-23 11:15:33] jausions The "proper" results for the script sample should be: A: 3851235679 B: -443704711 C: -443704711 D: 3851262585 So your values are way off... I'd suggest you run some basic bitwise xor tests so see where you server breaks. In particular with just lower and above 2147439833. BTW: "XOR" operator is a binary operator not a bitwise one, so it has no relevance to the topic. Bitwise xor is "^". ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://pear.php.net/bugs/bug.php?id=10162 -- Edit this bug report at http://pear.php.net/bugs/bug.php?id=10162&edit=1

« previous php.pear.bugs (#244) next »