code wiki / (root) / crc32.nx

crc32.nx

buildroot/runtime/crc32.nx

3464 B91 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic crc32
docsdependenciesstructsconstsfunctions

about

crc32.nx -- CRC-32 checksum (IEEE 802.3 + Castagnoli). Two widely-used variants: crc32 IEEE 802.3 polynomial 0xEDB88320 (reversed). Used by: ZIP, PNG, gzip, Ethernet, PNG, Adler (old TCP). crc32c Castagnoli polynomial 0x82F63B78 (reversed). Used by: iSCSI, SCTP, ZFS, BTRFS, Google Wire Format, AWS S3 checksum-algorithm-CRC32C. Better error detection + hardware-accelerated on x86 (CRC32Q op) and ARMv8. Not cryptographic -- trivial to forge. Good only as an integrity check against random bit-flips (storage, transmission). Algorithm: table-less bit-by-bit variant. 8 iterations per input byte; each iteration xor-shifts the current CRC by 1 and conditionally xors in the polynomial. ~50 CPU cycles per byte; for high-throughput callers, a future 256-entry table lookup lands when NishiLang gets proper const-array literals. Both variants start with CRC = 0xFFFFFFFF and end by xor'ing with 0xFFFFFFFF (i.e., complement) -- matches every reference implementation (zlib, CRC-32/BZIP2 identical handling). Invariants: CRC1 Output is exact match for zlib's crc32() / crc32c() for the same input. Known-answer: crc32("") = 0x00000000; crc32("123456789") = 0xCBF43926; crc32c("123456789") = 0xE3069283. CRC2 Input read-only; returns u32 result packed into the low 32 bits of i64. CRC3 No branch on data: the "conditionally xor" is a mask- multiply (0 or 1 times polynomial) -- not secret-time critical (CRC isn't crypto) but keeps the loop shape predictable.

dependencies 1 imports · 0 importers

syscalls.nx crc32.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

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

main crc32 crc32_core crc32c crc32_core ↻

structs

none

consts

41const CRC32_POLY: i64 = 0xEDB88320
42const CRC32C_POLY: i64 = 0x82F63B78
43const U32_MASK: i64 = 0xFFFFFFFF
44const U32_INIT: i64 = 0xFFFFFFFF

functions

48func crc32_core(poly: i64, bytes: *u8, n: i64, initial: i64) -> i64 {
called by 2: crc32crc32c
69func crc32(bytes: *u8, n: i64) -> i64 {
called by 1: main calls 1: crc32_core
75func crc32c(bytes: *u8, n: i64) -> i64 {
called by 1: main calls 1: crc32_core
83func main() -> i64 {
calls 2: crc32crc32c