[erlang-questions] checksum calculation

Matthias Lang matthias@REDACTED
Mon Apr 6 21:36:30 CEST 2009



On Monday, April 06, Gamoto wrote:
> If it is not a very good solution, would you like to suggest a 
> better one, for me and the other readers ?

The checksum you described has a number of undesirable properties. One
is that it's 'blind' to the addition or removal of any octets with all
bits set to zero. I.e.

   gamoto:checksum(<<1,2,3>>) == gamoto:checksum(<<1,0,2,3>>)

Another is that it's blind to reordering in general:

   gamoto:checksum(<<1,2,3>>) == gamoto:checksum(<<3,2,1>>)

Depending on the application, that might matter.

As for alternatives, two common ones are CRCs and cryptographic
checksums. They have various tradeoffs. erlang:md5sum() and crypto:sha() are
examples of the latter. The properties and limitations of CRCs are
well understood, while the limitations of cryptographic checksums are
the subject of very active research. Wikipedia has decent articles
about both sorts.

Matthias



More information about the erlang-questions mailing list