34 #define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-crc", __VA_ARGS__)
37 #if UINT_MAX >= 0xffffffff
38 typedef unsigned int GNUNET_uLong;
39 #elif ULONG_MAX >= 0xffffffff
40 typedef unsigned long GNUNET_uLong;
42 #error This compiler is not ANSI-compliant!
48 #define POLYNOMIAL (GNUNET_uLong) 0xedb88320
66 for (
unsigned int i = 128; i; i >>= 1)
70 for (
unsigned int j = 0; j < 256; j += 2 * i)
94 return crc ^ 0xffffffff;
112 const uint16_t *hdr =
buf;
114 for (;
len >= 2;
len -= 2)
117 sum += ntohs(*((uint8_t *)hdr) << 8);
135 const uint16_t *hdr =
buf;
155 unsigned int crc = 0;
159 for (j =
len; 0 != j; j--)
161 crc ^= (*
data++ << 8);
162 for (i = 8; 0 != i; i--)
164 if (0 != (crc & 0x8000))
165 crc ^= (0x1070 << 3);
169 return (uint8_t) (crc >> 8);
static GNUNET_uLong crc_table[256]
static GNUNET_uLong gn_crc32(GNUNET_uLong crc, const char *buf, size_t len)
static int once
Global to mark if we've run the initialization.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
uint32_t data
The data value.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
int32_t GNUNET_CRYPTO_crc32_n(const void *buf, size_t len)
Compute the CRC32 checksum for the first len bytes of the buffer.
uint8_t GNUNET_CRYPTO_crc8_n(const void *buf, size_t len)
Calculate the checksum of a buffer in one step.
uint16_t GNUNET_CRYPTO_crc16_n(const void *buf, size_t len)
Calculate the checksum of a buffer in one step.
uint16_t GNUNET_CRYPTO_crc16_finish(uint32_t sum)
Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
uint32_t GNUNET_CRYPTO_crc16_step(uint32_t sum, const void *buf, size_t len)
Perform an incremental step in a CRC16 (for TCP/IP) calculation.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.