I\'m trying to calculate/validate the CRC32 checksums for compressed bzip2 archives.
.magic:16 = \'BZ\' signature/magic number
.version:8
To add onto the existing answer, there is a final checksum at the end of the stream (The one after eos_magic
) It functions as a checksum for all the individual Huffman block checksums. It is initialized to zero. It is updated every time you have finished validating an existing Huffman block checksum. To update it, do as follows:
crc: u32 = # latest validated Huffman block CRC
ccrc: u32 = # current combined checksum
ccrc = (ccrc << 1) | (ccrc >> 31);
ccrc ^= crc;
In the end, validate the value of ccrc
against the 32-bit unsigned value you read from the compressed file.