hash::crc16
Implements the CRC-16 checksum algorithm. It is a non-cryptographic checksum.
Index
Types
type state;
Constants
const ANSI: u16;
const CCITT: u16;
const CMDA2000: u16;
const DECT: u16;
const SIZE: size;
Globals
let ansi_table: [256]u16;
let ccitt_table: [256]u16;
let cmda2000_table: [256]u16;
let dect_table: [256]u16;
Functions
fn crc16(*[256]u16) state;
fn memoize(u16, *[256]u16) void;
fn sum16(*hash::hash) u16;
Types
type state
Show undocumented member
type state = struct {
hash::hash,
table: *[256]u16,
cval: u16,
};
Constants
def ANSI
def ANSI: u16;
ANSI polynomial for CRC-16. Another widely used polynomial, it's seen in USB
devices, Modbus, ANSI X3.28, and many others places. Also known as CRC-IBM.
def CCITT
def CCITT: u16;
CRC-CCITT polynomial for CRC-16. The most commonly used polynomial, used in
Bluetooth, X.25, XMODEM, and many other places. Also known as CRC-X25.
def CMDA2000
def CMDA2000: u16;
CMDA200 polynomial for CRC-16. Used in the infrastructure of mobile networks.
def DECT
def DECT: u16;
DECT polynomial for CRC-16. Typically used in cordless phones.
def SIZE
def SIZE: size;
The size, in bytes, of a CRC-16 checksum.
Globals
let ansi_table
const ansi_table: [256]u16;
Table of memoized values for each byte with the ANSI polynomial.
let ccitt_table
const ccitt_table: [256]u16;
Table of memoized values for each byte with the CCITT polynomial.
let cmda2000_table
const cmda2000_table: [256]u16;
Table of memoized values for each byte with the CMDA2000 polynomial.
let dect_table
const dect_table: [256]u16;
Table of memoized values for each byte with the DECT polynomial.
Functions
fn crc16
fn crc16(table: *[256]u16) state;
Creates a hash::hash which computes the CRC-16 algorithm. This hash
function does not allocate any state, so you do not need to call
hash::close when you are done with it.
It takes a table of memoized values for a given polynomail (for example,
ccitt_table, dect_table, or ansi_table); a table for a
custom polynomial, populated by memoize function, may also be used.
fn memoize
fn memoize(polynomial: u16, buf: *[256]u16) void;
Populate a user-provided buffer with the memoized values for a custom
polynomial.
The user-provided polynomial must be in the reversed form.
fn sum16
Show undocumented member
fn sum16(h: *hash::hash) u16;