summaryrefslogtreecommitdiffstats
path: root/sys/dev/sk
diff options
context:
space:
mode:
authorimp <imp@FreeBSD.org>2004-05-19 02:16:46 +0000
committerimp <imp@FreeBSD.org>2004-05-19 02:16:46 +0000
commit763e60e31662c7ac5be6608a6d0e6e6d52f1c66f (patch)
treefb51b362cb051fb6cffd583cc996d96124f63621 /sys/dev/sk
parentfecf8b1849be1ee4b1e7d6dce50a6c3b0d55842b (diff)
downloadFreeBSD-src-763e60e31662c7ac5be6608a6d0e6e6d52f1c66f.zip
FreeBSD-src-763e60e31662c7ac5be6608a6d0e6e6d52f1c66f.tar.gz
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.
Diffstat (limited to 'sys/dev/sk')
-rw-r--r--sys/dev/sk/if_sk.c32
1 files changed, 9 insertions, 23 deletions
diff --git a/sys/dev/sk/if_sk.c b/sys/dev/sk/if_sk.c
index 272bdc5..14ff623 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;
}
}
OpenPOWER on IntegriCloud