Checksums
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 not yet confirmed 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.
adler32_z
uLong ZEXPORT adler32_z(uLong adler, const Bytef *buf, z_size_t len);
Update an Adler-32 checksum with a byte range, or obtain its initial value.
Return values and next calls
Return type. uLong — 32-bit checksum
Returns the updated Adler-32, or the initial value for a new checksum.
adler32_z()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
1Initial value |
buf == NULL and len == 0, with any incoming checksum; no bytes are read. | Start a new sequence at 1. |
reduce(adler)Empty range reduces the seed |
buf is non-NULL and len == 0; a one-past pointer is also allowed for the empty range. reduce takes the low 32 bits and reduces each 16-bit half modulo 65521. The result equals low32(adler) when adler is a genuine Adler-32, because both halves of a genuine Adler-32 are below 65521. |
Keep this value for the next update. |
Adler-32(A || buf)Checksum after append |
buf covers len readable bytes, len > 0, and the low 32 bits of adler are the Adler-32 of A. | Use this value in later updates or compare it with the expected checksum. |
Calling conditions and effects
Domain. Restricted domain. Effects: read-only when buf is non-NULL.
Pre: Either buf is NULL and len == 0, or it points to len readable
bytes. For the checksum postcondition, the low 32 bits of adler are the Adler-32 of A.
There is no setup or cleanup requirement.
Effects: Preserve all memory and ownership. Read only the given range.
Forged seeds are outside this functional contract: the one-byte path need not agree with first reducing both seed halves modulo 65521. See the Adler seed note.
Proof goals.
- Goal.
Goal.adler32_z_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.adler32_z_safety(public-stateless-safety.lean). - Applies when.
bufis NULL withlen == 0, orbufpoints tolenreadable bytes (AdlerBufferBytes). Forlen == 0a pointer one past the end of an object is allowed. - Covered without condition. Every
adler, also a value that is not a checksum; every content of the bytes; every heap, with or without the library's tables. - Guarantees.
- Returns. The call returns.
- State, writes, allocations. None: the heap after the call is the heap before it.
- Not in this goal. NULL
bufwith a nonzerolen: outside every goal; this is narrower thanzlib.h(deviations, row "Adler initialization queries"). The value returned: functional goalGoal.adler32_z(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: A NULL, zero-length query returns 1 for every adler, without reading
bytes. Otherwise return the Adler-32 of A followed by buf[0..len-1].
A non-NULL zero-length range returns the low 32 bits of adler with each 16-bit half reduced
modulo 65521 (adlerStart in Common/Checksums.lean).
For a genuine Adler-32 that is the incoming checksum unchanged; a seed of 0x0000FFFF returns
0x0000000E.
adler32
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len);
Update an Adler-32 checksum using a 32-bit byte count.
Return values and next calls
Return type. uLong — 32-bit checksum
Returns the updated Adler-32, or the initial value for a new checksum.
adler32()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
1Initial value |
buf == NULL and len == 0, with any incoming checksum; no bytes are read. | Start a new sequence at 1. |
reduce(adler)Empty range reduces the seed |
buf is non-NULL and len == 0; a one-past pointer is also allowed for the empty range. reduce takes the low 32 bits and reduces each 16-bit half modulo 65521. The result equals low32(adler) when adler is a genuine Adler-32, because both halves of a genuine Adler-32 are below 65521. |
Keep this value for the next update. |
Adler-32(A || buf)Checksum after append |
buf covers len readable bytes, len > 0, and the low 32 bits of adler are the Adler-32 of A. | Use this value in later updates or compare it with the expected checksum. |
Reading the result.
- len is uInt, at most 2^32 - 1 bytes; a larger count converted to uInt loses its high bits before the call. Use the _z form or multiple updates for larger counts.
Calling conditions and effects
Domain. Restricted domain. Effects: read-only when buf is non-NULL.
Pre: Either buf is NULL and len == 0, or it points to len readable
bytes. For the checksum postcondition, the low 32 bits of adler are the Adler-32 of A.
Effects: Preserve all memory and ownership. Read only the given range.
The forged-seed scope of adler32_z applies here too.
Proof goals.
- Goal.
Goal.adler32_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.adler32_safety(public-stateless-safety.lean). - Applies when.
bufis NULL withlen == 0, orbufpoints tolenreadable bytes (AdlerBufferBytes). Forlen == 0a pointer one past the end of an object is allowed. - Covered without condition. Every
adler, also a value that is not a checksum; every content of the bytes; every heap, with or without the library's tables. - Guarantees.
- Returns. The call returns.
- State, writes, allocations. None: the heap after the call is the heap before it.
- Not in this goal. NULL
bufwith a nonzerolen: outside every goal; this is narrower thanzlib.h(deviations, row "Adler initialization queries"). The value returned: functional goalGoal.adler32(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: Return exactly the result of adler32_z(adler, buf, len).
A NULL, zero-length query returns 1. A non-NULL empty range returns the low 32 bits of
adler with each 16-bit half reduced modulo 65521, which preserves a genuine checksum.
adler32_combine
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.
adler32_combine64
uLong ZEXPORT adler32_combine64(uLong adler1, uLong adler2, z_off64_t len2);
Compute the Adler-32 of A followed by B with an explicit 64-bit length.
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_combine64()| 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 independently computed Adler-32 checksums of A and B, and len2 is the
length of B. Negative lengths are included for rejection.
Effects: Preserve all memory and ownership. Read no buffers or stream state.
This entry has the same contract as adler32_combine in LP64.
The explicit width matters on other builds; this page does not cover them.
Proof goals.
- Goal.
Goal.adler32_combine64_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.adler32_combine64_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_combine64(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: Return 0xFFFFFFFF for a negative length. Otherwise return the
Adler-32 of A followed by B. Empty B leaves A's checksum unchanged.
get_crc_table
const z_crc_t FAR * ZEXPORT get_crc_table(void);
Return the library's byte-at-a-time CRC table.
Return values and next calls
Return type. const z_crc_t FAR * — Borrowed read-only table pointer
Returns the address of the byte CRC update table. This call does not return a status code.
get_crc_table()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
table != NULL256-entry CRC table |
The fixed CRC tables are present; every call returns the same pointer. Entry i is the reflected update for byte i from register zero, without public checksum complements. | Read the 256 entries during the program lifetime; do not write to or free the table. |
Reading the result.
- z_crc_t is unsigned 32-bit in this build; the pointer exposes only the byte table, not adjacent or braided tables.
Calling conditions and effects
Domain. Full type domain; there are no arguments. Effects: pure computation returning a pointer to library memory; it does not read the entries.
Pre: The library's fixed CRC tables are present, as in the selected build. No setup call is required.
Effects: Preserve all memory and ownership. The library retains the table; it lives for the program's lifetime. The caller may read the 256 entries, and must neither write through the pointer nor free it.
Proof goals. No required goal: zlib.h declares this function under "undocumented functions (not part of the zlib API)". A functional goal is stated for it: Goal.get_crc_table (Functional/Checksums.lean) (not planned; a theorem proves it), with the theorem ZlibF.Spec.Public.Proofs.get_crc_table (public-get-crc-table.lean). On a heap that holds the library's CRC tables (CrcGlobals) it states that the call returns, that the heap is unchanged, and the table contents given under Post.
Complete return conditions and boundaries
Post: Return a non-NULL pointer to a read-only array of 256 z_crc_t
entries. Entry i is the reflected CRC register update for byte i, starting
with register zero and without the public checksum complements.
Repeated calls return the same pointer.
crc32_z
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.
Return values and next calls
Return type. uLong — 32-bit checksum
Returns the updated CRC-32, or the initial value for a new checksum.
crc32_z()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
0Initial value |
buf == NULL, with any len and incoming checksum; no buffer is read. | Start a new sequence at 0. |
low32(crc)Empty range preserves value |
buf is non-NULL and len == 0; a one-past pointer is also allowed for the empty range. | Keep this value for the next update. |
CRC-32(A || buf)Checksum after append |
buf covers len readable bytes, len > 0, and the low 32 bits of crc are the CRC-32 of A. | Use this value in later updates or compare it with the expected checksum. |
Reading the result.
- The function handles complements; do not complement the running checksum.
Calling conditions and effects
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.
Effects: Preserve all memory and ownership. Read only the given byte range and fixed library tables.
The word-access model's limits are recorded in the safety model and trusted base.
Proof goals.
- Goal.
Goal.crc32_z_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.crc32_z_safety(public-stateless-safety.lean). - Applies when:
- the heap holds the library's two constant CRC tables (
CrcGlobals), the condition on the model stated at the top of this page; bufis NULL, with anylen, orbufpoints tolenreadable bytes (BufferBytes). Forlen == 0a pointer one past the end of an object is allowed.
- the heap holds the library's two constant CRC tables (
- Covered without condition. Every
crc, also a value that is not a checksum; every content of the bytes; every alignment ofbuf. - 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.crc32_z(not planned; a theorem proves it).
Complete return conditions and boundaries
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.
crc32
uLong ZEXPORT crc32(uLong crc, const unsigned char FAR *buf, uInt len);
Update a CRC-32 checksum using a 32-bit byte count.
Return values and next calls
Return type. uLong — 32-bit checksum
Returns the updated CRC-32, or the initial value for a new checksum.
crc32()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
0Initial value |
buf == NULL, with any len and incoming checksum; no buffer is read. | Start a new sequence at 0. |
low32(crc)Empty range preserves value |
buf is non-NULL and len == 0; a one-past pointer is also allowed for the empty range. | Keep this value for the next update. |
CRC-32(A || buf)Checksum after append |
buf covers len readable bytes, len > 0, and the low 32 bits of crc are the CRC-32 of A. | Use this value in later updates or compare it with the expected checksum. |
Reading the result.
- len is uInt, at most 2^32 - 1 bytes; a larger count converted to uInt loses its high bits before the call. Use the _z form or multiple updates for larger counts.
Calling conditions and effects
Domain. Restricted domain. Effects: read-only when buf is non-NULL,
and reads fixed library 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 fixed CRC tables are present.
Effects: Preserve all memory and ownership. Read only the given byte range and fixed library tables.
Proof goals.
- Goal.
Goal.crc32_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.crc32_safety(public-stateless-safety.lean). - Applies when:
- the heap holds the library's two constant CRC tables (
CrcGlobals), the condition on the model stated at the top of this page; bufis NULL, with anylen, orbufpoints tolenreadable bytes (BufferBytes). Forlen == 0a pointer one past the end of an object is allowed.
- the heap holds the library's two constant CRC tables (
- Covered without condition. Every
crc, also a value that is not a checksum; every content of the bytes; every alignment ofbuf. - 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.crc32(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: Return exactly the result of crc32_z(crc, buf, len).
NULL returns 0 even with a nonzero length. A non-NULL empty range preserves
the incoming checksum's low 32 bits. Complement handling is internal.
crc32_combine_gen64
uLong ZEXPORT crc32_combine_gen64(z_off64_t len2);
Generate an operator for repeated CRC combinations with the same B length.
Return values and next calls
Return type. uLong — CRC combination operator
Generates a reusable operator for the byte length of B. The result is not a checksum.
crc32_combine_gen64()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
0Negative length rejected |
len2 < 0. | Correct the length; do not treat this value as a valid generated operator. |
0x80000000Operator for empty B |
len2 == 0. | Keep the operator unchanged for crc32_combine_op with empty B. |
op != 0Operator for the given length |
len2 > 0; returns a nonzero 32-bit operator. | Keep it unchanged and reuse it only for pairs whose B length equals len2. |
Calling conditions and effects
Domain. Full type domain. Effects: pure computation, reading only fixed library tables.
Pre: No argument restriction. The selected build's fixed CRC tables are
present. len2 may be any signed 64-bit value.
Effects: Preserve all memory and ownership. Read no buffers or stream state.
Proof goals.
- Goal.
Goal.crc32_combine_gen64_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.crc32_combine_gen64_safety(public-stateless-safety.lean). - Applies when. The heap holds the library's two constant CRC tables (
CrcGlobals), the condition on the model stated at the top of this page. - Covered without condition. Every
len2, also negative lengths. - 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.crc32_combine_gen64(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: A negative length returns 0. A nonnegative length returns a nonzero
32-bit operator suitable for crc32_combine_op when B has length len2.
For length zero, return 0x80000000.
crc32_combine_gen
uLong ZEXPORT crc32_combine_gen(z_off_t len2);
Generate a CRC combination operator using the ordinary offset type.
Return values and next calls
Return type. uLong — CRC combination operator
Generates a reusable operator for the byte length of B. The result is not a checksum.
crc32_combine_gen()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
0Negative length rejected |
len2 < 0. | Correct the length; do not treat this value as a valid generated operator. |
0x80000000Operator for empty B |
len2 == 0. | Keep the operator unchanged for crc32_combine_op with empty B. |
op != 0Operator for the given length |
len2 > 0; returns a nonzero 32-bit operator. | Keep it unchanged and reuse it only for pairs whose B length equals len2. |
Reading the result.
- Both entries accept all signed 64-bit lengths in this LP64 build.
Calling conditions and effects
Domain. Full type domain. Effects: pure computation, reading only fixed library tables.
Pre: No argument restriction. The selected build's fixed CRC tables are
present. len2 may be any representable signed value.
Effects: Preserve all memory and ownership. Read no buffers or stream state.
Proof goals.
- Goal.
Goal.crc32_combine_gen_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.crc32_combine_gen_safety(public-stateless-safety.lean). - Applies when. The heap holds the library's two constant CRC tables (
CrcGlobals), the condition on the model stated at the top of this page. - Covered without condition. Every
len2, also negative lengths. - 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.crc32_combine_gen(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: Return the same operator as crc32_combine_gen64(len2).
Negative lengths return 0; zero returns 0x80000000; positive lengths return
a nonzero 32-bit operator for that B length.
crc32_combine_op
uLong ZEXPORT crc32_combine_op(uLong crc1, uLong crc2, uLong op);
Compute the CRC-32 of A followed by B using a previously generated operator.
Return values and next calls
Return type. uLong — CRC-32 checksum or operator-rejection value
Applies a previously generated operator to two independent CRCs. A zero operator has a separate rejection result.
crc32_combine_op()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
0Zero operator rejected |
op == 0; any checksum arguments are allowed. | Generate a valid operator from the actual length of B. |
CRC-32(A || B)Concatenated CRC |
The low 32 bits of crc1 and crc2 are the CRCs of A and B, each started at 0; op is the unchanged operator generated for the length of B. | Use the result as the concatenated CRC; reuse the operator for the same B length. |
Reading the result.
- A valid CRC can also be zero; the return value alone cannot distinguish rejection from a valid result.
- Forged operators and operators for the wrong length have no functional guarantee.
Calling conditions and effects
Domain. Restricted domain. Effects: pure computation.
Pre: For the concatenation result, the low 32 bits of crc1 and crc2
are the CRC-32 checksums of A and B, each started at 0. op is the unchanged
result of crc32_combine_gen or crc32_combine_gen64 for the length of B.
The separate rejection case permits op == 0 with any checksum arguments.
Effects: Preserve all memory and ownership. Read no buffers or stream state.
With a nonzero LP64 op whose low 32 bits are zero the call does not return:
uLong has 64 bits, the loop in multmodp looks for a set bit only among bits 31 to 0 of op,
and it has no other exit. crc32_combine_op_diverges proves this of the translation: the run
ends in the model's out-of-fuel fault (CRC-32 proof). For the C it is a
reading of the source. Such an op is outside the premise of the safety goal below, which covers
only operators that a generator returned: a generated operator is below 2^32, and it is zero or
has a set bit.
Proof goals.
- Goal.
Goal.crc32_combine_op_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.crc32_combine_op_safety(public-stateless-safety.lean). - Applies when:
- the heap holds the library's two constant CRC tables (
CrcGlobals), the condition on the model stated at the top of this page; opis a value thatcrc32_combine_genorcrc32_combine_gen64returns for somelen2. This is the domainzlib.hgives.
- the heap holds the library's two constant CRC tables (
- Covered without condition. Every
crc1andcrc2, also forged checksums; everylen2the operator was generated for, also a negative one, for which the operator is 0. - Guarantees.
- Returns. The call returns.
- State, writes, allocations. None: the heap after the call is the heap before it.
- Not in this goal. An
opthat no generator call returned: outside every goal (deviations, row "CRC combination operator"). The value returned: functional goalGoal.crc32_combine_op(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: Return the CRC-32 of A followed by B. If op == 0, return 0.
An operator for an empty B leaves A's checksum unchanged.
crc32_combine64
uLong ZEXPORT crc32_combine64(uLong crc1, uLong crc2, z_off64_t len2);
Compute the CRC-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 CRC-32 without reading A or B; negative lengths have a separate numeric result.
crc32_combine64()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
0Negative length rejected |
len2 < 0; no checksum restriction applies. | Correct the length of B before combining. |
CRC-32(A || B)Concatenated checksum |
len2 >= 0 is the length of B, and the low 32 bits of the inputs are the CRC-32 of A and B, each started at 0. | Use the result as the checksum of the concatenated sequence. |
Reading the result.
- Zero can also be a valid CRC; a returned zero alone does not identify rejection.
Calling conditions and effects
Domain. Restricted domain. Effects: pure computation, reading only fixed library tables.
Pre: For the concatenation result, the low 32 bits of crc1 and crc2
are the independently computed CRC-32 checksums of A and B, and len2 is the
length of B. The fixed CRC tables are present. Negative lengths are included
for rejection, with no checksum restriction.
Effects: Preserve all memory and ownership. Read no buffers or stream state.
The generated operator satisfies crc32_combine_op's input requirement.
For arbitrary checksums at length zero, the implementation returns the XOR of the low 32 bits.
Proof goals.
- Goal.
Goal.crc32_combine64_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.crc32_combine64_safety(public-stateless-safety.lean). - Applies when. The heap holds the library's two constant CRC tables (
CrcGlobals), the condition on the model stated at the top of this page. - Covered without condition. Every
crc1,crc2andlen2, also forged checksums and negative lengths. - 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.crc32_combine64(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: A negative length returns 0. Otherwise return the CRC-32 of A followed by B. Empty B has CRC 0 and leaves A's checksum unchanged.
crc32_combine
uLong ZEXPORT crc32_combine(uLong crc1, uLong crc2, z_off_t len2);
Compute the CRC-32 of A followed by B using the ordinary offset type.
Return values and next calls
Return type. uLong — Checksum or length-rejection value
Returns the concatenated CRC-32 without reading A or B; negative lengths have a separate numeric result.
crc32_combine()| Returned value | Meaning and conditions | Caller’s next step |
|---|---|---|
0Negative length rejected |
len2 < 0; no checksum restriction applies. | Correct the length of B before combining. |
CRC-32(A || B)Concatenated checksum |
len2 >= 0 is the length of B, and the low 32 bits of the inputs are the CRC-32 of A and B, each started at 0. | Use the result as the checksum of the concatenated sequence. |
Reading the result.
- Zero can also be a valid CRC; a returned zero alone does not identify rejection.
Calling conditions and effects
Domain. Restricted domain. Effects: pure computation, reading only fixed library tables.
Pre: For the concatenation result, the low 32 bits of crc1 and crc2
are the CRC-32 checksums of A and B, each started at 0, and len2 is the length
of B. The fixed CRC tables are present. Negative lengths are included for
rejection, with no checksum restriction.
Effects: Preserve all memory and ownership. Read no buffers or stream state.
Proof goals.
- Goal.
Goal.crc32_combine_safety(Safety/Checksums.lean); required. Theorem:ZlibF.Spec.Public.StatelessSafetyProof.crc32_combine_safety(public-stateless-safety.lean). - Applies when. The heap holds the library's two constant CRC tables (
CrcGlobals), the condition on the model stated at the top of this page. - Covered without condition. Every
crc1,crc2andlen2, also forged checksums and negative lengths. - 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.crc32_combine(not planned; a theorem proves it).
Complete return conditions and boundaries
Post: Return the same result as crc32_combine64(crc1, crc2, len2).
Negative lengths return 0. A genuine empty B preserves A's checksum.