From: jfrusciante at tiscali dot it
Operating system: [unknown]
PHP version: 5.2.6
PHP Bug Type: *Encryption and hash functions
Bug description: CRC32 output endianness is different between crc32() and
hash()
Description:
------------
When I use dechex() to convert a crc32(), and when I directly use
hash("crc32b", ...), I do not get the same output. In particular, the
endianness of the hash() output seems inverted.
In other words: the output of crc32() seems to be correct in its integer
representation (I compared it with Python implementation), but converting
it to hexadecimal (with dechex() or with any calculator) produces a hex
string inverted in its endianness respect to the output of hash('crc32b',
...) with the same input.
Reproduce code:
---------------
printf("dechex(crc32(\"AAAAAAAA\")): ".
dechex(crc32("AAAAAAAA")).
"<br><br>");
printf("hash(\"crc32b\",\"AAAAAAAA\"): "
.hash("crc32b", "AAAAAAAA")
."<br>");
Expected result:
----------------
dechex(crc32("AAAAAAAA")): 79b71c0a
hash("crc32b","AAAAAAAA"): 79b71c0a
(or
dechex(crc32("AAAAAAAA")): 0a1cb779
hash("crc32b","AAAAAAAA"): 0a1cb779
I think the first two are the right ones)
Actual result:
--------------
dechex(crc32("AAAAAAAA")): 79b71c0a
hash("crc32b","AAAAAAAA"): 0a1cb779
Please note that the difference is only in the bytes order. "0a-1c-b7-79"
is like "79-b7-1c-0a" with inverted endianness, while both lines should
output the same values despite different architectures.
--
Edit bug report at http://bugs.php.net/?id=45028&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=45028&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=45028&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=45028&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=45028&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=45028&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=45028&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=45028&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=45028&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=45028&r=support
Expected behavior: http://bugs.php.net/fix.php?id=45028&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=45028&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=45028&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=45028&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45028&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=45028&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=45028&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=45028&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=45028&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=45028&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=45028&r=mysqlcfg