4

Let's say I have two numbers X = 0xABC; Y = 0xDE. I want to calculate CRC-32 over Z, which is X concatenated to Y i.e. Z = 0xABCDE.

I have CRC(X) and CRC(Y) available. How can I compute CRC(Z) ?

Tushar
  • 415
  • 2
  • 16

1 Answers1

4

Take a look at crc32_combine() in zlib for the approach.

The basic idea is to use the linearity of CRCs. The CRC of 0xABC00 exclusive-or'ed with 0x000DE is the exclusive-or of their corresponding CRCs. If I ignore the pre and post-processing (which I can for reasons that are left to the reader to derive), leading zeros do not change the CRC, so the CRC of 0xDE is the same as the CRC of 0x000DE. So all I need to do is calculate the effect of appending zeros when starting with the CRC of 0xABC, in order to get the CRC of 0xABC00. Then exclusive-or those two CRCs.

crc32_combine() uses matrix multiplication to compute the effect of appending n zeros in O(log(n)) time instead of O(n) time, so combining CRCs is very fast regardless of the lengths of the original messages.

Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • 1
    I read your answer on google groups, [link](https://groups.google.com/forum/#!topic/comp.compression/SHyr5bp5rtc). The problem I am facing is, I am trying to implement this on hardware (FPGA). I have the parallel CRC-32 calculator for **0xABC** and **0xDE** but when I try to calculate the CRC-32 over **0xABC00** and **0x000DE** then XOR the CRCs then I get the wrong result because of the ZEROS. – Tushar May 24 '17 at 02:35
  • You need to write a question here, with the details of what you're doing, what you're expecting, and what you're getting. – Mark Adler Jan 08 '22 at 00:24