diff options
Diffstat (limited to 'src/lib/libcrypto/evp/digest.c')
-rw-r--r-- | src/lib/libcrypto/evp/digest.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index b69a928ab8..6a7d86d702 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: digest.c,v 1.29 2018/02/17 14:55:31 jsing Exp $ */ | 1 | /* $OpenBSD: digest.c,v 1.30 2018/04/14 07:09:21 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -146,9 +146,8 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | |||
146 | /* Ensure an ENGINE left lying around from last time is cleared | 146 | /* Ensure an ENGINE left lying around from last time is cleared |
147 | * (the previous check attempted to avoid this if the same | 147 | * (the previous check attempted to avoid this if the same |
148 | * ENGINE and EVP_MD could be used). */ | 148 | * ENGINE and EVP_MD could be used). */ |
149 | if (ctx->engine) | 149 | ENGINE_finish(ctx->engine); |
150 | ENGINE_finish(ctx->engine); | 150 | if (impl != NULL) { |
151 | if (impl) { | ||
152 | if (!ENGINE_init(impl)) { | 151 | if (!ENGINE_init(impl)) { |
153 | EVPerror(EVP_R_INITIALIZATION_ERROR); | 152 | EVPerror(EVP_R_INITIALIZATION_ERROR); |
154 | return 0; | 153 | return 0; |
@@ -156,10 +155,10 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | |||
156 | } else | 155 | } else |
157 | /* Ask if an ENGINE is reserved for this job */ | 156 | /* Ask if an ENGINE is reserved for this job */ |
158 | impl = ENGINE_get_digest_engine(type->type); | 157 | impl = ENGINE_get_digest_engine(type->type); |
159 | if (impl) { | 158 | if (impl != NULL) { |
160 | /* There's an ENGINE for this job ... (apparently) */ | 159 | /* There's an ENGINE for this job ... (apparently) */ |
161 | const EVP_MD *d = ENGINE_get_digest(impl, type->type); | 160 | const EVP_MD *d = ENGINE_get_digest(impl, type->type); |
162 | if (!d) { | 161 | if (d == NULL) { |
163 | /* Same comment from evp_enc.c */ | 162 | /* Same comment from evp_enc.c */ |
164 | EVPerror(EVP_R_INITIALIZATION_ERROR); | 163 | EVPerror(EVP_R_INITIALIZATION_ERROR); |
165 | ENGINE_finish(impl); | 164 | ENGINE_finish(impl); |
@@ -384,10 +383,7 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
384 | freezero(ctx->md_data, ctx->digest->ctx_size); | 383 | freezero(ctx->md_data, ctx->digest->ctx_size); |
385 | EVP_PKEY_CTX_free(ctx->pctx); | 384 | EVP_PKEY_CTX_free(ctx->pctx); |
386 | #ifndef OPENSSL_NO_ENGINE | 385 | #ifndef OPENSSL_NO_ENGINE |
387 | if (ctx->engine) | 386 | ENGINE_finish(ctx->engine); |
388 | /* The EVP_MD we used belongs to an ENGINE, release the | ||
389 | * functional reference we held for this reason. */ | ||
390 | ENGINE_finish(ctx->engine); | ||
391 | #endif | 387 | #endif |
392 | memset(ctx, 0, sizeof(*ctx)); | 388 | memset(ctx, 0, sizeof(*ctx)); |
393 | 389 | ||