Package: crcengine
CrcEngineA python library for CRC calculation providing table-based as well as
bit-bashing implementations (for reference).Free software: GNU General Public License v3Documentation:https://crcengine.readthedocs.io.InstallingCrcEngine can be installing using pip withpipinstallcrcengineUsagePre-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 algorithmscrc8, 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-ecmaExamplesUsing a pre-defined algorithmimportcrcenginecrc_algorithm=crcengine.new('crc32-bzip2')result=crc_algorithm(b'123456789')print('CRC=0x{:08x}'.format(result))Output:
> CRC=0xfc891918Defining an algorithmimportcrcengineparams=crcengine.CrcParams(0x864cfb,24,0xb704ce,reflect_in=False,reflect_out=False,xor_out=0)crc_openpgp=crcengine.create_from_params(params)# this is equivalent tocrc_openpgp=crcengine.create(params=params)# invocationresult=crc_openpgp(b'123456789')print(f'CRC=0x{result:08x}')When using create()paramsmust be passed as a keyword parameter, since the function also accepts polynomial and seed
parameters for backwards compatibility.Code GenerationThe 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 seeintel_soft_srcfor example. Some processors
also include instructions specifically for crc calculation.Code Generation Example usage:Generating code into a directory named “out” by passing CRC parametersparams=crcengine.get_algorithm_params('crc32')crcengine.generate_code(params,'out/')or referencing the algorithm by namecrcengine.generate_code('crc16-xmodem','out/')DownloadingThe source is available ongithubGit clonecrcengine.gitOnpypi.orgRunning the testsTests can be performed directly by executing pytest in the “tests” directoryRunning the Codegen testsThe codegen tests make use ofceedlingwhich 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 ofCRC definitions