diff options
author | joshua <> | 2024-03-26 11:25:08 +0000 |
---|---|---|
committer | joshua <> | 2024-03-26 11:25:08 +0000 |
commit | b4da27dc607f0df09ca9d4a261307534f5914cec (patch) | |
tree | 19a520e2dd2dbef6f38b20b9b8c3b3565bd89270 /src/lib | |
parent | 62319c0b6abd501459acfd764bc907fa318e7908 (diff) | |
download | openbsd-b4da27dc607f0df09ca9d4a261307534f5914cec.tar.gz openbsd-b4da27dc607f0df09ca9d4a261307534f5914cec.tar.bz2 openbsd-b4da27dc607f0df09ca9d4a261307534f5914cec.zip |
Clean up EVP_DigestSignFinal
ok jsing tb
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/evp/m_sigver.c | 58 |
1 files changed, 31 insertions, 27 deletions
diff --git a/src/lib/libcrypto/evp/m_sigver.c b/src/lib/libcrypto/evp/m_sigver.c index 5fe3cc8964..1e679fa83b 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.19 2024/03/26 01:41:06 tb Exp $ */ | 1 | /* $OpenBSD: m_sigver.c,v 1.20 2024/03/26 11:25:08 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,42 +166,46 @@ 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; | ||
170 | unsigned char md[EVP_MAX_MD_SIZE]; | ||
171 | unsigned int mdlen = 0; | ||
172 | int s; | ||
169 | int r = 0; | 173 | int r = 0; |
170 | 174 | ||
171 | if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) | 175 | if (pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) |
172 | return evp_digestsignfinal_sigctx_custom(ctx, sigret, siglen); | 176 | return evp_digestsignfinal_sigctx_custom(ctx, sigret, siglen); |
173 | 177 | ||
174 | if (sigret) { | 178 | if (sigret == NULL) { |
175 | EVP_MD_CTX tmp_ctx; | ||
176 | unsigned char md[EVP_MAX_MD_SIZE]; | ||
177 | unsigned int mdlen = 0; | ||
178 | EVP_MD_CTX_legacy_clear(&tmp_ctx); | ||
179 | if (!EVP_MD_CTX_copy_ex(&tmp_ctx, ctx)) | ||
180 | return 0; | ||
181 | if (ctx->pctx->pmeth->signctx != NULL) { | 179 | if (ctx->pctx->pmeth->signctx != NULL) { |
182 | r = tmp_ctx.pctx->pmeth->signctx(tmp_ctx.pctx, | 180 | if (ctx->pctx->pmeth->signctx(ctx->pctx, NULL, |
183 | sigret, siglen, &tmp_ctx); | ||
184 | EVP_MD_CTX_cleanup(&tmp_ctx); | ||
185 | return r; | ||
186 | } | ||
187 | r = EVP_DigestFinal_ex(&tmp_ctx, md, &mdlen); | ||
188 | EVP_MD_CTX_cleanup(&tmp_ctx); | ||
189 | if (!r) | ||
190 | return r; | ||
191 | if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0) | ||
192 | return 0; | ||
193 | } else { | ||
194 | if (ctx->pctx->pmeth->signctx != NULL) { | ||
195 | if (ctx->pctx->pmeth->signctx(ctx->pctx, sigret, | ||
196 | siglen, ctx) <= 0) | 181 | siglen, ctx) <= 0) |
197 | return 0; | 182 | return 0; |
198 | } else { | 183 | return 1; |
199 | int s = EVP_MD_size(ctx->digest); | ||
200 | if (s < 0 || EVP_PKEY_sign(ctx->pctx, sigret, siglen, | ||
201 | NULL, s) <= 0) | ||
202 | return 0; | ||
203 | } | 184 | } |
185 | |||
186 | if ((s = EVP_MD_size(ctx->digest)) < 0) | ||
187 | return 0; | ||
188 | if (EVP_PKEY_sign(ctx->pctx, NULL, siglen, NULL, s) <= 0) | ||
189 | return 0; | ||
190 | |||
191 | return 1; | ||
204 | } | 192 | } |
193 | |||
194 | EVP_MD_CTX_legacy_clear(&tmp_ctx); | ||
195 | if (!EVP_MD_CTX_copy_ex(&tmp_ctx, ctx)) | ||
196 | return 0; | ||
197 | if (ctx->pctx->pmeth->signctx != NULL) { | ||
198 | r = tmp_ctx.pctx->pmeth->signctx(tmp_ctx.pctx, | ||
199 | sigret, siglen, &tmp_ctx); | ||
200 | EVP_MD_CTX_cleanup(&tmp_ctx); | ||
201 | return r; | ||
202 | } | ||
203 | r = EVP_DigestFinal_ex(&tmp_ctx, md, &mdlen); | ||
204 | EVP_MD_CTX_cleanup(&tmp_ctx); | ||
205 | if (!r) | ||
206 | return r; | ||
207 | if (EVP_PKEY_sign(ctx->pctx, sigret, siglen, md, mdlen) <= 0) | ||
208 | return 0; | ||
205 | return 1; | 209 | return 1; |
206 | } | 210 | } |
207 | 211 | ||