]> 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:43:56 +0000 (17:43 +0200)
it has much better properties

src/lib/hash.c

index 48d8c989164e7677e995da0dc7500aca6bec5009..20d5ccff4219cb7d62091b3afe2064e7f8577b9e 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;