12.1. crc — Cyclic Redundancy Checks

Source code: src/hash/crc.h, src/hash/crc.c

Test code: tst/hash/crc/main.c

Test coverage: src/hash/crc.c


Functions

uint32_t crc_32(uint32_t crc, const void *buf_p, size_t size)
uint16_t crc_ccitt(uint16_t crc, const void *buf_p, size_t size)

Calculate a 16 bits crc using the CCITT algorithm (polynomial x^16+x^12+x^5+x^1).

Return
Calculated crc.
Parameters
  • crc: Initial crc. Should be 0xffff for CCITT.
  • buf_p: Buffer to calculate crc of.
  • size: Size of the buffer.

uint16_t crc_xmodem(uint16_t crc, const void *buf_p, size_t size)

Calculate a 16 bits crc using the XModem algorithm (polynomial x^16+x^12+x^5+x^1).

Return
Calculated crc.
Parameters
  • crc: Initial crc. Should be 0x0000 for XModem.
  • buf_p: Buffer to calculate crc of.
  • size: Size of the buffer.

uint8_t crc_7(const void *buf_p, size_t size)

Calculate a 8 bits crc using the CRC-7 algorithm (polynomial x^7+x^3+1).

Return
Calculated crc.
Parameters
  • buf_p: Buffer to calculate crc of.
  • size: Size of the buffer.