diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 15 | ||||
-rw-r--r-- | src/util/crypto_crc.c | 30 |
2 files changed, 45 insertions, 0 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 77b4d0452..23caade12 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -403,6 +403,19 @@ GNUNET_CRYPTO_seed_weak_random (int32_t seed); | |||
403 | 403 | ||
404 | 404 | ||
405 | /** | 405 | /** |
406 | * @ingroup hash | ||
407 | * Calculate the checksum of a buffer in one step. | ||
408 | * | ||
409 | * @param buf buffer to calculate CRC over | ||
410 | * @param len number of bytes in @a buf | ||
411 | * @return crc8 value | ||
412 | */ | ||
413 | uint8_t | ||
414 | GNUNET_CRYPTO_crc8_n (const void *buf, | ||
415 | size_t len); | ||
416 | |||
417 | |||
418 | /** | ||
406 | * Perform an incremental step in a CRC16 (for TCP/IP) calculation. | 419 | * Perform an incremental step in a CRC16 (for TCP/IP) calculation. |
407 | * | 420 | * |
408 | * @param sum current sum, initially 0 | 421 | * @param sum current sum, initially 0 |
@@ -439,6 +452,8 @@ GNUNET_CRYPTO_crc16_n (const void *buf, | |||
439 | size_t len); | 452 | size_t len); |
440 | 453 | ||
441 | 454 | ||
455 | |||
456 | |||
442 | /** | 457 | /** |
443 | * @ingroup hash | 458 | * @ingroup hash |
444 | * Compute the CRC32 checksum for the first len | 459 | * Compute the CRC32 checksum for the first len |
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 | */ | ||
176 | uint8_t | ||
177 | GNUNET_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 */ |