aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_crc.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-01-17 16:05:16 +0000
committerChristian Grothoff <christian@grothoff.org>2016-01-17 16:05:16 +0000
commit71e181512d1cd61d3865f93f5b85b208b5720ba5 (patch)
treedd2dbd4e56236318208f1dad5acf02faa341fa2b /src/util/crypto_crc.c
parent38e65c6c5268614b482d1234fea76cda11811044 (diff)
downloadgnunet-71e181512d1cd61d3865f93f5b85b208b5720ba5.tar.gz
gnunet-71e181512d1cd61d3865f93f5b85b208b5720ba5.zip
add crc8
Diffstat (limited to 'src/util/crypto_crc.c')
-rw-r--r--src/util/crypto_crc.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/util/crypto_crc.c b/src/util/crypto_crc.c
index ec2e80683..b5df01959 100644
--- a/src/util/crypto_crc.c
+++ b/src/util/crypto_crc.c
@@ -165,5 +165,35 @@ GNUNET_CRYPTO_crc16_n (const void *buf, size_t len)
165} 165}
166 166
167 167
168/**
169 * @ingroup hash
170 * Calculate the checksum of a buffer in one step.
171 *
172 * @param buf buffer to calculate CRC over
173 * @param len number of bytes in @a buf
174 * @return crc8 value
175 */
176uint8_t
177GNUNET_CRYPTO_crc8_n (const void *buf,
178 size_t len)
179{
180 const uint8_t *data = buf;
181 unsigned int crc = 0;
182 int i;
183 int j;
184
185 for (j = len; 0 != j; j--)
186 {
187 crc ^= (*data++ << 8);
188 for (i = 8; 0 != i; i--)
189 {
190 if (0 != (crc & 0x8000))
191 crc ^= (0x1070 << 3);
192 crc <<= 1;
193 }
194 }
195 return (uint8_t) (crc >> 8);
196}
197
168 198
169/* end of crypto_crc.c */ 199/* end of crypto_crc.c */