Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are CRC Polynomials given as Normal, Reversed, etc.?

Tags:

crc

I'm learning about CRCs, and search engines and SO turn up nothing on this....

Why do we have "Normal" and "Reversed" and "Reciprocal" Polynomials? Does one favor Big Endian, Little Endian, or something else?

like image 937
someprogrammer Avatar asked Mar 10 '23 01:03

someprogrammer


1 Answers

The classic definition of a CRC would use a non-reflected polynomial, which shifts the CRC left. If the word size being used for the calculation is larger than the CRC, then you would need an operation at the end to clear the high bits that were shifted into (e.g. & 0xffff for a 16-bit CRC).

You can flip the whole thing, use a reflected polynomial, and shift right instead of left. That gives the same CRC properties, but the bits from the message are effectively operated on from least to most significant bit, instead of most to least significant bit. Since you are shifting right, the extraneous bits get dropped off the bottom into oblivion, and there is no need for the additional operation. This may have been one of the early motivations to use a very slightly faster and more compact implementation.

Sometimes the specification from the original hardware is that the bits are processed from least to most significant, so then you have to use the reflected version.

No, none of this favors little or big endian. Either kind of CRC can be computed just as easily in little-endian or big-endian architectures.

like image 185
Mark Adler Avatar answered Mar 12 '23 14:03

Mark Adler