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.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 8410b7835..fe1f58df7 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -365,14 +365,17 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
365 365
366/** 366/**
367 * Calculate HMAC of a message (RFC 2104) 367 * Calculate HMAC of a message (RFC 2104)
368 * TODO: Shouldn' this be the standard hmac function and
369 * the above be renamed?
368 * 370 *
369 * @param key secret key 371 * @param key secret key
372 * @param key_len secret key length
370 * @param plaintext input plaintext 373 * @param plaintext input plaintext
371 * @param plaintext_len length of @a plaintext 374 * @param plaintext_len length of @a plaintext
372 * @param hmac where to store the hmac 375 * @param hmac where to store the hmac
373 */ 376 */
374void 377void
375GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 378GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len,
376 const void *plaintext, size_t plaintext_len, 379 const void *plaintext, size_t plaintext_len,
377 struct GNUNET_HashCode *hmac) 380 struct GNUNET_HashCode *hmac)
378{ 381{
@@ -390,7 +393,7 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
390 { 393 {
391 gcry_md_reset (md); 394 gcry_md_reset (md);
392 } 395 }
393 gcry_md_setkey (md, key->key, sizeof (key->key)); 396 gcry_md_setkey (md, key, key_len);
394 gcry_md_write (md, plaintext, plaintext_len); 397 gcry_md_write (md, plaintext, plaintext_len);
395 mc = gcry_md_read (md, GCRY_MD_SHA512); 398 mc = gcry_md_read (md, GCRY_MD_SHA512);
396 GNUNET_assert (NULL != mc); 399 GNUNET_assert (NULL != mc);
@@ -399,6 +402,25 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
399 402
400 403
401/** 404/**
405 * Calculate HMAC of a message (RFC 2104)
406 *
407 * @param key secret key
408 * @param plaintext input plaintext
409 * @param plaintext_len length of @a plaintext
410 * @param hmac where to store the hmac
411 */
412void
413GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
414 const void *plaintext, size_t plaintext_len,
415 struct GNUNET_HashCode *hmac)
416{
417 GNUNET_CRYPTO_hmac_raw ((void*) key->key, sizeof (key->key),
418 plaintext, plaintext_len,
419 hmac);
420}
421
422
423/**
402 * Context for cummulative hashing. 424 * Context for cummulative hashing.
403 */ 425 */
404struct GNUNET_HashContext 426struct GNUNET_HashContext