1 /* SPDX-License-Identifier: GPL-2.0-only */
9 /* This function is used to calculate crc7 byte by byte, with polynomial
12 * prev_crc: old crc result (0 for first)
14 * return value: new crc result
16 uint8_t crc7_byte(uint8_t prev_crc
, uint8_t data
);
18 /* This function is used to calculate crc16 byte by byte, with polynomial
19 * x^16 + x^12 + x^5 + 1.
21 * prev_crc: old crc result (0 for first)
23 * return value: new crc result
25 uint16_t crc16_byte(uint16_t prev_crc
, uint8_t data
);
27 /* This function is used to calculate crc32 byte by byte, with polynomial
28 * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^10 + x^8 + x^7 +
29 * x^5 + x^4 + x^2 + x + 1
31 * prev_crc: old crc result (0 for first)
33 * return value: new crc result
35 uint32_t crc32_byte(uint32_t prev_crc
, uint8_t data
);
37 #define CRC(buf, size, crc_func) ({ \
38 const uint8_t *_crc_local_buf = (const uint8_t *)buf; \
39 size_t _crc_local_size = size; \
40 __typeof__(crc_func(0, 0)) _crc_local_result = 0; \
41 while (_crc_local_size--) { \
42 _crc_local_result = crc_func(_crc_local_result, *_crc_local_buf++); \
47 #endif /* CRC_BYTE_H */