Make sure we use functions with the correct prototype.
Closes #15289
#define HMAC_MD5_LENGTH 16
-typedef CURLcode (* HMAC_hinit_func)(void *context);
-typedef void (* HMAC_hupdate_func)(void *context,
- const unsigned char *data,
- unsigned int len);
-typedef void (* HMAC_hfinal_func)(unsigned char *result, void *context);
-
+typedef CURLcode (*HMAC_hinit)(void *context);
+typedef void (*HMAC_hupdate)(void *context,
+ const unsigned char *data,
+ unsigned int len);
+typedef void (*HMAC_hfinal)(unsigned char *result, void *context);
/* Per-hash function HMAC parameters. */
struct HMAC_params {
- HMAC_hinit_func
- hmac_hinit; /* Initialize context procedure. */
- HMAC_hupdate_func hmac_hupdate; /* Update context with data. */
- HMAC_hfinal_func hmac_hfinal; /* Get final result procedure. */
- unsigned int hmac_ctxtsize; /* Context structure size. */
- unsigned int hmac_maxkeylen; /* Maximum key length (bytes). */
- unsigned int hmac_resultlen; /* Result length (bytes). */
+ HMAC_hinit hinit; /* Initialize context procedure. */
+ HMAC_hupdate hupdate; /* Update context with data. */
+ HMAC_hfinal hfinal; /* Get final result procedure. */
+ unsigned int ctxtsize; /* Context structure size. */
+ unsigned int maxkeylen; /* Maximum key length (bytes). */
+ unsigned int resultlen; /* Result length (bytes). */
};
/* HMAC computation context. */
struct HMAC_context {
- const struct HMAC_params *hmac_hash; /* Hash function definition. */
- void *hmac_hashctxt1; /* Hash function context 1. */
- void *hmac_hashctxt2; /* Hash function context 2. */
+ const struct HMAC_params *hash; /* Hash function definition. */
+ void *hashctxt1; /* Hash function context 1. */
+ void *hashctxt2; /* Hash function context 2. */
};
#define MD5_DIGEST_LEN 16
-typedef CURLcode (* Curl_MD5_init_func)(void *context);
-typedef void (* Curl_MD5_update_func)(void *context,
- const unsigned char *data,
- unsigned int len);
-typedef void (* Curl_MD5_final_func)(unsigned char *result, void *context);
+typedef CURLcode (*Curl_MD5_init_func)(void *context);
+typedef void (*Curl_MD5_update_func)(void *context,
+ const unsigned char *data,
+ unsigned int len);
+typedef void (*Curl_MD5_final_func)(unsigned char *result, void *context);
struct MD5_params {
Curl_MD5_init_func md5_init_func; /* Initialize context procedure */
void *md5_hashctx; /* Hash function context */
};
-extern const struct MD5_params Curl_DIGEST_MD5[1];
-extern const struct HMAC_params Curl_HMAC_MD5[1];
+extern const struct MD5_params Curl_DIGEST_MD5;
+extern const struct HMAC_params Curl_HMAC_MD5;
CURLcode Curl_md5it(unsigned char *output, const unsigned char *input,
const size_t len);
ascii_uppercase_to_unicode_le(identity, user, userlen);
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);
free(identity);
/* Concatenate the Type 2 challenge with the BLOB and do HMAC MD5 */
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);
if(result) {
free(ptr);
memcpy(&data[0], challenge_server, 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);
if(result)
return result;
#include <curl/curl.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
#define CURL_SHA256_DIGEST_LENGTH 32 /* fixed size */
static const unsigned char hmac_ipad = 0x36;
static const unsigned char hmac_opad = 0x5C;
-
-
struct HMAC_context *
Curl_HMAC_init(const struct HMAC_params *hashparams,
const unsigned char *key,
unsigned char b;
/* Create HMAC context. */
- i = sizeof(*ctxt) + 2 * hashparams->hmac_ctxtsize +
- hashparams->hmac_resultlen;
+ i = sizeof(*ctxt) + 2 * hashparams->ctxtsize + hashparams->resultlen;
ctxt = malloc(i);
if(!ctxt)
return ctxt;
- ctxt->hmac_hash = hashparams;
- ctxt->hmac_hashctxt1 = (void *) (ctxt + 1);
- ctxt->hmac_hashctxt2 = (void *) ((char *) ctxt->hmac_hashctxt1 +
- hashparams->hmac_ctxtsize);
+ ctxt->hash = hashparams;
+ ctxt->hashctxt1 = (void *) (ctxt + 1);
+ ctxt->hashctxt2 = (void *) ((char *) ctxt->hashctxt1 + hashparams->ctxtsize);
/* If the key is too long, replace it by its hash digest. */
- if(keylen > hashparams->hmac_maxkeylen) {
- (*hashparams->hmac_hinit)(ctxt->hmac_hashctxt1);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, key, keylen);
- hkey = (unsigned char *) ctxt->hmac_hashctxt2 + hashparams->hmac_ctxtsize;
- (*hashparams->hmac_hfinal)(hkey, ctxt->hmac_hashctxt1);
+ if(keylen > hashparams->maxkeylen) {
+ hashparams->hinit(ctxt->hashctxt1);
+ hashparams->hupdate(ctxt->hashctxt1, key, keylen);
+ hkey = (unsigned char *) ctxt->hashctxt2 + hashparams->ctxtsize;
+ hashparams->hfinal(hkey, ctxt->hashctxt1);
key = hkey;
- keylen = hashparams->hmac_resultlen;
+ keylen = hashparams->resultlen;
}
/* Prime the two hash contexts with the modified key. */
- (*hashparams->hmac_hinit)(ctxt->hmac_hashctxt1);
- (*hashparams->hmac_hinit)(ctxt->hmac_hashctxt2);
+ hashparams->hinit(ctxt->hashctxt1);
+ hashparams->hinit(ctxt->hashctxt2);
for(i = 0; i < keylen; i++) {
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);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &b, 1);
+ hashparams->hupdate(ctxt->hashctxt2, &b, 1);
}
- for(; i < hashparams->hmac_maxkeylen; i++) {
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt1, &hmac_ipad, 1);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2, &hmac_opad, 1);
+ for(; i < hashparams->maxkeylen; i++) {
+ hashparams->hupdate(ctxt->hashctxt1, &hmac_ipad, 1);
+ hashparams->hupdate(ctxt->hashctxt2, &hmac_opad, 1);
}
/* Done, return pointer to HMAC context. */
}
int Curl_HMAC_update(struct HMAC_context *ctxt,
- const unsigned char *data,
+ const unsigned char *ptr,
unsigned int len)
{
/* Update first hash calculation. */
- (*ctxt->hmac_hash->hmac_hupdate)(ctxt->hmac_hashctxt1, data, len);
+ ctxt->hash->hupdate(ctxt->hashctxt1, ptr, len);
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. */
- if(!result)
- result = (unsigned char *) ctxt->hmac_hashctxt2 +
- ctxt->hmac_hash->hmac_ctxtsize;
+ if(!output)
+ output = (unsigned char *) ctxt->hashctxt2 + ctxt->hash->ctxtsize;
- (*hashparams->hmac_hfinal)(result, ctxt->hmac_hashctxt1);
- (*hashparams->hmac_hupdate)(ctxt->hmac_hashctxt2,
- result, hashparams->hmac_resultlen);
- (*hashparams->hmac_hfinal)(result, ctxt->hmac_hashctxt2);
- free((char *) ctxt);
+ hashparams->hfinal(output, ctxt->hashctxt1);
+ hashparams->hupdate(ctxt->hashctxt2, output, hashparams->resultlen);
+ hashparams->hfinal(output, ctxt->hashctxt2);
+ free(ctxt);
return 0;
}
* hashparams [in] - The hash function (Curl_HMAC_MD5).
* key [in] - The key to use.
* keylen [in] - The length of the key.
- * data [in] - The data to encrypt.
- * datalen [in] - The length of the data.
+ * buf [in] - The data to encrypt.
+ * buflen [in] - The length of the data.
* output [in/out] - The output buffer.
*
* Returns CURLE_OK on success.
*/
CURLcode Curl_hmacit(const struct HMAC_params *hashparams,
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)
{
struct HMAC_context *ctxt =
return CURLE_OUT_OF_MEMORY;
/* 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 */
Curl_HMAC_final(ctxt, output);
#define HMAC_SHA256(k, kl, d, dl, o) \
do { \
- result = Curl_hmacit(Curl_HMAC_SHA256, \
+ result = Curl_hmacit(&Curl_HMAC_SHA256, \
(unsigned char *)k, \
kl, \
(unsigned char *)d, \
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);
return CURLE_OK;
}
-static void my_md5_update(my_md5_ctx *ctx,
+static void my_md5_update(void *ctx,
const unsigned char *input,
unsigned int inputLen)
{
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);
}
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))
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
-static void my_md5_update(my_md5_ctx *ctx,
+static void my_md5_update(void *ctx,
const unsigned char *input,
unsigned int 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);
}
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_md5_starts(ctx))
return CURLE_OK;
}
-static void my_md5_update(my_md5_ctx *ctx,
+static void my_md5_update(void *ctx,
const unsigned char *data,
unsigned int length)
{
#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)
(void) mbedtls_md5_finish(ctx, digest);
reliable than defining COMMON_DIGEST_FOR_OPENSSL on older cats. */
# 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))
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
-static void my_md5_update(my_md5_ctx *ctx,
+static void my_md5_update(void *ctx,
const unsigned char *input,
unsigned int 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);
}
};
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,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
-static void my_md5_update(my_md5_ctx *ctx,
+static void my_md5_update(void *in,
const unsigned char *input,
unsigned int inputLen)
{
+ my_md5_ctx *ctx = in;
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;
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
if(length == 16)
};
typedef struct md5_ctx my_md5_ctx;
-static CURLcode my_md5_init(my_md5_ctx *ctx);
-static void my_md5_update(my_md5_ctx *ctx, const void *data,
- unsigned long size);
-static void my_md5_final(unsigned char *result, my_md5_ctx *ctx);
+static CURLcode my_md5_init(void *ctx);
+static void my_md5_update(void *ctx, const unsigned char *data,
+ unsigned int size);
+static void my_md5_final(unsigned char *result, void *ctx);
/*
* The basic MD5 functions.
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->b = 0xefcdab89;
ctx->c = 0x98badcfe;
return CURLE_OK;
}
-static void my_md5_update(my_md5_ctx *ctx, const void *data,
- unsigned long size)
+static void my_md5_update(void *in, const unsigned char *data,
+ unsigned int size)
{
MD5_u32plus saved_lo;
- unsigned long used;
+ unsigned int used;
+ my_md5_ctx *ctx = (my_md5_ctx *)in;
saved_lo = ctx->lo;
ctx->lo = (saved_lo + size) & 0x1fffffff;
used = saved_lo & 0x3f;
if(used) {
- unsigned long available = 64 - used;
+ unsigned int available = 64 - used;
if(size < available) {
memcpy(&ctx->buffer[used], 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;
#endif /* CRYPTO LIBS */
-const struct HMAC_params Curl_HMAC_MD5[] = {
- {
- /* Hash initialization function. */
- CURLX_FUNCTION_CAST(HMAC_hinit_func, my_md5_init),
- /* Hash update function. */
- CURLX_FUNCTION_CAST(HMAC_hupdate_func, my_md5_update),
- /* Hash computation end function. */
- 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 HMAC_params Curl_HMAC_MD5 = {
+ my_md5_init, /* Hash initialization function. */
+ my_md5_update, /* Hash update function. */
+ my_md5_final, /* Hash computation end function. */
+ sizeof(my_md5_ctx), /* Size of hash context structure. */
+ 64, /* Maximum key length. */
+ 16 /* Result size. */
};
-const struct MD5_params Curl_DIGEST_MD5[] = {
- {
- /* Digest initialization function */
- CURLX_FUNCTION_CAST(Curl_MD5_init_func, my_md5_init),
- /* Digest update function */
- CURLX_FUNCTION_CAST(Curl_MD5_update_func, my_md5_update),
- /* 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
- }
+const struct MD5_params Curl_DIGEST_MD5 = {
+ my_md5_init, /* Digest initialization function */
+ my_md5_update, /* Digest update function */
+ my_md5_final, /* Digest computation end function */
+ sizeof(my_md5_ctx), /* Size of digest context struct */
+ 16 /* Result size */
};
/*
}
/* Create the digest */
- ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
+ ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
if(!ctxt)
return CURLE_OUT_OF_MEMORY;
};
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();
if(!ctx->openssl_ctx)
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
-static void my_sha256_update(my_sha256_ctx *ctx,
+static void my_sha256_update(void *in,
const unsigned char *data,
unsigned int length)
{
+ my_sha256_ctx *ctx = (my_sha256_ctx *)in;
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_MD_CTX_destroy(ctx->openssl_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);
return CURLE_OK;
}
-static void my_sha256_update(my_sha256_ctx *ctx,
+static void my_sha256_update(void *ctx,
const unsigned char *data,
unsigned int length)
{
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);
}
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)
(void) mbedtls_sha256_starts(ctx, 0);
return CURLE_OK;
}
-static void my_sha256_update(my_sha256_ctx *ctx,
+static void my_sha256_update(void *ctx,
const unsigned char *data,
unsigned int length)
{
#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)
(void) mbedtls_sha256_finish(ctx, digest);
#elif defined(AN_APPLE_OS)
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);
return CURLE_OK;
}
-static void my_sha256_update(my_sha256_ctx *ctx,
+static void my_sha256_update(void *ctx,
const unsigned char *data,
unsigned int 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);
}
#define CALG_SHA_256 0x0000800c
#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,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
return CURLE_OUT_OF_MEMORY;
return CURLE_OK;
}
-static void my_sha256_update(my_sha256_ctx *ctx,
+static void my_sha256_update(void *in,
const unsigned char *data,
unsigned int length)
{
+ my_sha256_ctx *ctx = (my_sha256_ctx *)in;
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;
CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
}
/* 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->length = 0;
md->state[0] = 0x6A09E667UL;
@param md The hash state
@param in The data to hash
@param inlen The length of the data (octets)
- @return 0 if successful
*/
-static int my_sha256_update(struct sha256_state *md,
- const unsigned char *in,
- unsigned long inlen)
+static void my_sha256_update(void *ctx,
+ const unsigned char *in,
+ unsigned int len)
{
+ unsigned long inlen = len;
unsigned long n;
-
+ struct sha256_state *md = (struct sha256_state *)ctx;
#define CURL_SHA256_BLOCK_SIZE 64
if(md->curlen > sizeof(md->buf))
- return -1;
+ return;
while(inlen > 0) {
if(md->curlen == 0 && inlen >= CURL_SHA256_BLOCK_SIZE) {
if(sha256_compress(md, (unsigned char *)in) < 0)
- return -1;
+ return;
md->length += CURL_SHA256_BLOCK_SIZE * 8;
in += CURL_SHA256_BLOCK_SIZE;
inlen -= CURL_SHA256_BLOCK_SIZE;
inlen -= n;
if(md->curlen == CURL_SHA256_BLOCK_SIZE) {
if(sha256_compress(md, md->buf) < 0)
- return -1;
+ return;
md->length += 8 * CURL_SHA256_BLOCK_SIZE;
md->curlen = 0;
}
}
}
-
- return 0;
}
/*
@param out [out] The destination of the hash (32 bytes)
@return 0 if successful
*/
-static int my_sha256_final(unsigned char *out,
- struct sha256_state *md)
+static void my_sha256_final(unsigned char *out, void *ctx)
{
+ struct sha256_state *md = ctx;
int i;
if(md->curlen >= sizeof(md->buf))
- return -1;
+ return;
/* Increase the length of the message */
md->length += md->curlen * 8;
/* Copy output */
for(i = 0; i < 8; i++)
WPA_PUT_BE32(out + (4 * i), md->state[i]);
-
- return 0;
}
#endif /* CRYPTO LIBS */
* Returns CURLE_OK on success.
*/
CURLcode Curl_sha256it(unsigned char *output, const unsigned char *input,
- const size_t length)
+ const size_t length)
{
CURLcode result;
my_sha256_ctx ctx;
}
-const struct HMAC_params Curl_HMAC_SHA256[] = {
- {
- /* Hash initialization function. */
- CURLX_FUNCTION_CAST(HMAC_hinit_func, my_sha256_init),
- /* Hash update function. */
- CURLX_FUNCTION_CAST(HMAC_hupdate_func, my_sha256_update),
- /* Hash computation end function. */
- 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
- }
+const struct HMAC_params Curl_HMAC_SHA256 = {
+ my_sha256_init, /* Hash initialization function. */
+ my_sha256_update, /* Hash update function. */
+ my_sha256_final, /* Hash computation end function. */
+ sizeof(my_sha256_ctx), /* Size of hash context structure. */
+ 64, /* Maximum key length. */
+ 32 /* Result size. */
};
char *response;
/* 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,
curlx_uztoui(strlen(passwdp)));
if(!ctxt)
return result;
/* 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)
return CURLE_OUT_OF_MEMORY;
curlx_uztoui(strlen(passwdp)));
Curl_MD5_final(ctxt, digest);
- ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
+ ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
if(!ctxt)
return CURLE_OUT_OF_MEMORY;
return CURLE_OUT_OF_MEMORY;
/* Calculate H(A2) */
- ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
+ ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
if(!ctxt) {
free(spn);
msnprintf(&HA2_hex[2 * i], 3, "%02x", digest[i]);
/* Now calculate the response hash */
- ctxt = Curl_MD5_init(Curl_DIGEST_MD5);
+ ctxt = Curl_MD5_init(&Curl_DIGEST_MD5);
if(!ctxt) {
free(spn);
unsigned char output[HMAC_MD5_LENGTH];
unsigned char *testp = output;
- Curl_hmacit(Curl_HMAC_MD5,
+ Curl_hmacit(&Curl_HMAC_MD5,
(const unsigned char *) password, strlen(password),
(const unsigned char *) string1, strlen(string1),
output);
"\xd1\x29\x75\x43\x58\xdc\xab\x78\xdf\xcd\x7f\x2b\x29\x31\x13"
"\x37", HMAC_MD5_LENGTH);
- Curl_hmacit(Curl_HMAC_MD5,
+ Curl_hmacit(&Curl_HMAC_MD5,
(const unsigned char *) password, strlen(password),
(const unsigned char *) string2, strlen(string2),
output);