2

From the Wikipedia page:

The checksum field is the 16 bit one's complement of the one's complement sum of all 16-bit words in the header and text.

Why, after summing the 16-bits in the header and text, is the one's complement taken to compute the TCP checksum?

Randomblue
  • 1,135
  • 5
  • 15
  • 33
  • 2
    I suspect you'll have to ask Vint Cerf. – Michael Hampton May 16 '13 at 21:39
  • 1
    Why is this even a SF question - how can we know what was in the mind of the designers of the TCP protocol ? – user9517 May 16 '13 at 21:57
  • 2
    @randomblue: You have forgotten about the line in our faq which says that questions should be of a practical, answerable, nature. In many years of working in the industry I've never needed to worry about the TCP checksum (except when interviewing) and I don't see how your question has any practical application today. – user9517 May 17 '13 at 06:14
  • @randomblue Why do **you** need to know? – Dan May 17 '13 at 09:44

4 Answers4

8

The complement is taken to make checksum validation simpler — instead of calculating the checksum again and then comparing the calculated value with the checksum field in the header (which is in the middle of the summed data), it is possible to sum (using one's complement arithmetic) all 16-bit words in the header (including the checksum word) and compare the result with zero.

Sergey Vlasov
  • 6,088
  • 1
  • 19
  • 30
3

It might be because a value of all zeros is meaningful (from RFC 793):

While computing the checksum, the checksum field itself is replaced with zeros.

so it can preserve this meaning against the unlikely event that the checksum really is zero.

Flup
  • 7,688
  • 1
  • 31
  • 43
1

Checksumming for the result to be ZEROs is problematic as all ZEROs is also generated by a powered off device or something not having power. With the result being ALL ONES there is more assurance that the hardware is properly functioning.

One's complement is more complicated term for analyzing the bits one-by-one and not as an entire unit (i.e. AND/OR/XOR/NOT).

mdpc
  • 11,698
  • 28
  • 51
  • 65
-2

One's complement arithmetic was used because TCP was designed in the 1970s for 1970s computers, most of which used one's complement arithmetic. The rise of two's complement arithmetic, which modern computers use, didn't really begin in earnest until the personal computers of the late 1970s and 1980s.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940