#30598 [Opn]: double to long truncation breaks TEA
| From: | os at sumu dot org | Date: | Thu, 28 Oct 2004 13:24:00 +0000 |
| Subject: | #30598 [Opn]: double to long truncation breaks TEA | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-68429@lists.php.net to get a copy of this message | ||
ID: 30598
User updated by: os at sumu dot org
Reported By: os at sumu dot org
Status: Open
Bug Type: Zend Engine 2 problem
Operating System: Any
PHP Version: 5.0.2
New Comment:
Oops.. looks like I should've searched the bug database a bit more,
this is basically a duplicate to #30315.
Previous Comments:
------------------------------------------------------------------------
[2004-10-28 15:15:11] os at sumu dot org
Description:
------------
The change for DVAL_TO_LVAL macro in 5.0.2 breaks some of my code that
worked in earlier versions. While it appears that it was relying on
undefined behaviour, it allowed for example a direct port of Tiny
Encryption Algorithm's reference C code for PHP to work.
(http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm)
Reproduce code:
---------------
function tea_encrypt($cycle, $key)
{
$a = $cycle[0];
$b = $cycle[1];
$sum = 0;
$delta = (int)0x9e3779b9;
for($i=0; $i<32; $i++)
{
$sum = (int)($sum + $delta);
$a += (($b << 4) + $key[1]) ^ ($b + $sum) ^ (($b >> 5) +
$key[2]);
$b += (($a << 4) + $key[3]) ^ ($a + $sum) ^ (($a >> 5) +
$key[4]);
}
return array($a, $b);
}
$result = tea_encrypt(array(123456, 987654), array(0, 1, 2, 3,
4));
var_dump(unpack("H*", pack("V*", $result[0], $result[1])));
Expected result:
----------------
PHP versions prior to 5.0.2:
~> php -q tea.php
array(1) {
[1]=>
string(16) "8f695fc4e6d3c507"
}
Actual result:
--------------
~> ./php-5.0.2/sapi/cli/php -q tea.php
array(1) {
[1]=>
string(16) "ffffff7f00000080"
}
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30598&edit=1