Skip to content
REFERENCE / ZLIB × LEAN

get_crc_table

Return the library's byte-at-a-time CRC table.

Full chapter and shared rules ↗
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 != NULL
256-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.

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.

Functional contract (beyond safety)

ZlibF.Spec.Public.Goal.get_crc_table

State: done · Status of the results

/-- `const z_crc_t *get_crc_table(void)`.
The returned table is static and read-only, has 256 entries given by the reflected CRC
recurrence, and leaves every heap observation unchanged. -/
def Goal.get_crc_table : Prop :=
  ∀ h : Heap, CrcGlobals h → ∃ pointer table,
    C.run Zlib.Crc32.get_crc_table h = .ok (pointer, h) ∧
    pointer = .ref .st_crc_table 0 ∧ Space.get h URef.st_crc_table = some table ∧
    Space.ro h URef.st_crc_table = true ∧ table.size = 256 ∧
    ∀ i : Fin 256, table[i.val]? = some (ZlibF.Spec.crcByte 0 (UInt8.ofNat i.val))
Related definitions and source ↗
ZLIB × LEAN

Contents

READING NOWget_crc_table