From 092d0b6b38bb8d1639143ffafaa879c10ad65335 Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Wed, 19 May 2004 02:16:46 +0000 Subject: [PATCH] Replace the lame big endian crc with wpaul's standard big endian crc algorithm, supplied by wpaul himself. The lame one has an origin that's been called into question, so rather than argue about that (one could make an excellent fair use argument), replace it with better code since that's what FreeBSD is about. Submitted by: wpaul[1], Klaus Klein [1] Bill called this a silly bikeshed. Maybe his is not incorrect. --- sys/dev/sk/if_sk.c | 32 +++++++++----------------------- sys/pci/if_sk.c | 32 +++++++++----------------------- 2 files changed, 18 insertions(+), 46 deletions(-) diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c index 272bdc5a397..14ff623236b 100644 --- a/sys/dev/sk/if_sk.c +++ b/sys/dev/sk/if_sk.c @@ -745,38 +745,24 @@ sk_xmchash(addr) return (~crc & ((1 << HASH_BITS) - 1)); } +/* gmchash is just a big endian crc */ static u_int32_t sk_gmchash(addr) const uint8_t *addr; { - u_int32_t crc; - u_int idx, bit; - uint8_t tmpData, data; + uint32_t crc, carry; + int idx, bit; + uint8_t data; /* Compute CRC for the address value. */ crc = 0xFFFFFFFF; /* initial value */ for (idx = 0; idx < 6; idx++) { - data = *addr++; - - /* Change bit order in byte. */ - tmpData = data; - for (bit = 0; bit < 8; bit++) { - if (tmpData & 1) { - data |= 1 << (7 - bit); - } else { - data &= ~(1 << (7 - bit)); - } - tmpData >>= 1; - } - - crc ^= (data << 24); - for (bit = 0; bit < 8; bit++) { - if (crc & 0x80000000) { - crc = (crc << 1) ^ GMAC_POLY; - } else { - crc <<= 1; - } + for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) { + carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01); + crc <<= 1; + if (carry) + crc = (crc ^ GMAC_POLY) | carry; } } diff --git a/sys/pci/if_sk.c b/sys/pci/if_sk.c index 272bdc5a397..14ff623236b 100644 --- a/sys/pci/if_sk.c +++ b/sys/pci/if_sk.c @@ -745,38 +745,24 @@ sk_xmchash(addr) return (~crc & ((1 << HASH_BITS) - 1)); } +/* gmchash is just a big endian crc */ static u_int32_t sk_gmchash(addr) const uint8_t *addr; { - u_int32_t crc; - u_int idx, bit; - uint8_t tmpData, data; + uint32_t crc, carry; + int idx, bit; + uint8_t data; /* Compute CRC for the address value. */ crc = 0xFFFFFFFF; /* initial value */ for (idx = 0; idx < 6; idx++) { - data = *addr++; - - /* Change bit order in byte. */ - tmpData = data; - for (bit = 0; bit < 8; bit++) { - if (tmpData & 1) { - data |= 1 << (7 - bit); - } else { - data &= ~(1 << (7 - bit)); - } - tmpData >>= 1; - } - - crc ^= (data << 24); - for (bit = 0; bit < 8; bit++) { - if (crc & 0x80000000) { - crc = (crc << 1) ^ GMAC_POLY; - } else { - crc <<= 1; - } + for (data = *addr++, bit = 0; bit < 8; bit++, data >>= 1) { + carry = ((crc & 0x80000000) ? 1 : 0) ^ (data & 0x01); + crc <<= 1; + if (carry) + crc = (crc ^ GMAC_POLY) | carry; } }