summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2026-01-30 13:42:46 +0000
committertb <>2026-01-30 13:42:46 +0000
commit941f37f21fb644009376b73f2065913887fa1bd0 (patch)
treee261320d5f8b7f1c049e1bb51fad3104e9c500af
parentb468f25e20a1bbfbabbc534c5c2b1b862fe98bbe (diff)
downloadopenbsd-941f37f21fb644009376b73f2065913887fa1bd0.tar.gz
openbsd-941f37f21fb644009376b73f2065913887fa1bd0.tar.bz2
openbsd-941f37f21fb644009376b73f2065913887fa1bd0.zip
EVP_OpenInit(): minor cleanup
Explicitly compare pointers against NULL, turn the function into single exit and explain why priv == NULL is a success (hint: muppet API). Prompted by a report by Niels Dossche. ok jsing kenjiro
-rw-r--r--src/lib/libcrypto/evp/p_legacy.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/lib/libcrypto/evp/p_legacy.c b/src/lib/libcrypto/evp/p_legacy.c
index 7c958a16e3..b2fa9dda53 100644
--- a/src/lib/libcrypto/evp/p_legacy.c
+++ b/src/lib/libcrypto/evp/p_legacy.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: p_legacy.c,v 1.7 2025/05/10 05:54:38 tb Exp $ */ 1/* $OpenBSD: p_legacy.c,v 1.8 2026/01/30 13:42:46 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 *
@@ -98,17 +98,22 @@ EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
98 const unsigned char *ek, int ekl, const unsigned char *iv, EVP_PKEY *priv) 98 const unsigned char *ek, int ekl, const unsigned char *iv, EVP_PKEY *priv)
99{ 99{
100 unsigned char *key = NULL; 100 unsigned char *key = NULL;
101 int i, size = 0, ret = 0; 101 int i, size = 0;
102 int ret = 0;
102 103
103 if (type) { 104 if (type != NULL) {
104 if (!EVP_CIPHER_CTX_reset(ctx)) 105 if (!EVP_CIPHER_CTX_reset(ctx))
105 return 0; 106 goto err;
106 if (!EVP_DecryptInit_ex(ctx, type, NULL, NULL, NULL)) 107 if (!EVP_DecryptInit_ex(ctx, type, NULL, NULL, NULL))
107 return 0; 108 goto err;
108 } 109 }
109 110
110 if (!priv) 111 /*
111 return 1; 112 * Per manpage: "It is possible to call EVP_OpenInit() twice in
113 * the same way as EVP_DecryptInit(3)."
114 */
115 if (priv == NULL)
116 goto done;
112 117
113 if (priv->type != EVP_PKEY_RSA) { 118 if (priv->type != EVP_PKEY_RSA) {
114 EVPerror(EVP_R_PUBLIC_KEY_NOT_RSA); 119 EVPerror(EVP_R_PUBLIC_KEY_NOT_RSA);
@@ -131,11 +136,13 @@ EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
131 if (!EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv)) 136 if (!EVP_DecryptInit_ex(ctx, NULL, NULL, key, iv))
132 goto err; 137 goto err;
133 138
139 done:
134 ret = 1; 140 ret = 1;
135 141
136err: 142 err:
137 freezero(key, size); 143 freezero(key, size);
138 return (ret); 144
145 return ret;
139} 146}
140LCRYPTO_ALIAS(EVP_OpenInit); 147LCRYPTO_ALIAS(EVP_OpenInit);
141 148