aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r--src/util/crypto_hash.c313
1 files changed, 167 insertions, 146 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index ebb1266b2..2bf03db58 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -29,9 +29,13 @@
29#include "benchmark.h" 29#include "benchmark.h"
30#include <gcrypt.h> 30#include <gcrypt.h>
31 31
32#define LOG(kind, ...) GNUNET_log_from(kind, "util-crypto-hash", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from (kind, "util-crypto-hash", __VA_ARGS__)
33 33
34#define LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file(kind, "util-crypto-hash", syscall, filename) 34#define LOG_STRERROR_FILE(kind, syscall, \
35 filename) GNUNET_log_from_strerror_file (kind, \
36 "util-crypto-hash", \
37 syscall, \
38 filename)
35 39
36/** 40/**
37 * Hash block of given size. 41 * Hash block of given size.
@@ -41,13 +45,13 @@
41 * @param ret pointer to where to write the hashcode 45 * @param ret pointer to where to write the hashcode
42 */ 46 */
43void 47void
44GNUNET_CRYPTO_hash(const void *block, 48GNUNET_CRYPTO_hash (const void *block,
45 size_t size, 49 size_t size,
46 struct GNUNET_HashCode *ret) 50 struct GNUNET_HashCode *ret)
47{ 51{
48 BENCHMARK_START(hash); 52 BENCHMARK_START (hash);
49 gcry_md_hash_buffer(GCRY_MD_SHA512, ret, block, size); 53 gcry_md_hash_buffer (GCRY_MD_SHA512, ret, block, size);
50 BENCHMARK_END(hash); 54 BENCHMARK_END (hash);
51} 55}
52 56
53 57
@@ -66,16 +70,18 @@ GNUNET_CRYPTO_hash(const void *block,
66 * safely cast to char*, a '\\0' termination is set). 70 * safely cast to char*, a '\\0' termination is set).
67 */ 71 */
68void 72void
69GNUNET_CRYPTO_hash_to_enc(const struct GNUNET_HashCode *block, 73GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
70 struct GNUNET_CRYPTO_HashAsciiEncoded *result) 74 struct GNUNET_CRYPTO_HashAsciiEncoded *result)
71{ 75{
72 char *np; 76 char *np;
73 77
74 np = GNUNET_STRINGS_data_to_string((const unsigned char *)block, 78 np = GNUNET_STRINGS_data_to_string ((const unsigned char *) block,
75 sizeof(struct GNUNET_HashCode), 79 sizeof(struct GNUNET_HashCode),
76 (char *)result, 80 (char *) result,
77 sizeof(struct GNUNET_CRYPTO_HashAsciiEncoded) - 1); 81 sizeof(struct
78 GNUNET_assert(NULL != np); 82 GNUNET_CRYPTO_HashAsciiEncoded)
83 - 1);
84 GNUNET_assert (NULL != np);
79 *np = '\0'; 85 *np = '\0';
80} 86}
81 87
@@ -89,18 +95,18 @@ GNUNET_CRYPTO_hash_to_enc(const struct GNUNET_HashCode *block,
89 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 95 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
90 */ 96 */
91int 97int
92GNUNET_CRYPTO_hash_from_string2(const char *enc, 98GNUNET_CRYPTO_hash_from_string2 (const char *enc,
93 size_t enclen, 99 size_t enclen,
94 struct GNUNET_HashCode *result) 100 struct GNUNET_HashCode *result)
95{ 101{
96 char upper_enc[enclen]; 102 char upper_enc[enclen];
97 char *up_ptr = upper_enc; 103 char *up_ptr = upper_enc;
98 104
99 GNUNET_STRINGS_utf8_toupper(enc, up_ptr); 105 GNUNET_STRINGS_utf8_toupper (enc, up_ptr);
100 106
101 return GNUNET_STRINGS_string_to_data(upper_enc, enclen, 107 return GNUNET_STRINGS_string_to_data (upper_enc, enclen,
102 (unsigned char*)result, 108 (unsigned char*) result,
103 sizeof(struct GNUNET_HashCode)); 109 sizeof(struct GNUNET_HashCode));
104} 110}
105 111
106 112
@@ -118,8 +124,8 @@ GNUNET_CRYPTO_hash_from_string2(const char *enc,
118 * hashcode proximity. 124 * hashcode proximity.
119 */ 125 */
120unsigned int 126unsigned int
121GNUNET_CRYPTO_hash_distance_u32(const struct GNUNET_HashCode *a, 127GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode *a,
122 const struct GNUNET_HashCode *b) 128 const struct GNUNET_HashCode *b)
123{ 129{
124 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; 130 unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16;
125 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; 131 unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16;
@@ -135,13 +141,13 @@ GNUNET_CRYPTO_hash_distance_u32(const struct GNUNET_HashCode *a,
135 * @param result hash code that is randomized 141 * @param result hash code that is randomized
136 */ 142 */
137void 143void
138GNUNET_CRYPTO_hash_create_random(enum GNUNET_CRYPTO_Quality mode, 144GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
139 struct GNUNET_HashCode *result) 145 struct GNUNET_HashCode *result)
140{ 146{
141 int i; 147 int i;
142 148
143 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(uint32_t)) - 1; i >= 0; i--) 149 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(uint32_t)) - 1; i >= 0; i--)
144 result->bits[i] = GNUNET_CRYPTO_random_u32(mode, UINT32_MAX); 150 result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, UINT32_MAX);
145} 151}
146 152
147 153
@@ -153,13 +159,14 @@ GNUNET_CRYPTO_hash_create_random(enum GNUNET_CRYPTO_Quality mode,
153 * @param result set to b - a 159 * @param result set to b - a
154 */ 160 */
155void 161void
156GNUNET_CRYPTO_hash_difference(const struct GNUNET_HashCode *a, 162GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode *a,
157 const struct GNUNET_HashCode *b, 163 const struct GNUNET_HashCode *b,
158 struct GNUNET_HashCode *result) 164 struct GNUNET_HashCode *result)
159{ 165{
160 int i; 166 int i;
161 167
162 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0; i--) 168 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0;
169 i--)
163 result->bits[i] = b->bits[i] - a->bits[i]; 170 result->bits[i] = b->bits[i] - a->bits[i];
164} 171}
165 172
@@ -172,12 +179,14 @@ GNUNET_CRYPTO_hash_difference(const struct GNUNET_HashCode *a,
172 * @param result set to a + delta 179 * @param result set to a + delta
173 */ 180 */
174void 181void
175GNUNET_CRYPTO_hash_sum(const struct GNUNET_HashCode * a, 182GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode *a,
176 const struct GNUNET_HashCode * delta, struct GNUNET_HashCode * result) 183 const struct GNUNET_HashCode *delta, struct
184 GNUNET_HashCode *result)
177{ 185{
178 int i; 186 int i;
179 187
180 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0; i--) 188 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0;
189 i--)
181 result->bits[i] = delta->bits[i] + a->bits[i]; 190 result->bits[i] = delta->bits[i] + a->bits[i];
182} 191}
183 192
@@ -190,13 +199,14 @@ GNUNET_CRYPTO_hash_sum(const struct GNUNET_HashCode * a,
190 * @param result set to a ^ b 199 * @param result set to a ^ b
191 */ 200 */
192void 201void
193GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a, 202GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a,
194 const struct GNUNET_HashCode *b, 203 const struct GNUNET_HashCode *b,
195 struct GNUNET_HashCode *result) 204 struct GNUNET_HashCode *result)
196{ 205{
197 int i; 206 int i;
198 207
199 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0; i--) 208 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0;
209 i--)
200 result->bits[i] = a->bits[i] ^ b->bits[i]; 210 result->bits[i] = a->bits[i] ^ b->bits[i];
201} 211}
202 212
@@ -209,20 +219,25 @@ GNUNET_CRYPTO_hash_xor(const struct GNUNET_HashCode *a,
209 * @param iv set to a valid initialization vector 219 * @param iv set to a valid initialization vector
210 */ 220 */
211void 221void
212GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc, 222GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode *hc,
213 struct GNUNET_CRYPTO_SymmetricSessionKey *skey, 223 struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
214 struct GNUNET_CRYPTO_SymmetricInitializationVector *iv) 224 struct
225 GNUNET_CRYPTO_SymmetricInitializationVector *iv)
215{ 226{
216 GNUNET_assert(GNUNET_YES == 227 GNUNET_assert (GNUNET_YES ==
217 GNUNET_CRYPTO_kdf(skey, sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey), 228 GNUNET_CRYPTO_kdf (skey, sizeof(struct
218 "Hash key derivation", strlen("Hash key derivation"), 229 GNUNET_CRYPTO_SymmetricSessionKey),
219 hc, sizeof(struct GNUNET_HashCode), 230 "Hash key derivation", strlen (
220 NULL, 0)); 231 "Hash key derivation"),
221 GNUNET_assert(GNUNET_YES == 232 hc, sizeof(struct GNUNET_HashCode),
222 GNUNET_CRYPTO_kdf(iv, sizeof(struct GNUNET_CRYPTO_SymmetricInitializationVector), 233 NULL, 0));
223 "Initialization vector derivation", strlen("Initialization vector derivation"), 234 GNUNET_assert (GNUNET_YES ==
224 hc, sizeof(struct GNUNET_HashCode), 235 GNUNET_CRYPTO_kdf (iv, sizeof(struct
225 NULL, 0)); 236 GNUNET_CRYPTO_SymmetricInitializationVector),
237 "Initialization vector derivation", strlen (
238 "Initialization vector derivation"),
239 hc, sizeof(struct GNUNET_HashCode),
240 NULL, 0));
226} 241}
227 242
228 243
@@ -233,10 +248,11 @@ GNUNET_CRYPTO_hash_to_aes_key(const struct GNUNET_HashCode *hc,
233 * @return Bit \a bit from hashcode \a code, -1 for invalid index 248 * @return Bit \a bit from hashcode \a code, -1 for invalid index
234 */ 249 */
235int 250int
236GNUNET_CRYPTO_hash_get_bit(const struct GNUNET_HashCode * code, unsigned int bit) 251GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, unsigned int
252 bit)
237{ 253{
238 GNUNET_assert(bit < 8 * sizeof(struct GNUNET_HashCode)); 254 GNUNET_assert (bit < 8 * sizeof(struct GNUNET_HashCode));
239 return (((unsigned char *)code)[bit >> 3] & (1 << (bit & 7))) > 0; 255 return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
240} 256}
241 257
242 258
@@ -253,14 +269,14 @@ GNUNET_CRYPTO_hash_get_bit(const struct GNUNET_HashCode * code, unsigned int bit
253 * @return the number of bits that match 269 * @return the number of bits that match
254 */ 270 */
255unsigned int 271unsigned int
256GNUNET_CRYPTO_hash_matching_bits(const struct GNUNET_HashCode * first, 272GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first,
257 const struct GNUNET_HashCode * second) 273 const struct GNUNET_HashCode *second)
258{ 274{
259 unsigned int i; 275 unsigned int i;
260 276
261 for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++) 277 for (i = 0; i < sizeof(struct GNUNET_HashCode) * 8; i++)
262 if (GNUNET_CRYPTO_hash_get_bit(first, i) != 278 if (GNUNET_CRYPTO_hash_get_bit (first, i) !=
263 GNUNET_CRYPTO_hash_get_bit(second, i)) 279 GNUNET_CRYPTO_hash_get_bit (second, i))
264 return i; 280 return i;
265 return sizeof(struct GNUNET_HashCode) * 8; 281 return sizeof(struct GNUNET_HashCode) * 8;
266} 282}
@@ -275,22 +291,23 @@ GNUNET_CRYPTO_hash_matching_bits(const struct GNUNET_HashCode * first,
275 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. 291 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
276 */ 292 */
277int 293int
278GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, 294GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode *h1,
279 const struct GNUNET_HashCode *h2) 295 const struct GNUNET_HashCode *h2)
280{ 296{
281 unsigned int *i1; 297 unsigned int *i1;
282 unsigned int *i2; 298 unsigned int *i2;
283 int i; 299 int i;
284 300
285 i1 = (unsigned int *)h1; 301 i1 = (unsigned int *) h1;
286 i2 = (unsigned int *)h2; 302 i2 = (unsigned int *) h2;
287 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0; i--) 303 for (i = (sizeof(struct GNUNET_HashCode) / sizeof(unsigned int)) - 1; i >= 0;
288 { 304 i--)
289 if (i1[i] > i2[i]) 305 {
290 return 1; 306 if (i1[i] > i2[i])
291 if (i1[i] < i2[i]) 307 return 1;
292 return -1; 308 if (i1[i] < i2[i])
293 } 309 return -1;
310 }
294 return 0; 311 return 0;
295} 312}
296 313
@@ -305,23 +322,24 @@ GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1,
305 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. 322 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2.
306 */ 323 */
307int 324int
308GNUNET_CRYPTO_hash_xorcmp(const struct GNUNET_HashCode *h1, 325GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode *h1,
309 const struct GNUNET_HashCode *h2, 326 const struct GNUNET_HashCode *h2,
310 const struct GNUNET_HashCode *target) 327 const struct GNUNET_HashCode *target)
311{ 328{
312 int i; 329 int i;
313 unsigned int d1; 330 unsigned int d1;
314 unsigned int d2; 331 unsigned int d2;
315 332
316 for (i = sizeof(struct GNUNET_HashCode) / sizeof(unsigned int) - 1; i >= 0; i--) 333 for (i = sizeof(struct GNUNET_HashCode) / sizeof(unsigned int) - 1; i >= 0;
317 { 334 i--)
318 d1 = ((unsigned int *)h1)[i] ^ ((unsigned int *)target)[i]; 335 {
319 d2 = ((unsigned int *)h2)[i] ^ ((unsigned int *)target)[i]; 336 d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i];
320 if (d1 > d2) 337 d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i];
321 return 1; 338 if (d1 > d2)
322 else if (d1 < d2) 339 return 1;
323 return -1; 340 else if (d1 < d2)
324 } 341 return -1;
342 }
325 return 0; 343 return 0;
326} 344}
327 345
@@ -335,15 +353,16 @@ GNUNET_CRYPTO_hash_xorcmp(const struct GNUNET_HashCode *h1,
335 * @param ... pair of void * & size_t for context chunks, terminated by NULL 353 * @param ... pair of void * & size_t for context chunks, terminated by NULL
336 */ 354 */
337void 355void
338GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, 356GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
339 const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, 357 const struct
340 const void *salt, size_t salt_len, ...) 358 GNUNET_CRYPTO_SymmetricSessionKey *rkey,
359 const void *salt, size_t salt_len, ...)
341{ 360{
342 va_list argp; 361 va_list argp;
343 362
344 va_start(argp, salt_len); 363 va_start (argp, salt_len);
345 GNUNET_CRYPTO_hmac_derive_key_v(key, rkey, salt, salt_len, argp); 364 GNUNET_CRYPTO_hmac_derive_key_v (key, rkey, salt, salt_len, argp);
346 va_end(argp); 365 va_end (argp);
347} 366}
348 367
349 368
@@ -356,15 +375,16 @@ GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key,
356 * @param argp pair of void * & size_t for context chunks, terminated by NULL 375 * @param argp pair of void * & size_t for context chunks, terminated by NULL
357 */ 376 */
358void 377void
359GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key, 378GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
360 const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, 379 const struct
361 const void *salt, size_t salt_len, 380 GNUNET_CRYPTO_SymmetricSessionKey *rkey,
362 va_list argp) 381 const void *salt, size_t salt_len,
382 va_list argp)
363{ 383{
364 GNUNET_CRYPTO_kdf_v(key->key, sizeof(key->key), 384 GNUNET_CRYPTO_kdf_v (key->key, sizeof(key->key),
365 salt, salt_len, 385 salt, salt_len,
366 rkey, sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey), 386 rkey, sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey),
367 argp); 387 argp);
368} 388}
369 389
370 390
@@ -380,29 +400,29 @@ GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key,
380 * @param hmac where to store the hmac 400 * @param hmac where to store the hmac
381 */ 401 */
382void 402void
383GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len, 403GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len,
384 const void *plaintext, size_t plaintext_len, 404 const void *plaintext, size_t plaintext_len,
385 struct GNUNET_HashCode *hmac) 405 struct GNUNET_HashCode *hmac)
386{ 406{
387 static int once; 407 static int once;
388 static gcry_md_hd_t md; 408 static gcry_md_hd_t md;
389 const unsigned char *mc; 409 const unsigned char *mc;
390 410
391 if (!once) 411 if (! once)
392 { 412 {
393 once = 1; 413 once = 1;
394 GNUNET_assert(GPG_ERR_NO_ERROR == 414 GNUNET_assert (GPG_ERR_NO_ERROR ==
395 gcry_md_open(&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC)); 415 gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC));
396 } 416 }
397 else 417 else
398 { 418 {
399 gcry_md_reset(md); 419 gcry_md_reset (md);
400 } 420 }
401 gcry_md_setkey(md, key, key_len); 421 gcry_md_setkey (md, key, key_len);
402 gcry_md_write(md, plaintext, plaintext_len); 422 gcry_md_write (md, plaintext, plaintext_len);
403 mc = gcry_md_read(md, GCRY_MD_SHA512); 423 mc = gcry_md_read (md, GCRY_MD_SHA512);
404 GNUNET_assert(NULL != mc); 424 GNUNET_assert (NULL != mc);
405 GNUNET_memcpy(hmac->bits, mc, sizeof(hmac->bits)); 425 GNUNET_memcpy (hmac->bits, mc, sizeof(hmac->bits));
406} 426}
407 427
408 428
@@ -415,20 +435,21 @@ GNUNET_CRYPTO_hmac_raw(const void *key, size_t key_len,
415 * @param hmac where to store the hmac 435 * @param hmac where to store the hmac
416 */ 436 */
417void 437void
418GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, 438GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
419 const void *plaintext, size_t plaintext_len, 439 const void *plaintext, size_t plaintext_len,
420 struct GNUNET_HashCode *hmac) 440 struct GNUNET_HashCode *hmac)
421{ 441{
422 GNUNET_CRYPTO_hmac_raw((void*)key->key, sizeof(key->key), 442 GNUNET_CRYPTO_hmac_raw ((void*) key->key, sizeof(key->key),
423 plaintext, plaintext_len, 443 plaintext, plaintext_len,
424 hmac); 444 hmac);
425} 445}
426 446
427 447
428/** 448/**
429 * Context for cummulative hashing. 449 * Context for cummulative hashing.
430 */ 450 */
431struct GNUNET_HashContext { 451struct GNUNET_HashContext
452{
432 /** 453 /**
433 * Internal state of the hash function. 454 * Internal state of the hash function.
434 */ 455 */
@@ -442,19 +463,19 @@ struct GNUNET_HashContext {
442 * @return context for incremental hash computation 463 * @return context for incremental hash computation
443 */ 464 */
444struct GNUNET_HashContext * 465struct GNUNET_HashContext *
445GNUNET_CRYPTO_hash_context_start() 466GNUNET_CRYPTO_hash_context_start ()
446{ 467{
447 struct GNUNET_HashContext *hc; 468 struct GNUNET_HashContext *hc;
448 469
449 BENCHMARK_START(hash_context_start); 470 BENCHMARK_START (hash_context_start);
450 471
451 hc = GNUNET_new(struct GNUNET_HashContext); 472 hc = GNUNET_new (struct GNUNET_HashContext);
452 GNUNET_assert(0 == 473 GNUNET_assert (0 ==
453 gcry_md_open(&hc->hd, 474 gcry_md_open (&hc->hd,
454 GCRY_MD_SHA512, 475 GCRY_MD_SHA512,
455 0)); 476 0));
456 477
457 BENCHMARK_END(hash_context_start); 478 BENCHMARK_END (hash_context_start);
458 479
459 return hc; 480 return hc;
460} 481}
@@ -468,13 +489,13 @@ GNUNET_CRYPTO_hash_context_start()
468 * @param size number of bytes in @a buf 489 * @param size number of bytes in @a buf
469 */ 490 */
470void 491void
471GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc, 492GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc,
472 const void *buf, 493 const void *buf,
473 size_t size) 494 size_t size)
474{ 495{
475 BENCHMARK_START(hash_context_read); 496 BENCHMARK_START (hash_context_read);
476 gcry_md_write(hc->hd, buf, size); 497 gcry_md_write (hc->hd, buf, size);
477 BENCHMARK_END(hash_context_read); 498 BENCHMARK_END (hash_context_read);
478} 499}
479 500
480 501
@@ -485,20 +506,20 @@ GNUNET_CRYPTO_hash_context_read(struct GNUNET_HashContext *hc,
485 * @param r_hash where to write the latest / final hash code 506 * @param r_hash where to write the latest / final hash code
486 */ 507 */
487void 508void
488GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc, 509GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc,
489 struct GNUNET_HashCode *r_hash) 510 struct GNUNET_HashCode *r_hash)
490{ 511{
491 const void *res = gcry_md_read(hc->hd, 0); 512 const void *res = gcry_md_read (hc->hd, 0);
492 513
493 BENCHMARK_START(hash_context_finish); 514 BENCHMARK_START (hash_context_finish);
494 515
495 GNUNET_assert(NULL != res); 516 GNUNET_assert (NULL != res);
496 if (NULL != r_hash) 517 if (NULL != r_hash)
497 GNUNET_memcpy(r_hash, 518 GNUNET_memcpy (r_hash,
498 res, 519 res,
499 sizeof(struct GNUNET_HashCode)); 520 sizeof(struct GNUNET_HashCode));
500 GNUNET_CRYPTO_hash_context_abort(hc); 521 GNUNET_CRYPTO_hash_context_abort (hc);
501 BENCHMARK_END(hash_context_finish); 522 BENCHMARK_END (hash_context_finish);
502} 523}
503 524
504 525
@@ -508,10 +529,10 @@ GNUNET_CRYPTO_hash_context_finish(struct GNUNET_HashContext *hc,
508 * @param hc hash context to destroy 529 * @param hc hash context to destroy
509 */ 530 */
510void 531void
511GNUNET_CRYPTO_hash_context_abort(struct GNUNET_HashContext *hc) 532GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc)
512{ 533{
513 gcry_md_close(hc->hd); 534 gcry_md_close (hc->hd);
514 GNUNET_free(hc); 535 GNUNET_free (hc);
515} 536}
516 537
517 538