lib: remove function pointer typecasts for hmac/sha256/md5
Make sure we use functions with the correct prototype. Closes #15289
This commit is contained in:
parent
335d325708
commit
ad1c49bc0e
@ -32,30 +32,28 @@
|
|||||||
|
|
||||||
#define HMAC_MD5_LENGTH 16
|
#define HMAC_MD5_LENGTH 16
|
||||||
|
|
||||||
typedef CURLcode (* HMAC_hinit_func)(void *context);
|
typedef CURLcode (*HMAC_hinit)(void *context);
|
||||||
typedef void (* HMAC_hupdate_func)(void *context,
|
typedef void (*HMAC_hupdate)(void *context,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
typedef void (* HMAC_hfinal_func)(unsigned char *result, void *context);
|
typedef void (*HMAC_hfinal)(unsigned char *result, void *context);
|
||||||
|
|
||||||
|
|
||||||
/* Per-hash function HMAC parameters. */
|
/* Per-hash function HMAC parameters. */
|
||||||
struct HMAC_params {
|
struct HMAC_params {
|
||||||
HMAC_hinit_func
|
HMAC_hinit hinit; /* Initialize context procedure. */
|
||||||
hmac_hinit; /* Initialize context procedure. */
|
HMAC_hupdate hupdate; /* Update context with data. */
|
||||||
HMAC_hupdate_func hmac_hupdate; /* Update context with data. */
|
HMAC_hfinal hfinal; /* Get final result procedure. */
|
||||||
HMAC_hfinal_func hmac_hfinal; /* Get final result procedure. */
|
unsigned int ctxtsize; /* Context structure size. */
|
||||||
unsigned int hmac_ctxtsize; /* Context structure size. */
|
unsigned int maxkeylen; /* Maximum key length (bytes). */
|
||||||
unsigned int hmac_maxkeylen; /* Maximum key length (bytes). */
|
unsigned int resultlen; /* Result length (bytes). */
|
||||||
unsigned int hmac_resultlen; /* Result length (bytes). */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* HMAC computation context. */
|
/* HMAC computation context. */
|
||||||
struct HMAC_context {
|
struct HMAC_context {
|
||||||
const struct HMAC_params *hmac_hash; /* Hash function definition. */
|
const struct HMAC_params *hash; /* Hash function definition. */
|
||||||
void *hmac_hashctxt1; /* Hash function context 1. */
|
void *hashctxt1; /* Hash function context 1. */
|
||||||
void *hmac_hashctxt2; /* Hash function context 2. */
|
void *hashctxt2; /* Hash function context 2. */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -31,11 +31,11 @@
|
|||||||
|
|
||||||
#define MD5_DIGEST_LEN 16
|
#define MD5_DIGEST_LEN 16
|
||||||
|
|
||||||
typedef CURLcode (* Curl_MD5_init_func)(void *context);
|
typedef CURLcode (*Curl_MD5_init_func)(void *context);
|
||||||
typedef void (* Curl_MD5_update_func)(void *context,
|
typedef void (*Curl_MD5_update_func)(void *context,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
unsigned int len);
|
unsigned int len);
|
||||||
typedef void (* Curl_MD5_final_func)(unsigned char *result, void *context);
|
typedef void (*Curl_MD5_final_func)(unsigned char *result, void *context);
|
||||||
|
|
||||||
struct MD5_params {
|
struct MD5_params {
|
||||||
Curl_MD5_init_func md5_init_func; /* Initialize context procedure */
|
Curl_MD5_init_func md5_init_func; /* Initialize context procedure */
|
||||||
@ -50,8 +50,8 @@ struct MD5_context {
|
|||||||
void *md5_hashctx; /* Hash function context */
|
void *md5_hashctx; /* Hash function context */
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct MD5_params Curl_DIGEST_MD5[1];
|
extern const struct MD5_params Curl_DIGEST_MD5;
|
||||||
extern const struct HMAC_params Curl_HMAC_MD5[1];
|
extern const struct HMAC_params Curl_HMAC_MD5;
|
||||||
|
|
||||||
CURLcode Curl_md5it(unsigned char *output, const unsigned char *input,
|
CURLcode Curl_md5it(unsigned char *output, const unsigned char *input,
|
||||||
const size_t len);
|
const size_t len);
|
||||||
|
|||||||
@ -528,7 +528,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_hash(const char *user, size_t userlen,
|
|||||||
ascii_uppercase_to_unicode_le(identity, user, userlen);
|
ascii_uppercase_to_unicode_le(identity, user, userlen);
|
||||||
ascii_to_unicode_le(identity + (userlen << 1), domain, domlen);
|
ascii_to_unicode_le(identity + (userlen << 1), domain, domlen);
|
||||||
|
|
||||||
result = Curl_hmacit(Curl_HMAC_MD5, ntlmhash, 16, identity, identity_len,
|
result = Curl_hmacit(&Curl_HMAC_MD5, ntlmhash, 16, identity, identity_len,
|
||||||
ntlmv2hash);
|
ntlmv2hash);
|
||||||
free(identity);
|
free(identity);
|
||||||
|
|
||||||
@ -613,7 +613,7 @@ CURLcode Curl_ntlm_core_mk_ntlmv2_resp(unsigned char *ntlmv2hash,
|
|||||||
|
|
||||||
/* Concatenate the Type 2 challenge with the BLOB and do HMAC MD5 */
|
/* Concatenate the Type 2 challenge with the BLOB and do HMAC MD5 */
|
||||||
memcpy(ptr + 8, &ntlm->nonce[0], 8);
|
memcpy(ptr + 8, &ntlm->nonce[0], 8);
|
||||||
result = Curl_hmacit(Curl_HMAC_MD5, ntlmv2hash, HMAC_MD5_LENGTH, ptr + 8,
|
result = Curl_hmacit(&Curl_HMAC_MD5, ntlmv2hash, HMAC_MD5_LENGTH, ptr + 8,
|
||||||
NTLMv2_BLOB_LEN + 8, hmac_output);
|
NTLMv2_BLOB_LEN + 8, hmac_output);
|
||||||
if(result) {
|
if(result) {
|
||||||
free(ptr);
|
free(ptr);
|
||||||
@ -656,7 +656,7 @@ CURLcode Curl_ntlm_core_mk_lmv2_resp(unsigned char *ntlmv2hash,
|
|||||||
memcpy(&data[0], challenge_server, 8);
|
memcpy(&data[0], challenge_server, 8);
|
||||||
memcpy(&data[8], challenge_client, 8);
|
memcpy(&data[8], challenge_client, 8);
|
||||||
|
|
||||||
result = Curl_hmacit(Curl_HMAC_MD5, ntlmv2hash, 16, &data[0], 16,
|
result = Curl_hmacit(&Curl_HMAC_MD5, ntlmv2hash, 16, &data[0], 16,
|
||||||
hmac_output);
|
hmac_output);
|
||||||
if(result)
|
if(result)
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@ -31,7 +31,7 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include "curl_hmac.h"
|
#include "curl_hmac.h"
|
||||||
|
|
||||||
extern const struct HMAC_params Curl_HMAC_SHA256[1];
|
extern const struct HMAC_params Curl_HMAC_SHA256;
|
||||||
|
|
||||||
#ifndef CURL_SHA256_DIGEST_LENGTH
|
#ifndef CURL_SHA256_DIGEST_LENGTH
|
||||||
#define CURL_SHA256_DIGEST_LENGTH 32 /* fixed size */
|
#define CURL_SHA256_DIGEST_LENGTH 32 /* fixed size */
|
||||||
|
|||||||
70
lib/hmac.c
70
lib/hmac.c
@ -49,8 +49,6 @@
|
|||||||
static const unsigned char hmac_ipad = 0x36;
|
static const unsigned char hmac_ipad = 0x36;
|
||||||
static const unsigned char hmac_opad = 0x5C;
|
static const unsigned char hmac_opad = 0x5C;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct HMAC_context *
|
struct HMAC_context *
|
||||||
Curl_HMAC_init(const struct HMAC_params *hashparams,
|
Curl_HMAC_init(const struct HMAC_params *hashparams,
|
||||||
const unsigned char *key,
|
const unsigned char *key,
|
||||||
@ -62,42 +60,40 @@ Curl_HMAC_init(const struct HMAC_params *hashparams,
|
|||||||
unsigned char b;
|
unsigned char b;
|
||||||
|
|
||||||
/* Create HMAC context. */
|
/* Create HMAC context. */
|
||||||
i = sizeof(*ctxt) + 2 * hashparams->hmac_ctxtsize +
|
i = sizeof(*ctxt) + 2 * hashparams->ctxtsize + hashparams->resultlen;
|
||||||
hashparams->hmac_resultlen;
|
|
||||||
ctxt = malloc(i);
|
ctxt = malloc(i);
|
||||||
|
|
||||||
if(!ctxt)
|
if(!ctxt)
|
||||||
return ctxt;
|
return ctxt;
|
||||||
|
|
||||||
ctxt->hmac_hash = hashparams;
|
ctxt->hash = hashparams;
|
||||||
ctxt->hmac_hashctxt1 = (void *) (ctxt + 1);
|
ctxt->hashctxt1 = (void *) (ctxt + 1);
|
||||||
ctxt->hmac_hashctxt2 = (void *) ((char *) ctxt->hmac_hashctxt1 +
|
ctxt->hashctxt2 = (void *) ((char *) ctxt->hashctxt1 + hashparams->ctxtsize);
|
||||||
hashparams->hmac_ctxtsize);
|
|
||||||
|
|
||||||
/* If the key is too long, replace it by its hash digest. */
|
/* If the key is too long, replace it by its hash digest. */
|
||||||
if(keylen > hashparams->hmac_maxkeylen) {
|
if(keylen > hashparams->maxkeylen) {
|
||||||
(*hashparams->hmac_hinit)(ctxt->hmac_hashctxt1);
|
hashparams->hinit(ctxt->hashctxt1);
|
||||||
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, key, keylen);
|
hashparams->hupdate(ctxt->hashctxt1, key, keylen);
|
||||||
hkey = (unsigned char *) ctxt->hmac_hashctxt2 + hashparams->hmac_ctxtsize;
|
hkey = (unsigned char *) ctxt->hashctxt2 + hashparams->ctxtsize;
|
||||||
(*hashparams->hmac_hfinal)(hkey, ctxt->hmac_hashctxt1);
|
hashparams->hfinal(hkey, ctxt->hashctxt1);
|
||||||
key = hkey;
|
key = hkey;
|
||||||
keylen = hashparams->hmac_resultlen;
|
keylen = hashparams->resultlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prime the two hash contexts with the modified key. */
|
/* Prime the two hash contexts with the modified key. */
|
||||||
(*hashparams->hmac_hinit)(ctxt->hmac_hashctxt1);
|
hashparams->hinit(ctxt->hashctxt1);
|
||||||
(*hashparams->hmac_hinit)(ctxt->hmac_hashctxt2);
|
hashparams->hinit(ctxt->hashctxt2);
|
||||||
|
|
||||||
for(i = 0; i < keylen; i++) {
|
for(i = 0; i < keylen; i++) {
|
||||||
b = (unsigned char)(*key ^ hmac_ipad);
|
b = (unsigned char)(*key ^ hmac_ipad);
|
||||||
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &b, 1);
|
hashparams->hupdate(ctxt->hashctxt1, &b, 1);
|
||||||
b = (unsigned char)(*key++ ^ hmac_opad);
|
b = (unsigned char)(*key++ ^ hmac_opad);
|
||||||
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &b, 1);
|
hashparams->hupdate(ctxt->hashctxt2, &b, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; i < hashparams->hmac_maxkeylen; i++) {
|
for(; i < hashparams->maxkeylen; i++) {
|
||||||
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &hmac_ipad, 1);
|
hashparams->hupdate(ctxt->hashctxt1, &hmac_ipad, 1);
|
||||||
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &hmac_opad, 1);
|
hashparams->hupdate(ctxt->hashctxt2, &hmac_opad, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Done, return pointer to HMAC context. */
|
/* Done, return pointer to HMAC context. */
|
||||||
@ -105,31 +101,29 @@ Curl_HMAC_init(const struct HMAC_params *hashparams,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Curl_HMAC_update(struct HMAC_context *ctxt,
|
int Curl_HMAC_update(struct HMAC_context *ctxt,
|
||||||
const unsigned char *data,
|
const unsigned char *ptr,
|
||||||
unsigned int len)
|
unsigned int len)
|
||||||
{
|
{
|
||||||
/* Update first hash calculation. */
|
/* Update first hash calculation. */
|
||||||
(*ctxt->hmac_hash->hmac_hupdate)(ctxt->hmac_hashctxt1, data, len);
|
ctxt->hash->hupdate(ctxt->hashctxt1, ptr, len);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *result)
|
int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *output)
|
||||||
{
|
{
|
||||||
const struct HMAC_params *hashparams = ctxt->hmac_hash;
|
const struct HMAC_params *hashparams = ctxt->hash;
|
||||||
|
|
||||||
/* Do not get result if called with a null parameter: only release
|
/* Do not get output if called with a null parameter: only release
|
||||||
storage. */
|
storage. */
|
||||||
|
|
||||||
if(!result)
|
if(!output)
|
||||||
result = (unsigned char *) ctxt->hmac_hashctxt2 +
|
output = (unsigned char *) ctxt->hashctxt2 + ctxt->hash->ctxtsize;
|
||||||
ctxt->hmac_hash->hmac_ctxtsize;
|
|
||||||
|
|
||||||
(*hashparams->hmac_hfinal)(result, ctxt->hmac_hashctxt1);
|
hashparams->hfinal(output, ctxt->hashctxt1);
|
||||||
(*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2,
|
hashparams->hupdate(ctxt->hashctxt2, output, hashparams->resultlen);
|
||||||
result, hashparams->hmac_resultlen);
|
hashparams->hfinal(output, ctxt->hashctxt2);
|
||||||
(*hashparams->hmac_hfinal)(result, ctxt->hmac_hashctxt2);
|
free(ctxt);
|
||||||
free((char *) ctxt);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,15 +138,15 @@ int Curl_HMAC_final(struct HMAC_context *ctxt, unsigned char *result)
|
|||||||
* hashparams [in] - The hash function (Curl_HMAC_MD5).
|
* hashparams [in] - The hash function (Curl_HMAC_MD5).
|
||||||
* key [in] - The key to use.
|
* key [in] - The key to use.
|
||||||
* keylen [in] - The length of the key.
|
* keylen [in] - The length of the key.
|
||||||
* data [in] - The data to encrypt.
|
* buf [in] - The data to encrypt.
|
||||||
* datalen [in] - The length of the data.
|
* buflen [in] - The length of the data.
|
||||||
* output [in/out] - The output buffer.
|
* output [in/out] - The output buffer.
|
||||||
*
|
*
|
||||||
* Returns CURLE_OK on success.
|
* Returns CURLE_OK on success.
|
||||||
*/
|
*/
|
||||||
CURLcode Curl_hmacit(const struct HMAC_params *hashparams,
|
CURLcode Curl_hmacit(const struct HMAC_params *hashparams,
|
||||||
const unsigned char *key, const size_t keylen,
|
const unsigned char *key, const size_t keylen,
|
||||||
const unsigned char *data, const size_t datalen,
|
const unsigned char *buf, const size_t buflen,
|
||||||
unsigned char *output)
|
unsigned char *output)
|
||||||
{
|
{
|
||||||
struct HMAC_context *ctxt =
|
struct HMAC_context *ctxt =
|
||||||
@ -162,7 +156,7 @@ CURLcode Curl_hmacit(const struct HMAC_params *hashparams,
|
|||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* Update the digest with the given challenge */
|
/* Update the digest with the given challenge */
|
||||||
Curl_HMAC_update(ctxt, data, curlx_uztoui(datalen));
|
Curl_HMAC_update(ctxt, buf, curlx_uztoui(buflen));
|
||||||
|
|
||||||
/* Finalise the digest */
|
/* Finalise the digest */
|
||||||
Curl_HMAC_final(ctxt, output);
|
Curl_HMAC_final(ctxt, output);
|
||||||
|
|||||||
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
#define HMAC_SHA256(k, kl, d, dl, o) \
|
#define HMAC_SHA256(k, kl, d, dl, o) \
|
||||||
do { \
|
do { \
|
||||||
result = Curl_hmacit(Curl_HMAC_SHA256, \
|
result = Curl_hmacit(&Curl_HMAC_SHA256, \
|
||||||
(unsigned char *)k, \
|
(unsigned char *)k, \
|
||||||
kl, \
|
kl, \
|
||||||
(unsigned char *)d, \
|
(unsigned char *)d, \
|
||||||
|
|||||||
99
lib/md5.c
99
lib/md5.c
@ -88,20 +88,20 @@
|
|||||||
|
|
||||||
typedef struct md5_ctx my_md5_ctx;
|
typedef struct md5_ctx my_md5_ctx;
|
||||||
|
|
||||||
static CURLcode my_md5_init(my_md5_ctx *ctx)
|
static CURLcode my_md5_init(void *ctx)
|
||||||
{
|
{
|
||||||
md5_init(ctx);
|
md5_init(ctx);
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_update(my_md5_ctx *ctx,
|
static void my_md5_update(void *ctx,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
unsigned int inputLen)
|
unsigned int inputLen)
|
||||||
{
|
{
|
||||||
md5_update(ctx, inputLen, input);
|
md5_update(ctx, inputLen, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_final(unsigned char *digest, my_md5_ctx *ctx)
|
static void my_md5_final(unsigned char *digest, void *ctx)
|
||||||
{
|
{
|
||||||
md5_digest(ctx, 16, digest);
|
md5_digest(ctx, 16, digest);
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ static void my_md5_final(unsigned char *digest, my_md5_ctx *ctx)
|
|||||||
|
|
||||||
typedef MD5_CTX my_md5_ctx;
|
typedef MD5_CTX my_md5_ctx;
|
||||||
|
|
||||||
static CURLcode my_md5_init(my_md5_ctx *ctx)
|
static CURLcode my_md5_init(void *ctx)
|
||||||
{
|
{
|
||||||
if(!MD5_Init(ctx))
|
if(!MD5_Init(ctx))
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
@ -118,14 +118,14 @@ static CURLcode my_md5_init(my_md5_ctx *ctx)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_update(my_md5_ctx *ctx,
|
static void my_md5_update(void *ctx,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
unsigned int len)
|
unsigned int len)
|
||||||
{
|
{
|
||||||
(void)MD5_Update(ctx, input, len);
|
(void)MD5_Update(ctx, input, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_final(unsigned char *digest, my_md5_ctx *ctx)
|
static void my_md5_final(unsigned char *digest, void *ctx)
|
||||||
{
|
{
|
||||||
(void)MD5_Final(digest, ctx);
|
(void)MD5_Final(digest, ctx);
|
||||||
}
|
}
|
||||||
@ -134,7 +134,7 @@ static void my_md5_final(unsigned char *digest, my_md5_ctx *ctx)
|
|||||||
|
|
||||||
typedef mbedtls_md5_context my_md5_ctx;
|
typedef mbedtls_md5_context my_md5_ctx;
|
||||||
|
|
||||||
static CURLcode my_md5_init(my_md5_ctx *ctx)
|
static CURLcode my_md5_init(void *ctx)
|
||||||
{
|
{
|
||||||
#if (MBEDTLS_VERSION_NUMBER >= 0x03000000)
|
#if (MBEDTLS_VERSION_NUMBER >= 0x03000000)
|
||||||
if(mbedtls_md5_starts(ctx))
|
if(mbedtls_md5_starts(ctx))
|
||||||
@ -148,7 +148,7 @@ static CURLcode my_md5_init(my_md5_ctx *ctx)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_update(my_md5_ctx *ctx,
|
static void my_md5_update(void *ctx,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
unsigned int length)
|
unsigned int length)
|
||||||
{
|
{
|
||||||
@ -159,7 +159,7 @@ static void my_md5_update(my_md5_ctx *ctx,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_final(unsigned char *digest, my_md5_ctx *ctx)
|
static void my_md5_final(unsigned char *digest, void *ctx)
|
||||||
{
|
{
|
||||||
#if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS)
|
#if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS)
|
||||||
(void) mbedtls_md5_finish(ctx, digest);
|
(void) mbedtls_md5_finish(ctx, digest);
|
||||||
@ -178,7 +178,7 @@ static void my_md5_final(unsigned char *digest, my_md5_ctx *ctx)
|
|||||||
reliable than defining COMMON_DIGEST_FOR_OPENSSL on older cats. */
|
reliable than defining COMMON_DIGEST_FOR_OPENSSL on older cats. */
|
||||||
# define my_md5_ctx CC_MD5_CTX
|
# define my_md5_ctx CC_MD5_CTX
|
||||||
|
|
||||||
static CURLcode my_md5_init(my_md5_ctx *ctx)
|
static CURLcode my_md5_init(void *ctx)
|
||||||
{
|
{
|
||||||
if(!CC_MD5_Init(ctx))
|
if(!CC_MD5_Init(ctx))
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
@ -186,14 +186,14 @@ static CURLcode my_md5_init(my_md5_ctx *ctx)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_update(my_md5_ctx *ctx,
|
static void my_md5_update(void *ctx,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
unsigned int inputLen)
|
unsigned int inputLen)
|
||||||
{
|
{
|
||||||
CC_MD5_Update(ctx, input, inputLen);
|
CC_MD5_Update(ctx, input, inputLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_final(unsigned char *digest, my_md5_ctx *ctx)
|
static void my_md5_final(unsigned char *digest, void *ctx)
|
||||||
{
|
{
|
||||||
CC_MD5_Final(digest, ctx);
|
CC_MD5_Final(digest, ctx);
|
||||||
}
|
}
|
||||||
@ -206,8 +206,9 @@ struct md5_ctx {
|
|||||||
};
|
};
|
||||||
typedef struct md5_ctx my_md5_ctx;
|
typedef struct md5_ctx my_md5_ctx;
|
||||||
|
|
||||||
static CURLcode my_md5_init(my_md5_ctx *ctx)
|
static CURLcode my_md5_init(void *in)
|
||||||
{
|
{
|
||||||
|
my_md5_ctx *ctx = (my_md5_ctx *)in;
|
||||||
if(!CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_FULL,
|
if(!CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_FULL,
|
||||||
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
@ -221,15 +222,17 @@ static CURLcode my_md5_init(my_md5_ctx *ctx)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_update(my_md5_ctx *ctx,
|
static void my_md5_update(void *in,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
unsigned int inputLen)
|
unsigned int inputLen)
|
||||||
{
|
{
|
||||||
|
my_md5_ctx *ctx = in;
|
||||||
CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
|
CryptHashData(ctx->hHash, (unsigned char *)input, inputLen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_final(unsigned char *digest, my_md5_ctx *ctx)
|
static void my_md5_final(unsigned char *digest, void *in)
|
||||||
{
|
{
|
||||||
|
my_md5_ctx *ctx = (my_md5_ctx *)in;
|
||||||
unsigned long length = 0;
|
unsigned long length = 0;
|
||||||
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
|
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
|
||||||
if(length == 16)
|
if(length == 16)
|
||||||
@ -292,10 +295,10 @@ struct md5_ctx {
|
|||||||
};
|
};
|
||||||
typedef struct md5_ctx my_md5_ctx;
|
typedef struct md5_ctx my_md5_ctx;
|
||||||
|
|
||||||
static CURLcode my_md5_init(my_md5_ctx *ctx);
|
static CURLcode my_md5_init(void *ctx);
|
||||||
static void my_md5_update(my_md5_ctx *ctx, const void *data,
|
static void my_md5_update(void *ctx, const unsigned char *data,
|
||||||
unsigned long size);
|
unsigned int size);
|
||||||
static void my_md5_final(unsigned char *result, my_md5_ctx *ctx);
|
static void my_md5_final(unsigned char *result, void *ctx);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The basic MD5 functions.
|
* The basic MD5 functions.
|
||||||
@ -455,8 +458,9 @@ static const void *my_md5_body(my_md5_ctx *ctx,
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CURLcode my_md5_init(my_md5_ctx *ctx)
|
static CURLcode my_md5_init(void *in)
|
||||||
{
|
{
|
||||||
|
my_md5_ctx *ctx = (my_md5_ctx *)in;
|
||||||
ctx->a = 0x67452301;
|
ctx->a = 0x67452301;
|
||||||
ctx->b = 0xefcdab89;
|
ctx->b = 0xefcdab89;
|
||||||
ctx->c = 0x98badcfe;
|
ctx->c = 0x98badcfe;
|
||||||
@ -468,11 +472,12 @@ static CURLcode my_md5_init(my_md5_ctx *ctx)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_update(my_md5_ctx *ctx, const void *data,
|
static void my_md5_update(void *in, const unsigned char *data,
|
||||||
unsigned long size)
|
unsigned int size)
|
||||||
{
|
{
|
||||||
MD5_u32plus saved_lo;
|
MD5_u32plus saved_lo;
|
||||||
unsigned long used;
|
unsigned int used;
|
||||||
|
my_md5_ctx *ctx = (my_md5_ctx *)in;
|
||||||
|
|
||||||
saved_lo = ctx->lo;
|
saved_lo = ctx->lo;
|
||||||
ctx->lo = (saved_lo + size) & 0x1fffffff;
|
ctx->lo = (saved_lo + size) & 0x1fffffff;
|
||||||
@ -483,7 +488,7 @@ static void my_md5_update(my_md5_ctx *ctx, const void *data,
|
|||||||
used = saved_lo & 0x3f;
|
used = saved_lo & 0x3f;
|
||||||
|
|
||||||
if(used) {
|
if(used) {
|
||||||
unsigned long available = 64 - used;
|
unsigned int available = 64 - used;
|
||||||
|
|
||||||
if(size < available) {
|
if(size < available) {
|
||||||
memcpy(&ctx->buffer[used], data, size);
|
memcpy(&ctx->buffer[used], data, size);
|
||||||
@ -504,9 +509,10 @@ static void my_md5_update(my_md5_ctx *ctx, const void *data,
|
|||||||
memcpy(ctx->buffer, data, size);
|
memcpy(ctx->buffer, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_md5_final(unsigned char *result, my_md5_ctx *ctx)
|
static void my_md5_final(unsigned char *result, void *in)
|
||||||
{
|
{
|
||||||
unsigned long used, available;
|
unsigned int used, available;
|
||||||
|
my_md5_ctx *ctx = (my_md5_ctx *)in;
|
||||||
|
|
||||||
used = ctx->lo & 0x3f;
|
used = ctx->lo & 0x3f;
|
||||||
|
|
||||||
@ -557,36 +563,21 @@ static void my_md5_final(unsigned char *result, my_md5_ctx *ctx)
|
|||||||
|
|
||||||
#endif /* CRYPTO LIBS */
|
#endif /* CRYPTO LIBS */
|
||||||
|
|
||||||
const struct HMAC_params Curl_HMAC_MD5[] = {
|
const struct HMAC_params Curl_HMAC_MD5 = {
|
||||||
{
|
my_md5_init, /* Hash initialization function. */
|
||||||
/* Hash initialization function. */
|
my_md5_update, /* Hash update function. */
|
||||||
CURLX_FUNCTION_CAST(HMAC_hinit_func, my_md5_init),
|
my_md5_final, /* Hash computation end function. */
|
||||||
/* Hash update function. */
|
sizeof(my_md5_ctx), /* Size of hash context structure. */
|
||||||
CURLX_FUNCTION_CAST(HMAC_hupdate_func, my_md5_update),
|
64, /* Maximum key length. */
|
||||||
/* Hash computation end function. */
|
16 /* Result size. */
|
||||||
CURLX_FUNCTION_CAST(HMAC_hfinal_func, my_md5_final),
|
|
||||||
/* Size of hash context structure. */
|
|
||||||
sizeof(my_md5_ctx),
|
|
||||||
/* Maximum key length. */
|
|
||||||
64,
|
|
||||||
/* Result size. */
|
|
||||||
16
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct MD5_params Curl_DIGEST_MD5[] = {
|
const struct MD5_params Curl_DIGEST_MD5 = {
|
||||||
{
|
my_md5_init, /* Digest initialization function */
|
||||||
/* Digest initialization function */
|
my_md5_update, /* Digest update function */
|
||||||
CURLX_FUNCTION_CAST(Curl_MD5_init_func, my_md5_init),
|
my_md5_final, /* Digest computation end function */
|
||||||
/* Digest update function */
|
sizeof(my_md5_ctx), /* Size of digest context struct */
|
||||||
CURLX_FUNCTION_CAST(Curl_MD5_update_func, my_md5_update),
|
16 /* Result size */
|
||||||
/* Digest computation end function */
|
|
||||||
CURLX_FUNCTION_CAST(Curl_MD5_final_func, my_md5_final),
|
|
||||||
/* Size of digest context struct */
|
|
||||||
sizeof(my_md5_ctx),
|
|
||||||
/* Result size */
|
|
||||||
16
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -504,7 +504,7 @@ static CURLcode pop3_perform_apop(struct Curl_easy *data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Create the digest */
|
/* Create the digest */
|
||||||
ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
|
ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
|
||||||
if(!ctxt)
|
if(!ctxt)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
|||||||
89
lib/sha256.c
89
lib/sha256.c
@ -105,8 +105,9 @@ struct ossl_sha256_ctx {
|
|||||||
};
|
};
|
||||||
typedef struct ossl_sha256_ctx my_sha256_ctx;
|
typedef struct ossl_sha256_ctx my_sha256_ctx;
|
||||||
|
|
||||||
static CURLcode my_sha256_init(my_sha256_ctx *ctx)
|
static CURLcode my_sha256_init(void *in)
|
||||||
{
|
{
|
||||||
|
my_sha256_ctx *ctx = (my_sha256_ctx *)in;
|
||||||
ctx->openssl_ctx = EVP_MD_CTX_create();
|
ctx->openssl_ctx = EVP_MD_CTX_create();
|
||||||
if(!ctx->openssl_ctx)
|
if(!ctx->openssl_ctx)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
@ -118,15 +119,17 @@ static CURLcode my_sha256_init(my_sha256_ctx *ctx)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_update(my_sha256_ctx *ctx,
|
static void my_sha256_update(void *in,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
unsigned int length)
|
unsigned int length)
|
||||||
{
|
{
|
||||||
|
my_sha256_ctx *ctx = (my_sha256_ctx *)in;
|
||||||
EVP_DigestUpdate(ctx->openssl_ctx, data, length);
|
EVP_DigestUpdate(ctx->openssl_ctx, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_final(unsigned char *digest, my_sha256_ctx *ctx)
|
static void my_sha256_final(unsigned char *digest, void *in)
|
||||||
{
|
{
|
||||||
|
my_sha256_ctx *ctx = (my_sha256_ctx *)in;
|
||||||
EVP_DigestFinal_ex(ctx->openssl_ctx, digest, NULL);
|
EVP_DigestFinal_ex(ctx->openssl_ctx, digest, NULL);
|
||||||
EVP_MD_CTX_destroy(ctx->openssl_ctx);
|
EVP_MD_CTX_destroy(ctx->openssl_ctx);
|
||||||
}
|
}
|
||||||
@ -135,20 +138,20 @@ static void my_sha256_final(unsigned char *digest, my_sha256_ctx *ctx)
|
|||||||
|
|
||||||
typedef struct sha256_ctx my_sha256_ctx;
|
typedef struct sha256_ctx my_sha256_ctx;
|
||||||
|
|
||||||
static CURLcode my_sha256_init(my_sha256_ctx *ctx)
|
static CURLcode my_sha256_init(void *ctx)
|
||||||
{
|
{
|
||||||
sha256_init(ctx);
|
sha256_init(ctx);
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_update(my_sha256_ctx *ctx,
|
static void my_sha256_update(void *ctx,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
unsigned int length)
|
unsigned int length)
|
||||||
{
|
{
|
||||||
sha256_update(ctx, length, data);
|
sha256_update(ctx, length, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_final(unsigned char *digest, my_sha256_ctx *ctx)
|
static void my_sha256_final(unsigned char *digest, void *ctx)
|
||||||
{
|
{
|
||||||
sha256_digest(ctx, SHA256_DIGEST_SIZE, digest);
|
sha256_digest(ctx, SHA256_DIGEST_SIZE, digest);
|
||||||
}
|
}
|
||||||
@ -157,7 +160,7 @@ static void my_sha256_final(unsigned char *digest, my_sha256_ctx *ctx)
|
|||||||
|
|
||||||
typedef mbedtls_sha256_context my_sha256_ctx;
|
typedef mbedtls_sha256_context my_sha256_ctx;
|
||||||
|
|
||||||
static CURLcode my_sha256_init(my_sha256_ctx *ctx)
|
static CURLcode my_sha256_init(void *ctx)
|
||||||
{
|
{
|
||||||
#if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS)
|
#if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS)
|
||||||
(void) mbedtls_sha256_starts(ctx, 0);
|
(void) mbedtls_sha256_starts(ctx, 0);
|
||||||
@ -167,7 +170,7 @@ static CURLcode my_sha256_init(my_sha256_ctx *ctx)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_update(my_sha256_ctx *ctx,
|
static void my_sha256_update(void *ctx,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
unsigned int length)
|
unsigned int length)
|
||||||
{
|
{
|
||||||
@ -178,7 +181,7 @@ static void my_sha256_update(my_sha256_ctx *ctx,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_final(unsigned char *digest, my_sha256_ctx *ctx)
|
static void my_sha256_final(unsigned char *digest, void *ctx)
|
||||||
{
|
{
|
||||||
#if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS)
|
#if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS)
|
||||||
(void) mbedtls_sha256_finish(ctx, digest);
|
(void) mbedtls_sha256_finish(ctx, digest);
|
||||||
@ -190,20 +193,20 @@ static void my_sha256_final(unsigned char *digest, my_sha256_ctx *ctx)
|
|||||||
#elif defined(AN_APPLE_OS)
|
#elif defined(AN_APPLE_OS)
|
||||||
typedef CC_SHA256_CTX my_sha256_ctx;
|
typedef CC_SHA256_CTX my_sha256_ctx;
|
||||||
|
|
||||||
static CURLcode my_sha256_init(my_sha256_ctx *ctx)
|
static CURLcode my_sha256_init(void *ctx)
|
||||||
{
|
{
|
||||||
(void) CC_SHA256_Init(ctx);
|
(void) CC_SHA256_Init(ctx);
|
||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_update(my_sha256_ctx *ctx,
|
static void my_sha256_update(void *ctx,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
unsigned int length)
|
unsigned int length)
|
||||||
{
|
{
|
||||||
(void) CC_SHA256_Update(ctx, data, length);
|
(void) CC_SHA256_Update(ctx, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_final(unsigned char *digest, my_sha256_ctx *ctx)
|
static void my_sha256_final(unsigned char *digest, void *ctx)
|
||||||
{
|
{
|
||||||
(void) CC_SHA256_Final(digest, ctx);
|
(void) CC_SHA256_Final(digest, ctx);
|
||||||
}
|
}
|
||||||
@ -220,8 +223,9 @@ typedef struct sha256_ctx my_sha256_ctx;
|
|||||||
#define CALG_SHA_256 0x0000800c
|
#define CALG_SHA_256 0x0000800c
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static CURLcode my_sha256_init(my_sha256_ctx *ctx)
|
static CURLcode my_sha256_init(void *in)
|
||||||
{
|
{
|
||||||
|
my_sha256_ctx *ctx = (my_sha256_ctx *)in;
|
||||||
if(!CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_AES,
|
if(!CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_AES,
|
||||||
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
@ -235,15 +239,17 @@ static CURLcode my_sha256_init(my_sha256_ctx *ctx)
|
|||||||
return CURLE_OK;
|
return CURLE_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_update(my_sha256_ctx *ctx,
|
static void my_sha256_update(void *in,
|
||||||
const unsigned char *data,
|
const unsigned char *data,
|
||||||
unsigned int length)
|
unsigned int length)
|
||||||
{
|
{
|
||||||
|
my_sha256_ctx *ctx = (my_sha256_ctx *)in;
|
||||||
CryptHashData(ctx->hHash, (unsigned char *) data, length, 0);
|
CryptHashData(ctx->hHash, (unsigned char *) data, length, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void my_sha256_final(unsigned char *digest, my_sha256_ctx *ctx)
|
static void my_sha256_final(unsigned char *digest, void *in)
|
||||||
{
|
{
|
||||||
|
my_sha256_ctx *ctx = (my_sha256_ctx *)in;
|
||||||
unsigned long length = 0;
|
unsigned long length = 0;
|
||||||
|
|
||||||
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
|
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
|
||||||
@ -388,8 +394,9 @@ static int sha256_compress(struct sha256_state *md,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the hash state */
|
/* Initialize the hash state */
|
||||||
static CURLcode my_sha256_init(struct sha256_state *md)
|
static CURLcode my_sha256_init(void *in)
|
||||||
{
|
{
|
||||||
|
struct sha256_state *md = (struct sha256_state *)in;
|
||||||
md->curlen = 0;
|
md->curlen = 0;
|
||||||
md->length = 0;
|
md->length = 0;
|
||||||
md->state[0] = 0x6A09E667UL;
|
md->state[0] = 0x6A09E667UL;
|
||||||
@ -409,21 +416,21 @@ static CURLcode my_sha256_init(struct sha256_state *md)
|
|||||||
@param md The hash state
|
@param md The hash state
|
||||||
@param in The data to hash
|
@param in The data to hash
|
||||||
@param inlen The length of the data (octets)
|
@param inlen The length of the data (octets)
|
||||||
@return 0 if successful
|
|
||||||
*/
|
*/
|
||||||
static int my_sha256_update(struct sha256_state *md,
|
static void my_sha256_update(void *ctx,
|
||||||
const unsigned char *in,
|
const unsigned char *in,
|
||||||
unsigned long inlen)
|
unsigned int len)
|
||||||
{
|
{
|
||||||
|
unsigned long inlen = len;
|
||||||
unsigned long n;
|
unsigned long n;
|
||||||
|
struct sha256_state *md = (struct sha256_state *)ctx;
|
||||||
#define CURL_SHA256_BLOCK_SIZE 64
|
#define CURL_SHA256_BLOCK_SIZE 64
|
||||||
if(md->curlen > sizeof(md->buf))
|
if(md->curlen > sizeof(md->buf))
|
||||||
return -1;
|
return;
|
||||||
while(inlen > 0) {
|
while(inlen > 0) {
|
||||||
if(md->curlen == 0 && inlen >= CURL_SHA256_BLOCK_SIZE) {
|
if(md->curlen == 0 && inlen >= CURL_SHA256_BLOCK_SIZE) {
|
||||||
if(sha256_compress(md, (unsigned char *)in) < 0)
|
if(sha256_compress(md, (unsigned char *)in) < 0)
|
||||||
return -1;
|
return;
|
||||||
md->length += CURL_SHA256_BLOCK_SIZE * 8;
|
md->length += CURL_SHA256_BLOCK_SIZE * 8;
|
||||||
in += CURL_SHA256_BLOCK_SIZE;
|
in += CURL_SHA256_BLOCK_SIZE;
|
||||||
inlen -= CURL_SHA256_BLOCK_SIZE;
|
inlen -= CURL_SHA256_BLOCK_SIZE;
|
||||||
@ -436,14 +443,12 @@ static int my_sha256_update(struct sha256_state *md,
|
|||||||
inlen -= n;
|
inlen -= n;
|
||||||
if(md->curlen == CURL_SHA256_BLOCK_SIZE) {
|
if(md->curlen == CURL_SHA256_BLOCK_SIZE) {
|
||||||
if(sha256_compress(md, md->buf) < 0)
|
if(sha256_compress(md, md->buf) < 0)
|
||||||
return -1;
|
return;
|
||||||
md->length += 8 * CURL_SHA256_BLOCK_SIZE;
|
md->length += 8 * CURL_SHA256_BLOCK_SIZE;
|
||||||
md->curlen = 0;
|
md->curlen = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -452,13 +457,13 @@ static int my_sha256_update(struct sha256_state *md,
|
|||||||
@param out [out] The destination of the hash (32 bytes)
|
@param out [out] The destination of the hash (32 bytes)
|
||||||
@return 0 if successful
|
@return 0 if successful
|
||||||
*/
|
*/
|
||||||
static int my_sha256_final(unsigned char *out,
|
static void my_sha256_final(unsigned char *out, void *ctx)
|
||||||
struct sha256_state *md)
|
|
||||||
{
|
{
|
||||||
|
struct sha256_state *md = ctx;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(md->curlen >= sizeof(md->buf))
|
if(md->curlen >= sizeof(md->buf))
|
||||||
return -1;
|
return;
|
||||||
|
|
||||||
/* Increase the length of the message */
|
/* Increase the length of the message */
|
||||||
md->length += md->curlen * 8;
|
md->length += md->curlen * 8;
|
||||||
@ -490,8 +495,6 @@ static int my_sha256_final(unsigned char *out,
|
|||||||
/* Copy output */
|
/* Copy output */
|
||||||
for(i = 0; i < 8; i++)
|
for(i = 0; i < 8; i++)
|
||||||
WPA_PUT_BE32(out + (4 * i), md->state[i]);
|
WPA_PUT_BE32(out + (4 * i), md->state[i]);
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CRYPTO LIBS */
|
#endif /* CRYPTO LIBS */
|
||||||
@ -510,7 +513,7 @@ static int my_sha256_final(unsigned char *out,
|
|||||||
* Returns CURLE_OK on success.
|
* Returns CURLE_OK on success.
|
||||||
*/
|
*/
|
||||||
CURLcode Curl_sha256it(unsigned char *output, const unsigned char *input,
|
CURLcode Curl_sha256it(unsigned char *output, const unsigned char *input,
|
||||||
const size_t length)
|
const size_t length)
|
||||||
{
|
{
|
||||||
CURLcode result;
|
CURLcode result;
|
||||||
my_sha256_ctx ctx;
|
my_sha256_ctx ctx;
|
||||||
@ -524,21 +527,13 @@ CURLcode Curl_sha256it(unsigned char *output, const unsigned char *input,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const struct HMAC_params Curl_HMAC_SHA256[] = {
|
const struct HMAC_params Curl_HMAC_SHA256 = {
|
||||||
{
|
my_sha256_init, /* Hash initialization function. */
|
||||||
/* Hash initialization function. */
|
my_sha256_update, /* Hash update function. */
|
||||||
CURLX_FUNCTION_CAST(HMAC_hinit_func, my_sha256_init),
|
my_sha256_final, /* Hash computation end function. */
|
||||||
/* Hash update function. */
|
sizeof(my_sha256_ctx), /* Size of hash context structure. */
|
||||||
CURLX_FUNCTION_CAST(HMAC_hupdate_func, my_sha256_update),
|
64, /* Maximum key length. */
|
||||||
/* Hash computation end function. */
|
32 /* Result size. */
|
||||||
CURLX_FUNCTION_CAST(HMAC_hfinal_func, my_sha256_final),
|
|
||||||
/* Size of hash context structure. */
|
|
||||||
sizeof(my_sha256_ctx),
|
|
||||||
/* Maximum key length. */
|
|
||||||
64,
|
|
||||||
/* Result size. */
|
|
||||||
32
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -67,7 +67,7 @@ CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg,
|
|||||||
char *response;
|
char *response;
|
||||||
|
|
||||||
/* Compute the digest using the password as the key */
|
/* Compute the digest using the password as the key */
|
||||||
ctxt = Curl_HMAC_init(Curl_HMAC_MD5,
|
ctxt = Curl_HMAC_init(&Curl_HMAC_MD5,
|
||||||
(const unsigned char *) passwdp,
|
(const unsigned char *) passwdp,
|
||||||
curlx_uztoui(strlen(passwdp)));
|
curlx_uztoui(strlen(passwdp)));
|
||||||
if(!ctxt)
|
if(!ctxt)
|
||||||
|
|||||||
@ -388,7 +388,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
|
|||||||
return result;
|
return result;
|
||||||
|
|
||||||
/* So far so good, now calculate A1 and H(A1) according to RFC 2831 */
|
/* So far so good, now calculate A1 and H(A1) according to RFC 2831 */
|
||||||
ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
|
ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
|
||||||
if(!ctxt)
|
if(!ctxt)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
@ -402,7 +402,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
|
|||||||
curlx_uztoui(strlen(passwdp)));
|
curlx_uztoui(strlen(passwdp)));
|
||||||
Curl_MD5_final(ctxt, digest);
|
Curl_MD5_final(ctxt, digest);
|
||||||
|
|
||||||
ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
|
ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
|
||||||
if(!ctxt)
|
if(!ctxt)
|
||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
@ -425,7 +425,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
|
|||||||
return CURLE_OUT_OF_MEMORY;
|
return CURLE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* Calculate H(A2) */
|
/* Calculate H(A2) */
|
||||||
ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
|
ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
|
||||||
if(!ctxt) {
|
if(!ctxt) {
|
||||||
free(spn);
|
free(spn);
|
||||||
|
|
||||||
@ -443,7 +443,7 @@ CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
|
|||||||
msnprintf(&HA2_hex[2 * i], 3, "%02x", digest[i]);
|
msnprintf(&HA2_hex[2 * i], 3, "%02x", digest[i]);
|
||||||
|
|
||||||
/* Now calculate the response hash */
|
/* Now calculate the response hash */
|
||||||
ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
|
ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
|
||||||
if(!ctxt) {
|
if(!ctxt) {
|
||||||
free(spn);
|
free(spn);
|
||||||
|
|
||||||
|
|||||||
@ -47,7 +47,7 @@ UNITTEST_START
|
|||||||
unsigned char output[HMAC_MD5_LENGTH];
|
unsigned char output[HMAC_MD5_LENGTH];
|
||||||
unsigned char *testp = output;
|
unsigned char *testp = output;
|
||||||
|
|
||||||
Curl_hmacit(Curl_HMAC_MD5,
|
Curl_hmacit(&Curl_HMAC_MD5,
|
||||||
(const unsigned char *) password, strlen(password),
|
(const unsigned char *) password, strlen(password),
|
||||||
(const unsigned char *) string1, strlen(string1),
|
(const unsigned char *) string1, strlen(string1),
|
||||||
output);
|
output);
|
||||||
@ -56,7 +56,7 @@ UNITTEST_START
|
|||||||
"\xd1\x29\x75\x43\x58\xdc\xab\x78\xdf\xcd\x7f\x2b\x29\x31\x13"
|
"\xd1\x29\x75\x43\x58\xdc\xab\x78\xdf\xcd\x7f\x2b\x29\x31\x13"
|
||||||
"\x37", HMAC_MD5_LENGTH);
|
"\x37", HMAC_MD5_LENGTH);
|
||||||
|
|
||||||
Curl_hmacit(Curl_HMAC_MD5,
|
Curl_hmacit(&Curl_HMAC_MD5,
|
||||||
(const unsigned char *) password, strlen(password),
|
(const unsigned char *) password, strlen(password),
|
||||||
(const unsigned char *) string2, strlen(string2),
|
(const unsigned char *) string2, strlen(string2),
|
||||||
output);
|
output);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user