Adler-32
Adler-32 is a 32-bit checksum formed from two running sums modulo 65521.
Start with s1=1, s2=0. For byte b, update s1=(s1+b) mod 65521, then s2=(s2+s1) mod 65521. Return 65536*s2+s1; empty input gives 1. The zlib trailer stores it most-significant byte first. [1]
The trailer covers decoded output, not compressed bytes or the separately supplied dictionary. Dictionary bytes copied into output are covered. DICTID separately checks the dictionary. A compliant decoder must check ADLER32 and report a mismatch. [1]
Raw DEFLATE has no wrapper checksum; gzip uses CRC32. The zlib library handles all three, so its name does not identify the checksum. Adler-32 supports incremental updates. [2]
The bytes 00 02 00 and 01 00 01 both have s1=3, s2=7 and checksum 0x00070003. Changes +1,-2,+1 cancel both sums. These deliberate collisions are not estimates of accidental-corruption frequency. [4] [5]
RFC 3309 explains SCTP's 2002 switch to CRC32C, including short-packet nonuniformity. For 128 bytes, s1 is between 1 and 32641 and cannot wrap. Neither is a storage error-rate estimate. [3] [4]
All 65536 two-byte inputs have distinct checksums. The sums s1=1+a+b and s2=2+2*a+b give a=s2-s1-1 and b=2*s1-s2. Exhaustive checks confirm this fixed-length result. It does not extend to the three-byte collision above. Unused output values alone do not determine undetected-error probability. [4]
Relations
- related
- Checksum, DEFLATE, Gzip, Compression dictionary, CRC-32C, Hash collision
Advantages
- Incremental updates allow the same checksum to be computed while processing successive chunks. [2]
Limitations
- A matching value does not prove byte identity or authenticate data; the constructed collision changes the input without changing its original checksum. [4, 5]
- Output width alone does not imply an undetected-error probability of 2^-32; message length, contents and the error model matter. [3]
Citations
- RFC 1950: ZLIB Compressed Data Format Specification version 3.3, sections 2.2-2.3
- zlib manual: inflateInit2, deflateSetDictionary and checksum functions
- RFC 3309: SCTP Checksum Change, section 1 (September 2002)
- Hesela: Adler-32 arithmetic and native zlib regression checks
- Hesela: When both zlib checksums accept the wrong dictionary
Sources & caveats
- Primary-format and API synthesis. RFC 1950 is Informational; RFC 3309 supplies historical SCTP context. The illustrative collision is exact arithmetic with native-library controls, not a new codec defect, benchmark or hardware experiment.