Fowler–Noll–Vo hash function

Fowler–Noll–Vo is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong Vo.

The basis of the FNV hash algorithm was taken from an idea sent as reviewer comments to the IEEE POSIX P1003.2 committee by Glenn Fowler and Phong Vo in 1991. In a subsequent ballot round, Landon Curt Noll improved on their algorithm. In an email message to Landon, they named it the Fowler/Noll/Vo or FNV hash.[1]

Overview

The current versions are FNV-1 and FNV-1a, which supply a means of creating non-zero FNV offset basis. FNV currently comes in 32-, 64-, 128-, 256-, 512-, and 1024-bit flavors. For pure FNV implementations, this is determined solely by the availability of FNV primes for the desired bit length; however, the FNV webpage discusses methods of adapting one of the above versions to a smaller length that may or may not be a power of two.[2][3]

The FNV hash algorithms and reference FNV source code[4][5] have been released into the public domain.[6]

FNV is not a cryptographic hash.[7]

The hash

One of FNV's key advantages is that it is very simple to implement. Start with an initial hash value of FNV offset basis. For each byte in the input, multiply hash by the FNV prime, then XOR it with the byte from the input. The alternate algorithm, FNV-1a, reverses the multiply and XOR steps.

FNV-1 hash

The FNV-1 hash algorithm is as follows:[8][9]

   hash = FNV_offset_basis
   for each byte_of_data to be hashed
   	hash = hash × FNV_prime
   	hash = hash XOR byte_of_data
   return hash

In the above pseudocode, all variables are unsigned integers. All variables, except for byte_of_data, have the same number of bits as the FNV hash. The variable, byte_of_data, is an 8 bit unsigned integer.

As an example, consider the 64-bit FNV-1 hash:

  • All variables, except for byte_of_data, are 64-bit unsigned integers.
  • The variable, byte_of_data, is an 8-bit unsigned integer.
  • The FNV_offset_basis is the 64-bit FNV offset basis value: 14695981039346656037 (in hex, 0xcbf29ce484222325).
  • The FNV_prime is the 64-bit FNV prime value: 1099511628211 (in hex, 0x100000001b3).
  • The multiply returns the lower 64-bits of the product.
  • The XOR is an 8-bit operation that modifies only the lower 8-bits of the hash value.
  • The hash value returned is a 64-bit unsigned integer.

FNV-1a hash

The FNV-1a hash differs from the FNV-1 hash by only the order in which the multiply and XOR is performed:[8][10]

   hash = FNV_offset_basis
   for each byte_of_data to be hashed
   	hash = hash XOR byte_of_data
   	hash = hash × FNV_prime
   return hash

The above pseudocode has the same assumptions that were noted for the FNV-1 pseudocode. The small change in order leads to slightly better avalanche characteristics.[8][11]

FNV-0 hash (deprecated)

The FNV-0 hash differs from the FNV-1 hash only by the initialisation value of the hash variable:[8][12]

   hash = 0
   for each byte_of_data to be hashed
   	hash = hash × FNV_prime
   	hash = hash XOR octet_of_data
   return hash

The above pseudocode has the same assumptions that were noted for the FNV-1 pseudocode.

Use of the FNV-0 hash is deprecated except for the computing of the FNV offset basis for use as the FNV-1 and FNV-1a hash parameters.[8][12]

FNV offset basis

There are several different FNV offset basis for various bit lengths. These FNV offset basis are computed by computing the FNV-0 from the following 32 octets when expressed in ASCII:

chongo <Landon Curt Noll> /\../\

which is one of Landon Curt Noll's signature lines. This is the only current practical use for the deprecated FNV-0.[8][12]

FNV prime

An FNV prime is a prime number and is determined as follows:[13][14]

For a given :

where is:

and where is:

NOTE: is the floor function

then the n-bit FNV prime is the smallest prime number that is of the form:

such that:

  • The number of one-bits in the binary number representation of is either 4 or 5

Experimentally, FNV prime matching the above constraints tend to have better dispersion properties. They improve the polynomial feedback characteristic when an FNV prime multiplies an intermediate hash value. As such, the hash values produced are more scattered throughout the n-bit hash space.[13][14]

FNV hash parameters

The above FNV prime constraints and the definition of the FNV offset basis yield the following table of FNV hash parameters:

FNV parameters [15][16]
Size in bits

FNV prime FNV offset basis
32 224 + 28 + 0x93 =

16777619

2166136261 =

0x811c9dc5

64 240 + 28 + 0xb3 =

1099511628211

14695981039346656037 =

0xcbf29ce484222325

128 288 + 28 + 0x3b =

309485009821345068724781371

144066263297769815596495629667062367629
=

0x6c62272e07bb014262b821756295c58d

256 2168 + 28 + 0x63 =

374144419156711147060143317
175368453031918731002211

100029257958052580907070968620625704837

092796014241193945225284501741471925557
=
0xdd268dbcaac550362d98c384c4e576ccc8b153
6847b6bbb31023b4c8caee0535

512 2344 + 28 + 0x57 =

358359158748448673689190764
890951084499463279557543925
583998256154206699388825751
26094039892345713852759

965930312949666949800943540071631046609

041874567263789610837432943446265799458
293219771643844981305189220653980578449
5328239340083876191928701583869517785
=
0xb86db0b1171f4416dca1e50f309990acac87d0
59c90000000000000000000d21e948f68a34c192
f62ea79bc942dbe7ce182036415f56e34bac982a
ac4afe9fd9

1024 2680 + 28 + 0x8d =

501645651011311865543459881
103527895503076534540479074
430301752383111205510814745
150915769222029538271616265
187852689524938529229181652
437508374669137180409427187
316048473796672026038921768
4476157468082573

14197795064947621068722070641403218320

88062279544193396087847491461758272325
22967323037177221508640965212023555493
65628174669108571814760471015076148029
75596980407732015769245856300321530495
71501574036444603635505054127112859663
61610267868082893823963790439336411086
884584107735010676915
=
0x5f7a76758ecc4d32e56d5a591028b74b29fc
4223fdada16c3bf34eda3674da9a21d9000000
00000000000000000000000000000000000000
00000000000000000000000000000000000000
00000000000000000004c6d7eb6e7380273451
0a555f256cc005ae556bde8cc9c6a93b21aff4
b16c71ee90b3

The prefix "0x" on numbers means that the subsequent numbers are in hexadecimal.

Non-cryptographic hash

The FNV hash was designed for fast hash table and checksum use, not cryptography. The authors have identified the following properties as making the algorithm unsuitable as a cryptographic hash function:[7]

  • Speed of Computation – As a hash designed primarily for hashtable and checksum use, FNV-1 and FNV-1a were designed to be fast to compute. However, this same speed makes finding specific hash values (collisions) by brute force faster.
  • Sticky State – Being an iterative hash based primarily on multiplication and XOR, the algorithm is sensitive to the number zero. Specifically, if the hash value were to become zero at any point during calculation, and the next byte hashed were also all zeroes, the hash would not change. This makes colliding messages trivial to create given a message that results in a hash value of zero at some point in its calculation. Additional operations, such as the addition of a third constant prime on each step, can mitigate this but may have detrimental effects on avalanche effect or random distribution of hash values.
  • Diffusion – The ideal secure hash function is one in which each byte of input has an equally-complex effect on every bit of the hash. In the FNV hash, the ones place (the rightmost bit) is always the XOR of the rightmost bit of every input byte. This can be mitigated by XOR-folding (computing a hash twice the desired length, and then XORing the bits in the "upper half" with the bits in the "lower half").[17]

See also

References

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.