Skip to main content

Module hash

Module hash 

Source
Expand description

Content hashing for schema ids.

The schema id is a content address: two parties that build the same logical schema must derive the same id, and an adversary must not be able to cheaply find two schemas sharing one id (schema-confusion resistance, and safe use as a registry key). That rules out a fast non-cryptographic hash like FNV, whose structure makes collisions trivial to construct.

We use SHA-256 truncated to 128 bits. (BLAKE3 would be a fine choice too; SHA-256 is chosen here because it is simple enough to implement correctly with zero dependencies — the whole crate stays dependency-free — and the schema hash is computed once per schema build, never on the hot path.)

128 bits gives ~2^64 birthday-collision resistance; a 64-bit id would give only ~2^32, which is within reach of a determined adversary — hence the wider id.

Functions§

crc32
CRC-32 (IEEE 802.3): reflected, polynomial 0xEDB8_8320, init and final XOR 0xFFFF_FFFF. Used by the .verit file footer to prove a commit was not torn by a crash (File Format Specification §7).
schema_id
The schema id: the first 128 bits of SHA-256 over the canonical schema bytes, read big-endian.
sha256
A straightforward, allocation-free SHA-256 (FIPS 180-4). Not constant-time — it hashes public schema bytes, not secrets.