From 857449e3f68d4e9633a0e8b45c9ab97e0373ad6b Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 1 Jul 2026 10:30:06 +0200 Subject: [PATCH] sync1 --- lib/curl_sha512_256.c | 38 +++++++++++++++----------------------- lib/md5.c | 6 +++--- lib/sha256.c | 6 +++--- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/lib/curl_sha512_256.c b/lib/curl_sha512_256.c index fe0905c2c0..78006f0d91 100644 --- a/lib/curl_sha512_256.c +++ b/lib/curl_sha512_256.c @@ -108,26 +108,23 @@ typedef EVP_MD_CTX *Curl_sha512_256_ctx; * @return CURLE_OK if succeed, * error code otherwise */ -static CURLcode Curl_sha512_256_init(void *context) +static CURLcode Curl_sha512_256_init(void *in) { - Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; - + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; *ctx = EVP_MD_CTX_new(); if(!*ctx) return CURLE_OUT_OF_MEMORY; - if(EVP_DigestInit_ex(*ctx, EVP_sha512_256(), NULL)) { - /* Check whether the header and this file use the same numbers */ - DEBUGASSERT(EVP_MD_CTX_size(*ctx) == CURL_SHA512_256_DIGEST_SIZE); - /* Check whether the block size is correct */ - DEBUGASSERT(EVP_MD_CTX_block_size(*ctx) == CURL_SHA512_256_BLOCK_SIZE); - - return CURLE_OK; /* Success */ + if(!EVP_DigestInit_ex(*ctx, EVP_sha512_256(), NULL)) { + EVP_MD_CTX_free(*ctx); + *ctx = NULL; + return CURLE_FAILED_INIT; } - - /* Cleanup */ - EVP_MD_CTX_free(*ctx); - return CURLE_FAILED_INIT; + /* Check whether the header and this file use the same numbers */ + DEBUGASSERT(EVP_MD_CTX_size(*ctx) == CURL_SHA512_256_DIGEST_SIZE); + /* Check whether the block size is correct */ + DEBUGASSERT(EVP_MD_CTX_block_size(*ctx) == CURL_SHA512_256_BLOCK_SIZE); + return CURLE_OK; } /** @@ -138,15 +135,13 @@ static CURLcode Curl_sha512_256_init(void *context) * @return CURLE_OK if succeed, * error code otherwise */ -static CURLcode Curl_sha512_256_update(void *context, +static CURLcode Curl_sha512_256_update(void *in, const unsigned char *data, size_t length) { - Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; - + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; if(!EVP_DigestUpdate(*ctx, data, length)) return CURLE_BAD_FUNCTION_ARGUMENT; - return CURLE_OK; } @@ -159,11 +154,10 @@ static CURLcode Curl_sha512_256_update(void *context, * @return CURLE_OK if succeed, * error code otherwise */ -static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) +static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *in) { CURLcode result; - Curl_sha512_256_ctx * const ctx = (Curl_sha512_256_ctx *)context; - + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; if(digest) { #ifdef NEED_NETBSD_SHA512_256_WORKAROUND /* Use a larger buffer to work around a bug in NetBSD: @@ -179,10 +173,8 @@ static CURLcode Curl_sha512_256_finish(unsigned char *digest, void *context) CURLE_OK : CURLE_BAD_FUNCTION_ARGUMENT; #endif /* NEED_NETBSD_SHA512_256_WORKAROUND */ } - EVP_MD_CTX_free(*ctx); *ctx = NULL; - return result; } diff --git a/lib/md5.c b/lib/md5.c index fa361d9de3..9d8b01988b 100644 --- a/lib/md5.c +++ b/lib/md5.c @@ -80,7 +80,7 @@ typedef EVP_MD_CTX *my_md5_ctx; static CURLcode my_md5_init(void *in) { - EVP_MD_CTX **ctx = (EVP_MD_CTX **)in; + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; *ctx = EVP_MD_CTX_new(); if(!*ctx) return CURLE_OUT_OF_MEMORY; @@ -96,13 +96,13 @@ static CURLcode my_md5_init(void *in) static void my_md5_update(void *in, const unsigned char *input, unsigned int len) { - EVP_MD_CTX **ctx = (EVP_MD_CTX **)in; + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; (void)EVP_DigestUpdate(*ctx, input, len); } static void my_md5_final(unsigned char *digest, void *in) { - EVP_MD_CTX **ctx = (EVP_MD_CTX **)in; + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; if(digest) (void)EVP_DigestFinal_ex(*ctx, digest, NULL); EVP_MD_CTX_free(*ctx); diff --git a/lib/sha256.c b/lib/sha256.c index f4f35a3826..6b1e90dcc1 100644 --- a/lib/sha256.c +++ b/lib/sha256.c @@ -57,7 +57,7 @@ typedef EVP_MD_CTX *my_sha256_ctx; static CURLcode my_sha256_init(void *in) { - EVP_MD_CTX **ctx = (EVP_MD_CTX **)in; + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; *ctx = EVP_MD_CTX_new(); if(!*ctx) return CURLE_OUT_OF_MEMORY; @@ -74,13 +74,13 @@ static void my_sha256_update(void *in, const unsigned char *data, unsigned int length) { - EVP_MD_CTX **ctx = (EVP_MD_CTX **)in; + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; (void)EVP_DigestUpdate(*ctx, data, length); } static void my_sha256_final(unsigned char *digest, void *in) { - EVP_MD_CTX **ctx = (EVP_MD_CTX **)in; + EVP_MD_CTX ** const ctx = (EVP_MD_CTX **)in; if(digest) (void)EVP_DigestFinal_ex(*ctx, digest, NULL); EVP_MD_CTX_free(*ctx);