algorithmcrccrc32crc16crc64

Generating of the polynomial key for crc


With reference to this article: https://www.digikey.com/eewiki/display/microcontroller/CRC+Basics

The polynomial key is an important part of the CRC. Keys are not just random polynomials; they are generated using a set of mathematical formulas and are intended to increase the number of mistakes that the CRC process identifies. The polynomial is typically defined by the network protocol or external device. Since there is a well-established set of keys available, the processes for defining keys is not discussed here.

I understand how the calculation of CRC with a given polynomial key, however, how does one generate the polynomial key, and to ensure it can catch as much error as possible with a given set of protocal?

I assume the polynomial key has something to do with:

  1. data lengh
  2. data speed
  3. others?

Solution

  • The part about using mathematical formulas to generate CRC polynomials is somewhat misleading. The number of 1 bits in a CRC polynomial is the maximum possible Hamming distance (HD)for the polynomial, and generally the actual Hamming distance will be less depending on the data length. The maximum bit error detection is the Hamming distance - 1.

    Generally CRC polynomials that detect a higher number of bits are the product of multiple prime polynomials. For example, for a 32 bit CRC that can detect up to 7 errors for data + crc length = 1024 bits, the 33 bit CRC polynomial 0x1f1922815 = 0x787*0x557*0x465*0x3*0x3. The 0x3 factor will detect any odd number of bit errors, so the CRC needs to detect all possible 6 bit errors in 1024 bits.

    I'm not aware of a formula to determine the maximum bit error detection, and generally a somewhat optimized brute force search is done. As an example, say a 32 bit CRC polynomial is being checked to see if it can detect all 6 bit errors for data + crc length of 1024 bits, the number of possible 6 bit error patterns in 1024 bits is comb(1024,6) = 1,577,953,087,760,896. To reduce this to something reasonable, the number of possible 3 bit errors, comb(1024,3) = 178,433,024, is used to create a large table, each entry containing the CRC and 3 bit indexes. The table is sorted, and then used to check for collisions where a 3 bit pattern's CRC is the same as a different 3 bit pattern's CRC. A check for failure for 4 bit patterns will also be needed (checking for collisions between two different 2 bit patterns).

    Generally as the data length gets smaller, the maximum number of error bits guaranteed to be detected increases. Here is a link to a bunch of CRC polynomials and their error detection capability.

    https://users.ece.cmu.edu/~koopman/crc/crc32.html

    The notes page explains the table entries:

    http://users.ece.cmu.edu/~koopman/crc/notes.html