[ih] UDP checksums (Was: UDP Length Field?)

Joseph Touch touch at strayalpha.com
Wed Dec 2 08:22:41 PST 2020


Hi, Louis, 

This issue seems to be a bit easier to address...

> On Dec 1, 2020, at 10:09 PM, Louis Mamakos <louie at transsys.com> wrote:
> 
>> The trick is that we don’t insert the complement of the ones complement sum. We insert that ONLY if the ones complement sum is not -0; if it is, we insert -0. However, those instructions are never given in RFC791, RFC1071; they appear only in RFC768:
>> 	If the computed  checksum  is zero,  it is transmitted  as all ones (the
>> 	equivalent  in one's complement  arithmetic).   An all zero  transmitted
>> 	checksum  value means that the transmitter  generated  no checksum  (for
>> 	debugging or for higher level protocols that don't care).
>> 
>> So - technically - the IP checksum CAN be 0 (when the ones complement sum is computed as -0, which can easily happen). That’s what I was thinking about.
>> 
> 
> But.. the UDP checksum field is the 1's complement of the sum of the bytes in
> the message (performed using 1's complement arithmetic.)

EXCEPT as per the quoted indented text above.

>  I wrote my first TCP/IP
> stack on a 1's complement, word addressable UNIVAC 1108 - and it's CPU would never
> compute a -0 result (all 1's) in the normal course of doing add arithmetic operations.
> So if you do the normal sort of sum and it resulted in a zero result (encoded as
> the +0 value), the 1's complement of that zero value would be -0, encoded as all
> 1 bits in the result.  Thus the checksum field would never has all zero bits as
> a normal checksum computation.

You’d have to take that into account both in the coding and the checking. I.e., for UDP on that machine, after a sum computation, if the sum were zero you’d have to force it to be -0 when written to the header.

Further, you’d need to adjust your expectations of a successful checksum calculation - rather than checking for -0 (per RFC791), you would check for 0.

> Some years after doing my UDP implementation, I started to undertake a port of the
> 4BSD network implementation when later generations of these mainframes supported
> a C compiler.  The BSD UDP implementation had a bug where they assumed 2's
> complement math, so https://github.com/dspinellis/unix-history-repo/commit/87d648fe7e142ce2207e57bba0965e760b43b05f <https://github.com/dspinellis/unix-history-repo/commit/87d648fe7e142ce2207e57bba0965e760b43b05f>
> got submitted by me.  ...

Indeed…

Joe





More information about the Internet-history mailing list