Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F178406748
D62532.1796683858.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
D62532.1796683858.diff
View Options
diff --git a/sys/net/toeplitz.c b/sys/net/toeplitz.c
--- a/sys/net/toeplitz.c
+++ b/sys/net/toeplitz.c
@@ -34,21 +34,26 @@
toeplitz_hash(u_int keylen, const uint8_t *key, u_int datalen,
const uint8_t *data)
{
- uint32_t hash = 0, v;
- u_int i, b;
+ uint64_t window;
+ uint32_t hash;
+ u_int b, i, k;
- /* XXXRW: Perhaps an assertion about key length vs. data length? */
-
- v = (key[0]<<24) + (key[1]<<16) + (key[2] <<8) + key[3];
+ /*
+ * Each input bit adds the 32 key bits that start at its own
+ * position. window holds the 64 key bits from the current input
+ * byte on, so those for its bit b (most significant first) are bits
+ * 32 - b to 63 - b. Key bits past the end of the key are 0.
+ */
+ window = 0;
+ for (k = 0; k < 8; k++)
+ window = (window << 8) | (k < keylen ? key[k] : 0);
+ hash = 0;
for (i = 0; i < datalen; i++) {
- for (b = 0; b < 8; b++) {
- if (data[i] & (1<<(7-b)))
- hash ^= v;
- v <<= 1;
- if ((i + 4) < keylen &&
- (key[i+4] & (1<<(7-b))))
- v |= 1;
- }
+ for (b = 0; b < 8; b++)
+ hash ^= (uint32_t)(window >> (32 - b)) &
+ -(uint32_t)((data[i] >> (7 - b)) & 1);
+ k = i + 8;
+ window = (window << 8) | (k < keylen ? key[k] : 0);
}
return (hash);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 7, 10:50 PM (23 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42290784
Default Alt Text
D62532.1796683858.diff (1 KB)
Attached To
Mode
D62532: toeplitz: Hash without a branch per input bit
Attached
Detach File
Event Timeline