21

Apparently the PHP function hash() can be called with the algorithms crc32 and crc32b? What is the difference between them?

AndreKR
  • 32,613
  • 18
  • 106
  • 168
  • There are a couple of users explaining it here: http://www.php.net/manual/en/function.hash-file.php#104836 – ulentini Apr 07 '13 at 09:54
  • 2
    google got me this-- shld help http://www.pal-blog.de/entwicklung/perl/2012/crc32-vs-crc32b.html – Dinesh Apr 07 '13 at 09:54

3 Answers3

8

Two different algorithms. CRC32b is an implementation of the consistency algorithm defined here, whereas CRC32 is the frame check sequence defined here. They're different things, though the differences are not often big.

One way to check this:

<?php
echo hash("crc32", __FILE__)."<br/>";
echo hash("crc32b", __FILE__); ?>

Due to their similarity, the starting hex values will be relatively similar.

Luiz Wynne
  • 460
  • 3
  • 10
  • 28
Sébastien Renauld
  • 19,203
  • 2
  • 46
  • 66
  • Is there a reason to choose one over the other? – Courtney Miles Oct 14 '13 at 20:33
  • 2
    @user2045006: Nope. They only differ in their implementation details and historical uses. One works with streams, the other with frames. For the large majority of cases, this can be assumed to be equivalent in performance. – Sébastien Renauld Oct 15 '13 at 10:42
5

As per answer by apm on php.net: "I have verified that the output of the "crc32" is the ITU I.363.5 algorithm (a.k.a. AAL5 CRC - popularised by BZIP2 but also used in ATM transmissions - the algorithm is the same as that in POSIX 1003.2-1992 in Cksum but that stuffs the size into the CRC at the end for extra measure). -- The crc32b is the 32-bit Frame Check Sequence of ITU V.42 (used in Ethernet and popularised by PKZip). The output from this CRC is popularised in Intel little endian format and would produce cbf43926 on the same file."

The full comment: http://www.php.net/manual/en/function.hash-file.php#104836

tsuriga
  • 675
  • 5
  • 7
1

The difference between crc32 and crc32b is explained on mhash man page. crc32 is the one used on ethernet, while crc32b is the one used on zip, png... They differ on the table used.

quote taken from php.net

8ctopus
  • 2,617
  • 2
  • 18
  • 25