diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-12 19:07:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-12 19:07:40 +0000 |
commit | 6c471eeb15e27f8226492b4860a3c2acb94c5f25 (patch) | |
tree | a3a9dcba12ee5356c03056c10b7aba5367b2ef34 /src/util/crypto_hash.c | |
parent | 16bcbbea7133fd2265d46bd2ae1dc70e8c9ba96f (diff) | |
download | gnunet-6c471eeb15e27f8226492b4860a3c2acb94c5f25.tar.gz gnunet-6c471eeb15e27f8226492b4860a3c2acb94c5f25.zip |
-consistently use struct GNUNET_HashCode
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r-- | src/util/crypto_hash.c | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index 4d957c00e..04225b3dc 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -49,7 +49,7 @@ | |||
49 | * @param ret pointer to where to write the hashcode | 49 | * @param ret pointer to where to write the hashcode |
50 | */ | 50 | */ |
51 | void | 51 | void |
52 | GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret) | 52 | GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode * ret) |
53 | { | 53 | { |
54 | gcry_md_hash_buffer (GCRY_MD_SHA512, ret, block, size); | 54 | gcry_md_hash_buffer (GCRY_MD_SHA512, ret, block, size); |
55 | } | 55 | } |
@@ -140,7 +140,7 @@ struct GNUNET_CRYPTO_FileHashContext | |||
140 | */ | 140 | */ |
141 | static void | 141 | static void |
142 | file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc, | 142 | file_hash_finish (struct GNUNET_CRYPTO_FileHashContext *fhc, |
143 | const GNUNET_HashCode * res) | 143 | const struct GNUNET_HashCode * res) |
144 | { | 144 | { |
145 | fhc->callback (fhc->callback_cls, res); | 145 | fhc->callback (fhc->callback_cls, res); |
146 | GNUNET_free (fhc->filename); | 146 | GNUNET_free (fhc->filename); |
@@ -161,7 +161,7 @@ static void | |||
161 | file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 161 | file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
162 | { | 162 | { |
163 | struct GNUNET_CRYPTO_FileHashContext *fhc = cls; | 163 | struct GNUNET_CRYPTO_FileHashContext *fhc = cls; |
164 | GNUNET_HashCode *res; | 164 | struct GNUNET_HashCode *res; |
165 | size_t delta; | 165 | size_t delta; |
166 | 166 | ||
167 | fhc->task = GNUNET_SCHEDULER_NO_TASK; | 167 | fhc->task = GNUNET_SCHEDULER_NO_TASK; |
@@ -179,7 +179,7 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
179 | fhc->offset += delta; | 179 | fhc->offset += delta; |
180 | if (fhc->offset == fhc->fsize) | 180 | if (fhc->offset == fhc->fsize) |
181 | { | 181 | { |
182 | res = (GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); | 182 | res = (struct GNUNET_HashCode *) gcry_md_read (fhc->md, GCRY_MD_SHA512); |
183 | file_hash_finish (fhc, res); | 183 | file_hash_finish (fhc, res); |
184 | return; | 184 | return; |
185 | } | 185 | } |
@@ -272,7 +272,7 @@ GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc) | |||
272 | * safely cast to char*, a '\\0' termination is set). | 272 | * safely cast to char*, a '\\0' termination is set). |
273 | */ | 273 | */ |
274 | void | 274 | void |
275 | GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, | 275 | GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode * block, |
276 | struct GNUNET_CRYPTO_HashAsciiEncoded *result) | 276 | struct GNUNET_CRYPTO_HashAsciiEncoded *result) |
277 | { | 277 | { |
278 | char *np; | 278 | char *np; |
@@ -296,7 +296,7 @@ GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block, | |||
296 | */ | 296 | */ |
297 | int | 297 | int |
298 | GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, | 298 | GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, |
299 | GNUNET_HashCode * result) | 299 | struct GNUNET_HashCode * result) |
300 | { | 300 | { |
301 | char upper_enc[enclen]; | 301 | char upper_enc[enclen]; |
302 | char* up_ptr = upper_enc; | 302 | char* up_ptr = upper_enc; |
@@ -321,8 +321,8 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, | |||
321 | * hashcode proximity. | 321 | * hashcode proximity. |
322 | */ | 322 | */ |
323 | unsigned int | 323 | unsigned int |
324 | GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, | 324 | GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode * a, |
325 | const GNUNET_HashCode * b) | 325 | const struct GNUNET_HashCode * b) |
326 | { | 326 | { |
327 | unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; | 327 | unsigned int x1 = (a->bits[1] - b->bits[1]) >> 16; |
328 | unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; | 328 | unsigned int x2 = (b->bits[1] - a->bits[1]) >> 16; |
@@ -339,11 +339,11 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a, | |||
339 | */ | 339 | */ |
340 | void | 340 | void |
341 | GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, | 341 | GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, |
342 | GNUNET_HashCode * result) | 342 | struct GNUNET_HashCode * result) |
343 | { | 343 | { |
344 | int i; | 344 | int i; |
345 | 345 | ||
346 | for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--) | 346 | for (i = (sizeof (struct GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--) |
347 | result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, UINT32_MAX); | 347 | result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, UINT32_MAX); |
348 | } | 348 | } |
349 | 349 | ||
@@ -356,13 +356,13 @@ GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, | |||
356 | * @param result set to b - a | 356 | * @param result set to b - a |
357 | */ | 357 | */ |
358 | void | 358 | void |
359 | GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, | 359 | GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode * a, |
360 | const GNUNET_HashCode * b, | 360 | const struct GNUNET_HashCode * b, |
361 | GNUNET_HashCode * result) | 361 | struct GNUNET_HashCode * result) |
362 | { | 362 | { |
363 | int i; | 363 | int i; |
364 | 364 | ||
365 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) | 365 | for (i = (sizeof (struct GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) |
366 | result->bits[i] = b->bits[i] - a->bits[i]; | 366 | result->bits[i] = b->bits[i] - a->bits[i]; |
367 | } | 367 | } |
368 | 368 | ||
@@ -375,12 +375,12 @@ GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, | |||
375 | * @param result set to a + delta | 375 | * @param result set to a + delta |
376 | */ | 376 | */ |
377 | void | 377 | void |
378 | GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, | 378 | GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode * a, |
379 | const GNUNET_HashCode * delta, GNUNET_HashCode * result) | 379 | const struct GNUNET_HashCode * delta, struct GNUNET_HashCode * result) |
380 | { | 380 | { |
381 | int i; | 381 | int i; |
382 | 382 | ||
383 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) | 383 | for (i = (sizeof (struct GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) |
384 | result->bits[i] = delta->bits[i] + a->bits[i]; | 384 | result->bits[i] = delta->bits[i] + a->bits[i]; |
385 | } | 385 | } |
386 | 386 | ||
@@ -393,12 +393,12 @@ GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, | |||
393 | * @param result set to a ^ b | 393 | * @param result set to a ^ b |
394 | */ | 394 | */ |
395 | void | 395 | void |
396 | GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, | 396 | GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode * a, const struct GNUNET_HashCode * b, |
397 | GNUNET_HashCode * result) | 397 | struct GNUNET_HashCode * result) |
398 | { | 398 | { |
399 | int i; | 399 | int i; |
400 | 400 | ||
401 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) | 401 | for (i = (sizeof (struct GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) |
402 | result->bits[i] = a->bits[i] ^ b->bits[i]; | 402 | result->bits[i] = a->bits[i] ^ b->bits[i]; |
403 | } | 403 | } |
404 | 404 | ||
@@ -411,11 +411,11 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b, | |||
411 | * @param iv set to a valid initialization vector | 411 | * @param iv set to a valid initialization vector |
412 | */ | 412 | */ |
413 | void | 413 | void |
414 | GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, | 414 | GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc, |
415 | struct GNUNET_CRYPTO_AesSessionKey *skey, | 415 | struct GNUNET_CRYPTO_AesSessionKey *skey, |
416 | struct GNUNET_CRYPTO_AesInitializationVector *iv) | 416 | struct GNUNET_CRYPTO_AesInitializationVector *iv) |
417 | { | 417 | { |
418 | GNUNET_assert (sizeof (GNUNET_HashCode) >= | 418 | GNUNET_assert (sizeof (struct GNUNET_HashCode) >= |
419 | GNUNET_CRYPTO_AES_KEY_LENGTH + | 419 | GNUNET_CRYPTO_AES_KEY_LENGTH + |
420 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); | 420 | sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); |
421 | memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); | 421 | memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); |
@@ -433,16 +433,16 @@ GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, | |||
433 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | 433 | * @return Bit \a bit from hashcode \a code, -1 for invalid index |
434 | */ | 434 | */ |
435 | int | 435 | int |
436 | GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit) | 436 | GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode * code, unsigned int bit) |
437 | { | 437 | { |
438 | GNUNET_assert (bit < 8 * sizeof (GNUNET_HashCode)); | 438 | GNUNET_assert (bit < 8 * sizeof (struct GNUNET_HashCode)); |
439 | return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; | 439 | return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; |
440 | } | 440 | } |
441 | 441 | ||
442 | 442 | ||
443 | /** | 443 | /** |
444 | * Determine how many low order bits match in two | 444 | * Determine how many low order bits match in two |
445 | * GNUNET_HashCodes. i.e. - 010011 and 011111 share | 445 | * struct GNUNET_HashCodes. i.e. - 010011 and 011111 share |
446 | * the first two lowest order bits, and therefore the | 446 | * the first two lowest order bits, and therefore the |
447 | * return value is two (NOT XOR distance, nor how many | 447 | * return value is two (NOT XOR distance, nor how many |
448 | * bits match absolutely!). | 448 | * bits match absolutely!). |
@@ -453,16 +453,16 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit) | |||
453 | * @return the number of bits that match | 453 | * @return the number of bits that match |
454 | */ | 454 | */ |
455 | unsigned int | 455 | unsigned int |
456 | GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, | 456 | GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode * first, |
457 | const GNUNET_HashCode * second) | 457 | const struct GNUNET_HashCode * second) |
458 | { | 458 | { |
459 | unsigned int i; | 459 | unsigned int i; |
460 | 460 | ||
461 | for (i = 0; i < sizeof (GNUNET_HashCode) * 8; i++) | 461 | for (i = 0; i < sizeof (struct GNUNET_HashCode) * 8; i++) |
462 | if (GNUNET_CRYPTO_hash_get_bit (first, i) != | 462 | if (GNUNET_CRYPTO_hash_get_bit (first, i) != |
463 | GNUNET_CRYPTO_hash_get_bit (second, i)) | 463 | GNUNET_CRYPTO_hash_get_bit (second, i)) |
464 | return i; | 464 | return i; |
465 | return sizeof (GNUNET_HashCode) * 8; | 465 | return sizeof (struct GNUNET_HashCode) * 8; |
466 | } | 466 | } |
467 | 467 | ||
468 | 468 | ||
@@ -475,7 +475,7 @@ GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first, | |||
475 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. | 475 | * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2. |
476 | */ | 476 | */ |
477 | int | 477 | int |
478 | GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2) | 478 | GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode * h1, const struct GNUNET_HashCode * h2) |
479 | { | 479 | { |
480 | unsigned int *i1; | 480 | unsigned int *i1; |
481 | unsigned int *i2; | 481 | unsigned int *i2; |
@@ -483,7 +483,7 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2) | |||
483 | 483 | ||
484 | i1 = (unsigned int *) h1; | 484 | i1 = (unsigned int *) h1; |
485 | i2 = (unsigned int *) h2; | 485 | i2 = (unsigned int *) h2; |
486 | for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) | 486 | for (i = (sizeof (struct GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; i--) |
487 | { | 487 | { |
488 | if (i1[i] > i2[i]) | 488 | if (i1[i] > i2[i]) |
489 | return 1; | 489 | return 1; |
@@ -504,15 +504,15 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2) | |||
504 | * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. | 504 | * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2. |
505 | */ | 505 | */ |
506 | int | 506 | int |
507 | GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, | 507 | GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode * h1, |
508 | const GNUNET_HashCode * h2, | 508 | const struct GNUNET_HashCode * h2, |
509 | const GNUNET_HashCode * target) | 509 | const struct GNUNET_HashCode * target) |
510 | { | 510 | { |
511 | int i; | 511 | int i; |
512 | unsigned int d1; | 512 | unsigned int d1; |
513 | unsigned int d2; | 513 | unsigned int d2; |
514 | 514 | ||
515 | for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) | 515 | for (i = sizeof (struct GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) |
516 | { | 516 | { |
517 | d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; | 517 | d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; |
518 | d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; | 518 | d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; |
@@ -576,7 +576,7 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key, | |||
576 | void | 576 | void |
577 | GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, | 577 | GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, |
578 | const void *plaintext, size_t plaintext_len, | 578 | const void *plaintext, size_t plaintext_len, |
579 | GNUNET_HashCode * hmac) | 579 | struct GNUNET_HashCode * hmac) |
580 | { | 580 | { |
581 | gcry_md_hd_t md; | 581 | gcry_md_hd_t md; |
582 | const unsigned char *mc; | 582 | const unsigned char *mc; |