Search code examples
phphashcrccrc32

CRC-32 oddity in PHP


Is there some specific reason why crc32($data) yields a completely different hash than hash("crc32", $data) in PHP?

Consider this code snippet (also posted online at http://ideone.com/eqbin4):

<?php
$data = "message";
echo(sprintf("%08x", crc32($data)) . "\n");
echo(hash("crc32", $data) . "\n");
?>

Output:

b6bd307f
c048b5b8

What am I getting wrong here, or is this just a PHP curiosity, using different CRC-32 computation methods for the same type of hash?


Solution

  • Looks like thecrc32($d) function is equalent to the hash("crc32b", $d) call, not the hash("crc32", $d).