diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-06-18 15:29:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-06-18 15:29:45 +0000 |
commit | 475452849162e7c123141d9710b2cf3480e8f868 (patch) | |
tree | 8620c2483f15825dcff38b000d635190ffa6cc6c /src/util/crypto_hash.c | |
parent | e4794e7e4bc63d2023768e3b1017f19bd0d41c5f (diff) | |
download | gnunet-475452849162e7c123141d9710b2cf3480e8f868.tar.gz gnunet-475452849162e7c123141d9710b2cf3480e8f868.zip |
hmac
Diffstat (limited to 'src/util/crypto_hash.c')
-rw-r--r-- | src/util/crypto_hash.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c index 74ea72de4..09366a949 100644 --- a/src/util/crypto_hash.c +++ b/src/util/crypto_hash.c | |||
@@ -806,4 +806,43 @@ GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, | |||
806 | return 0; | 806 | return 0; |
807 | } | 807 | } |
808 | 808 | ||
809 | |||
810 | /** | ||
811 | * Calculate HMAC of a message (RFC 2104) | ||
812 | * | ||
813 | * @param key secret key | ||
814 | * @param plaintext input plaintext | ||
815 | * @param plaintext_len length of plaintext | ||
816 | * @param hmac where to store the hmac | ||
817 | */ | ||
818 | void | ||
819 | GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AesSessionKey *key, | ||
820 | const void *plaintext, | ||
821 | size_t plaintext_len, | ||
822 | GNUNET_HashCode *hmac) | ||
823 | { | ||
824 | GNUNET_HashCode kh; | ||
825 | GNUNET_HashCode ipad; | ||
826 | GNUNET_HashCode opad; | ||
827 | GNUNET_HashCode him; | ||
828 | struct sha512_ctx sctx; | ||
829 | |||
830 | memset (&kh, 0, sizeof (kh)); | ||
831 | GNUNET_assert (sizeof (GNUNET_HashCode) > sizeof (struct GNUNET_CRYPTO_AesSessionKey)); | ||
832 | memcpy (&kh, key, sizeof (struct GNUNET_CRYPTO_AesSessionKey)); | ||
833 | memset (&ipad, 0x5c, sizeof (ipad)); | ||
834 | memset (&opad, 0x36, sizeof (opad)); | ||
835 | GNUNET_CRYPTO_hash_xor (&ipad, &kh, &ipad); | ||
836 | GNUNET_CRYPTO_hash_xor (&opad, &kh, &opad); | ||
837 | sha512_init (&sctx); | ||
838 | sha512_update (&sctx, (const unsigned char*) &ipad, sizeof (ipad)); | ||
839 | sha512_update (&sctx, plaintext, plaintext_len); | ||
840 | sha512_final (&sctx, (unsigned char*) &him); | ||
841 | sha512_init (&sctx); | ||
842 | sha512_update (&sctx, (const unsigned char*) &opad, sizeof (opad)); | ||
843 | sha512_update (&sctx, (const unsigned char*) &him, sizeof (him)); | ||
844 | sha512_final (&sctx, (unsigned char*) hmac); | ||
845 | } | ||
846 | |||
847 | |||
809 | /* end of crypto_hash.c */ | 848 | /* end of crypto_hash.c */ |