Skip to main content

Verified CRC source-code for C, Rust, VHDL, Python — catalogue-driven, self-test embedded.

Project description

crcglot

tests coverage ruff ty

Verified CRC source code for C, Rust, VHDL, and Python. Catalogue-driven, self-test embedded, multi-language by design.

LLMs will gladly write you CRC code. It might even be right. crcglot guarantees the generated code matches the canonical reveng catalogue test vector (crc("123456789") == <check value>) and ships a self-test you can run on your toolchain to prove it.

Quick start

pip install crcglot

crcglot c crc32 --slice8 file=mycrc       # → mycrc.h + mycrc.c
crcglot rust crc64-xz --slice8 > mycrc.rs
crcglot vhdl crc32 > mycrc.vhd
crcglot python crc16-modbus > mycrc.py

crcglot list                              # browse the catalogue
crcglot info crc32                        # show parameters

What you get per language

Function Purpose
<fname>_init / _update / _finalize Streaming triple — feed data chunk by chunk
<fname> One-shot wrapper that calls the streaming triple
<fname>_self_test Verify against the reveng check value on your toolchain

C / Rust / VHDL ship _self_test() returning 0/1 (or boolean for VHDL). Python verifies via the docstring's check: line — the same interpreter generated it.

CLI reference

crcglot <command> [options...]

crcglot list [GLOB]

Browse the catalogue. Optional GLOB filters by shell-style pattern (e.g. crc16-*). Exit code 1 if nothing matches.

crcglot list                # all 71 algorithms
crcglot list 'crc32-*'      # just the CRC-32 family

crcglot info <name>

Print parameters (width, poly, init, refin, refout, xorout, check, desc) for one algorithm. Exit 1 on unknown name.

crcglot info crc64-xz

crcglot {c | python | rust | vhdl} <algorithm> [options...] [tokens...]

Generate source code for the chosen target language.

Option / token Effect
(default) bit-by-bit Smallest code, zero RAM table, slowest. All widths.
--table 256-entry lookup table, 4-8× faster. All widths.
--slice8 8 lookup tables, 5-10× faster than --table. CRC-32 / CRC-64 only.
--custom Use raw Rocksoft/Williams params instead of a catalogue lookup (see below).
file=STEM Write to disk. C → STEM.h + STEM.c; python/rust/vhdl → STEM.py/.rs/.vhd. Omit for stdout.
symbol=NAME Override the emitted function name. Default: derived from algorithm, or from file=STEM if given.

Rules:

  • --table and --slice8 are mutually exclusive (exit 2 if both given).
  • --slice8 python silently falls back to --table (CPython's per-int overhead eats the slice-by-8 speedup; stderr warns).
  • Without file=, output goes to stdout. For C, header is emitted first, then source.
  • C / Rust / VHDL files embed <symbol>_self_test() returning 0 on success. In constrained embedded targets, standard toolchain flags (-Wl,--gc-sections for C, LTO for Rust) strip whatever you don't call.

--custom (raw Rocksoft/Williams parameters)

For algorithms not in the catalogue:

crcglot c --custom width=16 poly=0x1234 init=0xFFFF \
         refin=true refout=true xorout=0x0000 file=mycustom
Param Required Notes
width=N yes 8, 16, 32, or 64 only
poly=X yes Hex (0x...) or decimal
init=X no Default 0. Hex or decimal.
refin=B no Default false. Accepts true/false/1/0/yes/no/on/off.
refout=B no Default false. Same boolean syntax.
xorout=X no Default 0.
name=NAME no Default crc_custom. Used in generated comments.
desc=TEXT no Free-form description in comments.

The check value for the custom parameters is computed automatically (_generic_crc(b"123456789", ...)) and embedded into the generated _self_test().

Catalogue

64+ algorithms covering everything from CRC-8 (ATM, AUTOSAR, Bluetooth, Maxim 1-Wire) through CRC-16 (Modbus, XMODEM, CCITT, IBM SDLC) through CRC-32 (Ethernet, bzip2, iSCSI, AUTOSAR) to CRC-64 (XZ, ECMA-182, NVMe, Redis). Browse with crcglot list.

Example output

See EXAMPLES.md for the actual generated source for crc32 across all 9 language × implementation combinations (C / Rust / Python / VHDL crossed with bit-by-bit, table-driven, and slice-by-8 where supported). Every block is reproducible with one CLI command.

Acknowledgments

CRC catalogue data is derived from Greg Cook's reveng project — the canonical source for CRC algorithm parameters since 1999.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

crcglot-0.2.0.tar.gz (25.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

crcglot-0.2.0-py3-none-any.whl (31.5 kB view details)

Uploaded Python 3

File details

Details for the file crcglot-0.2.0.tar.gz.

File metadata

  • Download URL: crcglot-0.2.0.tar.gz
  • Upload date:
  • Size: 25.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for crcglot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4239695f22b5b93fcebf11e367f3bef07b2413feb59e8328a6d404bad776afbd
MD5 df876bc63c1d8c1156781f118839791d
BLAKE2b-256 621bcd5c00e59a76aad166328fec9ef3a59680ec8e747f4c861b82e627ccd737

See more details on using hashes here.

Provenance

The following attestation bundles were made for crcglot-0.2.0.tar.gz:

Publisher: publish.yml on hucker/crcglot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crcglot-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: crcglot-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 31.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for crcglot-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c4689656fcede31ce26d10b6efffb7c79ee44d9a3e13211a8f8635f123173cb
MD5 c9e38956e63f5d85b96c9868cd6f167e
BLAKE2b-256 0cb7c30dd14f933ae44c0fa351eb6bb5ddce7d364839d74cd89b947e022f4b09

See more details on using hashes here.

Provenance

The following attestation bundles were made for crcglot-0.2.0-py3-none-any.whl:

Publisher: publish.yml on hucker/crcglot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page