Re: Fletcher Checksum Question

From: Benjamin Goldberg (goldbb2@earthlink.net)
Date: 02/04/03


From: Benjamin Goldberg <goldbb2@earthlink.net>
Date: Tue, 04 Feb 2003 16:36:51 -0500

Stephen Ymage wrote:
>
> The Fletcher function I have is coded this way (for clarity, some
> lines were left out):
>
> while (n--) {
> s1 = (s1 + *bufp++) & 0x0000ffff;
> s2 = (s2 + s1) & 0x0000ffff;
> }
> return (s2 << 16) + s1;
>
> My question is, why not code it this way:
>
> while (n--) {
> s1 = (s1 + *bufp++) & 0x0000ffff;
> s2 += s1;
> }
> return s2;

The reason not to code it the second way is because it returns a
different result than the first. Now, what you *might* want, due to
it's being faster than either of those two, *and* gives the same results
as the first bit of code, would be this:

   while (n--) {
      s1 += *bufp++;
      s2 += s2;
   }
   return ((s2 << 16) | (s1 & 0xffff)) & 0xffffFFFF;

> Wont this be just as reliable as far as a check, if not better, and
> faster?

Maybe, maybe not, but your code definitely would be incompatible with
other programs which calculate *real* the fletcher checksum.

> Or, is there something I don't see?
> I realize these values wont match. I don't need to match with other
> Fletcher implementations.

Well, if you don't need that... then what *do* you need?

All checksum functions have their limitations; instead of picking an
existing one, fiddling with it, and asking if it's "better", decide what
requirements you have for your checksum function, and then go and find
one which *has* those requirements. Or if necessary, ask here.

[snip]
> Also, I didn't want this to be a debate of CRC vs. Fletcher vs. Adler
> checksums.

Well, you're already turning it into Fletcher vs
something-based-on-Fletcher-but-which-isn't-really-Fletcher.

Except that you haven't defined what "better" for a checksum means to
you, so we can't really tell you which is "better".

-- 
"So, who beat the clueless idiot today?"
"Well, we flipped for it, but when Kuno
 landed, he wasn't in any shape to fight."
"Next time, try flipping a *coin.*"


Relevant Pages

  • Re: Fletcher Checksum Question
    ... >>>Fletcher isnt flawed, but it has limitations, as does any checksum. ... I'm upset that they used Fletcher ... >to define the error model to make a comparison. ... any 16-bit CRC will catch bursts of no ...
    (sci.crypt)
  • Re: Fletcher Checksum Question
    ... I'm upset that they used Fletcher ... Im sure youre right that CRC ... >The checksum is being used to check the integrity of a data file. ... they always assume the attacker knows what ...
    (sci.crypt)
  • Re: Fletcher Checksum Question
    ... The checksum is being used to check the integrity of a data file. ... nothing at all whatsoever to do with communications systems. ... For my purposes, Fletcher is great. ... Using only a 16 bit Fletcher or Adler checksum would not be nearly as good. ...
    (sci.crypt)
  • Fletcher Checksum Question
    ... The Fletcher function I have is coded this way (for clarity, ... I realize these values wont match. ... two-byte "Fletch-16" function which returns a 32 byte checksum. ...
    (sci.crypt)