adler32_combine
Compute the Adler-32 of A followed by B without reading either sequence.
Full chapter and shared rules ↗uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2);
Compute the Adler-32 of A followed by B without reading either sequence.
Return values and next calls
Return type. uLong — Checksum or length-rejection value
Returns the concatenated Adler-32 without reading A or B; negative lengths have a separate numeric result.
adler32_combine()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
0xFFFFFFFFNegative length rejected |
len2 < 0; no checksum restriction applies. | Correct the length of B before combining. |
Adler-32(A || B)Concatenated checksum |
len2 >= 0 is the length of B, and the low 32 bits of the inputs are the Adler-32 of A and B, each started at 1. | Use the result as the checksum of the concatenated sequence. |
Reading the result.
- 0xFFFFFFFF is not a valid Adler-32; ordinary and 64-bit entries have the same length range in this LP64 build.
Calling conditions and effects
Domain Restricted domain. Effects: pure computation.
Pre For the concatenation result, the low 32 bits of adler1 and adler2
are the Adler-32 checksums of A and B, and len2 is the length of B.
In particular, B's checksum starts at 1, independently of A.
Negative lengths are included only for the rejection result below.
Effects Preserve all memory and ownership. Read no buffers or stream state.
Proof goals.
- Goal.
Goal.adler32_combine_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.adler32_combine_safety(public-stateless-safety.lean). - Applies when. Always: the statement has no premise.
- Covered without condition. Every
adler1,adler2andlen2, also forged checksums and negative lengths; every heap. - Guarantees.
- Returns. The call returns.
- State, writes, allocations. None: the heap after the call is the heap before it.
- Not in this goal. The value returned: functional goal
Goal.adler32_combine(not planned; a theorem proves it).
Complete return conditions and boundaries
Post If len2 < 0, return 0xFFFFFFFF. Otherwise return the Adler-32
of A followed by B. An empty B has checksum 1 and leaves A's checksum unchanged.
Shared conditions and scope
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. For example, after processing A and then B, the checksum of A can be the starting value of the next update; if A and B were processed independently, the combination functions give the checksum of A followed by B.
In the update functions, buf points to this batch of input, len is its byte count, and the
incoming adler or crc is the value to continue from. In the combination functions, len2 is
the byte count of the second sequence B only, not the total length of the two.
| 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 |
The contracts follow the pinned adler32.c, crc32.c and zlib.h in the default LP64 Linux
static build. No patch touches these two C files (patches).
Dynamic table generation, hardware CRC hooks and generated table executables are not covered
(build and platform). 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.
These are focused contracts: Pre describes ordinary correct use and is deliberately narrower than
what the function accepts. A call outside Pre is not thereby undefined, and it need not return an
error code.
What is proved. Safety only (safety): each safety goal (Safety/Checksums.lean) says that the call returns and that the heap after the call is the heap before it. It says nothing about the value. Each entry gives its goal under Proof goals, in the five items and with the fixed phrases that Reading a Proof goals paragraph defines. The proof assumes the conditions listed there, not the documentary Pre. Post, the return tables and the notes describe functional behaviour. They are read from the C, are to confirm where no theorem states them, and are not required for the safety results. Progress says which goals are done.
The CRC goals have a premise on the model's heap: its two constant CRC tables, crc_table and
x2n_table, equal the tables of the translated crc32.h (CrcGlobals). The premise is assumed
of the heap the call starts on; no theorem derives it for an arbitrary heap. It is a condition on
the model, not a duty of the caller
(model limits). Two facts are
proved about it. A library heap, which is what the
stream goals start from, meets it (crc_globals_of_library). Each checksum goal returns the heap
unchanged, so the premise still holds after the call.
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 functional goals in Functional/Checksums.lean
also describe arbitrary seeds and exact scalar results. Both the Adler entries and their Lean
goals, safety and functional, require zero length for NULL initialization queries
(AdlerBufferBytes in Common/Checksums.lean).
See deviations.
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.
Safety goal
ZlibF.Spec.Public.Goal.adler32_combine_safety
State: done · Status of the results
/-- `uLong adler32_combine(uLong adler1, uLong adler2, z_off_t len2)`.
**Safety of `adler32_combine`**: for every argument, also forged checksums and negative lengths,
the call returns and the heap is unchanged. -/
def Goal.adler32_combine_safety : Prop :=
∀ (h : Heap) (first second : UInt64) (length : Int64),
∃ value, C.run (Zlib.Adler32.adler32_combine first second length) h = .ok (value, h)Related definitions and source ↗Functional contract (beyond safety)
ZlibF.Spec.Public.Goal.adler32_combine
State: done · Status of the results
/-- `uLong adler32_combine(uLong adler1, uLong adler2, z_off_t len2)`.
Total execution, immutable heap, negative-length rejection and checksum concatenation. -/
def Goal.adler32_combine : Prop := AdlerCombine Zlib.Adler32.adler32_combineRelated definitions and source ↗