[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r36823 - in gnunet/src: include util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r36823 - in gnunet/src: include util |
Date: |
Sun, 17 Jan 2016 17:05:16 +0100 |
Author: grothoff
Date: 2016-01-17 17:05:16 +0100 (Sun, 17 Jan 2016)
New Revision: 36823
Modified:
gnunet/src/include/gnunet_crypto_lib.h
gnunet/src/util/crypto_crc.c
Log:
add crc8
Modified: gnunet/src/include/gnunet_crypto_lib.h
===================================================================
--- gnunet/src/include/gnunet_crypto_lib.h 2016-01-17 16:04:53 UTC (rev
36822)
+++ gnunet/src/include/gnunet_crypto_lib.h 2016-01-17 16:05:16 UTC (rev
36823)
@@ -403,6 +403,19 @@
/**
+ * @ingroup hash
+ * Calculate the checksum of a buffer in one step.
+ *
+ * @param buf buffer to calculate CRC over
+ * @param len number of bytes in @a buf
+ * @return crc8 value
+ */
+uint8_t
+GNUNET_CRYPTO_crc8_n (const void *buf,
+ size_t len);
+
+
+/**
* Perform an incremental step in a CRC16 (for TCP/IP) calculation.
*
* @param sum current sum, initially 0
@@ -439,6 +452,8 @@
size_t len);
+
+
/**
* @ingroup hash
* Compute the CRC32 checksum for the first len
Modified: gnunet/src/util/crypto_crc.c
===================================================================
--- gnunet/src/util/crypto_crc.c 2016-01-17 16:04:53 UTC (rev 36822)
+++ gnunet/src/util/crypto_crc.c 2016-01-17 16:05:16 UTC (rev 36823)
@@ -165,5 +165,35 @@
}
+/**
+ * @ingroup hash
+ * Calculate the checksum of a buffer in one step.
+ *
+ * @param buf buffer to calculate CRC over
+ * @param len number of bytes in @a buf
+ * @return crc8 value
+ */
+uint8_t
+GNUNET_CRYPTO_crc8_n (const void *buf,
+ size_t len)
+{
+ const uint8_t *data = buf;
+ unsigned int crc = 0;
+ int i;
+ int j;
+ for (j = len; 0 != j; j--)
+ {
+ crc ^= (*data++ << 8);
+ for (i = 8; 0 != i; i--)
+ {
+ if (0 != (crc & 0x8000))
+ crc ^= (0x1070 << 3);
+ crc <<= 1;
+ }
+ }
+ return (uint8_t) (crc >> 8);
+}
+
+
/* end of crypto_crc.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r36823 - in gnunet/src: include util,
gnunet <=