CRC32C Checksum Library

2.8 · active · verified Mon Apr 06

The `crc32c` Python package provides an implementation of the CRC32C checksum algorithm, intelligently leveraging hardware acceleration (Intel SSE 4.2, ARMv8 crc32 instructions) when available, and falling back to an optimized software implementation otherwise. As of version 2.8, it offers robust data integrity verification across various platforms. The library aims for regular updates.

Warnings

Install

Imports

Quickstart

Demonstrates basic CRC32C calculation, incremental updates, usage of the `CRC32CHash` object, and how to check for hardware acceleration.

import crc32c

# Calculate CRC32C for a byte string
data = b"hello world"
checksum = crc32c.crc32c(data)
print(f"CRC32C checksum of '{data.decode()}': {checksum}")

# Incremental calculation (similar to binascii.crc32 with 'value' parameter)
crc_part1 = crc32c.crc32c(b"hello")
crc_total = crc32c.crc32c(b" world", value=crc_part1)
print(f"Incremental CRC32C: {crc_total}")

# Using the hash-like object
hash_obj = crc32c.CRC32CHash()
hash_obj.update(b"hello")
hash_obj.update(b" world")
print(f"CRC32CHash object checksum: {hash_obj.checksum}")

# Check if hardware acceleration is in use
print(f"Hardware acceleration in use: {crc32c.hardware_based}")

view raw JSON →