Appendix A. Checksum Algorithms (from ISO/IEC 8473)
Symbols used in algorithms:
c0, c1 variables used in the algorithms
i position of octet in header (first
octet is i=1)
Bi value of octet i in the header
n position of first octet of checksum (n=8)
L Length of header in octets
X Value of octet one of the checksum parameter
Y Value of octet two of the checksum parameter
Die Addition wird in einem der beiden folgenden Modi durchgeführt:
* modulo 255 arithmetic;
* eight-bit one's complement arithmetic;
Der Algorithmus zur Erzeugung des Prüfsummenparameterwerts ist wie folgt:
A. Construct the complete header with the value of the
checksum parameter field set to zero; i.e., c0 <- c1 <- 0;
B. Process each octet of the header sequentially from i=1 to L
by:
* c0 <- c0 + Bi
* c1 <- c1 + c0
C. Calculate X, Y as follows:
* X <- (L - 8)(c0 - c1) modulo 255
* Y <- (L - 7)(-C0) + c1
D. If X = 0, then X <- 255
E. If Y = 0, then Y <- 255
F. place the values of X and Y in octets 8 and 9 of the
header, respectively
Der Algorithmus zur Prüfung des Werts des Prüfsummenparameters ist wie folgt:
A. If octets 8 and 9 of the header both contain zero, then the
checksum calculation has succeeded; else if either but not
both of these octets contains the value zero then the
checksum is incorrect; otherwise, initialize: c0 <- c1 <- 0
B. Process each octet of the header sequentially from i = 1 to
L by:
* c0 <- c0 + Bi
* c1 <- c1 + c0
C. When all the octets have been processed, if c0 = c1 = 0,
then the checksum calculation has succeeded, else it has
failed.
Es gibt einen getrennten Algorithmus zur Anpassung des Prüfsummenparameterwerts, wenn ein Oktett verändert wurde (etwa die TTL). Angenommen, der Wert in Oktett k wird um Z = newvalue - oldvalue verändert. Bezeichnen X und Y die in den Oktetten n bzw. n+1 gespeicherten Prüfsummenwerte, dann sind X und Y wie folgt anzupassen:
Wenn X = 0 und Y = 0 ist, ist nichts zu tun; wenn jedoch X = 0 oder Y = 0 ist, ist die Prüfsumme falsch; andernfalls:
X <- (k - n - 1)Z + X modulo 255
Y <- (n - k)Z + Y modulo 255
Wenn X = 0 ist, dann X <- 255; wenn Y = 0 ist, dann Y <- 255.
Im Beispiel ist n = 89; wenn das veränderte Oktett die TTL ist (Oktett 4), dann ist k = 4. Für den Fall, dass die Lebensdauer um eine Einheit verringert wird (Z = -1), vereinfachen sich die Zuweisungsanweisungen für die neuen Werte von X und Y im unmittelbar vorangegangenen Algorithmus zu:
X <- X + 5 Modulo 255
Y <- Y - 4 Modulo 255