Skip to main content

Module checksum

Module checksum 

Source
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.
NibbleSum
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 entry sum16.
Xor8
XOR of all bytes: the catalogue entry xor8.

Constants§

CRC_8_MSB_0X12
CRC-8 with polynomial 12, init 00, no reflection, no final XOR.
CRC_8_SMBUS
CRC-8/SMBUS: polynomial 07, init 00, no reflection, no final XOR.
CRC_16_ARC
CRC-16/ARC: polynomial 8005, reflected, init 0000.
CRC_16_IBM_3740
CRC-16/IBM-3740, also known as CRC-16/CCITT-FALSE: polynomial 1021, init FFFF.
CRC_16_IBM_SDLC
CRC-16/IBM-SDLC, also known as CRC-16/X-25: polynomial 1021, reflected, init and final XOR FFFF.
CRC_16_MODBUS
CRC-16/MODBUS: polynomial 8005, reflected, init FFFF.
CRC_16_XMODEM
CRC-16/XMODEM: polynomial 1021, init 0000.
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.