zweig@p.cs.uiuc.edu (03/17/89)
I am not the world's best mathematician, and 1's complement arithmetic is sometimes scary, so I'll post this here, since probably many of you out in netland have come up against this. A TCP checksum is the complement of the sum of all the words in a file (everything done in 1's complement instead of 2's complement, as any fool can see). Suppose I have a checksum for a packet that I'm brewing up, and I change 1 word that has the value 0xNNNN to 0xMMMM. Could I just set the checksum to complement(complement(old-chksum) - 0xNNNN + 0xMMMM)?? That is, is 1's complement addition associative in real life? A similar trick is to stash the checksum of the data-portion while twiddling the bits in the header. The reason I was thinking of this is that it would be possible to stash checksums of various pieces of messages and header-templates and whatnot, then when a packet it put together before going out, it might be possible to save time recalculating the checksum (esp. if the data portion is big). Recalculating checksums on retransmissions might be easier, too, though the overall performance impact should be negligible. In short, what shortcuts do folks know to make checksumming in software (apologies to anyone at AT&T who cringes at the thought) less expensive???? Johnny Zweig University of Illinois at Urbana-Champaign Department of Computer Science