Skip to main content

Module crc32c

Module crc32c 

Source
Expand description

Shared CRC-32C (Castagnoli, reflected) — the canonical integrity primitive for the .10d container and the q42/p64_weight.rs weight container.

P0.3 consolidates the two previously-duplicated implementations (one in q42/p64_weight.rs, one in container_10d/section.rs) into this single module. Both call sites delegate here. The P0.3 acceptance gate verifies that p64_weight.rs checksums stay byte-identical after delegation (the p64 round-trip tests are the proof — they fail on any CRC change).

Algorithm: CRC-32C (Castagnoli), reflected, init = 0xFFFF_FFFF, polynomial 0x82F63B78 (the reflected form of 0x1EDC6F41), final XOR = 0xFFFF_FFFF (i.e., bitwise NOT).

Implementation: 256-entry slice table (built once via OnceLock) — bit-identical to the historical table-less 8-shift-per-byte loop (pinned by the RFC 3720 check value + crc32c_table_matches_tableless_bit_identical). Table form is far faster over multi-hundred-MB P64 tensors (toolkit probe: SmolLM2 from_p64 spent tens of seconds in table-less CRC).

The canonical check value (the ASCII string "123456789"0xE3069283) is pinned by a test below so a future refactor cannot silently change the algorithm.

Functions§

crc32c
CRC-32C (Castagnoli, reflected) over data.
crc32c_update
Incremental CRC-32C update: continue a running CRC over data starting from crc (the previous state, NOT yet final-XOR’d). Returns the updated state (also NOT yet final-XOR’d). To get the final checksum, bitwise-NOT the result (or call crc32c for the one-shot form).