0

Another zlib CRC Combine related question :P I want to be able to combine CRC(X) + CRC(Y) = CRC(Z), problem is that I don't know what CRC(Y) is supposed to be. Is there somehow that I can say use CRC(X) and CRC(Z) to get what CRC(Y) is supposed to be? Total sizes are known at this point in time (e.g. CRC(X) will be say 40 bytes, CRC(Z) should be 100 bytes so CRC(Y) is 60 bytes long)

VenoMpie
  • 45
  • 6

1 Answers1

1

Yes. zlib's crc32_combine64() function has one line:

return multmodp(x2nmodp(len2, 3), crc1) ^ crc2;

If we call the total CRC crc3, then you can get crc2 simply as:

crc2 = multmodp(x2nmodp(len2, 3), crc1) ^ crc3;
Mark Adler
  • 101,978
  • 13
  • 118
  • 158
  • Thank you! I will try it tonight when I get chance and accept answer :P – VenoMpie Aug 18 '20 at 15:30
  • It's unfortunate you can't also suggest some bit magic for my broken CRC issue ;) – VenoMpie Aug 18 '20 at 19:54
  • One thing, I can't seem to get it to work the other way around, e.g. if I have crc2 and crc3 and want crc1 e.g. `private byte[] testBytes = new byte[] { 2, 3, 4, 5, 6, 7, 8, 9 }; private byte[] finalBytes = new byte[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 };` Works to get the missing 10 value of 0x32D70693 but if the final bytes look like this `private byte[] testBytes = new byte[] { 10, 2, 3, 4, 5, 6, 7, 8, 9 };` then I can't seem to get it doesn't matter which length I pass in as len2 and switching crc2/3 – VenoMpie Aug 18 '20 at 20:12
  • To get `crc1`, you would have to reverse the effect of applying `len2` zeros. See [here](https://stackoverflow.com/a/37150978/1180620) for how to run a CRC backwards. – Mark Adler Aug 18 '20 at 20:40
  • Thanks! I'll have a look. Not that I would really need it but just incase, you never know :P – VenoMpie Aug 18 '20 at 20:49