diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-10-12 10:13:31 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2005-10-12 10:13:31 +0000 |
commit | abffe9b174e9d5c4d2bdf819d9c31432ed115884 (patch) | |
tree | 113eae237b3370ca60cf36950544ede0a6b0a218 | |
parent | 04ad4a2c4512cbf0a81ab2a93c60ae92f1ad29bb (diff) |
Revert last commit. That file was not intended to be commited.
-rw-r--r-- | usr.sbin/ospfd/iso_cksum.c | 38 |
1 files changed, 14 insertions, 24 deletions
diff --git a/usr.sbin/ospfd/iso_cksum.c b/usr.sbin/ospfd/iso_cksum.c index de8d2c6a156..7863539ce15 100644 --- a/usr.sbin/ospfd/iso_cksum.c +++ b/usr.sbin/ospfd/iso_cksum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iso_cksum.c,v 1.2 2005/10/12 09:51:58 claudio Exp $ */ +/* $OpenBSD: iso_cksum.c,v 1.3 2005/10/12 10:13:30 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -21,18 +21,17 @@ #include "ospfd.h" #include "log.h" -/* implementation of Fletcher Checksum -- see RFC 1008 for more info */ - /* pos needs to be 0 for verify and 2 <= pos < len for calculation */ u_int16_t iso_cksum(void *buf, u_int16_t len, u_int16_t pos) { u_int8_t *p = buf; - int c0 = 0, c1 = 0, x; /* counters */ + int c0 = 0, c1 = 0; /* counters */ + int r0, r1; /* results */ u_int16_t sop; - sop = len - pos - 1; /* pos is an offset (pos 2 is 3rd element) */ - p += 2; /* jump over age field */ + sop = len - pos - 1; /* pos is an offset (pos 2 is at len 3) */ + p += 2; len -= 2; while (len--) { c0 += *p++; @@ -42,27 +41,18 @@ iso_cksum(void *buf, u_int16_t len, u_int16_t pos) c0 %= 255; c1 %= 255; } -#ifdef DEBUG - if (c0 + 256 < c0 || c1 + 256 < c1) - fatalx("iso_cksum: overflowed"); -#endif } + r0 = c0 = c0 % 255; + r1 = c1 % 255; if (pos) { - x = ((sop * c0 - c1)) % 255; - if (x <= 0) - x += 255; -#if 1 - c1 = 510 - c0 - x; - if (c1 > 255) - c1 -= 255; -#else - c1 = (-c0 - x) % 255; - if (c1 < 0) - c1 += 255; -#endif - c0 = x; + r0 = ((sop * r0 - r1)) % 255; + if (r0 <= 0) + r0 += 255; + r1 = 510 - r0 - c0; + if (r1 > 255) + r1 -= 255; } - return (c0 << 8 | c1); + return (r0 << 8 | r1); } |