Checksums

Checksum consists of htf.checksum.CRC.

CRC

htf.checksum.CRC allows users to easily calculate crc checksums over data.

class htf.checksum.CRC(width: int, polynomial: int, reflect_input: bool, initial_value: int, reflect_output: bool, xor_output: int)

A configurable CRC calculator.

The CRC constructor.

Parameters:
  • width – the CRC’s width in bits

  • polynomial – the CRC’s polynomial

  • reflect_input – if set to True input is reflected

  • initial_value – the initial value

  • reflect_output – if set to True output is reflected

  • xor_output – xor all outputs with xor_output

calculate(data: str | bytes | List[int]) int

Calculates the crc over data bit by bit.

Parameters:

data – the input data to be used for the crc calculation

Returns:

the calculated crc for data

Return type:

int

Example

This example calculates a CRC-16 over "123456789".

from htf.checksum import CRC

crc16 = CRC(width=16,
            polynomial=0x8005,
            reflect_input=True,
            initial_value=0,
            reflect_output=True,
            xor_output=0)

result = crc16.calculate(b"123456789")
assert result == 0xBB3D

Changelog

htf-checksum-3.1.4

  • add requirements for validation purposes

htf-checksum-3.1.3

  • add build environment data for validation purposes

htf-checksum-3.1.2

  • htf-checksum can now be used standalone

htf-checksum-3.1.1

  • add support for Python 3.12

htf-checksum-3.1.0

  • add type-hints

  • use hlm-3.1

htf-checksum-3.0.1

  • add support for Python 3.11

htf-checksum-3.0.0

  • extract htf-checksum from htf