Module fnv

Module fnv 

Source
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_basis values.

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 b for 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 data as a lowercase hex string.
fnv0_64_hex
Computes the 64-bit FNV-0 hash of data as 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 data as big-endian bytes.
fnv0_512
Computes the 512-bit FNV-0 hash of data as big-endian bytes.
fnv0_128_hex
Computes the 128-bit FNV-0 hash of data as a lowercase hex string.
fnv0_256_hex
Computes the 256-bit FNV-0 hash of data as a lowercase hex string.
fnv0_512_hex
Computes the 512-bit FNV-0 hash of data as a lowercase hex string.
fnv0_1024
Computes the 1024-bit FNV-0 hash of data as big-endian bytes.
fnv0_1024_hex
Computes the 1024-bit FNV-0 hash of data as 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 data as a lowercase hex string.
fnv1_64_hex
Computes the 64-bit FNV-1 hash of data as 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 data as big-endian bytes.
fnv1_512
Computes the 512-bit FNV-1 hash of data as big-endian bytes.
fnv1_128_hex
Computes the 128-bit FNV-1 hash of data as a lowercase hex string.
fnv1_256_hex
Computes the 256-bit FNV-1 hash of data as a lowercase hex string.
fnv1_512_hex
Computes the 512-bit FNV-1 hash of data as a lowercase hex string.
fnv1_1024
Computes the 1024-bit FNV-1 hash of data as big-endian bytes.
fnv1_1024_hex
Computes the 1024-bit FNV-1 hash of data as 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 data via XOR-folding from 32 bits.
fnv1a_24
Computes the 24-bit FNV-1a hash of data via 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 data via 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 data as a lowercase hex string.
fnv1a_24_hex
Computes the 24-bit FNV-1a hash of data as a lowercase hex string.
fnv1a_32_hex
Computes the 32-bit FNV-1a hash of data as 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 data using a custom offset_basis, per RFC 9923 Section 4.
fnv1a_48_hex
Computes the 48-bit FNV-1a hash of data as a lowercase hex string.
fnv1a_64_hex
Computes the 64-bit FNV-1a hash of data as 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 data using a custom offset_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 data as big-endian bytes.
fnv1a_512
Computes the 512-bit FNV-1a hash of data as big-endian bytes.
fnv1a_128_hex
Computes the 128-bit FNV-1a hash of data as 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 data using a custom offset_basis, per RFC 9923 Section 4.
fnv1a_256_hex
Computes the 256-bit FNV-1a hash of data as a lowercase hex string.
fnv1a_512_hex
Computes the 512-bit FNV-1a hash of data as a lowercase hex string.
fnv1a_1024
Computes the 1024-bit FNV-1a hash of data as big-endian bytes.
fnv1a_1024_hex
Computes the 1024-bit FNV-1a hash of data as 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 data to a value in 0..=max using 32-bit FNV-1a with retry-based modulo bias avoidance, per RFC 9923 Section 3.
fnv1a_range_u64
Maps data to a value in 0..=max using 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.