The current versions are FNV-1 and FNV-1a, which supply a means of creating non-zero FNV offset basis. FNV currently[as of?] 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.23
The FNV hash algorithms and reference FNV source code45 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.8
One of FNV's key advantages is that it is very simple to implement.9 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.
The FNV-1 hash algorithm is as follows:1011
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:
The FNV-1a hash differs from the FNV-1 hash only by the order in which the multiply and XOR is performed:1213
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.1415
The FNV-0 hash differs from the FNV-1 hash only by the initialisation value of the hash variable:1617
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.18
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.1920
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:
This is one of Landon Curt Noll's signature lines. This is the only current practical use for the deprecated FNV-0.2122
An FNV prime is a prime number and is determined as follows:2324
For a given integer s such that 4 < s < 11, let n = 2s and t = ⌊(5 + n) / 12⌋; then the n-bit FNV prime is the smallest prime number p that is of the form
such that:
Experimentally, FNV primes 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.2526
The above FNV prime constraints and the definition of the FNV offset basis yield the following table of FNV hash parameters:
n = 2 s {\displaystyle n=2^{s}}
374144419156711147060143317175368453031918731002211
100029257958052580907070968620625704837092796014241193945225284501741471925557
0x0000000000000000000001000000000000000000000000000000000000000163
0xdd268dbcaac550362d98c384c4e576ccc8b1536847b6bbb31023b4c8caee0535
35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759
9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785
0x0000000000000000 00000000000000000000000001000000 00000000000000000000000000000000 00000000000000000000000000000000 0000000000000157
0xb86db0b1171f4416 dca1e50f309990acac87d059c9000000 0000000000000d21e948f68a34c192f6 2ea79bc942dbe7ce182036415f56e34b ac982aac4afe9fd9
5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573
14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915
0x0000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000100000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 000000000000018d
0x0000000000000000 005f7a76758ecc4d32e56d5a591028b7 4b29fc4223fdada16c3bf34eda3674da 9a21d900000000000000000000000000 00000000000000000000000000000000 00000000000000000000000000000000 000000000004c6d7eb6e73802734510a 555f256cc005ae556bde8cc9c6a93b21 aff4b16c71ee90b3
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:29
A structural weakness of FNV-1a arises from its use of XOR before multiplication, which can cause predictable relationships between hashes of related inputs. For example, the following identity holds in both the 32-bit and 64-bit variants:
because the differing characters ('a' vs 'b', and '1' vs '2') differ by the same bit pattern. This illustrates how certain bitwise symmetries in input can lead to unintended hash correlations. XOR-folding does not remove this weakness.
"FNV Hash - FNV hash history". www.isthe.com. http://www.isthe.com/chongo/tech/comp/fnv/index.html#history ↩
"FNV Hash - Changing the FNV hash size - xor-folding". www.isthe.com. http://www.isthe.com/chongo/tech/comp/fnv/index.html#xor-fold ↩
"FNV Hash - Changing the FNV hash size - non-powers of 2". www.isthe.com. http://www.isthe.com/chongo/tech/comp/fnv/index.html#other-folding ↩
Eastlake, Donald; Hansen, Tony; Fowler, Glenn; Vo, Kiem-Phong; Noll, Landon (29 May 2019). "The FNV Non-Cryptographic Hash Algorithm". tools.ietf.org. https://tools.ietf.org/html/draft-eastlake-fnv-17.html ↩
"FNV Hash - FNV source". www.isthe.com. http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-source ↩
FNV put into the public domain on isthe.com http://www.isthe.com/chongo/tech/comp/fnv/index.html#public_domain ↩
"PEP 456 -- Secure and interchangeable hash algorithm". Python.org. https://www.python.org/dev/peps/pep-0456/ ↩
Smith, James (2022-05-29). "Hash Functions in Go". Golang Project Structure. Retrieved 2024-10-19. https://golangprojectstructure.com/hash-functions-go-code/#implementing-the-fowler%e2%80%93noll%e2%80%93vo-fnv-hash-function ↩
Eastlake, Donald; Hansen, Tony; Fowler, Glenn; Vo, Kiem-Phong; , Landon Noll (June 4, 2020). "The FNV Non-Cryptographic Hash Algorithm". tools.ietf.org. Retrieved 2020-06-04. {{cite journal}}: |last5= has generic name (help) https://tools.ietf.org/html/draft-eastlake-fnv-17.html ↩
"FNV Hash - The core of the FNV hash". www.isthe.com. Retrieved 2020-06-04. http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-1 ↩
"FNV Hash - FNV-1a alternate algorithm". www.isthe.com. http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-1a ↩
"avalanche - murmurhash". sites.google.com. https://sites.google.com/site/murmurhash/avalanche ↩
"FNV Hash - FNV-0 Historic not". www.isthe.com. http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-0 ↩
"FNV Hash - A few remarks on FNV primes". www.isthe.com. http://www.isthe.com/chongo/tech/comp/fnv/index.html#fnv-prime ↩
"FNV Hash - Parameters of the FNV-1/FNV-1a hash". www.isthe.com. http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param ↩
Eastlake, Donald; Hansen, Tony; Fowler, Glenn; Vo, Kiem-Phong; Noll, Landon (29 May 2019). "The FNV Non-Cryptographic Hash Algorithm". tools.ietf.org. Retrieved 2021-01-12. https://tools.ietf.org/html/draft-eastlake-fnv-17.html ↩