summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp
diff options
context:
space:
mode:
authortb <>2018-04-14 07:09:21 +0000
committertb <>2018-04-14 07:09:21 +0000
commita32b35170819e9b07e0183d19aee21b9a246943b (patch)
tree83fef660683163befc47beedefbc0b11b71b2756 /src/lib/libcrypto/evp
parent7eaeb0d1b3ae143b8adb8634c48219a657764be9 (diff)
downloadopenbsd-a32b35170819e9b07e0183d19aee21b9a246943b.tar.gz
openbsd-a32b35170819e9b07e0183d19aee21b9a246943b.tar.bz2
openbsd-a32b35170819e9b07e0183d19aee21b9a246943b.zip
make ENGINE_finish() succeed on NULL and simplify callers as in
OpenSSL commit 7c96dbcdab9 by Rich Salz. This cleans up the caller side quite a bit and reduces the number of lines enclosed in #ifndef OPENSSL_NO_ENGINE. codesearch.debian.net shows that almost nothing checks the return value of ENGINE_finish(). While there, replace a few nearby 'if (!ptr)' with 'if (ptr == NULL)'. ok jsing, tested by & ok inoguchi
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r--src/lib/libcrypto/evp/digest.c16
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c7
-rw-r--r--src/lib/libcrypto/evp/p_lib.c20
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c12
4 files changed, 19 insertions, 36 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
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index de7c690ca7..db2deb6905 100644
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_enc.c,v 1.38 2018/02/17 16:54:08 jsing Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.39 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 *
@@ -577,10 +577,7 @@ EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
577 } 577 }
578 free(c->cipher_data); 578 free(c->cipher_data);
579#ifndef OPENSSL_NO_ENGINE 579#ifndef OPENSSL_NO_ENGINE
580 if (c->engine) 580 ENGINE_finish(c->engine);
581 /* The EVP_CIPHER we used belongs to an ENGINE, release the
582 * functional reference we held for this reason. */
583 ENGINE_finish(c->engine);
584#endif 581#endif
585 explicit_bzero(c, sizeof(EVP_CIPHER_CTX)); 582 explicit_bzero(c, sizeof(EVP_CIPHER_CTX));
586 return 1; 583 return 1;
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 811fe0c86d..b14c95f14d 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_lib.c,v 1.20 2018/02/20 18:05:28 tb Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.21 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 *
@@ -229,11 +229,8 @@ pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
229 if ((type == pkey->save_type) && pkey->ameth) 229 if ((type == pkey->save_type) && pkey->ameth)
230 return 1; 230 return 1;
231#ifndef OPENSSL_NO_ENGINE 231#ifndef OPENSSL_NO_ENGINE
232 /* If we have an ENGINE release it */ 232 ENGINE_finish(pkey->engine);
233 if (pkey->engine) { 233 pkey->engine = NULL;
234 ENGINE_finish(pkey->engine);
235 pkey->engine = NULL;
236 }
237#endif 234#endif
238 } 235 }
239 if (str) 236 if (str)
@@ -241,7 +238,7 @@ pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
241 else 238 else
242 ameth = EVP_PKEY_asn1_find(&e, type); 239 ameth = EVP_PKEY_asn1_find(&e, type);
243#ifndef OPENSSL_NO_ENGINE 240#ifndef OPENSSL_NO_ENGINE
244 if (!pkey && e) 241 if (pkey == NULL)
245 ENGINE_finish(e); 242 ENGINE_finish(e);
246#endif 243#endif
247 if (!ameth) { 244 if (!ameth) {
@@ -426,8 +423,7 @@ EVP_PKEY_type(int type)
426 else 423 else
427 ret = NID_undef; 424 ret = NID_undef;
428#ifndef OPENSSL_NO_ENGINE 425#ifndef OPENSSL_NO_ENGINE
429 if (e) 426 ENGINE_finish(e);
430 ENGINE_finish(e);
431#endif 427#endif
432 return ret; 428 return ret;
433} 429}
@@ -470,10 +466,8 @@ EVP_PKEY_free_it(EVP_PKEY *x)
470 x->pkey.ptr = NULL; 466 x->pkey.ptr = NULL;
471 } 467 }
472#ifndef OPENSSL_NO_ENGINE 468#ifndef OPENSSL_NO_ENGINE
473 if (x->engine) { 469 ENGINE_finish(x->engine);
474 ENGINE_finish(x->engine); 470 x->engine = NULL;
475 x->engine = NULL;
476 }
477#endif 471#endif
478} 472}
479 473
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c
index fc5f4ef91e..6b86a0ecfb 100644
--- a/src/lib/libcrypto/evp/pmeth_lib.c
+++ b/src/lib/libcrypto/evp/pmeth_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_lib.c,v 1.13 2017/01/29 17:49:23 beck Exp $ */ 1/* $OpenBSD: pmeth_lib.c,v 1.14 2018/04/14 07:09:21 tb 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 */
@@ -188,10 +188,9 @@ int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
188 } 188 }
189 189
190 ret = malloc(sizeof(EVP_PKEY_CTX)); 190 ret = malloc(sizeof(EVP_PKEY_CTX));
191 if (!ret) { 191 if (ret == NULL) {
192#ifndef OPENSSL_NO_ENGINE 192#ifndef OPENSSL_NO_ENGINE
193 if (e) 193 ENGINE_finish(e);
194 ENGINE_finish(e);
195#endif 194#endif
196 EVPerror(ERR_R_MALLOC_FAILURE); 195 EVPerror(ERR_R_MALLOC_FAILURE);
197 return NULL; 196 return NULL;
@@ -394,10 +393,7 @@ EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
394 EVP_PKEY_free(ctx->pkey); 393 EVP_PKEY_free(ctx->pkey);
395 EVP_PKEY_free(ctx->peerkey); 394 EVP_PKEY_free(ctx->peerkey);
396#ifndef OPENSSL_NO_ENGINE 395#ifndef OPENSSL_NO_ENGINE
397 if (ctx->engine) 396 ENGINE_finish(ctx->engine);
398 /* The EVP_PKEY_CTX we used belongs to an ENGINE, release the
399 * functional reference we held for this reason. */
400 ENGINE_finish(ctx->engine);
401#endif 397#endif
402 free(ctx); 398 free(ctx);
403} 399}