Skip to main content
https://img.shields.io/pypi/v/crcengine.svg https://img.shields.io/github/actions/workflow/status/GardenTools/CrcEngine/python-package.yml https://img.shields.io/pypi/pyversions/CrcEngine.svg https://img.shields.io/pypi/format/CrcEngine.svg Documentation Status

CrcEngine

A python library for CRC calculation providing table-based as well as bit-bashing implementations (for reference).

Installing

CrcEngine can be installing using pip with

pip install crcengine

Usage

Pre-defined algorithms such as CRC32 are available. Tailored algorithms can be created by calling CrcEngine.create() and other related methods.

A calculation engine for a specific named algorithm can be obtained using CrcEngine.new(). Algorithms which are not pre-defined can be created using CrcEngine.create()

A list of pre-defined algorithms can be obtained using crcengine.algorithms_available()

>>> list(crcengine.algorithms_available())
['crc8', 'crc8-autosar', 'crc8-bluetooth', 'crc8-ccitt', 'crc8-gsm-b', 'crc8-sae-j1850', 'crc15-can', 'crc16-kermit', 'crc16-ccitt-true', 'crc16-xmodem', 'crc16-autosar', 'crc16-ccitt-false', 'crc16-cdma2000', 'crc16-ibm', 'crc16-modbus', 'crc16-profibus', 'crc24-flexray16-a', 'crc24-flexray16-b', 'crc32', 'crc32-bzip2', 'crc32-c', 'crc64-ecma']

Built-in algorithms

crc8, crc8-autosar, crc8-bluetooth, crc8-ccitt, crc8-gsm-b, crc8-sae-j1850, crc15-can, crc16-kermit, crc16-ccitt-true, crc16-xmodem, crc16-autosar, crc16-ccitt-false, crc16-cdma2000, crc16-ibm, crc16-modbus, crc16-profibus, crc24-flexray16-a, crc24-flexray16-b, crc32, crc32-bzip2, crc32-c, crc64-ecma

Examples

Using a pre-defined algorithm

import crcengine
crc_algorithm = crcengine.new('crc32-bzip2')
result = crc_algorithm(b'123456789')
print('CRC=0x{:08x}'.format(result))

Output: > CRC=0xfc891918

Defining an algorithm

import crcengine
params = crcengine.CrcParams(0x864cfb, 24, 0xb704ce, reflect_in=False, reflect_out=False, xor_out=0)
crc_openpgp = crcengine.create_from_params(params)
# this is equivalent to
crc_openpgp = crcengine.create(params=params)
# invocation
result = crc_openpgp(b'123456789')
print(f'CRC=0x{result:08x}')

When using create() params must be passed as a keyword parameter, since the function also accepts polynomial and seed parameters for backwards compatibility.

Code Generation

The library can generate C code for a given table-algorithm. The code produced is intended to be a reasonable compromise between size, complexity and speed without requiring allocation of memory for table generation at runtime.

Faster implementations of specific algorithms can be achieved in software which unroll loops and pipeline the operations different bytes to introduce parallelism in the calculation see intel_soft_src for example. Some processors also include instructions specifically for crc calculation.

Code Generation Example usage:

Generating code into a directory named “out” by passing CRC parameters

params = crcengine.get_algorithm_params('crc32')
crcengine.generate_code(params, 'out/')

or referencing the algorithm by name

crcengine.generate_code('crc16-xmodem', 'out/')

Downloading

Running the tests

Tests can be performed directly by executing pytest in the “tests” directory

Running the Codegen tests

The codegen tests make use of ceedling which is expected to be installed as a ruby gem. The unit tests are configured to compile with gcc.


With thanks to Greg Cook for providing such a thoroughly collated list of CRC definitions

Release files for crcengine 0.4.0.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crcengine 0.4.0.post1
File Size Uploaded
crcengine-0.4.0.post1.tar.gz 31.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crcengine 0.4.0.post1
File Interpreter ABI Platform
crcengine-0.4.0.post1-py3-none-any.whl Python 3 none any Details

Total release size: 71.7 kB

Release files / crcengine-0.4.0.post1.tar.gz

Download URL crcengine-0.4.0.post1.tar.gz
Size 31.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6dd0640dcb27692299f1156bcae9061e8ec4f7a90fec7c0d882a2ee4544a8eb0
BLAKE2b-256 checksum
How to use checksums
10786369a058f50319e54fdabadf9a8fa44cd69aef4afa64519e8240b886217b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.4

Release files / crcengine-0.4.0.post1-py3-none-any.whl

Download URL crcengine-0.4.0.post1-py3-none-any.whl
Size 40.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
422c0ba6c7c0ef172fed41f2888b24ded27cb8a767baf42b265b3b5eea77bb7b
BLAKE2b-256 checksum
How to use checksums
88574fddb77d87163862e78933ebb097292cbdf3ca91475a788c9f33d5d21323
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.4

Release history Release notifications | RSS feed

This release

0.4.0.post1 This release

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page