Expand description
Checksums and CRCs used by dive computer protocols.
Each algorithm is defined once, named after its entry in the
checksum catalogue.
CRCs are crc::Crc instances, so callers get both one-shot
(Crc::checksum) and incremental (Crc::digest) computation. The simple sums are
small digest types with the same update/value shape.
use divecomputer_core::checksum::{CRC_16_XMODEM, Sum8, Xor8};
// Cressi Goa dive request: CRC over length, command and arguments.
assert_eq!(CRC_16_XMODEM.checksum(&[0x02, 0x22, 0x01, 0x00]), 0x36FF);
// Suunto version query: XOR over the command bytes.
assert_eq!(Xor8::of(&[0x05, 0x00, 0x16, 0x14]).value(), 0x07);
// Sum of data plus its negated sum8 is zero.
let data = [0x10, 0x20, 0x30];
assert_eq!(Sum8::of(&data).negated(), 0xA0);Structs§
- Crc
- Crc instance with a specific width, algorithm, and implementation.
- Nibble
Sum - Sum of the high and low nibble of every byte, modulo 256: the catalogue entry
nibble-sum. - Sum8
- Sum of bytes modulo 256.
- Sum16
- Sum of bytes (each
0..=255) modulo 65536: the catalogue entrysum16. - Xor8
- XOR of all bytes: the catalogue entry
xor8.
Constants§
- CRC_
8_ MSB_ 0X12 - CRC-8 with polynomial
12, init00, no reflection, no final XOR. - CRC_
8_ SMBUS - CRC-8/SMBUS: polynomial
07, init00, no reflection, no final XOR. - CRC_
16_ ARC - CRC-16/ARC: polynomial
8005, reflected, init0000. - CRC_
16_ IBM_ 3740 - CRC-16/IBM-3740, also known as CRC-16/CCITT-FALSE: polynomial
1021, initFFFF. - CRC_
16_ IBM_ SDLC - CRC-16/IBM-SDLC, also known as CRC-16/X-25: polynomial
1021, reflected, init and final XORFFFF. - CRC_
16_ MODBUS - CRC-16/MODBUS: polynomial
8005, reflected, initFFFF. - CRC_
16_ XMODEM - CRC-16/XMODEM: polynomial
1021, init0000. - CRC_
32_ BZIP2 - CRC-32/BZIP2: polynomial
04C11DB7, not reflected. - CRC_
32_ ISO_ HDLC - CRC-32/ISO-HDLC, the common “CRC-32”: polynomial
04C11DB7, reflected.