|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45028 CRC32 output endianness is different between crc32() and hash()
Submitted: 2008-05-17 16:03 UTC Modified: 2008-08-18 14:33 UTC
From: jfrusciante at tiscali dot it Assigned: scottmac (profile)
Status: Closed Package: *Encryption and hash functions
PHP Version: 5.2.6 OS: *
Private report: No CVE-ID: None
 [2008-05-17 16:03 UTC] jfrusciante at tiscali dot it
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\")): ".

printf("hash(\"crc32b\",\"AAAAAAAA\"): "
.hash("crc32b", "AAAAAAAA")

Expected result:
dechex(crc32("AAAAAAAA")): 79b71c0a
hash("crc32b","AAAAAAAA"): 79b71c0a

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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-11 11:07 UTC]
Mike, can you confirm that this patch is correct?
 [2008-08-18 14:33 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Apr 15 09:01:28 2024 UTC