crc8-pure
Zero-dependency, pure-Python CRC-8 over 7 RevEng-catalogued variants.
crc8-pure provides a single, self-contained implementation of seven widely
used CRC-8 variants — crc-8, crc-8-darc, crc-8-i-code, crc-8-itu
(CCITT), crc-8-maxim (DOW), crc-8-rohc, and crc-8-wcdma — together
with a class-based incremental API and a command-line entry point. No
C-extension dependencies; only the Python standard library is used at
runtime.
Install
pip install crc8-pure
Or from a local checkout:
pip install -e .
Requires Python ≥ 3.8. There are no runtime dependencies.
Quickstart
import crc8_pure
# Functional API: returns an int 0–255
crc8_pure.crc8(b"hello") # crc-8 variant (default)
crc8_pure.crc8(b"hello", variant="crc-8-maxim")
crc8_pure.crc8_maxim(b"hello") # convenience wrapper
# Incremental / streaming API
crc8_pure.crc8(b"hel", init=0x00)
crc8_pure.crc8(b"lo", init=<prev>) # continues from previous state
# Class API
h = crc8_pure.CRC8(variant="crc-8-maxim")
h.update(b"hello")
h.digest() # -> bytes
h.hexdigest() # -> "3b"
CLI
# String input
python -m crc8_pure crc8-maxim "123456789"
# Hex-prefixed output
python -m crc8_pure crc8 "123456789" --hex
# File input
python -m crc8_pure crc8-maxim path/to/file.bin
# Read from stdin
cat file.bin | python -m crc8_pure crc-8 -
7 Variants
| Variant | Polynomial | Init | RefIn | RefOut | XOR Out | Check ("123456789") |
|---|---|---|---|---|---|---|
crc-8 |
0x07 |
0x00 |
no | no | 0x00 |
0xF4 |
crc-8-darc |
0x39 |
0x00 |
yes | yes | 0x00 |
0x15 |
crc-8-i-code |
0x1D |
0xFD |
no | no | 0x00 |
0x7E |
crc-8-itu |
0x07 |
0x55 |
no | no | 0x55 |
0xA1 |
crc-8-maxim |
0x31 |
0x00 |
yes | yes | 0x00 |
0xA1 |
crc-8-rohc |
0x07 |
0xFF |
yes | yes | 0x00 |
0xD0 |
crc-8-wcdma |
0x9B |
0x00 |
yes | yes | 0x00 |
0x25 |
Check values come from the
RevEng CRC Catalogue
and have been verified byte-exact against crcmod.
Aliases: CCITT → crc-8-itu, MAXIM → crc-8-maxim,
DOW-CRC → crc-8-maxim.
API
crc8(data=b"", variant="crc-8", init=None) -> int
Compute a CRC-8 checksum. init lets you resume from a previous partial
result: crc8(b"lo", init=crc8(b"hel")) is equivalent to
crc8(b"hello").
CRC8(variant="crc-8", init=None)
Incremental calculator. Use update(data) to feed bytes, then
digest() (bytes) or hexdigest() (string).
CLI
python -m crc8_pure <variant> [FILE_OR_STRING...] [--hex]
If no input is given (or -), data is read from stdin. A single argument
is treated as a file path if it exists, otherwise as a string literal.
Multiple arguments are concatenated.
Tests
pip install pytest
pytest -q
The test suite covers all 21 canonical vectors (3 inputs × 7 variants) plus boundary conditions, alias resolution, incremental equivalence, class API, and CLI smoke tests.
Current test count: 126 tests.
Known Issues / Limitations
The following are honest documented limits of crc8-pure:
- CRC-8 is not cryptographic. CRC-8 is for error-detection on trusted media; do not use it as a cryptographic integrity check or MAC.
- CLI stdin/file materialization.
python -m crc8_pure <variant> <file>fully materializes the file into RAM before processing. For multi-GB inputs this may exhaust memory; no streaming boundary is applied. - Thread-safety. A
CRC8instance is not safe for concurrentupdate()calls from multiple threads; create one instance per thread. dataaccepts non-bytes silently. Pass bytes-like objects (bytes/bytearray/ memoryview). Passing a non-bytes value will produce a non-canonical result without raising an error.- No
CRC8.copy()/CRC8.reset(). Re-using aCRC8instance requires constructing a new one; there is nocopy()orreset()method.
License
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crc8_pure-0.1.0.tar.gz.
File metadata
- Download URL: crc8_pure-0.1.0.tar.gz
- Upload date:
- Size: 8.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
736c715362a8afb76f2b66a039540a45e14b53b4e6777ecb78166086b5d23d72
|
|
| MD5 |
aeae54a35f4b620814cd87f7659f021b
|
|
| BLAKE2b-256 |
951644929aed135d3ac7aa2ee2b5ad83fe51e7a0510ee3d7b91e04e4ca7737d0
|
File details
Details for the file crc8_pure-0.1.0-py3-none-any.whl.
File metadata
- Download URL: crc8_pure-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a602559119b04640d802e9f3542f15d63f88644c70d2aef602b6580d9b3337e
|
|
| MD5 |
1ba270982323eb2ac630eec2bad0018f
|
|
| BLAKE2b-256 |
5d7b0129b62e8536bf77824ff53d10f3da5909d0c2ec64b81b0eeb8f3f2c683c
|