Expand description
Fowler-Noll-Vo (FNV-0, FNV-1, FNV-1a) hash functions computed from scratch.
FIXME: They can be folded to arbitrary bit lengths (fnv_xor_fold) but
there’s no FormatId or parameterized format variant for that.
Provides an independent implementation of 32, 64, 128, 256, 512, and 1024-bit FNV hashes derived from the mathematical specifications of RFC 9923 (“The FNV Non-Cryptographic Hash Algorithm”, February 2026), without using reference source code:
- Section 1.4 & Section 6: Non-cryptographic characteristics (sticky state, dispersion limits on low bits, low work factor) and security considerations regarding collision resistance.
- Section 2 & Section 5: Core FNV-0, FNV-1, and FNV-1a algorithms, primes, and offset bases.
- Section 2.3: Little-endian representation for storage and interoperability.
- Section 3: XOR folding to arbitrary bit widths and modulo range mapping with retry-based bias avoidance.
- Section 4: Hashing multiple values together and support for non-standard
offset_basisvalues.
All offset bases are derived dynamically by executing the n-bit FNV-0
algorithm over the standard 32-octet basis string (FNV_BASIS_STRING).
FNV primes are constructed according to the formula:
FNV_Prime = 256**k + 2**8 + b where k = int((5 + 2**s) / 12).
Structs§
- FnvStream
- Streaming hasher for incremental FNV hash computation.
- FnvWord
- A fixed-width unsigned word for FNV calculations, stored in little-endian
byte order (
bytes[0]is least significant).
Enums§
- FnvVariant
- Represents an algorithm variant of the Fowler-Noll-Vo hash family.
Constants§
- FNV_
BASIS_ STRING - Standard FNV offset basis derivation string from RFC 9923 Section 2.2.
Functions§
- compute_
offset_ basis - Computes the offset basis for an n-bit FNV hash by running FNV-0 over the 32-octet Landon Curt Noll signature string, per RFC 9923 Section 2.2.
- find_
fnv_ prime_ param - Discovers the smallest prime parameter
bfor power-of-two size $2^s$ ($s \in [5, 10]$) satisfying the RFC 9923 Section 2.1 constraints: - fnv0_32
- Computes the 32-bit FNV-0 hash of
data. - fnv0_64
- Computes the 64-bit FNV-0 hash of
data. - fnv0_
32_ hex - Computes the 32-bit FNV-0 hash of
dataas a lowercase hex string. - fnv0_
64_ hex - Computes the 64-bit FNV-0 hash of
dataas a lowercase hex string. - fnv0_
128 - Computes the 128-bit FNV-0 hash of
data. - fnv0_
256 - Computes the 256-bit FNV-0 hash of
dataas big-endian bytes. - fnv0_
512 - Computes the 512-bit FNV-0 hash of
dataas big-endian bytes. - fnv0_
128_ hex - Computes the 128-bit FNV-0 hash of
dataas a lowercase hex string. - fnv0_
256_ hex - Computes the 256-bit FNV-0 hash of
dataas a lowercase hex string. - fnv0_
512_ hex - Computes the 512-bit FNV-0 hash of
dataas a lowercase hex string. - fnv0_
1024 - Computes the 1024-bit FNV-0 hash of
dataas big-endian bytes. - fnv0_
1024_ hex - Computes the 1024-bit FNV-0 hash of
dataas a lowercase hex string. - fnv0_
update_ word - Updates an existing FNV-0 hash with data.
- fnv1_32
- Computes the 32-bit FNV-1 hash of
data. - fnv1_64
- Computes the 64-bit FNV-1 hash of
data. - fnv1_
32_ hex - Computes the 32-bit FNV-1 hash of
dataas a lowercase hex string. - fnv1_
64_ hex - Computes the 64-bit FNV-1 hash of
dataas a lowercase hex string. - fnv1_
128 - Computes the 128-bit FNV-1 hash of
data. - fnv1_
256 - Computes the 256-bit FNV-1 hash of
dataas big-endian bytes. - fnv1_
512 - Computes the 512-bit FNV-1 hash of
dataas big-endian bytes. - fnv1_
128_ hex - Computes the 128-bit FNV-1 hash of
dataas a lowercase hex string. - fnv1_
256_ hex - Computes the 256-bit FNV-1 hash of
dataas a lowercase hex string. - fnv1_
512_ hex - Computes the 512-bit FNV-1 hash of
dataas a lowercase hex string. - fnv1_
1024 - Computes the 1024-bit FNV-1 hash of
dataas big-endian bytes. - fnv1_
1024_ hex - Computes the 1024-bit FNV-1 hash of
dataas a lowercase hex string. - fnv1_
update_ word - Updates an existing FNV-1 hash with data.
- fnv1a32
- Alias for
fnv1a_32. - fnv1a64
- Alias for
fnv1a_64. - fnv1a32_
hex - Alias for
fnv1a_32_hex. - fnv1a32_
update - Alias for
fnv1a_32_update. - fnv1a64_
hex - Alias for
fnv1a_64_hex. - fnv1a64_
update - Alias for
fnv1a_64_update. - fnv1a_
16 - Computes the 16-bit FNV-1a hash of
datavia XOR-folding from 32 bits. - fnv1a_
24 - Computes the 24-bit FNV-1a hash of
datavia XOR-folding from 32 bits. - fnv1a_
32 - Computes the 32-bit FNV-1a hash of
data. - fnv1a_
48 - Computes the 48-bit FNV-1a hash of
datavia XOR-folding from 64 bits. - fnv1a_
64 - Computes the 64-bit FNV-1a hash of
data. - fnv1a_
16_ hex - Computes the 16-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
24_ hex - Computes the 24-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
32_ hex - Computes the 32-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
32_ update - Updates an existing 32-bit FNV-1a hash with
data. - fnv1a_
32_ with_ basis - Computes the 32-bit FNV-1a hash of
datausing a customoffset_basis, per RFC 9923 Section 4. - fnv1a_
48_ hex - Computes the 48-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
64_ hex - Computes the 64-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
64_ update - Updates an existing 64-bit FNV-1a hash with
data. - fnv1a_
64_ with_ basis - Computes the 64-bit FNV-1a hash of
datausing a customoffset_basis, per RFC 9923 Section 4. - fnv1a_
128 - Computes the 128-bit FNV-1a hash of
data. - fnv1a_
256 - Computes the 256-bit FNV-1a hash of
dataas big-endian bytes. - fnv1a_
512 - Computes the 512-bit FNV-1a hash of
dataas big-endian bytes. - fnv1a_
128_ hex - Computes the 128-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
128_ update - Updates an existing 128-bit FNV-1a hash with
data. - fnv1a_
128_ with_ basis - Computes the 128-bit FNV-1a hash of
datausing a customoffset_basis, per RFC 9923 Section 4. - fnv1a_
256_ hex - Computes the 256-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
512_ hex - Computes the 512-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
1024 - Computes the 1024-bit FNV-1a hash of
dataas big-endian bytes. - fnv1a_
1024_ hex - Computes the 1024-bit FNV-1a hash of
dataas a lowercase hex string. - fnv1a_
fold_ u64 - Folds an FNV-1a hash of input data to an arbitrary bit length $k \le 64$.
- fnv1a_
range_ u32 - Maps
datato a value in0..=maxusing 32-bit FNV-1a with retry-based modulo bias avoidance, per RFC 9923 Section 3. - fnv1a_
range_ u64 - Maps
datato a value in0..=maxusing 64-bit FNV-1a with retry-based modulo bias avoidance, per RFC 9923 Section 3. - fnv1a_
update_ word - Updates an existing FNV-1a hash with data.
- fnv_
xor_ fold - Folds an FNV hash of input data to an arbitrary bit length
k_bits(where $0 < k_bits < 1024$), per RFC 9923 Section 3.