diff options
author | joshua <> | 2024-03-27 01:55:40 +0000 |
---|---|---|
committer | joshua <> | 2024-03-27 01:55:40 +0000 |
commit | 8d703ebb40c321a34627b32dd8d4803f0dbb4bb5 (patch) | |
tree | 50e4722f832b1df963dc46d977232bf3691f867e /src/lib | |
parent | 0ebac5b8389e8df2fef0cc0020d68180ada55044 (diff) | |
download | openbsd-8d703ebb40c321a34627b32dd8d4803f0dbb4bb5.tar.gz openbsd-8d703ebb40c321a34627b32dd8d4803f0dbb4bb5.tar.bz2 openbsd-8d703ebb40c321a34627b32dd8d4803f0dbb4bb5.zip |
Clean up use of EVP_MD_CTX_{legacy_clear,cleanup} in
EVP_DigestSignFinal
Additionally, this cleans up some more surrounding code.
ok tB
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/evp/m_sigver.c | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/src/lib/libcrypto/evp/m_sigver.c b/src/lib/libcrypto/evp/m_sigver.c index 1e679fa83b..eea2de49e5 100644 --- a/src/lib/libcrypto/evp/m_sigver.c +++ b/src/lib/libcrypto/evp/m_sigver.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: m_sigver.c,v 1.20 2024/03/26 11:25:08 joshua Exp $ */ | 1 | /* $OpenBSD: m_sigver.c,v 1.21 2024/03/27 01:55:40 joshua Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 2006. | 3 | * project 2006. |
4 | */ | 4 | */ |
@@ -166,11 +166,11 @@ int | |||
166 | EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) | 166 | EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) |
167 | { | 167 | { |
168 | EVP_PKEY_CTX *pctx = ctx->pctx; | 168 | EVP_PKEY_CTX *pctx = ctx->pctx; |
169 | EVP_MD_CTX tmp_ctx; | 169 | EVP_MD_CTX *md_ctx = NULL; |
170 | unsigned char md[EVP_MAX_MD_SIZE]; | 170 | unsigned char md[EVP_MAX_MD_SIZE]; |
171 | unsigned int mdlen = 0; | 171 | unsigned int mdlen = 0; |
172 | int s; | 172 | int s; |
173 | int r = 0; | 173 | int ret = 0; |
174 | 174 | ||
175 | if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) | 175 | if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) |
176 | return evp_digestsignfinal_sigctx_custom(ctx, sigret, siglen); | 176 | return evp_digestsignfinal_sigctx_custom(ctx, sigret, siglen); |
@@ -191,22 +191,27 @@ EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) | |||
191 | return 1; | 191 | return 1; |
192 | } | 192 | } |
193 | 193 | ||
194 | EVP_MD_CTX_legacy_clear(&tmp_ctx); | 194 | |
195 | if (!EVP_MD_CTX_copy_ex(&tmp_ctx, ctx)) | 195 | if ((md_ctx = EVP_MD_CTX_new()) == NULL) |
196 | return 0; | 196 | goto err; |
197 | if (ctx->pctx->pmeth->signctx != NULL) { | 197 | if (!EVP_MD_CTX_copy_ex(md_ctx, ctx)) |
198 | r = tmp_ctx.pctx->pmeth->signctx(tmp_ctx.pctx, | 198 | goto err; |
199 | sigret, siglen, &tmp_ctx); | 199 | if (md_ctx->pctx->pmeth->signctx != NULL) { |
200 | EVP_MD_CTX_cleanup(&tmp_ctx); | 200 | if(md_ctx->pctx->pmeth->signctx(md_ctx->pctx, |
201 | return r; | 201 | sigret, siglen, md_ctx) <= 0) |
202 | goto err; | ||
202 | } | 203 | } |
203 | r = EVP_DigestFinal_ex(&tmp_ctx, md, &mdlen); | 204 | if (!EVP_DigestFinal_ex(md_ctx, md, &mdlen)) |
204 | EVP_MD_CTX_cleanup(&tmp_ctx); | 205 | goto err; |
205 | if (!r) | ||
206 | return r; | ||
207 | if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0) | 206 | if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0) |
208 | return 0; | 207 | goto err; |
209 | return 1; | 208 | |
209 | ret = 1; | ||
210 | |||
211 | err: | ||
212 | EVP_MD_CTX_free(md_ctx); | ||
213 | |||
214 | return ret; | ||
210 | } | 215 | } |
211 | 216 | ||
212 | int | 217 | int |