What is the polynomial used for crc32? The ANSI X3.66 CRC-32 is 0x104C11DB7. The man page for crc32 does not indicate the polynomial it uses.
1 Answers
The question as is phrased is off-topic, however I'll try to make it on-topic by addressing how to search for documentation on tools that rely on Perl modules in a general way; in order:
man <tool>
;From
man crc32
:This utility is supplied with the Archive::Zip module for Perl.
perldoc <module>
;From
perldoc Archive::Zip
:Archive::Zip::computeCRC32( $string [, $crc] ) Archive::Zip::computeCRC32( { string => $string [, checksum => $crc ] } ) This is a utility function that uses the Compress::Raw::Zlib CRC routine to compute a CRC-32.
Apply recursively until something avails or the "root" module is reached; in this case the recursion ends with
perldoc Compress::Raw::Zlib
, which doesn't avail;Dig the source code of the "root" module:
Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
Polynomials over GF(2) are represented in binary, one bit per coefficient, with the lowest powers in the most significant bit. Then adding polynomials is just exclusive-or, and multiplying a polynomial by x is a right shift by one. If we call the above polynomial p, and represent a byte as the polynomial q, also with the lowest power in the most significant bit (so the byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, where a mod b means the remainder after dividing a by b.
This calculation is done using the shift-register method of multiplying and taking the remainder. The register is initialized to zero, and for each incoming bit, x^32 is added mod p to the register if the bit is a one (where x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by x (which is shifting right by one and adding x^32 mod p if the bit shifted out is a one). We start with the highest power (least significant bit) of q and repeat for all eight bits of q.
The first table is simply the CRC of all possible eight bit values. This is all the information needed to generate CRCs on data a byte at a time for all combinations of CRC register values and incoming bytes. The remaining tables allow for word-at-a-time CRC calculation for both big-endian and little- endian machines, where a word is four bytes.

- 35,891
-
1In short, the polynomial is 0x104C11DB7. It does implement the ANSI X3.66 CRC-32. It would be nice if the man crc32 page included this its prose. – Luke Perkins Nov 23 '15 at 21:30
-
1
-
@muru: I would love to. Not intuitively obvious how to do this. I do not have enough "points". – Luke Perkins Nov 24 '15 at 05:04
-
1@LukePerkins You don't points (not on this site, anyway). See http://askubuntu.com/a/5126/158442, essentially: run
ubuntu-bug libarchive-zip-perl
. – muru Nov 24 '15 at 05:06 -
crc32
program is included in Ubuntu, I don't believe that the mathematical background of the standardized CRC32 algorithm is on topic on AskUbuntu. – David Foerster Nov 26 '15 at 12:24