Cyclic Redundancy Check (crc)

Keywords: cyclic redundancy check CRC checksum error detection crc32 crc24 crc16

A cyclic redundancy check (CRC) is, in essence, a strong algebraic error detection code that computes a key on a block of data using base-2 polynomials. While it is a strong error-detection method, a CRC is not an error-correction code. Here is a simple example:

#include <liquid/liquid.h>

int main() {
    // initialize data array
    unsigned char data[4] = {0x25, 0x62, 0x3F, 0x52};
    crc_scheme scheme = LIQUID_CRC_32;

    // compute CRC on original data
    unsigned char key = crc_generate_key(scheme, data, 4);

    // ... channel ...

    // validate (received) message
    int valid_data = crc_validate_message(scheme, data, 4, key);

Also available for error detection in liquid is a checksum. A checksum is a simple way to validate data received through un-reliable means (e.g. a noisy channel). A checksum is, in essence, a weak error detection code that simply counts the number of ones in a block of data (modulo 256). The limitation, however, is that multiple bit errors might result in a false positive validation of the corrupted data. The checksum is not a strong an error detection scheme as the cyclic redundancy check.[ref:tab-crc-codecs] lists the available codecs and gives a brief description for each.

Table [tab-crc-codecs]. Error-detection codecs available in liquid

Scheme Size (bits) Description
LIQUID_CRC_UNKNOWN - unknown/unsupported scheme
LIQUID_CRC_NONE 0 no error-detection
LIQUID_CRC_CHECKSUM 8 basic checksum
LIQUID_CRC_8 8 8-bit CRC, poly= 0x07
LIQUID_CRC_16 16 16-bit CRC, poly= 0x8005
LIQUID_CRC_24 24 24-bit CRC, poly= 0x5D6DCB
LIQUID_CRC_32 32 32-bit CRC, poly= 0x04C11DB7

For a detailed example program, see examples/crc_example.c in the main liquid directory.