code wiki / (root) / adler32.nx

adler32.nx

buildroot/runtime/adler32.nx

2587 B82 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

adler32.nx -- Adler-32 checksum (Mark Adler, zlib/gzip). 32-bit rolling checksum used inside zlib streams (RFC 1950) and pigz / gzip integrity checks. Faster than CRC-32 at the cost of worse collision resistance -- acceptable for short frames, weak for megabyte-scale files. Algorithm: a = 1; b = 0 for each byte x: a = (a + x) mod 65521 b = (b + a) mod 65521 checksum = (b << 16) | a 65521 is the largest prime less than 2^16. The running quantities a,b never exceed 2^32 if we reduce after every NMAX = 5552 bytes (Adler's tuning so we can defer the modulo). We do the naive per-byte modulo here; simplest; still trivially beats a CRC table. Invariants: A1 Empty input gives checksum = 1 (a=1, b=0). A2 Output fits in a 32-bit unsigned; we return it in an i64 to avoid sign issues in downstream callers. A3 adler32_combine not implemented (zlib has a closed-form but it needs 64-bit modular arithmetic tricks -- future commit if we need to concatenate streams).

dependencies 1 imports · 0 importers

syscalls.nx adler32.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 adler32 adler32_init adler32_update

structs

none

consts

31const ADLER_MOD: i64 = 65521

functions

33func adler32(data: *u8, n: i64) -> i64 {
called by 1: main
48func adler32_init() -> i64 {
called by 1: main
52func adler32_update(state: i64, data: *u8, n: i64) -> i64 {
called by 1: main
67func main() -> i64 {