hash::crc32+x86_64 +linux

Implements the CRC-32 checksum algorithm. It is a non-cryptographic checksum.

Index

Types

// Undocumented types:
type state = struct {
	hash::hash,
	table: *[256]u32,
	cval: u32,
};

Constants

def CASTAGNOLI: u32 = 2197175160;
def IEEE: u32 = 3988292384;
def KOOPMAN: u32 = 3945912366;
def SZ: size = 4;

Globals

const castagnoli_table: [256]u32;
const ieee_table: [256]u32;
const koopman_table: [256]u32;

Functions

fn crc32(table: *[256]u32) state;
fn memoize(polynomial: u32, buf: *[256]u32) void;
fn sum32(h: *hash::hash) u32;

Types

type state[link]

Show undocumented member
type state = struct {
	hash::hash,
	table: *[256]u32,
	cval: u32,
};

Constants

def CASTAGNOLI[link]

def CASTAGNOLI: u32 = 2197175160;

Castagnoli polynomial for CRC-32. Used in iSCSI, SCTP, SSE4.2, btrfs, ext4, and others. It's known to have better error detection than IEEE.

def IEEE[link]

def IEEE: u32 = 3988292384;

IEEE polynomial for CRC-32. Used in ethernet, SATA, MPEG-2, gzip, bzip2, cksum, PNG, etc. It is by far the most common polynomial used.

def KOOPMAN[link]

def KOOPMAN: u32 = 3945912366;

Koopman polnomial for CRC-32. It has good performance for small datasets, but poor performance for large ones. Like the Castagnoli polynomial, it has better error detection than the IEEE polynomial.

def SZ[link]

def SZ: size = 4;

The size, in bytes, of a CRC-32 checksum.

Globals

let castagnoli_table[link]

const castagnoli_table: [256]u32;

Table of memoized values for each byte with the Castagnoli polynomial.

let ieee_table[link]

const ieee_table: [256]u32;

Table of memoized values for each byte with the IEEE polynomial.

let koopman_table[link]

const koopman_table: [256]u32;

Table of memoized values for each byte with the Koopman polynomial.

Functions

fn crc32[link]

fn crc32(table: *[256]u32) state;

Creates a hash::hash which computes the CRC-32 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, ieee_table, castagnoli_table, or koopman_table); a table for a custom polynomial, populated by memoize function, may also be used.

fn memoize[link]

fn memoize(polynomial: u32, buf: *[256]u32) 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 sum32[link]

fn sum32(h: *hash::hash) u32;

Returns the computed 32-bit CRC.