Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between crc32 and crc32b?

Tags:

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

like image 691
AndreKR Avatar asked Apr 07 '13 09:04

AndreKR


2 Answers

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.

like image 195
Sébastien Renauld Avatar answered Oct 13 '22 01:10

Sébastien Renauld


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

like image 26
tsuriga Avatar answered Oct 13 '22 00:10

tsuriga