CRC16 (lightweight)

Lightweight CRC16 checksum algorithms. More...

Detailed Description

Lightweight CRC16 checksum algorithms.

This CRC16 implementation does not use pre-calculated lookup tables and is thus very lightweight (memory-wise), but as a caveat slower (about factor 8) than the version with pre-calculated lookup tables.

Additionally compared to CRC16-CCITT this is a generalized implementation. One can easily exchange generator polynomials and starting seeds.

Files

file  ucrc16.h
 ucrc16 definitions
 

Functions

uint16_t ucrc16_calc_be (const uint8_t *buf, size_t len, uint16_t poly, uint16_t seed)
 Calculate CRC16 (big-endian version) More...
 
uint16_t ucrc16_calc_le (const uint8_t *buf, size_t len, uint16_t poly, uint16_t seed)
 Calculate CRC16 (little-endian version) More...
 
#define UCRC16_CCITT_POLY_BE   (0x1021)
 Various generator polynomials. More...
 
#define UCRC16_CCITT_POLY_LE   (0x8408)
 CRC16-CCITT polynomial (little-endian)
 

Macro Definition Documentation

◆ UCRC16_CCITT_POLY_BE

#define UCRC16_CCITT_POLY_BE   (0x1021)

Various generator polynomials.

CRC16-CCITT polynomial (big-endian)

Definition at line 43 of file ucrc16.h.

Function Documentation

◆ ucrc16_calc_be()

uint16_t ucrc16_calc_be ( const uint8_t *  buf,
size_t  len,
uint16_t  poly,
uint16_t  seed 
)

Calculate CRC16 (big-endian version)

Parameters
[in]bufStart of memory are to checksum
[in]lenNumber of bytes in buf to calculate checksum for
[in]polyThe generator polynomial for the checksum
[in]seedThe seed (starting value) for the checksum
Returns
Checksum of the specified memory area based on seed and poly
Note
The return value is not the complement of the sum but the sum itself

◆ ucrc16_calc_le()

uint16_t ucrc16_calc_le ( const uint8_t *  buf,
size_t  len,
uint16_t  poly,
uint16_t  seed 
)

Calculate CRC16 (little-endian version)

Parameters
[in]bufStart of memory are to checksum
[in]lenNumber of bytes in buf to calculate checksum for
[in]polyThe generator polynomial for the checksum
[in]seedThe seed (starting value) for the checksum
Returns
Checksum of the specified memory area based on seed and poly
Note
The return value is not the complement of the sum but the sum itself