crc32_z
Update a CRC-32 checksum with a byte range, or obtain its initial value.
Full chapter and shared rules ↗57ad356e10ec68ee · Source at the matching commit ↗Read the function’s preconditions and results first. Expand the shared rules below for buffer and ownership requirements used throughout this API group.
uLong ZEXPORT crc32_z(uLong crc, const unsigned char FAR *buf, z_size_t len);
Update a CRC-32 checksum with a byte range, or obtain its initial value.
Domain Restricted domain. Effects: read-only when buf is non-NULL,
and reads the fixed library CRC tables.
Pre Either buf is NULL, or it points to len readable bytes, at any
alignment. For the checksum postcondition, the low 32 bits of crc are the
CRC-32 of A. The selected build's fixed CRC tables are present.
Post A NULL buf returns 0 for every crc and len, without reading the
buffer. Otherwise return the CRC-32 of A followed by buf[0..len-1].
A non-NULL empty range returns the low 32 bits of crc.
Effects Preserve all memory and ownership. Read only the given byte range and fixed library tables. A one-past pointer is allowed for an empty range.
Start a new checksum at 0. The function performs the CRC complements itself; the caller must not complement the running value. Alignment does not change the contract. The word-access model's limits are recorded in the safety model and trusted base.
Shared conditions and scope
API manual · Contract conventions · Buffer utilities
Compute a checksum a buffer at a time, or combine the checksums of independently processed byte sequences without rereading them. The byte sequences A and B below are ordinary data; the contracts use the Adler-32 or CRC-32 of those sequences.
| Task | Entries |
|---|---|
| Update Adler-32 | Size-type length, 32-bit length |
| Combine Adler-32 | Ordinary offset, explicit 64-bit offset |
| Update CRC-32 | Size-type length, 32-bit length |
| Combine CRC-32 | Ordinary offset, explicit 64-bit offset |
| Reuse a CRC combination operator | Generate, generate with 64-bit length, apply |
| Inspect the byte table | get_crc_table |
These focused contracts follow adler32.c, crc32.c and zlib.h in the default LP64 Linux
static build, with the pinned source and listed patches. Source readings are to confirm
by proof. No checksum entry writes state, allocates, frees or performs I/O. Exceptional
numeric results are ordinary values, rather than error codes. Domain and effects remain
independent as explained in contract conventions.
The practical checksum contracts use actual byte sequences A and B. Each checksum is computed independently, starting at 1 for Adler-32 or 0 for CRC-32. These contracts deliberately omit functional promises for forged checksums. The Lean targets also describe arbitrary seeds and exact scalar results. Both the Adler entries and their Lean targets require zero length for NULL initialization queries. See scope deviations and public goals.
In this build, uLong and z_size_t are unsigned 64-bit types; uInt is
unsigned 32-bit. z_off_t and z_off64_t are signed 64-bit. Input checksum bits
above bit 31 are ignored; returned checksums fit in 32 bits. The explicit
*64 declarations depend on the header's large-file feature macros.
Formal contract
ZlibF.Spec.Public.Goal.crc32_z
Proof status: Registered proof · Evidence and remaining work
/-- `uLong crc32_z(uLong crc, const Bytef *buf, z_size_t len)`.
All readable represented buffers, alignments, seeds and 64-bit lengths. NULL returns zero.
The exact RFC recurrence is returned and the heap is unchanged. -/
def Goal.crc32_z : Prop :=
∀ (h : Heap) (seed : UInt64) (pointer : BPtr) (length : UInt64) (bytes : List UInt8),
CrcGlobals h → BufferBytes h pointer length.toNat bytes →
C.run (Zlib.Crc32.crc32_z seed pointer length) h =
.ok ((if pointer = .null then 0 else (ZlibF.Spec.crc32Update seed.toUInt32 bytes).toUInt64), h)Related definitions and source ↗