Skip to main content

Module checksum

Module checksum 

Source
Expand description

Frame checksums.

The Checksum trait describes an integrity check that produces a fixed number of bytes. Three common CRCs are built in, implemented locally with const-generated lookup tables (slice-by-8 for the CRC-32 variants) so the crate stays dependency-free:

TypeAlgorithm (catalogue name)WidthTypical use
Crc16CcittFalseCRC-16/IBM-3740 (a.k.a. CRC-16/CCITT-FALSE)2 bytesSerial links, Bluetooth, many embedded protocols
Crc32CRC-32/ISO-HDLC (IEEE 802.3, zlib, PNG)4 bytesEthernet, gzip, general purpose
Crc32cCRC-32/ISCSI (Castagnoli)4 bytesiSCSI, SCTP, ext4, Kafka record batches

Pair a checksum with any framer through Checksummed. Implement Checksum yourself to plug in a different algorithm (for example a hardware CRC unit on a microcontroller).

A CRC detects accidental corruption. It is not a MAC: anyone can compute a valid CRC for forged data. Use an authenticated cipher or a keyed MAC when the peer is adversarial.

Structs§

Crc32
CRC-32/ISO-HDLC, the CRC-32 of IEEE 802.3, zlib, gzip, and PNG.
Crc16CcittFalse
CRC-16/IBM-3740, widely known as CRC-16/CCITT-FALSE.
Crc32c
CRC-32/ISCSI (Castagnoli), used by iSCSI, SCTP, ext4, and Kafka.

Traits§

Checksum
An integrity check over a byte slice that yields Checksum::LEN bytes.

Functions§

crc32
Compute CRC-32/ISO-HDLC (IEEE) of data.
crc16_ccitt_false
Compute CRC-16/IBM-3740 (CRC-16/CCITT-FALSE) of data.
crc32c
Compute CRC-32/ISCSI (Castagnoli) of data.