Fowler–Noll–Vo hash function explained

Fowler–Noll–Vo (or FNV) 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 variants. 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]

The Python programming language previously used a modified version of the FNV scheme for its default hash function. From Python 3.4, FNV has been replaced with SipHash to resist "hash flooding" denial-of-service attacks.[7]

FNV is not a cryptographic hash.[4]

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]

algorithm fnv-1 is hash := FNV_offset_basis for each byte_of_data to be hashed do 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:

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:[10]

algorithm fnv-1a is hash := FNV_offset_basis for each byte_of_data to be hashed do 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 change in order leads to slightly better avalanche characteristics.[11]

FNV-0 hash (deprecated)

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

algorithm fnv-0 is hash := 0 for each byte_of_data to be hashed do hash := hash × FNV_prime hash := hash XOR byte_of_data return hash

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

A consequence of the initialisation of the hash to 0 is that empty messages and all messages consisting of only the byte 0, regardless of their length, hash to 0.

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.

FNV offset basis

There are several different FNV offset bases for various bit lengths. These offset bases 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.

FNV prime

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

For a given

s

:

s\inZ*~

(i.e., s is an integer)

4<s<11

where

n

is:

n=2s

and where

t

is:

t=\left\lfloor

5+n
12

\right\rfloor

NOTE:

\lfloorx\rfloor

is the floor function

p

that is of the form:

256t+28+b

such that:

0<b<28

b

is either 4 or 5

p\mod(240-224-1)>(224+28+27)

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.

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 [14] ! Size in bits

n=2s

! Representation! FNV prime ! FNV offset basis
32Expression224 + 28 + 0x93
Decimal167776192166136261
Hexadecimal0x010001930x811c9dc5
64Expression240 + 28 + 0xb3
Decimal109951162821114695981039346656037
Hexadecimal0x00000100000001B30xcbf29ce484222325
128Representation288 + 28 + 0x3b
Decimal309485009821345068724781371144066263297769815596495629667062367629
Hexadecimal0x0000000001000000000000000000013B0x6c62272e07bb014262b821756295c58d
256Representation2168 + 28 + 0x63
Decimal374144419156711147060143317
175368453031918731002211
100029257958052580907070968620625704837
092796014241193945225284501741471925557
Hexadecimal0x00000000000000000000010000000000
00000000000000000000000000000163
0xdd268dbcaac550362d98c384c4e576ccc8b153
6847b6bbb31023b4c8caee0535
512Representation2344 + 28 + 0x57
Decimal358359158748448673689190764
890951084499463279557543925
583998256154206699388825751
26094039892345713852759
965930312949666949800943540071631046609
041874567263789610837432943446265799458
293219771643844981305189220653980578449
5328239340083876191928701583869517785
Hexadecimal0x0000000000000000 0000000000000000
0000000001000000 0000000000000000
0000000000000000 0000000000000000
0000000000000000 0000000000000157
0xb86db0b1171f4416 dca1e50f309990ac
ac87d059c9000000 0000000000000d21
e948f68a34c192f6 2ea79bc942dbe7ce
182036415f56e34b ac982aac4afe9fd9
1024Representation2680 + 28 + 0x8d
Decimal501645651011311865543459881103
527895503076534540479074430301
752383111205510814745150915769
222029538271616265187852689524
938529229181652437508374669137
180409427187316048473796672026
0389217684476157468082573
14197795064947621068722070641403218320
88062279544193396087847491461758272325
22967323037177221508640965212023555493
65628174669108571814760471015076148029
75596980407732015769245856300321530495
71501574036444603635505054127112859663
61610267868082893823963790439336411086
884584107735010676915
Hexadecimal0x0000000000000000 0000000000000000
0000000000000000 0000000000000000
0000000000000000 0000010000000000
0000000000000000 0000000000000000
0000000000000000 0000000000000000
0000000000000000 0000000000000000
0000000000000000 0000000000000000
0000000000000000 000000000000018D
0x0000000000000000 005f7a76758ecc4d
32e56d5a591028b7 4b29fc4223fdada1
6c3bf34eda3674da 9a21d90000000000
0000000000000000 0000000000000000
0000000000000000 0000000000000000
0000000000000000 000000000004c6d7
eb6e73802734510a 555f256cc005ae55
6bde8cc9c6a93b21 aff4b16c71ee90b3

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:[15]

See also

External links

Notes and References

  1. Web site: FNV Hash - FNV hash history. www.isthe.com.
  2. Web site: FNV Hash - Changing the FNV hash size - xor-folding. www.isthe.com.
  3. Web site: FNV Hash - Changing the FNV hash size - non-powers of 2. www.isthe.com.
  4. Web site: Eastlake. Donald. Hansen. Tony. Fowler. Glenn. Vo. Kiem-Phong. Noll. Landon. The FNV Non-Cryptographic Hash Algorithm. tools.ietf.org.
  5. Web site: FNV Hash - FNV source. www.isthe.com.
  6. http://www.isthe.com/chongo/tech/comp/fnv/index.html#public_domain FNV put into the public domain
  7. Web site: PEP 456 -- Secure and interchangeable hash algorithm. Python.org.
  8. Web site: Eastlake. Donald. Hansen. Tony. Fowler. Glenn. Vo. Kiem-Phong. . Landon Noll. June 4, 2020. The FNV Non-Cryptographic Hash Algorithm. 2020-06-04. tools.ietf.org. en.
  9. Web site: FNV Hash - The core of the FNV hash. 2020-06-04. www.isthe.com.
  10. Web site: FNV Hash - FNV-1a alternate algorithm. www.isthe.com.
  11. Web site: avalanche - murmurhash. sites.google.com.
  12. Web site: FNV Hash - FNV-0 Historic not. www.isthe.com.
  13. Web site: FNV Hash - A few remarks on FNV primes. www.isthe.com.
  14. Web site: FNV Hash - Parameters of the FNV-1/FNV-1a hash. www.isthe.com.
  15. Web site: Eastlake. Donald. Hansen. Tony. Fowler. Glenn. Vo. Kiem-Phong. Noll. Landon. The FNV Non-Cryptographic Hash Algorithm. 2021-01-12. tools.ietf.org. en.