GNUnet 0.21.1
crypto_crc.c File Reference

implementation of CRC16 and CRC32 More...

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

Go to the source code of this file.

Macros

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

Functions

static void crc_init ()
 
static GNUNET_uLong gn_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...
 

Variables

static GNUNET_uLong crc_table [256]
 

Detailed Description

implementation of CRC16 and CRC32

Author
Christian Grothoff

Definition in file crypto_crc.c.

Macro Definition Documentation

◆ LOG

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

Definition at line 34 of file crypto_crc.c.

◆ Z_NULL

#define Z_NULL   0

Definition at line 45 of file crypto_crc.c.

◆ POLYNOMIAL

#define POLYNOMIAL   (GNUNET_uLong) 0xedb88320

Definition at line 48 of file crypto_crc.c.

Function Documentation

◆ crc_init()

static void crc_init ( )
static

Definition at line 57 of file crypto_crc.c.

58{
59 static int once;
60 GNUNET_uLong h = 1;
61
62 if (once)
63 return;
64 once = 1;
65 crc_table[0] = 0;
66 for (unsigned int i = 128; i; i >>= 1)
67 {
68 h = (h >> 1) ^ ((h & 1) ? POLYNOMIAL : 0);
69 /* h is now crc_table[i] */
70 for (unsigned int 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:49
#define POLYNOMIAL
Definition: crypto_crc.c:48
static int once
Global to mark if we've run the initialization.
Definition: gnsrecord.c:67
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99

References crc_table, h, once, and POLYNOMIAL.

Referenced by gn_crc32().

Here is the caller graph for this function:

◆ gn_crc32()

static GNUNET_uLong gn_crc32 ( GNUNET_uLong  crc,
const char *  buf,
size_t  len 
)
static

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:57
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.

References crc_init(), crc_table, and GNUNET_assert.

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]
static

Definition at line 49 of file crypto_crc.c.

Referenced by crc_init(), and gn_crc32().