Skip to main content
Dick Lin
Senior
January 10, 2020
Question

CRC32 questions

  • January 10, 2020
  • 6 replies
  • 2758 views

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,

****

This topic has been closed for replies.

6 replies

Tesla DeLorean
Guru
January 10, 2020

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 VenmoUp vote any posts that you find helpful, it shows what's working..
Dick Lin
Dick LinAuthor
Senior
January 10, 2020

Thanks for response.

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

Tesla DeLorean
Guru
January 10, 2020

>>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 VenmoUp vote any posts that you find helpful, it shows what's working..
Dick Lin
Dick LinAuthor
Senior
January 10, 2020

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
Principal III
January 10, 2020

You can implement it like this:

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

Piranha
Principal III
January 10, 2020

> 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
Dick LinAuthor
Senior
January 11, 2020

OK. Thanks a lot.

Michel Solecki
Associate
February 11, 2020

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