I frequently see on SO questions about crc (Cyclic Redundancy Check), usually about buggy implementations. The same points frequently need to be clarified, and the errors found in the code are often similar across questions and languages. The problem especially frequently occurs with CRC-32, since there are two common CRC-32's, one called CRC-32 and one called CRC-32C.
Therefore I'd like to suggest the following:
- That a checklist be added to the tag wiki, containing the following or similar:
Have you checked:
- Which CRC algorithm is being discussed? List of CRC polynomials
- 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. 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.
- Processing:
- Is the data being CRCed correctly byte-swapped?
- 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.
That disambiguation tags be added for:
- CRC-32 (the family of CRCs with 33-bit generator polynomials)
- CRC-32 (the specific CRC-32 with polynomial
0x04C11DB7
) - CRC-32C (the specific CRC-32 with polynomial
0x1EDC6F41
)
given that these two CRC-32's are by far the most used and asked about.
0
or0xFFFFFFFF
' - does requiring a polynomial result be XORed with0
have much effect?