为 crc 生成多项式密钥

Generating of the polynomial key for crc

参考本文: 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.

我了解如何使用给定的多项式密钥计算 CRC,但是,如何生成多项式密钥,并确保它可以使用给定的一组协议捕获尽可能多的错误?

我假设多项式密钥与以下内容有关:

  1. 数据长度
  2. 数据速度
  3. 其他?

关于使用数学公式生成 CRC 多项式的部分有些误导。 CRC 多项式中 1 的位数是多项式的最大可能汉明距离 (HD),通常实际汉明距离会因数据长度而变小。最大误码检测为汉明距离 - 1.

通常,检测更多位数的 CRC 多项式是多个素数多项式的乘积。例如,对于最多可以检测 7 个数据错误的 32 位 CRC + crc 长度 = 1024 位,33 位 CRC 多项式 0x1f1922815 = 0x787*0x557*0x465*0x3*0x3。 0x3 因子将检测任何奇数位错误,因此 CRC 需要检测 1024 位中所有可能的 6 位错误。

我不知道确定最大误码检测的公式,通常会进行某种程度的优化蛮力搜索。例如,假设正在检查一个 32 位 CRC 多项式,看它是否可以检测数据的所有 6 位错误 + crc 长度为 1024 位,1024 位中可能的 6 位错误模式的数量是 comb(1024,6) = 1,577,953,087,760,896。为了将其减少到合理的程度,可能的 3 位错误数 comb(1024,3) = 178,433,024 用于创建一个大的 table,每个条目都包含 CRC 和 3 位索引。 table 被排序,然后用于检查 3 位模式的 CRC 与不同的 3 位模式的 CRC 相同的冲突。还需要检查 4 位模式的失败(检查两个不同的 2 位模式之间的冲突)。

一般来说,随着数据长度变小,保证检测到的最大错误位数会增加。这是一组 CRC 多项式及其错误检测能力的 link。

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

注释页面解释了 table 个条目:

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