aboutsummaryrefslogtreecommitdiff
path: root/src/util/crypto_hash.c
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2010-10-03 13:29:09 +0000
committerNils Durner <durner@gnunet.org>2010-10-03 13:29:09 +0000
commit9d9853441df5b565f6932fcf7fbb156b2d929392 (patch)
tree87d09554c804030a48fe33e46206c91dc312bf12 /src/util/crypto_hash.c
parentb7c95147188502651e4cb2b60c7062137f73e878 (diff)
downloadgnunet-9d9853441df5b565f6932fcf7fbb156b2d929392.tar.gz
gnunet-9d9853441df5b565f6932fcf7fbb156b2d929392.zip
KDF code
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r--src/util/crypto_hash.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 0fb2451b2..db911aa5f 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -832,6 +832,48 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
832 832
833 833
834/** 834/**
835 * @brief Derive an authentication key
836 * @param key authentication key
837 * @param rkey root key
838 * @param salt salt
839 * @param salt_len size of the salt
840 * @param ... pair of void * & size_t for context chunks, terminated by NULL
841 */
842void
843GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key,
844 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
845 const void *salt,
846 const size_t salt_len,
847 ...)
848{
849 va_list argp;
850
851 va_start (argp, salt_len);
852 GNUNET_CRYPTO_hmac_derive_key_v (key, rkey, salt, salt_len, argp);
853 va_end (argp);
854}
855
856
857/**
858 * @brief Derive an authentication key
859 * @param key authentication key
860 * @param rkey root key
861 * @param salt salt
862 * @param salt_len size of the salt
863 * @param argp pair of void * & size_t for context chunks, terminated by NULL
864 */
865void
866GNUNET_CRYPTO_hmac_derive_key_v(struct GNUNET_CRYPTO_AuthKey *key,
867 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
868 const void *salt,
869 const size_t salt_len,
870 const va_list argp)
871{
872 GNUNET_CRYPTO_kdf_v (key->key, sizeof(key->key), salt, salt_len, rkey->key,
873 sizeof(rkey->key), argp);
874}
875
876/**
835 * Calculate HMAC of a message (RFC 2104) 877 * Calculate HMAC of a message (RFC 2104)
836 * 878 *
837 * @param key secret key 879 * @param key secret key
@@ -840,7 +882,7 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
840 * @param hmac where to store the hmac 882 * @param hmac where to store the hmac
841 */ 883 */
842void 884void
843GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AesSessionKey *key, 885GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
844 const void *plaintext, 886 const void *plaintext,
845 size_t plaintext_len, 887 size_t plaintext_len,
846 GNUNET_HashCode *hmac) 888 GNUNET_HashCode *hmac)
@@ -852,8 +894,7 @@ GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AesSessionKey *key,
852 struct sha512_ctx sctx; 894 struct sha512_ctx sctx;
853 895
854 memset (&kh, 0, sizeof (kh)); 896 memset (&kh, 0, sizeof (kh));
855 GNUNET_assert (sizeof (GNUNET_HashCode) > sizeof (struct GNUNET_CRYPTO_AesSessionKey)); 897 memcpy (&kh, key->key, sizeof (struct GNUNET_CRYPTO_AuthKey));
856 memcpy (&kh, key, sizeof (struct GNUNET_CRYPTO_AesSessionKey));
857 memset (&ipad, 0x5c, sizeof (ipad)); 898 memset (&ipad, 0x5c, sizeof (ipad));
858 memset (&opad, 0x36, sizeof (opad)); 899 memset (&opad, 0x36, sizeof (opad));
859 GNUNET_CRYPTO_hash_xor (&ipad, &kh, &ipad); 900 GNUNET_CRYPTO_hash_xor (&ipad, &kh, &ipad);