4 #define CRC32_PRESET 0xFFFFFFFF
6 static void crc32_byte(uint32_t *crc
, const uint8_t value
);
8 static void crc32_byte(uint32_t *crc
, const uint8_t value
) {
9 /* x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1 */
10 const uint32_t poly
= 0xEDB88320;
13 for (int current_bit
= 7; current_bit
>= 0; current_bit
--) {
14 int bit_out
= (*crc
) & 0x00000001;
21 void crc32_ex(const uint8_t *d
, const size_t n
, uint8_t *crc
) {
22 uint32_t c
= CRC32_PRESET
;
23 for (size_t i
= 0; i
< n
; i
++) {
27 crc
[1] = (uint8_t)(c
>> 8);
28 crc
[2] = (uint8_t)(c
>> 16);
29 crc
[3] = (uint8_t)(c
>> 24);
33 void crc32_append(uint8_t *d
, const size_t n
) {
34 crc32_ex(d
, n
, d
+ n
);