About FNV164 hash
FNV-1a 64-bit (Fowler-Noll-Vo version 1a with a 64-bit output) is a variant of the FNV-1a hash function that produces a 64-bit hash value. It extends the original FNV-1a algorithm to handle larger hash outputs, providing improved dispersion and reduced collision rates compared to its 32-bit counterpart.
Characteristics of FNV-1a 64-bit
Output Size:
- FNV-1a 64-bit produces a fixed-length output of 64 bits (8 bytes).
Initialization Value:
- The initial hash value (
hash
) for FNV-1a 64-bit is typically set to0xcbf29ce484222325
. This value is chosen to help ensure good dispersion of hash values across the output space.
- The initial hash value (
Prime and XOR Constants:
- FNV-1a 64-bit uses a prime number and XOR operation for hash calculation:
- Prime: The prime number used in FNV-1a 64-bit is
0x100000001b3
. - XOR: Each byte of the input data is XORed into the hash value before multiplying by the prime.
- Prime: The prime number used in FNV-1a 64-bit is
- FNV-1a 64-bit uses a prime number and XOR operation for hash calculation:
Hash Calculation:
- For each byte
data[i]
in the input data:- Update the hash value using the formula:
hash = (hash ^ data[i]) * Prime
.
- Update the hash value using the formula:
- After processing all bytes, the hash value is the final 64-bit FNV-1a hash.
- For each byte
Properties:
- FNV-1a 64-bit is designed for fast computation of hash values with improved dispersion compared to its 32-bit counterpart.
- It is deterministic and produces the same hash value for identical input data.
- Like FNV-1a 32-bit, FNV-1a 64-bit is not suitable for cryptographic purposes due to its vulnerability to collision attacks and its predictable nature.
Usage
Applications: FNV-1a 64-bit is commonly used in applications where a larger hash output size is required for data integrity checks, hash tables, and some non-critical hash-based operations.
Implementation: It is efficient in terms of computational resources and straightforward to implement, making it suitable for scenarios requiring rapid computation of 64-bit hash values.
Example Calculation
Given a sequence of bytes data
, the FNV-1a 64-bit hash FNV1a_64(data)
is calculated as follows:
- Initialize the hash value
hash
to0xcbf29ce484222325
. - For each byte
data[i]
in the input data:- XOR
hash
withdata[i]
. - Multiply
hash
by the prime number0x100000001b3
.
- XOR
- The final FNV-1a 64-bit hash value after processing all bytes is
hash
.
Security Considerations
- FNV-1a 64-bit, like its 32-bit counterpart, is not designed for cryptographic purposes and should not be used where strong security guarantees are required.
- It is susceptible to collision attacks and should only be used in scenarios where data integrity verification is the primary concern rather than security against malicious attacks.
Summary
FNV-1a 64-bit is an extension of the FNV-1a hash function that provides a larger 64-bit hash output. It is suitable for applications requiring a larger hash size with moderate integrity checking capabilities. However, it is not suitable for cryptographic purposes due to its predictable nature and vulnerability to attacks.