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.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index cce9cf82a..fe1f58df7 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -2,20 +2,18 @@
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2001-2013 GNUnet e.V. 3 Copyright (C) 2001-2013 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software: you can redistribute it and/or modify it
6 it under the terms of the GNU General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation; either version 3, or (at your 7 by the Free Software Foundation, either version 3 of the License,
8 option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 17
20*/ 18*/
21/** 19/**
@@ -367,14 +365,17 @@ GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
367 365
368/** 366/**
369 * 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?
370 * 370 *
371 * @param key secret key 371 * @param key secret key
372 * @param key_len secret key length
372 * @param plaintext input plaintext 373 * @param plaintext input plaintext
373 * @param plaintext_len length of @a plaintext 374 * @param plaintext_len length of @a plaintext
374 * @param hmac where to store the hmac 375 * @param hmac where to store the hmac
375 */ 376 */
376void 377void
377GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key, 378GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len,
378 const void *plaintext, size_t plaintext_len, 379 const void *plaintext, size_t plaintext_len,
379 struct GNUNET_HashCode *hmac) 380 struct GNUNET_HashCode *hmac)
380{ 381{
@@ -392,7 +393,7 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
392 { 393 {
393 gcry_md_reset (md); 394 gcry_md_reset (md);
394 } 395 }
395 gcry_md_setkey (md, key->key, sizeof (key->key)); 396 gcry_md_setkey (md, key, key_len);
396 gcry_md_write (md, plaintext, plaintext_len); 397 gcry_md_write (md, plaintext, plaintext_len);
397 mc = gcry_md_read (md, GCRY_MD_SHA512); 398 mc = gcry_md_read (md, GCRY_MD_SHA512);
398 GNUNET_assert (NULL != mc); 399 GNUNET_assert (NULL != mc);
@@ -401,6 +402,25 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
401 402
402 403
403/** 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/**
404 * Context for cummulative hashing. 424 * Context for cummulative hashing.
405 */ 425 */
406struct GNUNET_HashContext 426struct GNUNET_HashContext