]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
FNV-1a: xor then multiply, not multiply then xor
authorAlan T. DeKok <aland@freeradius.org>
Mon, 28 May 2012 15:42:06 +0000 (17:42 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 28 May 2012 15:42:06 +0000 (17:42 +0200)
it has much better properties

src/lib/hash.c

index b7bbf0988f7cce147d7224a619962680a8cdd3f5..5bcab6bc1d3678e2dd2eee2503ab33a2b4d58c50 100644 (file)
@@ -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;