Appendix I: The 8-bit Fletcher Checksum Algorithm
The 8-bit Fletcher Checksum Algorithm is calculated over a sequence of data octets (call them D[1] through D[N]) by maintaining 2 unsigned 1's-complement 8-bit accumulators A and B whose contents are initially zero, and performing the following loop where i ranges from 1 to N:
A := A + D[i]
B := B + A
It can be shown that at the end of the loop A will contain the 8-bit 1's complement sum of all octets in the datagram, and that B will contain (N)D[1] + (N-1)D[2] + ... + D[N].
The octets covered by this algorithm should be the same as those over which the standard TCP checksum calculation is performed, with the pseudoheader being D[1] through D[12] and the TCP header beginning at D[13]. Note that, for purposes of the checksum computation, the checksum field itself must be equal to zero.
At the end of the loop, the A goes in the first byte of the TCP checksum and B goes in the second byte.
Note that, unlike the OSI version of the Fletcher checksum, this checksum does not adjust the check bytes so that the receiver checksum is 0.
There are a number of much faster algorithms for calculating the two octets of the 8-bit Fletcher checksum. For more information see [Sklower89], [Nakassis88] and [Fletcher82]. Naturally, any computation which computes the same number as would be calculated by the loop above may be used to calculate the checksum. One advantage of the Fletcher algorithms over the standard TCP checksum algorithm is the ability to detect the transposition of octets/words of any size within a datagram.