Fowler-Noll-Vo is a non-cryptographic hash function created by Glenn Fowler, Landon Curt Noll, and Kiem-Phong Vo.
Contents
- Overview
- The hash
- FNV 1 hash
- FNV 1a hash
- FNV 0 hash deprecated
- FNV offset basis
- FNV prime
- FNV hash parameters
- Non cryptographic hash
- References
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.
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.
The FNV hash algorithms and reference FNV source code have been released into the public domain.
FNV is not a cryptographic hash .
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:
hash = FNV_offset_basis for each byte_of_data to be hashed hash = hash × FNV_prime hash = hash XOR byte_of_data return hashIn 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:
hash = FNV_offset_basis for each byte_of_data to be hashed hash = hash XOR byte_of_data hash = hash × FNV_prime return hashThe 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.
FNV-0 hash (deprecated)
The FNV-0 hash differs from the FNV-1a hash only by the initialisation value of the hash variable:
hash = 0 for each octet_of_data to be hashed hash = hash XOR octet_of_data hash = hashThe 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 the FNV offset basis for the FNV-1 and FNV-1a hash parameters.
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.
FNV prime
An FNV prime is a prime number and is determined as follows:
For a given
where
and where
then the n-bit FNV prime is the smallest prime number
such that:
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:
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: