aboutsummaryrefslogtreecommitdiffstats
path: root/lib/md5.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/md5.c')
-rw-r--r--lib/md5.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/lib/md5.c b/lib/md5.c
index 32d06349..b3912c58 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -27,19 +27,30 @@
#include <string.h>
#include "curl_md5.h"
+#include "curl_hmac.h"
#ifdef USE_GNUTLS
#include <gcrypt.h>
-void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
- const unsigned char *input)
+typedef gcry_md_hd_t MD5_CTX;
+
+static void MD5_Init(MD5_CTX * ctx)
+{
+ gcry_md_open(ctx, GCRY_MD_MD5, 0);
+}
+
+static void MD5_Update(MD5_CTX * ctx,
+ const unsigned char * input,
+ unsigned int inputLen)
+{
+ gcry_md_write(*ctx, input, inputLen);
+}
+
+static void MD5_Final(unsigned char digest[16], MD5_CTX * ctx)
{
- gcry_md_hd_t ctx;
- gcry_md_open(&ctx, GCRY_MD_MD5, 0);
- gcry_md_write(ctx, input, (unsigned int)strlen((char *)input));
- memcpy (outbuffer, gcry_md_read (ctx, 0), 16);
- gcry_md_close(ctx);
+ memcpy(digest, gcry_md_read(*ctx, 0), 16);
+ gcry_md_close(*ctx);
}
#else
@@ -194,7 +205,7 @@ static void MD5_Update (struct md5_ctx *context, /* context */
/* Transform as many times as possible. */
if(inputLen >= partLen) {
- memcpy((void *)&context->buffer[bufindex], (void *)input, partLen);
+ memcpy(&context->buffer[bufindex], input, partLen);
MD5Transform(context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64)
@@ -206,7 +217,7 @@ static void MD5_Update (struct md5_ctx *context, /* context */
i = 0;
/* Buffer remaining input */
- memcpy((void *)&context->buffer[bufindex], (void *)&input[i], inputLen-i);
+ memcpy(&context->buffer[bufindex], &input[i], inputLen-i);
}
/* MD5 finalization. Ends an MD5 message-digest operation, writing the
@@ -358,6 +369,20 @@ static void Decode (UINT4 *output,
#endif /* USE_SSLEAY */
+#endif /* USE_GNUTLS */
+
+const HMAC_params Curl_HMAC_MD5[] = {
+ {
+ (HMAC_hinit_func) MD5_Init, /* Hash initialization function. */
+ (HMAC_hupdate_func) MD5_Update, /* Hash update function. */
+ (HMAC_hfinal_func) MD5_Final, /* Hash computation end function. */
+ sizeof(MD5_CTX), /* Size of hash context structure. */
+ 64, /* Maximum key length. */
+ 16 /* Result size. */
+ }
+};
+
+
void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
const unsigned char *input)
{
@@ -367,6 +392,4 @@ void Curl_md5it(unsigned char *outbuffer, /* 16 bytes */
MD5_Final(outbuffer, &ctx);
}
-#endif /* USE_GNUTLS */
-
#endif /* CURL_DISABLE_CRYPTO_AUTH */