-2

I'm very new to checksums, and fairly new to programming. I have a fairly simple C++ program (measuring psi) that I'm transferring to an Arduino board. Would crc16 be OK or should I go with crc32 or would that be overkill?

Aspen
  • 1
  • 4
  • 2
    What do you use that checksum for? Without motivations, we cannot answer your question. So please **edit your question** to improve it. – Basile Starynkevitch Aug 04 '16 at 08:22
  • 3
    If your needs require cryptographically strong digests, trust me: don't write it yourself. use a well known, well *tested*, cryptographic library. If you need a simple crc32 or similar non-crypto-strong check, you can write it, but honestly there are so many such things in the public already I can't imagine you would need to do so. This is largely need-based, and only you know that need for your situation. – WhozCraig Aug 04 '16 at 08:23
  • Are you sure that "accuracy" is the right word in your question? Do you mean "correctness"? – Basile Starynkevitch Aug 04 '16 at 08:36

2 Answers2

0

Checksums come up in the context of unreliable communication channels. A communication channel is an abstraction; bits go in one end and come out on the other end. An unreliable channel simply means that the bits which come out aren't the same as those which went in.

Now obviously the most extreme unreliable channel has random bits come out. That's unusable, so we focus on the channels where the input and output are correlated.

Still, we have many different corruption models. One common model is each bit is P% likely to fail. Another common model considers that bit errors typically come in bursts. Each bit then has a P% chance to start a bust of errors of length N, in which each bit is 50% likely to be wrong. Quite a few more models exist, depending on your problem - more advanced models also consider the chance of bits going completely missing.

The correct checksum has a very, very high likelihood of detecting the type of error predicted by the model, but might not work well for other types of errors.

For instance, I think with the Internet IP layer, the most common error is an entire IP packet going missing. That's why TCP uses sequence numbers to detect this particular error.

MSalters
  • 173,980
  • 10
  • 155
  • 350
0

A possible way to check that an executable has been correctly transmited to your Arduino board could be to use a simple checksum like md5, or even something even simpler, like some crude hash function computing a 16 bit hash. See e.g. this answer for inspiration.

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547