nx_adler32.nx
buildroot/runtime/nx_adler32.nx
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
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
structs
| none |
consts
| 37 | const ADLER_MOD: i64 = 65521 |
functions
| 39 | func adler32(data: *u8, n: i64) -> i64 |
| 54 | func adler32_init() -> i64 called by 1: main |
| 58 | func adler32_update(state: i64, data: *u8, n: i64) -> i64 called by 1: main |
| 73 | func main() -> i64 |