summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/evp/p_lib.c
diff options
context:
space:
mode:
authortb <>2023-11-29 21:35:57 +0000
committertb <>2023-11-29 21:35:57 +0000
commitfc4faac9b396d551d0f7729a4dffa6ee31ac2d3e (patch)
tree545e6a340462469cf3c04b8bfe5d2a0f9f885ddb /src/lib/libcrypto/evp/p_lib.c
parent0423d363b45d6891ba1e59c1ae770ef1443bf41c (diff)
downloadopenbsd-fc4faac9b396d551d0f7729a4dffa6ee31ac2d3e.tar.gz
openbsd-fc4faac9b396d551d0f7729a4dffa6ee31ac2d3e.tar.bz2
openbsd-fc4faac9b396d551d0f7729a4dffa6ee31ac2d3e.zip
Ignore ENGINE at the API boundary
This removes the remaining ENGINE members from various internal structs and functions. Any ENGINE passed into a public API is now completely ignored functions returning an ENGINE always return NULL. ok jsing
Diffstat (limited to 'src/lib/libcrypto/evp/p_lib.c')
-rw-r--r--src/lib/libcrypto/evp/p_lib.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index eaeb456cbb..4591c05234 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.38 2023/11/19 15:46:10 tb Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.39 2023/11/29 21:35:57 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 *
@@ -206,7 +206,6 @@ EVP_PKEY_new(void)
206 ret->save_type = EVP_PKEY_NONE; 206 ret->save_type = EVP_PKEY_NONE;
207 ret->references = 1; 207 ret->references = 1;
208 ret->ameth = NULL; 208 ret->ameth = NULL;
209 ret->engine = NULL;
210 ret->pkey.ptr = NULL; 209 ret->pkey.ptr = NULL;
211 ret->attributes = NULL; 210 ret->attributes = NULL;
212 ret->save_parameters = 1; 211 ret->save_parameters = 1;
@@ -220,18 +219,14 @@ EVP_PKEY_up_ref(EVP_PKEY *pkey)
220 return ((refs > 1) ? 1 : 0); 219 return ((refs > 1) ? 1 : 0);
221} 220}
222 221
223/* Setup a public key ASN1 method and ENGINE from a NID or a string. 222/* Setup a public key ASN1 method from a NID or a string.
224 * If pkey is NULL just return 1 or 0 if the algorithm exists. 223 * If pkey is NULL just return 1 or 0 if the algorithm exists.
225 */ 224 */
226 225
227static int 226static int
228pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len) 227pkey_set_type(EVP_PKEY *pkey, int type, const char *str, int len)
229{ 228{
230 const EVP_PKEY_ASN1_METHOD *ameth; 229 const EVP_PKEY_ASN1_METHOD *ameth;
231 ENGINE **eptr = NULL;
232
233 if (e == NULL)
234 eptr = &e;
235 230
236 if (pkey) { 231 if (pkey) {
237 if (pkey->pkey.ptr) 232 if (pkey->pkey.ptr)
@@ -242,17 +237,16 @@ pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len)
242 if ((type == pkey->save_type) && pkey->ameth) 237 if ((type == pkey->save_type) && pkey->ameth)
243 return 1; 238 return 1;
244 } 239 }
245 if (str) 240 if (str != NULL)
246 ameth = EVP_PKEY_asn1_find_str(eptr, str, len); 241 ameth = EVP_PKEY_asn1_find_str(NULL, str, len);
247 else 242 else
248 ameth = EVP_PKEY_asn1_find(eptr, type); 243 ameth = EVP_PKEY_asn1_find(NULL, type);
249 if (!ameth) { 244 if (!ameth) {
250 EVPerror(EVP_R_UNSUPPORTED_ALGORITHM); 245 EVPerror(EVP_R_UNSUPPORTED_ALGORITHM);
251 return 0; 246 return 0;
252 } 247 }
253 if (pkey) { 248 if (pkey) {
254 pkey->ameth = ameth; 249 pkey->ameth = ameth;
255 pkey->engine = e;
256 250
257 pkey->type = pkey->ameth->pkey_id; 251 pkey->type = pkey->ameth->pkey_id;
258 pkey->save_type = type; 252 pkey->save_type = type;
@@ -263,7 +257,7 @@ pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len)
263int 257int
264EVP_PKEY_set_type(EVP_PKEY *pkey, int type) 258EVP_PKEY_set_type(EVP_PKEY *pkey, int type)
265{ 259{
266 return pkey_set_type(pkey, NULL, type, NULL, -1); 260 return pkey_set_type(pkey, type, NULL, -1);
267} 261}
268 262
269EVP_PKEY * 263EVP_PKEY *
@@ -275,7 +269,7 @@ EVP_PKEY_new_raw_private_key(int type, ENGINE *engine,
275 if ((ret = EVP_PKEY_new()) == NULL) 269 if ((ret = EVP_PKEY_new()) == NULL)
276 goto err; 270 goto err;
277 271
278 if (!pkey_set_type(ret, engine, type, NULL, -1)) 272 if (!pkey_set_type(ret, type, NULL, -1))
279 goto err; 273 goto err;
280 274
281 if (ret->ameth->set_priv_key == NULL) { 275 if (ret->ameth->set_priv_key == NULL) {
@@ -304,7 +298,7 @@ EVP_PKEY_new_raw_public_key(int type, ENGINE *engine,
304 if ((ret = EVP_PKEY_new()) == NULL) 298 if ((ret = EVP_PKEY_new()) == NULL)
305 goto err; 299 goto err;
306 300
307 if (!pkey_set_type(ret, engine, type, NULL, -1)) 301 if (!pkey_set_type(ret, type, NULL, -1))
308 goto err; 302 goto err;
309 303
310 if (ret->ameth->set_pub_key == NULL) { 304 if (ret->ameth->set_pub_key == NULL) {
@@ -368,10 +362,10 @@ EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, size_t len,
368 if ((cmctx = CMAC_CTX_new()) == NULL) 362 if ((cmctx = CMAC_CTX_new()) == NULL)
369 goto err; 363 goto err;
370 364
371 if (!pkey_set_type(ret, e, EVP_PKEY_CMAC, NULL, -1)) 365 if (!pkey_set_type(ret, EVP_PKEY_CMAC, NULL, -1))
372 goto err; 366 goto err;
373 367
374 if (!CMAC_Init(cmctx, priv, len, cipher, e)) { 368 if (!CMAC_Init(cmctx, priv, len, cipher, NULL)) {
375 EVPerror(EVP_R_KEY_SETUP_FAILED); 369 EVPerror(EVP_R_KEY_SETUP_FAILED);
376 goto err; 370 goto err;
377 } 371 }
@@ -389,7 +383,7 @@ EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv, size_t len,
389int 383int
390EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len) 384EVP_PKEY_set_type_str(EVP_PKEY *pkey, const char *str, int len)
391{ 385{
392 return pkey_set_type(pkey, NULL, EVP_PKEY_NONE, str, len); 386 return pkey_set_type(pkey, EVP_PKEY_NONE, str, len);
393} 387}
394 388
395int 389int
@@ -563,15 +557,12 @@ EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
563int 557int
564EVP_PKEY_type(int type) 558EVP_PKEY_type(int type)
565{ 559{
566 int ret;
567 const EVP_PKEY_ASN1_METHOD *ameth; 560 const EVP_PKEY_ASN1_METHOD *ameth;
568 ENGINE *e; 561
569 ameth = EVP_PKEY_asn1_find(&e, type); 562 if ((ameth = EVP_PKEY_asn1_find(NULL, type)) != NULL)
570 if (ameth) 563 return ameth->pkey_id;
571 ret = ameth->pkey_id; 564
572 else 565 return NID_undef;
573 ret = NID_undef;
574 return ret;
575} 566}
576 567
577int 568int