19 #define ADLER32_BASE 65521
23 uint32_t
adler32(uint32_t adler,
const uint8_t *buf,
int len)
26 uint32_t s1 = adler & 0xffff;
27 uint32_t s2 = (adler >> 16) & 0xffff;
30 for (n = 0; n < len; ++n, ++buf) {
34 if (s1 >= ADLER32_BASE) s1 -= ADLER32_BASE;
39 if (s2 >= ADLER32_BASE) s2 -= ADLER32_BASE;
42 return (s2 << 16) + s1;
50 static const uint32_t crc32_tbl[] = {
51 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
52 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c,
53 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c,
54 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
57 uint32_t
crc32(uint32_t crc,
const uint8_t *ptr,
int cnt,
bool dbg)
60 if (dbg) printf(
"%02x ", *ptr);
62 crc = (crc >> 4) ^ crc32_tbl[(crc & 0xf) ^ (*ptr & 0xf)];
63 crc = (crc >> 4) ^ crc32_tbl[(crc & 0xf) ^ (*(ptr++) >> 4)];
uint32_t adler32(uint32_t adler, const uint8_t *buf, int len)
Update the adler32 checkum with the new data.
uint32_t crc32(uint32_t crc, const uint8_t *ptr, int cnt, bool dbg)
Lightweight CRC32 algorithm, using Ethernet polynomial.
This module provides checksum functions.