cancel
Showing results for 
Search instead for 
Did you mean: 

CRC32 questions

Dick Lin
Senior

Hi,

I have a general question regarding CRC32 for data read from flash. For example I am reading 2048 bytes of data total 512 bytes chunk each time. My question is

  • does it make any difference if I check CRC32 for every 512 bytes read or after read of 2048 bytes?

Thanks,

****

9 REPLIES 9

CRC at each 512 byte point would be different, it you let is accumulate over the 4 blocks the value should be the same as 1 block of 2048 bytes

ie

crc = 0xFFFFFFFF

crc = CRC32(crc, &p[0], 512);

crc = CRC32(crc, &p[512], 512);

crc = CRC32(crc, &p[1024], 512); // intermediate values not same as final (typically, depends on patterns)

crc = CRC32(crc, &p[1536], 512);

printf("%08lX\n", crc);

crc = 0xFFFFFFFF

crc = CRC32(crc, &p[0], 2048);

printf("%08lX\n", crc); // final value same

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Dick Lin
Senior

Thanks for response.

So the key is accumulate all of the 2048 bytes. What's wrong of not accumulate all?

Piranha
Chief II

You can implement it like this:

CRC_Begin();
while (NewData) {
	CRC_Process();
}
CRC_End();

>>What's wrong of not accumulate all?

Not sure I understand the underlying question here.

The CRC will be done over the data you tell it too. It is like the remainder to a long-division, the remainder at any instance will depend on the data feed thru it to that point.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

My question is if each 512 block CRC32 are correct, is it possible the 2048 data as whole still has error didn't find by the process as supposed to check whole 2048 bytes?

Piranha
Chief II

> My question is if each 512 block CRC32 are correct, is it possible the 2048 data as whole still has error didn't find by the process as supposed to check whole 2048 bytes?

OK, you mean separate CRC for each block? Generally smaller blocks are "better protected" compared to larger blocks, because larger blocks have a larger probability of getting a false positive - a CRC match for a corrupted data. Also remember that CRC or any other checksum can't guarantee 100% correctness. In fact absolutely nothing can guarantee it at all...

Strongly recommended:

https://www.slideshare.net/PhilipKoopman/crc-and-checksum-presentation-for-faa

https://users.ece.cmu.edu/~koopman/crc/

Dick Lin
Senior

OK. Thanks a lot.

It is possible, but less probable.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Michel Solecki
Associate II

As long as you don"t reset the result of the previous chunk, the end result will be the same. You can test to see that it doesn't make any difference.

Regards,

Michel