From owner-freebsd-hackers Wed May 1 06:07:54 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id GAA08105 for hackers-outgoing; Wed, 1 May 1996 06:07:54 -0700 (PDT) Received: from labinfo.iet.unipi.it (labinfo.iet.unipi.it [131.114.9.5]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id GAA08090 for ; Wed, 1 May 1996 06:07:47 -0700 (PDT) Received: from localhost (luigi@localhost) by labinfo.iet.unipi.it (8.6.5/8.6.5) id OAA08931 for hackers@freebsd.org; Wed, 1 May 1996 14:54:46 +0200 From: Luigi Rizzo Message-Id: <199605011254.OAA08931@labinfo.iet.unipi.it> Subject: Fast IP/TCP checksums ? To: hackers@freebsd.org Date: Wed, 1 May 1996 14:54:46 +0200 (MET DST) X-Mailer: ELM [version 2.4 PL23] Content-Type: text Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Hi, I was looking at TCP/IP checksums recently. Can someone explain why IP/TCP checksums can be computed using the same algorithm on both big-endian and little-endian systems, yet produce the same result (after a final ntohs() of course) ? It surely has to do with the fact that the representations of 0 in 1's complement have the same low & high bytes, but I haven't been able to find a formal proof of why it works. Besides (hence the Subject for this message) it appears that you can compute checksums using 32-bit sums and yet produce the same result! This could save something in the computation of checksums, as you need half as many adds, and much less data movements as all operands are 32-bit aligned. Luigi ==================================================================== Luigi Rizzo Dip. di Ingegneria dell'Informazione email: luigi@iet.unipi.it Universita' di Pisa tel: +39-50-568533 via Diotisalvi 2, 56126 PISA (Italy) fax: +39-50-568522 http://www.iet.unipi.it/~luigi/ ====================================================================