summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjoshua <>2024-03-27 04:18:50 +0000
committerjoshua <>2024-03-27 04:18:50 +0000
commit12b93ff740101a3ee8c3d5daba35d06c6ec8641f (patch)
tree120fae7f4381b0eb5babf3f9e0926f49932e9af3
parent76ab412c4bf0a80924205a270be9e3cf5d65190f (diff)
downloadopenbsd-12b93ff740101a3ee8c3d5daba35d06c6ec8641f.tar.gz
openbsd-12b93ff740101a3ee8c3d5daba35d06c6ec8641f.tar.bz2
openbsd-12b93ff740101a3ee8c3d5daba35d06c6ec8641f.zip
Recommit r1.20
ok tb jsing
-rw-r--r--src/lib/libcrypto/evp/m_sigver.c58
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 9472999417..5612d5ab52 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.22 2024/03/27 03:05:59 jsing Exp $ */ 1/* $OpenBSD: m_sigver.c,v 1.23 2024/03/27 04:18:50 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
166EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen) 166EVP_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