From: Alan T. DeKok Date: Mon, 28 May 2012 15:42:06 +0000 (+0200) Subject: FNV-1a: xor then multiply, not multiply then xor X-Git-Tag: release_2_2_0~125 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f46e77e5958bf27ea6d22aecb996ac1f464b0c94;p=thirdparty%2Ffreeradius-server.git FNV-1a: xor then multiply, not multiply then xor it has much better properties --- diff --git a/src/lib/hash.c b/src/lib/hash.c index b7bbf0988f7..5bcab6bc1d3 100644 --- a/src/lib/hash.c +++ b/src/lib/hash.c @@ -706,6 +706,12 @@ uint32_t fr_hash(const void *data, size_t size) * FNV-1 hash each octet in the buffer */ while (p != q) { + /* + * XOR the 8-bit quantity into the bottom of + * the hash. + */ + hash ^= (uint32_t) (*p++); + /* * Multiple by 32-bit magic FNV prime, mod 2^32 */ @@ -716,11 +722,6 @@ uint32_t fr_hash(const void *data, size_t size) */ hash += (hash<<1) + (hash<<4) + (hash<<7) + (hash<<8) + (hash<<24); #endif - /* - * XOR the 8-bit quantity into the bottom of - * the hash. - */ - hash ^= (uint32_t) (*p++); } return hash;