<!-- HILSTER htf 4.3.1 -->
**htf 4.3.1** · [HTML](../checksums.html) · [Complete PDF manual](../_downloads/htf-4.3.1.pdf)

# Checksums

Checksum consists of [`htf.checksum.CRC`](#htf.checksum.CRC).

## CRC

[`htf.checksum.CRC`](#htf.checksum.CRC) allows users to easily calculate crc checksums
over data.

<a id="module-htf.checksum"></a>

### *class* htf.checksum.CRC(width: [int](https://docs.python.org/3/builtins/functions.html#int), polynomial: [int](https://docs.python.org/3/builtins/functions.html#int), reflect_input: [bool](https://docs.python.org/3/builtins/functions.html#bool), initial_value: [int](https://docs.python.org/3/builtins/functions.html#int), reflect_output: [bool](https://docs.python.org/3/builtins/functions.html#bool), xor_output: [int](https://docs.python.org/3/builtins/functions.html#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](https://docs.python.org/3/builtins/stdtypes.html#str) | [bytes](https://docs.python.org/3/builtins/stdtypes.html#bytes) | [List](https://docs.python.org/3/library/typing.html#typing.List)[[int](https://docs.python.org/3/builtins/functions.html#int)]) → [int](https://docs.python.org/3/builtins/functions.html#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](https://docs.python.org/3/builtins/functions.html#int)

### Example

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

```python
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.2.0

> - ship `cp312-abi3` wheels that are compatible with Python 3.12 and newer versions

### htf-checksum-3.1.6

> - implement Cyber Resilience Act Conformity (CRA)
> - update dependencies

### htf-checksum-3.1.5

> - add support for Python 3.13

### 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`
