Skip to content

feat: add IEEE CRC32 and CRC32C checksums - #27

Draft
tisonkun wants to merge 1 commit into
mainfrom
codex/crc-api
Draft

feat: add IEEE CRC32 and CRC32C checksums#27
tisonkun wants to merge 1 commit into
mainfrom
codex/crc-api

Conversation

@tisonkun

@tisonkun tisonkun commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Add IEEE CRC32 and Castagnoli CRC32C for checksumming existing records, pages, and protocol payloads. Both variants live under hashcrew::crc, behind the opt-in crc feature, and preserve the dependency-free, allocation-free, no_std library and Rust 1.85 MSRV.

  • Provide crc32_iso_hdlc / Crc32IsoHdlc and crc32_iscsi / Crc32Iscsi, with incremental updates, repeatable digest, reset, finalized-checksum resumption, and std::io::Write integration.
  • Provide variant-specific combine functions taking two finalized checksums and the right segment's u64 byte length.
  • Add differential tests against crc, crc32fast, and crc32c, covering byte boundaries, arbitrary partitions, zeroed checksum fields, resumption, concatenation, and lengths beyond 4 GiB.

Design Notes

Each state stores one u32. from_digest takes a finalized checksum, not a raw register seed; digest preserves the state. The two polynomials have distinct types and names. CRC operates on raw bytes without Hasher or BuildHasher adapters. Output byte order belongs to the consuming format.

This draft establishes the API and a safe slicing-by-8 scalar baseline with an 8 KiB compile-time table per variant. Hardware acceleration remains follow-up work. Ecosystem benchmarks cover short and large inputs and several streaming chunk sizes; competing crates retain their available hardware acceleration. crc-fast 1.10 is an optional benchmark comparison requiring Rust 1.89+, so ordinary workspace build/test workflows remain compatible with 1.85.

Local 1 MiB one-shot medians on Apple M4 Max, aarch64-apple-darwin, Rust 1.99.0-nightly (3d6c19bb9), in microseconds (lower is better):

Implementation IEEE CRC32 CRC32C
Hashcrew scalar 430.1 442.3
crc 3.4.0, Table<1> 2175 2068
crc 3.4.0, Table<16> 198.4 196.4
crc32fast 1.5.1 / crc32c 0.6.8 30.08 33.58
crc-fast 1.10.0, specialized helper 10.41 10.41

At 1 MiB with 64 KiB updates, Hashcrew measured 433.0 / 431.5 microseconds (IEEE / CRC32C). These short local runs establish the optimization gap; they are not a cross-platform performance claim.

Validation passed: cargo +1.85.0 x build --locked, cargo +1.85.0 x test, cargo +1.85.0 x check, cargo x lint, cargo x miri, and cargo x check --target <target> --no-std for thumbv7em-none-eabihf and wasm32-unknown-unknown.

Benchmark commands:

cargo x bench throughput --crc-fast -- crc32 --min-time 0.03 --max-time 0.08 --bytes-format binary
cargo x bench streaming --crc-fast -- crc32 --min-time 0.03 --max-time 0.08 --bytes-format binary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant