From 9bd90e6e25f1e55f50201c87a1b5837de7e5b64a Mon Sep 17 00:00:00 2001 From: Lucas Eckels Date: Mon, 6 Aug 2012 15:07:02 -0700 Subject: Add Music Manager's curl 7.21.2 source. Change-Id: I259a43fa52d581524a5ce8ae1711467acb1d9d50 --- lib/md5.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'lib/md5.c') diff --git a/lib/md5.c b/lib/md5.c index 32d0634..b3912c5 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2008, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2010, Daniel Stenberg, , 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 #include "curl_md5.h" +#include "curl_hmac.h" #ifdef USE_GNUTLS #include -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 */ -- cgit v1.2.3