X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fevp%2Fdigest.c;h=5ff43fdd6433c0d1ed04d9dca455ac3d331d8e90;hp=4f6b68c667842eddee9a60155d33fe860ca1d3e8;hb=72df8f8825d54a7f1be48cc9035f4e3a86f639b4;hpb=19cfe7847c17fb4d73c8b7267da841ec1a639dd3 diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index 4f6b68c667..5ff43fdd64 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -285,6 +285,24 @@ int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t count) if (count == 0) return 1; + if (ctx->pctx != NULL + && EVP_PKEY_CTX_IS_SIGNATURE_OP(ctx->pctx) + && ctx->pctx->op.sig.sigprovctx != NULL) { + /* + * Prior to OpenSSL 3.0 EVP_DigestSignUpdate() and + * EVP_DigestVerifyUpdate() were just macros for EVP_DigestUpdate(). + * Some code calls EVP_DigestUpdate() directly even when initialised + * with EVP_DigestSignInit_ex() or EVP_DigestVerifyInit_ex(), so we + * detect that and redirect to the correct EVP_Digest*Update() function + */ + if (ctx->pctx->operation == EVP_PKEY_OP_SIGNCTX) + return EVP_DigestSignUpdate(ctx, data, count); + if (ctx->pctx->operation == EVP_PKEY_OP_VERIFYCTX) + return EVP_DigestVerifyUpdate(ctx, data, count); + EVPerr(EVP_F_EVP_DIGESTUPDATE, EVP_R_UPDATE_ERROR); + return 0; + } + if (ctx->digest == NULL || ctx->digest->prov == NULL) goto legacy; @@ -665,7 +683,7 @@ int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) ret = EVP_MD_CTX_set_params(ctx, params); else ret = EVP_MD_CTX_get_params(ctx, params); - return ret; + goto conclude; /* TODO(3.0): Remove legacy code below */ @@ -676,6 +694,7 @@ int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) } ret = ctx->digest->md_ctrl(ctx, cmd, p1, p2); + conclude: if (ret <= 0) return 0; return ret;