sha256/md5: return errors when init fails

Closes #8133
This commit is contained in:
x2018 2021-12-10 21:33:39 +08:00 committed by Daniel Stenberg
parent da97316596
commit d6ff35b5a5
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
9 changed files with 73 additions and 40 deletions

View file

@ -62,9 +62,10 @@
typedef struct md5_ctx MD5_CTX;
static void MD5_Init(MD5_CTX *ctx)
static CURLcode MD5_Init(MD5_CTX *ctx)
{
md5_init(ctx);
return CURLE_OK;
}
static void MD5_Update(MD5_CTX *ctx,
@ -98,13 +99,14 @@ static void MD5_Final(unsigned char *digest, MD5_CTX *ctx)
typedef mbedtls_md5_context MD5_CTX;
static void MD5_Init(MD5_CTX *ctx)
static CURLcode MD5_Init(MD5_CTX *ctx)
{
#if !defined(HAS_MBEDTLS_RESULT_CODE_BASED_FUNCTIONS)
(void) mbedtls_md5_starts(ctx);
#else
(void) mbedtls_md5_starts_ret(ctx);
#endif
return CURLE_OK;
}
static void MD5_Update(MD5_CTX *ctx,
@ -146,9 +148,10 @@ static void MD5_Final(unsigned char *digest, MD5_CTX *ctx)
/* The last #include file should be: */
#include "memdebug.h"
static void MD5_Init(MD5_CTX *ctx)
static CURLcode MD5_Init(MD5_CTX *ctx)
{
CC_MD5_Init(ctx);
return CURLE_OK;
}
static void MD5_Update(MD5_CTX *ctx,
@ -176,12 +179,13 @@ struct md5_ctx {
};
typedef struct md5_ctx MD5_CTX;
static void MD5_Init(MD5_CTX *ctx)
static CURLcode MD5_Init(MD5_CTX *ctx)
{
if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_FULL,
CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash);
}
return CURLE_OK;
}
static void MD5_Update(MD5_CTX *ctx,
@ -261,7 +265,7 @@ struct md5_ctx {
};
typedef struct md5_ctx MD5_CTX;
static void MD5_Init(MD5_CTX *ctx);
static CURLcode MD5_Init(MD5_CTX *ctx);
static void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size);
static void MD5_Final(unsigned char *result, MD5_CTX *ctx);
@ -422,7 +426,7 @@ static const void *body(MD5_CTX *ctx, const void *data, unsigned long size)
return ptr;
}
static void MD5_Init(MD5_CTX *ctx)
static CURLcode MD5_Init(MD5_CTX *ctx)
{
ctx->a = 0x67452301;
ctx->b = 0xefcdab89;
@ -431,6 +435,8 @@ static void MD5_Init(MD5_CTX *ctx)
ctx->lo = 0;
ctx->hi = 0;
return CURLE_OK;
}
static void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
@ -555,8 +561,9 @@ const struct MD5_params Curl_DIGEST_MD5[] = {
/*
* @unittest: 1601
* Returns CURLE_OK on success.
*/
void Curl_md5it(unsigned char *outbuffer, const unsigned char *input,
CURLcode Curl_md5it(unsigned char *outbuffer, const unsigned char *input,
const size_t len)
{
MD5_CTX ctx;
@ -564,6 +571,8 @@ void Curl_md5it(unsigned char *outbuffer, const unsigned char *input,
MD5_Init(&ctx);
MD5_Update(&ctx, input, curlx_uztoui(len));
MD5_Final(outbuffer, &ctx);
return CURLE_OK;
}
struct MD5_context *Curl_MD5_init(const struct MD5_params *md5params)