From: jsing Date: Wed, 27 Mar 2024 03:05:59 +0000 (+0000) Subject: Revert to r1.19 while we track down a bug in the last two commits. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=4d498910b2f5de085315d4ba5267551499c46ddd;p=openbsd Revert to r1.19 while we track down a bug in the last two commits. --- diff --git a/lib/libcrypto/evp/m_sigver.c b/lib/libcrypto/evp/m_sigver.c index eea2de49e51..94729994172 100644 --- a/lib/libcrypto/evp/m_sigver.c +++ b/lib/libcrypto/evp/m_sigver.c @@ -1,4 +1,4 @@ -/* $OpenBSD: m_sigver.c,v 1.21 2024/03/27 01:55:40 joshua Exp $ */ +/* $OpenBSD: m_sigver.c,v 1.22 2024/03/27 03:05:59 jsing Exp $ */ /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL * project 2006. */ @@ -166,52 +166,43 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) { EVP_PKEY_CTX *pctx = ctx->pctx; - EVP_MD_CTX *md_ctx = NULL; - unsigned char md[EVP_MAX_MD_SIZE]; - unsigned int mdlen = 0; - int s; - int ret = 0; + int r = 0; if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) return evp_digestsignfinal_sigctx_custom(ctx, sigret, siglen); - if (sigret == NULL) { + if (sigret) { + EVP_MD_CTX tmp_ctx; + unsigned char md[EVP_MAX_MD_SIZE]; + unsigned int mdlen = 0; + EVP_MD_CTX_legacy_clear(&tmp_ctx); + if (!EVP_MD_CTX_copy_ex(&tmp_ctx, ctx)) + return 0; + if (ctx->pctx->pmeth->signctx != NULL) { + r = tmp_ctx.pctx->pmeth->signctx(tmp_ctx.pctx, + sigret, siglen, &tmp_ctx); + EVP_MD_CTX_cleanup(&tmp_ctx); + return r; + } + r = EVP_DigestFinal_ex(&tmp_ctx, md, &mdlen); + EVP_MD_CTX_cleanup(&tmp_ctx); + if (!r) + return r; + if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0) + return 0; + } else { if (ctx->pctx->pmeth->signctx != NULL) { - if (ctx->pctx->pmeth->signctx(ctx->pctx, NULL, + if (ctx->pctx->pmeth->signctx(ctx->pctx, sigret, siglen, ctx) <= 0) return 0; - return 1; + } else { + int s = EVP_MD_size(ctx->digest); + if (s < 0 || EVP_PKEY_sign(ctx->pctx, sigret, siglen, + NULL, s) <= 0) + return 0; } - - if ((s = EVP_MD_size(ctx->digest)) < 0) - return 0; - if (EVP_PKEY_sign(ctx->pctx, NULL, siglen, NULL, s) <= 0) - return 0; - - return 1; } - - - if ((md_ctx = EVP_MD_CTX_new()) == NULL) - goto err; - if (!EVP_MD_CTX_copy_ex(md_ctx, ctx)) - goto err; - if (md_ctx->pctx->pmeth->signctx != NULL) { - if(md_ctx->pctx->pmeth->signctx(md_ctx->pctx, - sigret, siglen, md_ctx) <= 0) - goto err; - } - if (!EVP_DigestFinal_ex(md_ctx, md, &mdlen)) - goto err; - if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0) - goto err; - - ret = 1; - - err: - EVP_MD_CTX_free(md_ctx); - - return ret; + return 1; } int