[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
Draft
[Repo Assist] feat: add l_crc32 and l_crc32_update — CRC-32/ISO-HDLC checksum#156github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
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>
This was referenced Apr 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist.
Summary
Implements
l_crc32andl_crc32_update— CRC-32/ISO-HDLC (IEEE 802.3 / gzip / zip) checksums — asstatic inlinefunctions inl_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
Implementation
Bit-by-bit (8 iterations/byte), fully unrolled, reflected polynomial
0xEDB88320(IEEE 802.3). No tables, no allocations, no initialization — purestatic 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:"123456789"0xCBF439260x00000000"abc"0x352441C2"The quick brown fox..."0x414FA3390x000xD202EF8DTest Status
✅
./Taskfile test— all non-infrastructure tests pass. (BearSSL submodule absent in this environment — pre-existing, not caused by this change.)