aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-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 */