aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_hash.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-10-07 20:04:54 +0000
committerChristian Grothoff <christian@grothoff.org>2010-10-07 20:04:54 +0000
commit0ff0854fcadc3c84f5f5125610306fadcf202649 (patch)
tree8a499e4b5415d11b0d95e9371881c533cf0cd8ae /src/util/crypto_hash.c
parentfaf7ea3640432864044108d16c311f72e4a0826d (diff)
downloadgnunet-0ff0854fcadc3c84f5f5125610306fadcf202649.tar.gz
gnunet-0ff0854fcadc3c84f5f5125610306fadcf202649.zip
small fixes and style issues
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r--src/util/crypto_hash.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 8ec822434..879285772 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -401,9 +401,11 @@ GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
401 result->bits[i] = delta->bits[i] + a->bits[i]; 401 result->bits[i] = delta->bits[i] + a->bits[i];
402} 402}
403 403
404
404void 405void
405GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, 406GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a,
406 const GNUNET_HashCode * b, GNUNET_HashCode * result) 407 const GNUNET_HashCode * b,
408 GNUNET_HashCode * result)
407{ 409{
408 int i; 410 int i;
409 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 411 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
@@ -411,6 +413,7 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a,
411 result->bits[i] = a->bits[i] ^ b->bits[i]; 413 result->bits[i] = a->bits[i] ^ b->bits[i];
412} 414}
413 415
416
414/** 417/**
415 * Convert a hashcode into a key. 418 * Convert a hashcode into a key.
416 */ 419 */
@@ -430,6 +433,7 @@ GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
430 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 433 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
431} 434}
432 435
436
433/** 437/**
434 * Obtain a bit from a hashcode. 438 * Obtain a bit from a hashcode.
435 * @param code the GNUNET_CRYPTO_hash to index bit-wise 439 * @param code the GNUNET_CRYPTO_hash to index bit-wise
@@ -437,7 +441,8 @@ GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
437 * @return Bit \a bit from hashcode \a code, -1 for invalid index 441 * @return Bit \a bit from hashcode \a code, -1 for invalid index
438 */ 442 */
439int 443int
440GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit) 444GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code,
445 unsigned int bit)
441{ 446{
442 GNUNET_assert (bit < 8 * sizeof (GNUNET_HashCode)); 447 GNUNET_assert (bit < 8 * sizeof (GNUNET_HashCode));
443 return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0; 448 return (((unsigned char *) code)[bit >> 3] & (1 << (bit & 7))) > 0;
@@ -455,7 +460,9 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit)
455 * 460 *
456 * @return the number of bits that match 461 * @return the number of bits that match
457 */ 462 */
458unsigned int GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, const GNUNET_HashCode *second) 463unsigned int
464GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first,
465 const GNUNET_HashCode *second)
459{ 466{
460 unsigned int i; 467 unsigned int i;
461 468
@@ -465,6 +472,7 @@ unsigned int GNUNET_CRYPTO_hash_matching_bits(const GNUNET_HashCode *first, cons
465 return sizeof (GNUNET_HashCode) * 8; 472 return sizeof (GNUNET_HashCode) * 8;
466} 473}
467 474
475
468/** 476/**
469 * Compare function for HashCodes, producing a total ordering 477 * Compare function for HashCodes, producing a total ordering
470 * of all hashcodes. 478 * of all hashcodes.
@@ -491,6 +499,7 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1,
491 return 0; 499 return 0;
492} 500}
493 501
502
494/** 503/**
495 * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target 504 * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target
496 * in the XOR metric (Kademlia). 505 * in the XOR metric (Kademlia).
@@ -556,10 +565,15 @@ GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key,
556 const size_t salt_len, 565 const size_t salt_len,
557 va_list argp) 566 va_list argp)
558{ 567{
559 GNUNET_CRYPTO_kdf_v (key->key, sizeof(key->key), salt, salt_len, rkey->key, 568 GNUNET_CRYPTO_kdf_v (key->key,
560 sizeof(rkey->key), argp); 569 sizeof(key->key),
570 salt, salt_len,
571 rkey->key,
572 sizeof(rkey->key), /* FIXME: this is likely wrong! */
573 argp);
561} 574}
562 575
576
563/** 577/**
564 * Calculate HMAC of a message (RFC 2104) 578 * Calculate HMAC of a message (RFC 2104)
565 * 579 *
@@ -577,7 +591,9 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
577 gcry_md_hd_t md; 591 gcry_md_hd_t md;
578 unsigned char *mc; 592 unsigned char *mc;
579 593
580 GNUNET_assert (GPG_ERR_NO_ERROR == gcry_md_open (&md, GCRY_MD_SHA512, GCRY_MD_FLAG_HMAC)); 594 GNUNET_assert (GPG_ERR_NO_ERROR == gcry_md_open (&md,
595 GCRY_MD_SHA512,
596 GCRY_MD_FLAG_HMAC));
581 gcry_md_setkey (md, key->key, sizeof(key->key)); 597 gcry_md_setkey (md, key->key, sizeof(key->key));
582 gcry_md_write (md, plaintext, plaintext_len); 598 gcry_md_write (md, plaintext, plaintext_len);
583 mc = gcry_md_read (md, GCRY_MD_SHA512); 599 mc = gcry_md_read (md, GCRY_MD_SHA512);