Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use CRC-16 or IP checksum (RFC1071) for an embedded application?

I'm writing an embedded application on an ARM7 processor and I need some form of checksum for data that I'm sending over a serial link as well for data that I'm storing in the flash. I was wondering which of the two CRCs would be better suited for the purpose. The main trade-off are code speed versus robustness. Should I consider another CRC? Do you have a link to an efficient implementation for ARM?

like image 671
florin Avatar asked Dec 29 '22 18:12

florin


1 Answers

RFC1071 is a simple 16-bit sum of pairs of bytes. As such, it's possible that two errors could "cancel out", and still give a "pass" checksum. E.g. a bit error flips a bit from 1 to 0. Then another bit error 16 bits later flips a bit from 0 to 1. RFC1071 will not detect this. But the same double-bit-flip error, if being checked with a CRC, would be detected.

This sort of double-bit-flip error is possible in a serial transmission. (It is much more likely on a parallel cable especially if one wire is "noisy" but who uses parallel these days?) It's also possible in a Flash chip, especially if the PCB has a bad solder joint between micro and Flash chip. Overall, a CRC is statistically more robust at detecting errors because a single bit change in the input affects multiple bits in the CRC shift register.

In practice the other thing that's likely, that you want to detect, is an incomplete Flash upload, so a large chunk of the code is simply missing. For that, statistically a checksum is probably fine but I've always favoured a CRC in projects I've worked on. With a table-based CRC algorithm, we've been able to get the calculation speeds required.

like image 181
Craig McQueen Avatar answered Jan 01 '23 08:01

Craig McQueen