TCP/IP checksum byte-swap invariance

Chris Torek (
Mon, 28 Mar 88 23:13:32 EST

The invariance follows (I am tempted to say `is intuitively obvious',
but I suppose that would be teasing) from the fact that carries are
added back in at the low end of the sum as one goes along. To
visualise this, imagine the bits arranged in a ring. Note that the
ring is rotation independent---each bit depends only upon itself and
its nearest clockwise neighbour (in the figure below)---and that a byte
swap is simply an eight-bit rotation.

               1 0 15
             2 14
           3 13
          4 12
           5 11
             6 10
               7 8 9

(Apologies to those with proportionally spaced fonts.) The only
time an orientation is imposed upon this ring is when it is placed
in a TCP or IP header, so this is the only time the machine's
byte sex must affect the calculation.

(As far as I know, I came up with this explanation myself. It
seems obvious enough that someone else should have used it before.)


This archive was generated by hypermail 2.0b3 on Thu Mar 09 2000 - 14:41:07 GMT