Skip to content

[Repo Assist] feat: add l_crc32 and l_crc32_update — CRC-32/ISO-HDLC checksum#156

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/feat-crc32-2026-04-26-fde1ffc4698948af
Draft

[Repo Assist] feat: add l_crc32 and l_crc32_update — CRC-32/ISO-HDLC checksum#156
github-actions[bot] wants to merge 1 commit intomainfrom
repo-assist/feat-crc32-2026-04-26-fde1ffc4698948af

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist.

Summary

Implements l_crc32 and l_crc32_update — CRC-32/ISO-HDLC (IEEE 802.3 / gzip / zip) checksums — as static inline functions in l_os.h.

Motivation

CRC-32 is the most widely used non-cryptographic checksum (gzip, zip, Ethernet frames, PNG). The library already has SHA-256, HMAC-SHA-256, and Base64. Adding CRC-32 completes the most common checksum/encoding needs without external dependencies.

API

/// One-shot CRC-32/ISO-HDLC checksum over len bytes of data.
unsigned int l_crc32(const void *data, size_t len);

/// Incremental update: pass crc=0 for the first chunk.
/// Feed subsequent chunks with the returned value.
unsigned int l_crc32_update(unsigned int crc, const void *data, size_t len);

Implementation

Bit-by-bit (8 iterations/byte), fully unrolled, reflected polynomial 0xEDB88320 (IEEE 802.3). No tables, no allocations, no initialization — pure static inline. On x86-64/AArch64, GCC/clang typically emit branchless CMOV/CSEL for the inner loop.

Tests

Six new tests in tests/test_utils.c:

Test Value
RFC 3720 check value "123456789" 0xCBF43926
Empty string 0x00000000
"abc" 0x352441C2
"The quick brown fox..." 0x414FA339
Two-chunk incremental matches single-shot
Single zero byte 0x00 0xD202EF8D

Test Status

./Taskfile test — all non-infrastructure tests pass. (BearSSL submodule absent in this environment — pre-existing, not caused by this change.)

Generated by 🌈 Repo Assist at {run-started}. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@1f672aef974f4246124860fc532f82fe8a93a57e

Implements the CRC-32/ISO-HDLC checksum (IEEE 802.3 polynomial,
0xEDB88320 in reflected form — same as gzip, zip, Ethernet).

API:
  l_crc32(data, len)                  — one-shot checksum
  l_crc32_update(crc, data, len)      — incremental (streaming) update

Both functions are static inline and require no tables, no
initialization, and no allocations — matching the freestanding style of
the rest of the library.

The bit-by-bit implementation processes 8 bits per byte (8 unrolled
conditional XORs), which compilers typically lower to branchless code
with CMOVcc / CSEL on x86-64 and AArch64.

Tests added to tests/test_utils.c:
  - RFC 3720 check value: CRC-32("123456789") == 0xCBF43926
  - Empty input: CRC-32("") == 0x00000000
  - "abc" == 0x352441C2
  - "The quick brown fox..." == 0x414FA339
  - Incremental two-chunk feeding matches single-shot
  - Single zero byte == 0xD202EF8D

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants