code wiki / (root) / nx_adler32.nx

nx_adler32.nx

buildroot/runtime/nx_adler32.nx

2759 B88 linesdepth 2pulls 2 transitivereach 125 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 · 10 importers

nx_syscalls.nx nx_adler32.nx nx_adler32_real_test.nx nx_image_e2e_gate.nx nx_image_index_gate.nx nx_img_decode_gate.nx nx_img_to_rgb_gate.nx nx_imgquery_e2e_gate.nx nx_png_real_smoke.nx nx_revimg_crawl_gate.nx nx_sovgit_obj.nx nx_zlib_wrap.nx

imports: nx_syscalls.nx

imported by: nx_adler32_real_test.nxnx_image_e2e_gate.nxnx_image_index_gate.nxnx_img_decode_gate.nxnx_img_to_rgb_gate.nxnx_imgquery_e2e_gate.nxnx_png_real_smoke.nxnx_revimg_crawl_gate.nxnx_sovgit_obj.nxnx_zlib_wrap.nx

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

main adler32 adler32_init adler32_update

structs

none

consts

37const ADLER_MOD: i64 = 65521

functions

39func adler32(data: *u8, n: i64) -> i64
54func adler32_init() -> i64
called by 1: main
58func adler32_update(state: i64, data: *u8, n: i64) -> i64
called by 1: main
73func main() -> i64