summaryrefslogtreecommitdiff
path: root/src/lib
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
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')
-rw-r--r--src/lib/libcrypto/asn1/ameth_lib.c12
-rw-r--r--src/lib/libcrypto/cmac/cm_pmeth.c4
-rw-r--r--src/lib/libcrypto/cmac/cmac.c6
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c4
-rw-r--r--src/lib/libcrypto/dh/dh_local.h3
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c4
-rw-r--r--src/lib/libcrypto/dsa/dsa_local.h4
-rw-r--r--src/lib/libcrypto/ec/ec_key.c4
-rw-r--r--src/lib/libcrypto/ec/ec_local.h3
-rw-r--r--src/lib/libcrypto/evp/digest.c4
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c8
-rw-r--r--src/lib/libcrypto/evp/evp_local.h7
-rw-r--r--src/lib/libcrypto/evp/m_sigver.c12
-rw-r--r--src/lib/libcrypto/evp/p_lib.c43
-rw-r--r--src/lib/libcrypto/evp/pmeth_gn.c4
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c10
-rw-r--r--src/lib/libcrypto/hmac/hm_pmeth.c4
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c5
-rw-r--r--src/lib/libcrypto/rsa/rsa_local.h4
19 files changed, 61 insertions, 84 deletions
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c
index 42f2f6fd52..aa4bb87667 100644
--- a/src/lib/libcrypto/asn1/ameth_lib.c
+++ b/src/lib/libcrypto/asn1/ameth_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ameth_lib.c,v 1.33 2023/11/19 15:46:09 tb Exp $ */ 1/* $OpenBSD: ameth_lib.c,v 1.34 2023/11/29 21:35:57 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 */
@@ -158,6 +158,9 @@ EVP_PKEY_asn1_find(ENGINE **pe, int type)
158{ 158{
159 const EVP_PKEY_ASN1_METHOD *mp; 159 const EVP_PKEY_ASN1_METHOD *mp;
160 160
161 if (pe != NULL)
162 *pe = NULL;
163
161 for (;;) { 164 for (;;) {
162 if ((mp = pkey_asn1_find(type)) == NULL) 165 if ((mp = pkey_asn1_find(type)) == NULL)
163 break; 166 break;
@@ -165,9 +168,7 @@ EVP_PKEY_asn1_find(ENGINE **pe, int type)
165 break; 168 break;
166 type = mp->pkey_base_id; 169 type = mp->pkey_base_id;
167 } 170 }
168 if (pe) { 171
169 *pe = NULL;
170 }
171 return mp; 172 return mp;
172} 173}
173 174
@@ -179,9 +180,8 @@ EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len)
179 180
180 if (len == -1) 181 if (len == -1)
181 len = strlen(str); 182 len = strlen(str);
182 if (pe) { 183 if (pe != NULL)
183 *pe = NULL; 184 *pe = NULL;
184 }
185 for (i = EVP_PKEY_asn1_get_count() - 1; i >= 0; i--) { 185 for (i = EVP_PKEY_asn1_get_count() - 1; i >= 0; i--) {
186 ameth = EVP_PKEY_asn1_get0(i); 186 ameth = EVP_PKEY_asn1_get0(i);
187 if (ameth->pkey_flags & ASN1_PKEY_ALIAS) 187 if (ameth->pkey_flags & ASN1_PKEY_ALIAS)
diff --git a/src/lib/libcrypto/cmac/cm_pmeth.c b/src/lib/libcrypto/cmac/cm_pmeth.c
index d47cfb7b73..fa2d53e53d 100644
--- a/src/lib/libcrypto/cmac/cm_pmeth.c
+++ b/src/lib/libcrypto/cmac/cm_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cm_pmeth.c,v 1.10 2022/11/26 16:08:51 tb Exp $ */ 1/* $OpenBSD: cm_pmeth.c,v 1.11 2023/11/29 21:35:57 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 2010. 3 * project 2010.
4 */ 4 */
@@ -143,7 +143,7 @@ pkey_cmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
143 break; 143 break;
144 144
145 case EVP_PKEY_CTRL_CIPHER: 145 case EVP_PKEY_CTRL_CIPHER:
146 if (!CMAC_Init(cmctx, NULL, 0, p2, ctx->engine)) 146 if (!CMAC_Init(cmctx, NULL, 0, p2, NULL))
147 return 0; 147 return 0;
148 break; 148 break;
149 149
diff --git a/src/lib/libcrypto/cmac/cmac.c b/src/lib/libcrypto/cmac/cmac.c
index f5b5f5e320..f653219b8f 100644
--- a/src/lib/libcrypto/cmac/cmac.c
+++ b/src/lib/libcrypto/cmac/cmac.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cmac.c,v 1.15 2023/11/29 18:11:10 tb Exp $ */ 1/* $OpenBSD: cmac.c,v 1.16 2023/11/29 21:35:57 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. 3 * project.
4 */ 4 */
@@ -178,7 +178,7 @@ CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
178 int bl; 178 int bl;
179 179
180 /* All zeros means restart */ 180 /* All zeros means restart */
181 if (key == NULL && cipher == NULL && impl == NULL && keylen == 0) { 181 if (key == NULL && cipher == NULL && keylen == 0) {
182 /* Not initialised */ 182 /* Not initialised */
183 if (ctx->nlast_block == -1) 183 if (ctx->nlast_block == -1)
184 return 0; 184 return 0;
@@ -191,7 +191,7 @@ CMAC_Init(CMAC_CTX *ctx, const void *key, size_t keylen,
191 191
192 /* Initialise context. */ 192 /* Initialise context. */
193 if (cipher != NULL) { 193 if (cipher != NULL) {
194 if (!EVP_EncryptInit_ex(&ctx->cctx, cipher, impl, NULL, NULL)) 194 if (!EVP_EncryptInit_ex(&ctx->cctx, cipher, NULL, NULL, NULL))
195 return 0; 195 return 0;
196 } 196 }
197 197
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index 90ce7625c6..d8698859f0 100644
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_lib.c,v 1.42 2023/11/19 15:46:09 tb Exp $ */ 1/* $OpenBSD: dh_lib.c,v 1.43 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 *
@@ -230,7 +230,7 @@ LCRYPTO_ALIAS(DH_security_bits);
230ENGINE * 230ENGINE *
231DH_get0_engine(DH *dh) 231DH_get0_engine(DH *dh)
232{ 232{
233 return dh->engine; 233 return NULL;
234} 234}
235LCRYPTO_ALIAS(DH_get0_engine); 235LCRYPTO_ALIAS(DH_get0_engine);
236 236
diff --git a/src/lib/libcrypto/dh/dh_local.h b/src/lib/libcrypto/dh/dh_local.h
index 928f2c0c8b..22e2256906 100644
--- a/src/lib/libcrypto/dh/dh_local.h
+++ b/src/lib/libcrypto/dh/dh_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dh_local.h,v 1.3 2022/01/14 08:25:44 tb Exp $ */ 1/* $OpenBSD: dh_local.h,v 1.4 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 *
@@ -100,7 +100,6 @@ struct dh_st {
100 int references; 100 int references;
101 CRYPTO_EX_DATA ex_data; 101 CRYPTO_EX_DATA ex_data;
102 const DH_METHOD *meth; 102 const DH_METHOD *meth;
103 ENGINE *engine;
104}; 103};
105 104
106/* 105/*
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index 5c01c20255..65eb65288d 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_lib.c,v 1.45 2023/11/19 15:46:09 tb Exp $ */ 1/* $OpenBSD: dsa_lib.c,v 1.46 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 *
@@ -397,7 +397,7 @@ LCRYPTO_ALIAS(DSA_set_flags);
397ENGINE * 397ENGINE *
398DSA_get0_engine(DSA *d) 398DSA_get0_engine(DSA *d)
399{ 399{
400 return d->engine; 400 return NULL;
401} 401}
402LCRYPTO_ALIAS(DSA_get0_engine); 402LCRYPTO_ALIAS(DSA_get0_engine);
403 403
diff --git a/src/lib/libcrypto/dsa/dsa_local.h b/src/lib/libcrypto/dsa/dsa_local.h
index a413db9747..3e688b8ce6 100644
--- a/src/lib/libcrypto/dsa/dsa_local.h
+++ b/src/lib/libcrypto/dsa/dsa_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_local.h,v 1.2 2023/03/04 20:54:52 tb Exp $ */ 1/* $OpenBSD: dsa_local.h,v 1.3 2023/11/29 21:35:57 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 2007 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -106,8 +106,6 @@ struct dsa_st {
106 int references; 106 int references;
107 CRYPTO_EX_DATA ex_data; 107 CRYPTO_EX_DATA ex_data;
108 const DSA_METHOD *meth; 108 const DSA_METHOD *meth;
109 /* functional reference if 'meth' is ENGINE-provided */
110 ENGINE *engine;
111} /* DSA */; 109} /* DSA */;
112 110
113int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, 111int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index 2716db6dd0..dd976898ad 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_key.c,v 1.38 2023/11/19 15:46:09 tb Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.39 2023/11/29 21:35:57 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -191,7 +191,7 @@ EC_KEY_dup(const EC_KEY *ec_key)
191{ 191{
192 EC_KEY *ret; 192 EC_KEY *ret;
193 193
194 if ((ret = EC_KEY_new_method(ec_key->engine)) == NULL) 194 if ((ret = EC_KEY_new_method(NULL)) == NULL)
195 return NULL; 195 return NULL;
196 if (EC_KEY_copy(ret, ec_key) == NULL) { 196 if (EC_KEY_copy(ret, ec_key) == NULL) {
197 EC_KEY_free(ret); 197 EC_KEY_free(ret);
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h
index 3252eeb1c8..6ea78eaac4 100644
--- a/src/lib/libcrypto/ec/ec_local.h
+++ b/src/lib/libcrypto/ec/ec_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_local.h,v 1.26 2023/07/28 15:50:33 tb Exp $ */ 1/* $OpenBSD: ec_local.h,v 1.27 2023/11/29 21:35:57 tb Exp $ */
2/* 2/*
3 * Originally written by Bodo Moeller for the OpenSSL project. 3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */ 4 */
@@ -223,7 +223,6 @@ struct ec_group_st {
223 223
224struct ec_key_st { 224struct ec_key_st {
225 const EC_KEY_METHOD *meth; 225 const EC_KEY_METHOD *meth;
226 ENGINE *engine;
227 226
228 int version; 227 int version;
229 228
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
index 9a2a304250..ee0c68e707 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.39 2023/11/19 15:46:09 tb Exp $ */ 1/* $OpenBSD: digest.c,v 1.40 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 *
@@ -271,7 +271,7 @@ EVP_Digest(const void *data, size_t count,
271 271
272 EVP_MD_CTX_init(&ctx); 272 EVP_MD_CTX_init(&ctx);
273 EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_ONESHOT); 273 EVP_MD_CTX_set_flags(&ctx, EVP_MD_CTX_FLAG_ONESHOT);
274 ret = EVP_DigestInit_ex(&ctx, type, impl) && 274 ret = EVP_DigestInit_ex(&ctx, type, NULL) &&
275 EVP_DigestUpdate(&ctx, data, count) && 275 EVP_DigestUpdate(&ctx, data, count) &&
276 EVP_DigestFinal_ex(&ctx, md, size); 276 EVP_DigestFinal_ex(&ctx, md, size);
277 EVP_MD_CTX_cleanup(&ctx); 277 EVP_MD_CTX_cleanup(&ctx);
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index 172d8b4019..0867070a76 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.55 2023/11/19 15:46:09 tb Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.56 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 *
@@ -93,7 +93,7 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
93 if (cipher) { 93 if (cipher) {
94 /* Ensure a context left lying around from last time is cleared 94 /* Ensure a context left lying around from last time is cleared
95 * (the previous check attempted to avoid this if the same 95 * (the previous check attempted to avoid this if the same
96 * ENGINE and EVP_CIPHER could be used). */ 96 * EVP_CIPHER could be used). */
97 if (ctx->cipher) { 97 if (ctx->cipher) {
98 unsigned long flags = ctx->flags; 98 unsigned long flags = ctx->flags;
99 EVP_CIPHER_CTX_cleanup(ctx); 99 EVP_CIPHER_CTX_cleanup(ctx);
@@ -236,7 +236,7 @@ int
236EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, 236EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
237 const unsigned char *key, const unsigned char *iv) 237 const unsigned char *key, const unsigned char *iv)
238{ 238{
239 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 1); 239 return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 1);
240} 240}
241 241
242int 242int
@@ -250,7 +250,7 @@ int
250EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, 250EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
251 const unsigned char *key, const unsigned char *iv) 251 const unsigned char *key, const unsigned char *iv)
252{ 252{
253 return EVP_CipherInit_ex(ctx, cipher, impl, key, iv, 0); 253 return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 0);
254} 254}
255 255
256int 256int
diff --git a/src/lib/libcrypto/evp/evp_local.h b/src/lib/libcrypto/evp/evp_local.h
index 015fbb50a9..5df1733cbc 100644
--- a/src/lib/libcrypto/evp/evp_local.h
+++ b/src/lib/libcrypto/evp/evp_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: evp_local.h,v 1.5 2023/09/28 11:29:10 tb Exp $ */ 1/* $OpenBSD: evp_local.h,v 1.6 2023/11/29 21:35:57 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 2000. 3 * project 2000.
4 */ 4 */
@@ -97,7 +97,6 @@ struct evp_pkey_st {
97 int save_type; 97 int save_type;
98 int references; 98 int references;
99 const EVP_PKEY_ASN1_METHOD *ameth; 99 const EVP_PKEY_ASN1_METHOD *ameth;
100 ENGINE *engine;
101 union { 100 union {
102 void *ptr; 101 void *ptr;
103#ifndef OPENSSL_NO_RSA 102#ifndef OPENSSL_NO_RSA
@@ -140,7 +139,6 @@ struct evp_md_st {
140 139
141struct evp_md_ctx_st { 140struct evp_md_ctx_st {
142 const EVP_MD *digest; 141 const EVP_MD *digest;
143 ENGINE *engine; /* functional reference if 'digest' is ENGINE-provided */
144 unsigned long flags; 142 unsigned long flags;
145 void *md_data; 143 void *md_data;
146 /* Public key context for sign/verify */ 144 /* Public key context for sign/verify */
@@ -169,7 +167,6 @@ struct evp_cipher_st {
169 167
170struct evp_cipher_ctx_st { 168struct evp_cipher_ctx_st {
171 const EVP_CIPHER *cipher; 169 const EVP_CIPHER *cipher;
172 ENGINE *engine; /* functional reference if 'cipher' is ENGINE-provided */
173 int encrypt; /* encrypt or decrypt */ 170 int encrypt; /* encrypt or decrypt */
174 int buf_len; /* number we have left */ 171 int buf_len; /* number we have left */
175 172
@@ -205,8 +202,6 @@ struct evp_Encode_Ctx_st {
205struct evp_pkey_ctx_st { 202struct evp_pkey_ctx_st {
206 /* Method associated with this operation */ 203 /* Method associated with this operation */
207 const EVP_PKEY_METHOD *pmeth; 204 const EVP_PKEY_METHOD *pmeth;
208 /* Engine that implements this method or NULL if builtin */
209 ENGINE *engine;
210 /* Key: may be NULL */ 205 /* Key: may be NULL */
211 EVP_PKEY *pkey; 206 EVP_PKEY *pkey;
212 /* Peer key for key agreement, may be NULL */ 207 /* Peer key for key agreement, may be NULL */
diff --git a/src/lib/libcrypto/evp/m_sigver.c b/src/lib/libcrypto/evp/m_sigver.c
index 47c01f784a..3ce7f7e2a6 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.13 2023/07/07 19:37:53 beck Exp $ */ 1/* $OpenBSD: m_sigver.c,v 1.14 2023/11/29 21:35:57 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 */
@@ -74,10 +74,10 @@ update_oneshot_only(EVP_MD_CTX *ctx, const void *data, size_t datalen)
74 74
75static int 75static int
76do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, 76do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type,
77 ENGINE *e, EVP_PKEY *pkey, int ver) 77 EVP_PKEY *pkey, int ver)
78{ 78{
79 if (ctx->pctx == NULL) 79 if (ctx->pctx == NULL)
80 ctx->pctx = EVP_PKEY_CTX_new(pkey, e); 80 ctx->pctx = EVP_PKEY_CTX_new(pkey, NULL);
81 if (ctx->pctx == NULL) 81 if (ctx->pctx == NULL)
82 return 0; 82 return 0;
83 83
@@ -122,7 +122,7 @@ do_sigver_init(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type,
122 *pctx = ctx->pctx; 122 *pctx = ctx->pctx;
123 if (ctx->pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM) 123 if (ctx->pctx->pmeth->flags & EVP_PKEY_FLAG_SIGCTX_CUSTOM)
124 return 1; 124 return 1;
125 if (!EVP_DigestInit_ex(ctx, type, e)) 125 if (!EVP_DigestInit_ex(ctx, type, NULL))
126 return 0; 126 return 0;
127 return 1; 127 return 1;
128} 128}
@@ -131,14 +131,14 @@ int
131EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, 131EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type,
132 ENGINE *e, EVP_PKEY *pkey) 132 ENGINE *e, EVP_PKEY *pkey)
133{ 133{
134 return do_sigver_init(ctx, pctx, type, e, pkey, 0); 134 return do_sigver_init(ctx, pctx, type, pkey, 0);
135} 135}
136 136
137int 137int
138EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, 138EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type,
139 ENGINE *e, EVP_PKEY *pkey) 139 ENGINE *e, EVP_PKEY *pkey)
140{ 140{
141 return do_sigver_init(ctx, pctx, type, e, pkey, 1); 141 return do_sigver_init(ctx, pctx, type, pkey, 1);
142} 142}
143 143
144int 144int
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
diff --git a/src/lib/libcrypto/evp/pmeth_gn.c b/src/lib/libcrypto/evp/pmeth_gn.c
index b4c0395d97..c91076b8db 100644
--- a/src/lib/libcrypto/evp/pmeth_gn.c
+++ b/src/lib/libcrypto/evp/pmeth_gn.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pmeth_gn.c,v 1.13 2023/07/07 19:37:54 beck Exp $ */ 1/* $OpenBSD: pmeth_gn.c,v 1.14 2023/11/29 21:35:57 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 */
@@ -208,7 +208,7 @@ EVP_PKEY_new_mac_key(int type, ENGINE *e, const unsigned char *key, int keylen)
208 EVP_PKEY_CTX *mac_ctx = NULL; 208 EVP_PKEY_CTX *mac_ctx = NULL;
209 EVP_PKEY *mac_key = NULL; 209 EVP_PKEY *mac_key = NULL;
210 210
211 mac_ctx = EVP_PKEY_CTX_new_id(type, e); 211 mac_ctx = EVP_PKEY_CTX_new_id(type, NULL);
212 if (!mac_ctx) 212 if (!mac_ctx)
213 return NULL; 213 return NULL;
214 if (EVP_PKEY_keygen_init(mac_ctx) <= 0) 214 if (EVP_PKEY_keygen_init(mac_ctx) <= 0)
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c
index 7ebf273415..cf27862488 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.34 2023/11/19 15:43:52 tb Exp $ */ 1/* $OpenBSD: pmeth_lib.c,v 1.35 2023/11/29 21:35:57 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 */
@@ -147,7 +147,7 @@ EVP_PKEY_meth_find(int type)
147} 147}
148 148
149static EVP_PKEY_CTX * 149static EVP_PKEY_CTX *
150evp_pkey_ctx_new(EVP_PKEY *pkey, ENGINE *engine, int id) 150evp_pkey_ctx_new(EVP_PKEY *pkey, int id)
151{ 151{
152 EVP_PKEY_CTX *pkey_ctx = NULL; 152 EVP_PKEY_CTX *pkey_ctx = NULL;
153 const EVP_PKEY_METHOD *pmeth; 153 const EVP_PKEY_METHOD *pmeth;
@@ -167,8 +167,6 @@ evp_pkey_ctx_new(EVP_PKEY *pkey, ENGINE *engine, int id)
167 EVPerror(ERR_R_MALLOC_FAILURE); 167 EVPerror(ERR_R_MALLOC_FAILURE);
168 goto err; 168 goto err;
169 } 169 }
170 pkey_ctx->engine = engine;
171 engine = NULL;
172 pkey_ctx->pmeth = pmeth; 170 pkey_ctx->pmeth = pmeth;
173 pkey_ctx->operation = EVP_PKEY_OP_UNDEFINED; 171 pkey_ctx->operation = EVP_PKEY_OP_UNDEFINED;
174 if ((pkey_ctx->pkey = pkey) != NULL) 172 if ((pkey_ctx->pkey = pkey) != NULL)
@@ -234,13 +232,13 @@ EVP_PKEY_meth_free(EVP_PKEY_METHOD *pmeth)
234EVP_PKEY_CTX * 232EVP_PKEY_CTX *
235EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *engine) 233EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *engine)
236{ 234{
237 return evp_pkey_ctx_new(pkey, engine, -1); 235 return evp_pkey_ctx_new(pkey, -1);
238} 236}
239 237
240EVP_PKEY_CTX * 238EVP_PKEY_CTX *
241EVP_PKEY_CTX_new_id(int id, ENGINE *engine) 239EVP_PKEY_CTX_new_id(int id, ENGINE *engine)
242{ 240{
243 return evp_pkey_ctx_new(NULL, engine, id); 241 return evp_pkey_ctx_new(NULL, id);
244} 242}
245 243
246EVP_PKEY_CTX * 244EVP_PKEY_CTX *
diff --git a/src/lib/libcrypto/hmac/hm_pmeth.c b/src/lib/libcrypto/hmac/hm_pmeth.c
index bb043d1a23..5ec86aa095 100644
--- a/src/lib/libcrypto/hmac/hm_pmeth.c
+++ b/src/lib/libcrypto/hmac/hm_pmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hm_pmeth.c,v 1.15 2022/11/26 16:08:53 tb Exp $ */ 1/* $OpenBSD: hm_pmeth.c,v 1.16 2023/11/29 21:35:57 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 2007. 3 * project 2007.
4 */ 4 */
@@ -204,7 +204,7 @@ pkey_hmac_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
204 case EVP_PKEY_CTRL_DIGESTINIT: 204 case EVP_PKEY_CTRL_DIGESTINIT:
205 key = ctx->pkey->pkey.ptr; 205 key = ctx->pkey->pkey.ptr;
206 if (!HMAC_Init_ex(&hctx->ctx, key->data, key->length, hctx->md, 206 if (!HMAC_Init_ex(&hctx->ctx, key->data, key->length, hctx->md,
207 ctx->engine)) 207 NULL))
208 return 0; 208 return 0;
209 break; 209 break;
210 210
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index db0e75518b..d4e6599a77 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_lib.c,v 1.54 2023/11/19 15:46:10 tb Exp $ */ 1/* $OpenBSD: pem_lib.c,v 1.55 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 *
@@ -220,8 +220,7 @@ check_pem(const char *nm, const char *name)
220 const EVP_PKEY_ASN1_METHOD *ameth; 220 const EVP_PKEY_ASN1_METHOD *ameth;
221 slen = pem_check_suffix(nm, "PARAMETERS"); 221 slen = pem_check_suffix(nm, "PARAMETERS");
222 if (slen > 0) { 222 if (slen > 0) {
223 ENGINE *e; 223 ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
224 ameth = EVP_PKEY_asn1_find_str(&e, nm, slen);
225 if (ameth) { 224 if (ameth) {
226 int r; 225 int r;
227 if (ameth->param_decode) 226 if (ameth->param_decode)
diff --git a/src/lib/libcrypto/rsa/rsa_local.h b/src/lib/libcrypto/rsa/rsa_local.h
index 51ed925908..f2639d59b1 100644
--- a/src/lib/libcrypto/rsa/rsa_local.h
+++ b/src/lib/libcrypto/rsa/rsa_local.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_local.h,v 1.6 2023/08/09 12:09:06 tb Exp $ */ 1/* $OpenBSD: rsa_local.h,v 1.7 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 *
@@ -108,8 +108,6 @@ struct rsa_st {
108 long version; 108 long version;
109 const RSA_METHOD *meth; 109 const RSA_METHOD *meth;
110 110
111 /* functional reference if 'meth' is ENGINE-provided */
112 ENGINE *engine;
113 BIGNUM *n; 111 BIGNUM *n;
114 BIGNUM *e; 112 BIGNUM *e;
115 BIGNUM *d; 113 BIGNUM *d;