diff options
author | Anders Broman <anders.broman@ericsson.com> | 2011-10-03 04:53:17 +0000 |
---|---|---|
committer | Anders Broman <anders.broman@ericsson.com> | 2011-10-03 04:53:17 +0000 |
commit | f08f09ecd42493885c2db0e2c97b5d4ffefc0995 (patch) | |
tree | 4d41cf36dedde631475e9d980680375b32c1dd8f | |
parent | b7bdb4a98518e64c087d8bcbd4de7b3e476f92b9 (diff) | |
download | wireshark-f08f09ecd42493885c2db0e2c97b5d4ffefc0995.tar.gz |
From Michael Mann:
Condense all SCTP CRC routines to wsutil/crc32.[ch]. Also made
crc32_ccitt_table not explicitly accessible (must use crc32_ccitt_table_lookup).
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6298
svn path=/trunk/; revision=39233
-rw-r--r-- | epan/dissectors/packet-sctp.c | 24 | ||||
-rw-r--r-- | wsutil/airpdcap_wep.c | 2 | ||||
-rw-r--r-- | wsutil/crc32.c | 15 | ||||
-rw-r--r-- | wsutil/crc32.h | 16 | ||||
-rw-r--r-- | wsutil/libwsutil.def | 2 |
5 files changed, 34 insertions, 25 deletions
diff --git a/epan/dissectors/packet-sctp.c b/epan/dissectors/packet-sctp.c index 081f5ea8c1..9f657327b7 100644 --- a/epan/dissectors/packet-sctp.c +++ b/epan/dissectors/packet-sctp.c @@ -446,23 +446,19 @@ sctp_adler32(const unsigned char* buf, unsigned int len) static guint32 sctp_crc32c(const unsigned char* buf, unsigned int len) { - unsigned int i; - guint32 crc32 = CRC32C_PRELOAD; + guint32 crc32, + zero = 0; guint32 result; - for (i = 0; i < SOURCE_PORT_LENGTH + DESTINATION_PORT_LENGTH + VERIFICATION_TAG_LENGTH; i++) - { - CRC32C(crc32, buf[i]); - } + /* CRC for header */ + crc32 = crc32c_calculate_no_swap(buf, SOURCE_PORT_LENGTH + DESTINATION_PORT_LENGTH + VERIFICATION_TAG_LENGTH, CRC32C_PRELOAD); + /* handle four 0 bytes as checksum */ - CRC32C(crc32, 0); - CRC32C(crc32, 0); - CRC32C(crc32, 0); - CRC32C(crc32, 0); - for (i = COMMON_HEADER_LENGTH; i < len; i++) - { - CRC32C(crc32, buf[i]); - } + crc32 = crc32c_calculate_no_swap(&zero, 4, crc32); + + /* CRC for the rest of the packet */ + crc32 = crc32c_calculate_no_swap(&buf[COMMON_HEADER_LENGTH], len-COMMON_HEADER_LENGTH, crc32); + result = CRC32C_SWAP(crc32); return ( ~result ); diff --git a/wsutil/airpdcap_wep.c b/wsutil/airpdcap_wep.c index 6689535885..29d7d44743 100644 --- a/wsutil/airpdcap_wep.c +++ b/wsutil/airpdcap_wep.c @@ -77,7 +77,7 @@ int AirPDcapWepDecrypt( j = (j + S[i]) & 0xff; S_SWAP(i, j); *cypher_text ^= S[(S[i] + S[j]) & 0xff]; - crc = crc32_ccitt_table[(crc ^ *cypher_text) & 0xff] ^ (crc >> 8); + crc = crc32_ccitt_table_lookup((crc ^ *cypher_text) & 0xff) ^ (crc >> 8); cypher_text++; } diff --git a/wsutil/crc32.c b/wsutil/crc32.c index c40047dffe..5882ba9f5c 100644 --- a/wsutil/crc32.c +++ b/wsutil/crc32.c @@ -53,6 +53,8 @@ /* in the FTP archive "ftp.adelaide.edu.au/pub/rocksoft". */ /* */ /*****************************************************************/ +#define CRC32C(c,d) (c=(c>>8)^crc32c_table[(c^(d))&0xFF]) + static const guint32 crc32c_table[256] = { 0x00000000L, 0xF26B8303L, 0xE13B70F7L, 0x1350F3F4L, 0xC79A971FL, 0x35F1141CL, 0x26A1E7E8L, 0xD4CA64EBL, 0x8AD958CFL, 0x78B2DBCCL, @@ -115,7 +117,7 @@ static const guint32 crc32c_table[256] = { * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^8 + x^7 + * x^5 + x^4 + x^2 + x + 1 */ -const guint32 crc32_ccitt_table[256] = { +static const guint32 crc32_ccitt_table[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, @@ -193,6 +195,17 @@ crc32c_calculate(const void *buf, int len, guint32 crc) return CRC32C_SWAP(crc); } +guint32 +crc32c_calculate_no_swap(const void *buf, int len, guint32 crc) +{ + const guint8 *p = (const guint8 *)buf; + while (len-- > 0) { + CRC32C(crc, *p++); + } + + return crc; +} + guint32 crc32_ccitt(const guint8 *buf, guint len) { diff --git a/wsutil/crc32.h b/wsutil/crc32.h index 514a437596..bb998d1c6e 100644 --- a/wsutil/crc32.h +++ b/wsutil/crc32.h @@ -41,14 +41,6 @@ extern "C" { ((crc32c_value & 0x0000ff00) << 8) | \ ((crc32c_value & 0x000000ff) << 24)) -#define CRC32C(c,d) (c=(c>>8)^crc32c_table_lookup((c^(d))&0xFF)) - -extern const guint32 crc32_ccitt_table[256]; - -/** Lookup the crc value in the crc32c_table - @param pos Position in the table. */ -extern guint32 crc32c_table_lookup (guchar pos); - /** Lookup the crc value in the crc32_ccitt_table @param pos Position in the table. */ extern guint32 crc32_ccitt_table_lookup (guchar pos); @@ -60,6 +52,14 @@ extern guint32 crc32_ccitt_table_lookup (guchar pos); @return The CRC32C checksum. */ extern guint32 crc32c_calculate(const void *buf, int len, guint32 crc); +/** Compute CRC32C checksum of a buffer of data without swapping seed crc + or completed checksum + @param buf The buffer containing the data. + @param len The number of bytes to include in the computation. + @param crc The preload value for the CRC32C computation. + @return The CRC32C checksum. */ +extern guint32 crc32c_calculate_no_swap(const void *buf, int len, guint32 crc); + /** Compute CRC32 CCITT checksum of a buffer of data. @param buf The buffer containing the data. @param len The number of bytes to include in the computation. diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def index 70ef7bb78e..19f2e2b676 100644 --- a/wsutil/libwsutil.def +++ b/wsutil/libwsutil.def @@ -30,7 +30,7 @@ crc32_ccitt crc32_ccitt_seed crc32_ccitt_table_lookup crc32c_calculate -crc32c_table_lookup +crc32c_calculate_no_swap ; crcdrm.c crc_drm |