Path: utzoo!utgpu!water!watmath!clyde!rutgers!bellcore!faline!thumper!karn From: karn@thumper.bellcore.com (Phil R. Karn) Newsgroups: comp.protocols.tcp-ip Subject: Re: Checksums (was Re: Ping, checksum algorithm?) Summary: Other notes on Internet checksums Keywords: TCP IP UDP one's complement checksum Message-ID: <1006@thumper.bellcore.com> Date: 24 Mar 88 07:07:53 GMT References: <123@heart-of-gold> <1080@maccs.UUCP> Organization: Bell Communications Research, Inc Lines: 25 Thanks for an excellent tutorial on checksumming. Some additional notes: The Internet checksum algorithm has an interesting property that is very useful when working on little-endian machines: the sum of the byte-swapped words is equal to the byte-swapped sum of the words. In other words, there is no need to byteswap each word on a little-endian machine before summing it; you can sum the words in machine order and then byteswap the result. If you write an "assist" routine in assembler you can exploit the "add with carry" instruction found in many machines. E.g., on the 808x family, you can accumulate a sum as follows: doit: lodsw adc dx,ax loop doit (once you've set everything up, of course). This can speed up checksumming enormously on 16-bit machines like the PC since the long (32-bit) arithmetic you would normally use to accumulate the carries is much slower. The actual code I use goes further, in that I unwound the loop and used "Duff's Device" to handle blocks that are not integral multiples of the loop length. Phil