code wiki / (root) / nx_fnv.nx

nx_fnv.nx

buildroot/runtime/nx_fnv.nx

3067 B99 linesdepth 2pulls 2 transitivereach 61 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

fnv.nx -- FNV-1a non-cryptographic hash (Fowler-Noll-Vo). Canonical: this is the substrate-wide canonical FNV-1a 64-bit implementation per [[feedback-no-tool-proliferation-bit-level]]. All other primitives needing FNV-1a MUST `import "nx_fnv.nx"` and compose fnv1a / fnv1a_init / fnv1a_update / fnv1a_cstr; re-implementing FNV inline is refused per the cardinal. 64-bit FNV-1a. Used for: hash table keying, file fingerprinting, Bloom filter mixing, deduplication. NOT for security -- an attacker who controls input can construct collisions. For cryptographic hashing use sha256 / sha512 / sha3. Algorithm (Fowler-Noll-Vo 1991; rfc draft-eastlake-fnv): hash = FNV_OFFSET_BASIS for each byte b in input: hash = hash XOR b hash = hash * FNV_PRIME FNV-1a (xor-then-multiply) has better avalanche than plain FNV-1 (multiply-then-xor) so we implement 1a. 64-bit constants (Eastlake RFC draft): offset_basis = 0xCBF29CE484222325 prime = 0x100000001B3 Invariants: F1 Empty input hashes to offset_basis (14695981039346656037). F2 Identical byte sequences always hash to the same value across runs / machines / endianness (state is plain i64 arithmetic, no byte-order dependence). F3 Multiplication overflows are wrapped mod 2^64 by the underlying i64 arithmetic -- matches reference spec.

dependencies 1 imports · 6 importers

nx_syscalls.nx nx_fnv.nx nx_artifact_id.nx nx_cms_abtest.nx nx_cms_email.nx nx_cms_image.nx nx_docportal_lib.nx nx_etg.nx

imports: nx_syscalls.nx

imported by: nx_artifact_id.nxnx_cms_abtest.nxnx_cms_email.nxnx_cms_image.nxnx_docportal_lib.nxnx_etg.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main fnv1a fnv1a_init fnv1a_update

structs

none

consts

44const FNV_OFFSET_BASIS: i64 = 0xCBF29CE484222325
45const FNV_PRIME: i64 = 0x100000001B3

functions

48func fnv1a(data: *u8, n: i64) -> i64
60func fnv1a_init() -> i64
65func fnv1a_update(state: i64, data: *u8, n: i64) -> i64
77func fnv1a_cstr(s: *u8) -> i64
calls 1: fnv1a
85func main() -> i64