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

Louis Mamakos louie at transsys.com
Tue Dec 1 22:09:54 PST 2020



On 29 Nov 2020, at 19:44, Joseph Touch via Internet-history wrote:

>> On Nov 29, 2020, at 1:15 PM, Noel Chiappa <jnc at mercury.lcs.mit.edu> 
>> wrote:
>>
>>> From: Joseph Touch
>>
>>> Either 0 or -0 could come up as a valid 1's complement sum over the
>>> words
>>
>> Perhaps I'm confused, but I don't see how you could get 0 (i.e. all 0 
>> bits) as
>> a 1's complement sum from anything except a 'packet' containing 
>> nothing but
>> 0's,
>
> Yes, but...
>
>> i.e. no valid packet (and from that observation, _if correct_, the 
>> rest
>> of my prior comment flows).
>
> No valid IP or UDP, but that’s not the case necessarily everywhere 
> the IP checksum is used. That’s what I was considering.
>
>> Here's my thinking about 'no 0 sum'; if I've
>> somehow blown it, I would appreciate having my error pointed out! 
>> (Truly! :-)
>
> The one’s complement is a ring, but as you note, 0 is a special 
> case.
>
> Only 0 + 0 -> 0
>
> All other additions and subtractions yeid -n..n or -0 only (including, 
> strictly, 0 - 0).
>
> The only way you get back to 0 is multiplication (n * 0 = 0).
>
> And the sum over the data + inverted checksum is always -0 (never 0).
>
> 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.)   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.

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
got submitted by me.  The mainframe disappeared before I got much 
further in my port.

Louis Mamakos




More information about the Internet-history mailing list