projects
/
oweals
/
gnunet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
merging configs
[oweals/gnunet.git]
/
src
/
util
/
crypto_crc.c
diff --git
a/src/util/crypto_crc.c
b/src/util/crypto_crc.c
index c6cd83a7494d65d363045758e6c6fcb56e8e8eb8..ea50b636c0913e4fcf1761abf485db1e70366686 100644
(file)
--- a/
src/util/crypto_crc.c
+++ b/
src/util/crypto_crc.c
@@
-27,7
+27,6
@@
* @brief implementation of CRC16 and CRC32
* @author Christian Grothoff
*/
* @brief implementation of CRC16 and CRC32
* @author Christian Grothoff
*/
-
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_crypto_lib.h"
#include "platform.h"
#include "gnunet_common.h"
#include "gnunet_crypto_lib.h"
@@
-51,7
+50,7
@@
static uLong crc_table[256];
/*
* This routine writes each crc_table entry exactly once,
/*
* This routine writes each crc_table entry exactly once,
- * with the c
c
orrect final value. Thus, it is safe to call
+ * with the correct final value. Thus, it is safe to call
* even on a table that someone else is using concurrently.
*/
static void
* even on a table that someone else is using concurrently.
*/
static void
@@
-118,20
+117,22
@@
GNUNET_CRYPTO_crc32_n (const void *buf, size_t len)
* Perform an incremental step in a CRC16 (for TCP/IP) calculation.
*
* @param sum current sum, initially 0
* Perform an incremental step in a CRC16 (for TCP/IP) calculation.
*
* @param sum current sum, initially 0
- * @param
hdr
buffer to calculate CRC over (must be 16-bit aligned)
+ * @param
buf
buffer to calculate CRC over (must be 16-bit aligned)
* @param len number of bytes in hdr, must be multiple of 2
* @return updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish to get actual crc16)
*/
uint32_t
* @param len number of bytes in hdr, must be multiple of 2
* @return updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish to get actual crc16)
*/
uint32_t
-GNUNET_CRYPTO_crc16_step (uint32_t sum,
uint16_t * hdr
, size_t len)
+GNUNET_CRYPTO_crc16_step (uint32_t sum,
const void *buf
, size_t len)
{
{
+ const uint16_t *hdr = buf;
for (; len >= 2; len -= 2)
sum += *(hdr++);
if (len == 1)
for (; len >= 2; len -= 2)
sum += *(hdr++);
if (len == 1)
- sum +=
*((unsigned char *) hdr
);
+ sum +=
(*hdr) & ntohs(0xFF00
);
return sum;
}
return sum;
}
+
/**
* Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
*
/**
* Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
*
@@
-151,13
+152,14
@@
GNUNET_CRYPTO_crc16_finish (uint32_t sum)
/**
* Calculate the checksum of a buffer in one step.
*
/**
* Calculate the checksum of a buffer in one step.
*
- * @param
hdr
buffer to calculate CRC over (must be 16-bit aligned)
+ * @param
buf
buffer to calculate CRC over (must be 16-bit aligned)
* @param len number of bytes in hdr, must be multiple of 2
* @return crc16 value
*/
uint16_t
* @param len number of bytes in hdr, must be multiple of 2
* @return crc16 value
*/
uint16_t
-GNUNET_CRYPTO_crc16_n (
uint16_t *hdr
, size_t len)
+GNUNET_CRYPTO_crc16_n (
const void *buf
, size_t len)
{
{
+ const uint16_t *hdr = buf;
uint32_t sum = GNUNET_CRYPTO_crc16_step (0, hdr, len);
return GNUNET_CRYPTO_crc16_finish (sum);
uint32_t sum = GNUNET_CRYPTO_crc16_step (0, hdr, len);
return GNUNET_CRYPTO_crc16_finish (sum);