From 8d6dce4a010bbc95c6ea51d2f8e005d7d69f8260 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 1 Dec 2012 23:03:05 +0000 Subject: [PATCH] Fix CRC32c calculation on 64-bit platforms. Patch by Pontus Andersson. http://seclists.org/nmap-dev/2012/q4/361 --- CHANGELOG | 3 +++ nbase/nbase_misc.c | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d54f6ff2c..8a6b8e525 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ # Nmap Changelog ($Id$); -*-text-*- +o Fixed CRC32c calculation (as used in SCTP scans) on 64-bit + platforms. [Pontus Andersson] + o [NSE] Added multicast group name output to broadcast-igmp-discovery.nse. [Vasily Kulikov] diff --git a/nbase/nbase_misc.c b/nbase/nbase_misc.c index fc4179d3a..391ab19f6 100644 --- a/nbase/nbase_misc.c +++ b/nbase/nbase_misc.c @@ -560,14 +560,17 @@ unsigned long nbase_crc32(unsigned char *buf, int len) /* * CRC-32C (Castagnoli) Cyclic Redundancy Check. - * Taken straight from RFC 4960 (SCTP). + * Taken straight from Appendix C of RFC 4960 (SCTP), with the difference that + * the remainder register (crc32) is initialized to 0xffffffffL rather than ~0L, + * for correct operation on platforms where unisigned long is longer than 32 + * bits. */ /* Return the CRC-32C of the bytes buf[0..len-1] */ unsigned long nbase_crc32c(unsigned char *buf, int len) { int i; - unsigned long crc32 = ~0L; + unsigned long crc32 = 0xffffffffL; unsigned long result; unsigned char byte0, byte1, byte2, byte3;