Home > Back-end >  Using crcmod to generate a checksum in Python
Using crcmod to generate a checksum in Python

Time:10-13

I'm trying to get the results I expect from my custom crcmod in Python 3.

I currently have the following

#                poly,        initCrc,    rev,   xorOut
crc32 = mkCrcFun(0x104c11db7, 0xFFFFFFFF, False, 0xFFFFFFFF)
print(hex(crc32(b'\x0f\x0f\x0f\x0f')

This prints 0x94913aa6. However, I expect to see 0x5395e7dd, which I calculated here with the following settings:

  • CRC width - CRC-32
  • CRC parametrization - Custom
  • Input reflected - unchecked
  • Result reflected - unchecked
  • Polynomial - 0x4c11db7
  • Initial Value - 0xFFFFFFFF
  • Final Xor Value - 0xFFFFFFFF
  • Input - Bytes 0f0f0f0f

I'm certain that the website is generating the expected checksum. I just can't get crcmod to duplicate it for the life of me. Any insight?

CodePudding user response:

Use mkCrcFun(0x104c11db7, 0, False, 0xFFFFFFFF).

This is due to the "initial value" having more than one meaning. In the case of crcmod, it means the initial register value. In the case of the CRC web page, it means the initial value of the returned CRC. In the latter case, the initial register value is the initial CRC value exclusive-or'ed with the final xor value.

  • Related