Chaining Checksums

Hello,

I have one more Checksum related question, I tried the crc chaining method again and it still failed. This code for example.

    local int64 crcInitValue=-1;
    for (count_sides=0;count_sides<total_sides;count_sides++)
    {
         crcInitValue=Checksum(CHECKSUM_CRC32,start_of_block2[count_sides],last_file_end[count_sides]-start_of_block2[count_sides],-1,crcInitValue);
         Printf ("\nSide %d checksum is %X",count_sides,crcInitValue);
    }
    

On the first Iteration shows the correct 'side CRC32, however on the final iteration (I have not checked in between values). It comes out with the wrong CRC32. However if I use the same method as before and copy into a linear array as follows.

    local byte temp_buffer[FDS_SIZE];
    local byte full_disk_buffer[FDS_SIZE*4];
    local uint length;
    local int64 full_disk_length=0;

    local uint crc_data_size=0;
    for (count_sides=0;count_sides<total_sides;count_sides++)
    {        
        length=last_file_end[count_sides]-start_of_block2[count_sides];
        ReadBytes(temp_buffer,start_of_block2[count_sides],length);    // Read from Block 2 to the end of the files
        for (i=0;i<length;i++)
        {
              full_disk_buffer[full_disk_length++]=temp_buffer[i];          
        }                
    }
        
    ChecksumAlgArrayBytes(CHECKSUM_CRC32,crc_result,full_disk_buffer,full_disk_length);
    Printf ("\nFull Reference checksum using Array is ");
    DisplayByteArray(crc_result);  
    Printf ("\n");

this last method matches my Python scripts results

This is a little tricky. You can chain together multiple calls of ‘Checksum’ together but 010 Editor does a bit-flip at the end of each CRC32 call. You have to undo this bit-flip to pass the initial value back in.

    for (count_sides=0;count_sides<total_sides;count_sides++)
    {
         if( count_sides != 0 )
             crcInitValue = ~crcInitValue; // need to flip here
         crcInitValue=Checksum(CHECKSUM_CRC32,start_of_block2[count_sides],last_file_end[count_sides]-start_of_block2[count_sides],-1,crcInitValue);
         Printf ("\nSide %d checksum is %X",count_sides,crcInitValue);
    }

Graeme
SweetScape Software