GNUnet  0.17.6
Macros | Functions | Variables
crypto_crc.c File Reference

implementation of CRC16 and CRC32 More...

#include "platform.h"
#include "gnunet_crypto_lib.h"
Include dependency graph for crypto_crc.c:

Go to the source code of this file.


#define LOG(kind, ...)   GNUNET_log_from (kind, "util-crypto-crc", __VA_ARGS__)
#define Z_NULL   0
#define POLYNOMIAL   (GNUNET_uLong) 0xedb88320


static void crc_init ()
static GNUNET_uLong crc32 (GNUNET_uLong crc, const char *buf, size_t len)
int32_t GNUNET_CRYPTO_crc32_n (const void *buf, size_t len)
 Compute the CRC32 checksum for the first len bytes of the buffer. More...
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. More...
uint16_t GNUNET_CRYPTO_crc16_finish (uint32_t sum)
 Convert results from GNUNET_CRYPTO_crc16_step to final crc16. More...
uint16_t GNUNET_CRYPTO_crc16_n (const void *buf, size_t len)
 Calculate the checksum of a buffer in one step. More...
uint8_t GNUNET_CRYPTO_crc8_n (const void *buf, size_t len)
 Calculate the checksum of a buffer in one step. More...


static GNUNET_uLong crc_table [256]

Detailed Description

implementation of CRC16 and CRC32

Christian Grothoff

Definition in file crypto_crc.c.

Macro Definition Documentation


#define LOG (   kind,
)    GNUNET_log_from (kind, "util-crypto-crc", __VA_ARGS__)

Definition at line 33 of file crypto_crc.c.


#define Z_NULL   0

Definition at line 44 of file crypto_crc.c.


#define POLYNOMIAL   (GNUNET_uLong) 0xedb88320

Definition at line 47 of file crypto_crc.c.

Function Documentation

◆ crc_init()

static void crc_init ( )

Definition at line 56 of file crypto_crc.c.

57 {
58  static int once;
59  unsigned int i, j;
60  GNUNET_uLong h = 1;
62  if (once)
63  return;
64  once = 1;
65  crc_table[0] = 0;
66  for (i = 128; i; i >>= 1)
67  {
68  h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0);
69  /* h is now crc_table[i] */
70  for (j = 0; j < 256; j += 2 * i)
71  crc_table[i + j] = crc_table[j] ^ h;
72  }
73 }
static GNUNET_uLong crc_table[256]
Definition: crypto_crc.c:48
Definition: crypto_crc.c:47
static int once
Global to mark if we've run the initialization.
Definition: gnsrecord.c:68
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99

References crc_table, h, once, and POLYNOMIAL.

Referenced by crc32().

Here is the caller graph for this function:

◆ crc32()

static GNUNET_uLong crc32 ( GNUNET_uLong  crc,
const char *  buf,
size_t  len 

Definition at line 87 of file crypto_crc.c.

88 {
89  crc_init ();
90  GNUNET_assert (crc_table[255] != 0);
91  crc ^= 0xffffffff;
92  while (len--)
93  crc = (crc >> 8) ^ crc_table[(crc ^ *buf++) & 0xff];
94  return crc ^ 0xffffffff;
95 }
static void crc_init()
Definition: crypto_crc.c:56
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static char buf[2048]
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References buf, crc_init(), crc_table, GNUNET_assert, and len.

Referenced by GNUNET_CRYPTO_crc32_n().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ crc_table

GNUNET_uLong crc_table[256]

Definition at line 48 of file crypto_crc.c.

Referenced by crc32(), and crc_init().