crc32.nx
buildroot/runtime/crc32.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 41 | const CRC32_POLY: i64 = 0xEDB88320 |
| 42 | const CRC32C_POLY: i64 = 0x82F63B78 |
| 43 | const U32_MASK: i64 = 0xFFFFFFFF |
| 44 | const U32_INIT: i64 = 0xFFFFFFFF |
functions
| 48 | func crc32_core(poly: i64, bytes: *u8, n: i64, initial: i64) -> i64 { |
| 69 | func crc32(bytes: *u8, n: i64) -> i64 { |
| 75 | func crc32c(bytes: *u8, n: i64) -> i64 { |
| 83 | func main() -> i64 { |