A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data.
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks and storage devices to detect accidental changes to raw data. Blocks of data entering these systems get a short check value attached, based on the remainder of a polynomial division of their contents; on retrieval the calculation is repeated, and corrective action can be taken against presumed data corruption if the check values do not match. wikipedia
The most commonly used polynomial lengths are:
- CRC-8: 9 bits
- CRC-16: 17 bits
- CRC-32: 33 bits
- CRC-64: 65 bits
A truly excellent tutorial on CRC's is Ross Williams' “Painless Guide to CRC Detection Algorithms”, which can also be found here, here, here, here, and here.
Before you ask a question about CRC, have you first checked:
- Which CRC algorithm is being discussed?
- Be specific about the source of your CRC. If you're asking about the Ethernet CRC-32, say so. If you're asking about the Castagnoli CRC-32C, say so.
- There exists a catalogue of CRC parameters and a list of CRC polynomials on Wikipedia, both of which can be used to name more exotic specimens.
- Make sure to select the correct tag.
- Polynomial: Is the polynomial correct?
- Is it bit-reversed?
- Is it byte-swapped?
- Is it complemented?
- Initialization: Is the CRC correctly initialized?
- Some are initialized with all-zeros, some with all-ones, and some with something entirely different. Be sure to have the correct initialization.
- For non-zero initialization it makes a difference whether the message is passed through the shift register or just XORed to its output.
- Processing:
- Is the data being CRCed correctly byte-swapped?
- Are you shifting in the right direction?
- Are you using any CRC intrinsics, like Intel's SSE4.2
crc32
instruction? - Is your lookup table correct for the polynomial and byte-order you chose?
- Finalization: Is the CRC correctly finalized?
- Some CRC schemes call for the polynomial result to be XORed with a particular constant, like
0xFFFFFFFF
, while some don't. - The CRC output might be bit-reversed in your implementation.
- Some CRC schemes call for the polynomial result to be XORed with a particular constant, like