summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2023-11-19 15:46:10 +0000
committertb <>2023-11-19 15:46:10 +0000
commit9e356d4225ee2dcd3e3eebabf384851ee547ec95 (patch)
tree9a8bf5329015d40f6a79820880c1ca7bb820bf58
parentfea63fbd7eeaebeff6720b8ec754575f90e8eb77 (diff)
downloadopenbsd-9e356d4225ee2dcd3e3eebabf384851ee547ec95.tar.gz
openbsd-9e356d4225ee2dcd3e3eebabf384851ee547ec95.tar.bz2
openbsd-9e356d4225ee2dcd3e3eebabf384851ee547ec95.zip
Unifdef OPENSSL_NO_ENGINE in libcrypto
This is mechanical apart from a few manual edits to avoid doubled empty lines. ok jsing
-rw-r--r--src/lib/libcrypto/asn1/a_pkey.c10
-rw-r--r--src/lib/libcrypto/asn1/ameth_lib.c29
-rw-r--r--src/lib/libcrypto/conf/conf_mall.c9
-rw-r--r--src/lib/libcrypto/conf/conf_sap.c10
-rw-r--r--src/lib/libcrypto/crypto_init.c8
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c31
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c30
-rw-r--r--src/lib/libcrypto/ec/ec_key.c18
-rw-r--r--src/lib/libcrypto/ec/ec_kmeth.c27
-rw-r--r--src/lib/libcrypto/engine/engine_stubs.c6
-rw-r--r--src/lib/libcrypto/err/err_all.c8
-rw-r--r--src/lib/libcrypto/evp/digest.c62
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c55
-rw-r--r--src/lib/libcrypto/evp/p_lib.c21
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c8
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c6
-rw-r--r--src/lib/libcrypto/rand/rand.h5
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c11
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c35
-rw-r--r--src/lib/libcrypto/ts/ts.h7
-rw-r--r--src/lib/libcrypto/ts/ts_conf.c56
21 files changed, 21 insertions, 431 deletions
diff --git a/src/lib/libcrypto/asn1/a_pkey.c b/src/lib/libcrypto/asn1/a_pkey.c
index 6e715d4f9e..1e8ebc913f 100644
--- a/src/lib/libcrypto/asn1/a_pkey.c
+++ b/src/lib/libcrypto/asn1/a_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: a_pkey.c,v 1.6 2023/07/07 19:37:52 beck Exp $ */ 1/* $OpenBSD: a_pkey.c,v 1.7 2023/11/19 15:46:09 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 *
@@ -67,10 +67,6 @@
67#include <openssl/objects.h> 67#include <openssl/objects.h>
68#include <openssl/x509.h> 68#include <openssl/x509.h>
69 69
70#ifndef OPENSSL_NO_ENGINE
71#include <openssl/engine.h>
72#endif
73
74#include "asn1_local.h" 70#include "asn1_local.h"
75#include "evp_local.h" 71#include "evp_local.h"
76 72
@@ -87,10 +83,6 @@ d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
87 } 83 }
88 } else { 84 } else {
89 ret = *a; 85 ret = *a;
90#ifndef OPENSSL_NO_ENGINE
91 ENGINE_finish(ret->engine);
92 ret->engine = NULL;
93#endif
94 } 86 }
95 87
96 if (!EVP_PKEY_set_type(ret, type)) { 88 if (!EVP_PKEY_set_type(ret, type)) {
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c
index 153ad21a81..42f2f6fd52 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.32 2023/07/07 19:37:52 beck Exp $ */ 1/* $OpenBSD: ameth_lib.c,v 1.33 2023/11/19 15:46:09 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 */
@@ -64,10 +64,6 @@
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
65#include <openssl/x509.h> 65#include <openssl/x509.h>
66 66
67#ifndef OPENSSL_NO_ENGINE
68#include <openssl/engine.h>
69#endif
70
71#include "asn1_local.h" 67#include "asn1_local.h"
72#include "evp_local.h" 68#include "evp_local.h"
73 69
@@ -170,15 +166,6 @@ EVP_PKEY_asn1_find(ENGINE **pe, int type)
170 type = mp->pkey_base_id; 166 type = mp->pkey_base_id;
171 } 167 }
172 if (pe) { 168 if (pe) {
173#ifndef OPENSSL_NO_ENGINE
174 ENGINE *e;
175 /* type will contain the final unaliased type */
176 e = ENGINE_get_pkey_asn1_meth_engine(type);
177 if (e) {
178 *pe = e;
179 return ENGINE_get_pkey_asn1_meth(e, type);
180 }
181#endif
182 *pe = NULL; 169 *pe = NULL;
183 } 170 }
184 return mp; 171 return mp;
@@ -193,20 +180,6 @@ EVP_PKEY_asn1_find_str(ENGINE **pe, const char *str, int len)
193 if (len == -1) 180 if (len == -1)
194 len = strlen(str); 181 len = strlen(str);
195 if (pe) { 182 if (pe) {
196#ifndef OPENSSL_NO_ENGINE
197 ENGINE *e;
198 ameth = ENGINE_pkey_asn1_find_str(&e, str, len);
199 if (ameth) {
200 /* Convert structural into
201 * functional reference
202 */
203 if (!ENGINE_init(e))
204 ameth = NULL;
205 ENGINE_free(e);
206 *pe = e;
207 return ameth;
208 }
209#endif
210 *pe = NULL; 183 *pe = NULL;
211 } 184 }
212 for (i = EVP_PKEY_asn1_get_count() - 1; i >= 0; i--) { 185 for (i = EVP_PKEY_asn1_get_count() - 1; i >= 0; i--) {
diff --git a/src/lib/libcrypto/conf/conf_mall.c b/src/lib/libcrypto/conf/conf_mall.c
index 18631b3ba8..e2a1d2db07 100644
--- a/src/lib/libcrypto/conf/conf_mall.c
+++ b/src/lib/libcrypto/conf/conf_mall.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_mall.c,v 1.9 2014/07/11 08:44:48 jsing Exp $ */ 1/* $OpenBSD: conf_mall.c,v 1.10 2023/11/19 15:46:09 tb Exp $ */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL 2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -65,10 +65,6 @@
65#include <openssl/crypto.h> 65#include <openssl/crypto.h>
66#include <openssl/x509.h> 66#include <openssl/x509.h>
67 67
68#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71
72/* Load all OpenSSL builtin modules */ 68/* Load all OpenSSL builtin modules */
73 69
74void 70void
@@ -76,7 +72,4 @@ OPENSSL_load_builtin_modules(void)
76{ 72{
77 /* Add builtin modules here */ 73 /* Add builtin modules here */
78 ASN1_add_oid_module(); 74 ASN1_add_oid_module();
79#ifndef OPENSSL_NO_ENGINE
80 ENGINE_add_conf_module();
81#endif
82} 75}
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c
index 827cf96e74..689b7a325d 100644
--- a/src/lib/libcrypto/conf/conf_sap.c
+++ b/src/lib/libcrypto/conf/conf_sap.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: conf_sap.c,v 1.14 2018/03/19 03:56:08 beck Exp $ */ 1/* $OpenBSD: conf_sap.c,v 1.15 2023/11/19 15:46:09 tb Exp $ */
2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL 2/* Written by Stephen Henson (steve@openssl.org) for the OpenSSL
3 * project 2001. 3 * project 2001.
4 */ 4 */
@@ -67,10 +67,6 @@
67#include <openssl/err.h> 67#include <openssl/err.h>
68#include <openssl/x509.h> 68#include <openssl/x509.h>
69 69
70#ifndef OPENSSL_NO_ENGINE
71#include <openssl/engine.h>
72#endif
73
74/* This is the automatic configuration loader: it is called automatically by 70/* This is the automatic configuration loader: it is called automatically by
75 * OpenSSL when any of a number of standard initialisation functions are called, 71 * OpenSSL when any of a number of standard initialisation functions are called,
76 * unless this is overridden by calling OPENSSL_no_config() 72 * unless this is overridden by calling OPENSSL_no_config()
@@ -84,10 +80,6 @@ static void
84OPENSSL_config_internal(void) 80OPENSSL_config_internal(void)
85{ 81{
86 OPENSSL_load_builtin_modules(); 82 OPENSSL_load_builtin_modules();
87#ifndef OPENSSL_NO_ENGINE
88 /* Need to load ENGINEs */
89 ENGINE_load_builtin_engines();
90#endif
91 /* Add others here? */ 83 /* Add others here? */
92 84
93 ERR_clear_error(); 85 ERR_clear_error();
diff --git a/src/lib/libcrypto/crypto_init.c b/src/lib/libcrypto/crypto_init.c
index a2c1c786c3..2b39d2604b 100644
--- a/src/lib/libcrypto/crypto_init.c
+++ b/src/lib/libcrypto/crypto_init.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: crypto_init.c,v 1.11 2023/07/08 08:28:23 beck Exp $ */ 1/* $OpenBSD: crypto_init.c,v 1.12 2023/11/19 15:46:09 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org> 3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
4 * 4 *
@@ -22,9 +22,6 @@
22 22
23#include <openssl/asn1.h> 23#include <openssl/asn1.h>
24#include <openssl/conf.h> 24#include <openssl/conf.h>
25#ifndef OPENSSL_NO_ENGINE
26#include <openssl/engine.h>
27#endif
28#include <openssl/err.h> 25#include <openssl/err.h>
29#include <openssl/evp.h> 26#include <openssl/evp.h>
30#include <openssl/objects.h> 27#include <openssl/objects.h>
@@ -84,9 +81,6 @@ OPENSSL_cleanup(void)
84 ERR_free_strings(); 81 ERR_free_strings();
85 82
86 CRYPTO_cleanup_all_ex_data(); 83 CRYPTO_cleanup_all_ex_data();
87#ifndef OPENSSL_NO_ENGINE
88 ENGINE_cleanup();
89#endif
90 EVP_cleanup(); 84 EVP_cleanup();
91 85
92 ASN1_STRING_TABLE_cleanup(); 86 ASN1_STRING_TABLE_cleanup();
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index 8d63787689..90ce7625c6 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.41 2023/08/13 12:09:14 tb Exp $ */ 1/* $OpenBSD: dh_lib.c,v 1.42 2023/11/19 15:46:09 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 *
@@ -65,10 +65,6 @@
65#include <openssl/dh.h> 65#include <openssl/dh.h>
66#include <openssl/err.h> 66#include <openssl/err.h>
67 67
68#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71
72#include "dh_local.h" 68#include "dh_local.h"
73 69
74static const DH_METHOD *default_DH_method = NULL; 70static const DH_METHOD *default_DH_method = NULL;
@@ -101,10 +97,6 @@ DH_set_method(DH *dh, const DH_METHOD *meth)
101 mtmp = dh->meth; 97 mtmp = dh->meth;
102 if (mtmp->finish) 98 if (mtmp->finish)
103 mtmp->finish(dh); 99 mtmp->finish(dh);
104#ifndef OPENSSL_NO_ENGINE
105 ENGINE_finish(dh->engine);
106 dh->engine = NULL;
107#endif
108 dh->meth = meth; 100 dh->meth = meth;
109 if (meth->init) 101 if (meth->init)
110 meth->init(dh); 102 meth->init(dh);
@@ -133,24 +125,6 @@ DH_new_method(ENGINE *engine)
133 dh->flags = dh->meth->flags & ~DH_FLAG_NON_FIPS_ALLOW; 125 dh->flags = dh->meth->flags & ~DH_FLAG_NON_FIPS_ALLOW;
134 dh->references = 1; 126 dh->references = 1;
135 127
136#ifndef OPENSSL_NO_ENGINE
137 if (engine != NULL) {
138 if (!ENGINE_init(engine)) {
139 DHerror(ERR_R_ENGINE_LIB);
140 goto err;
141 }
142 dh->engine = engine;
143 } else
144 dh->engine = ENGINE_get_default_DH();
145 if (dh->engine != NULL) {
146 if ((dh->meth = ENGINE_get_DH(dh->engine)) == NULL) {
147 DHerror(ERR_R_ENGINE_LIB);
148 goto err;
149 }
150 dh->flags = dh->meth->flags & ~DH_FLAG_NON_FIPS_ALLOW;
151 }
152#endif
153
154 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, dh, &dh->ex_data)) 128 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, dh, &dh->ex_data))
155 goto err; 129 goto err;
156 if (dh->meth->init != NULL && !dh->meth->init(dh)) 130 if (dh->meth->init != NULL && !dh->meth->init(dh))
@@ -178,9 +152,6 @@ DH_free(DH *r)
178 152
179 if (r->meth != NULL && r->meth->finish != NULL) 153 if (r->meth != NULL && r->meth->finish != NULL)
180 r->meth->finish(r); 154 r->meth->finish(r);
181#ifndef OPENSSL_NO_ENGINE
182 ENGINE_finish(r->engine);
183#endif
184 155
185 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data); 156 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data);
186 157
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index a9d2179aeb..5c01c20255 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.44 2023/08/12 06:14:36 tb Exp $ */ 1/* $OpenBSD: dsa_lib.c,v 1.45 2023/11/19 15:46:09 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 *
@@ -70,9 +70,6 @@
70#ifndef OPENSSL_NO_DH 70#ifndef OPENSSL_NO_DH
71#include <openssl/dh.h> 71#include <openssl/dh.h>
72#endif 72#endif
73#ifndef OPENSSL_NO_ENGINE
74#include <openssl/engine.h>
75#endif
76 73
77#include "dh_local.h" 74#include "dh_local.h"
78#include "dsa_local.h" 75#include "dsa_local.h"
@@ -113,10 +110,6 @@ DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
113 mtmp = dsa->meth; 110 mtmp = dsa->meth;
114 if (mtmp->finish) 111 if (mtmp->finish)
115 mtmp->finish(dsa); 112 mtmp->finish(dsa);
116#ifndef OPENSSL_NO_ENGINE
117 ENGINE_finish(dsa->engine);
118 dsa->engine = NULL;
119#endif
120 dsa->meth = meth; 113 dsa->meth = meth;
121 if (meth->init) 114 if (meth->init)
122 meth->init(dsa); 115 meth->init(dsa);
@@ -138,24 +131,6 @@ DSA_new_method(ENGINE *engine)
138 dsa->flags = dsa->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW; 131 dsa->flags = dsa->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW;
139 dsa->references = 1; 132 dsa->references = 1;
140 133
141#ifndef OPENSSL_NO_ENGINE
142 if (engine) {
143 if (!ENGINE_init(engine)) {
144 DSAerror(ERR_R_ENGINE_LIB);
145 goto err;
146 }
147 dsa->engine = engine;
148 } else
149 dsa->engine = ENGINE_get_default_DSA();
150 if (dsa->engine != NULL) {
151 if ((dsa->meth = ENGINE_get_DSA(dsa->engine)) == NULL) {
152 DSAerror(ERR_R_ENGINE_LIB);
153 goto err;
154 }
155 dsa->flags = dsa->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW;
156 }
157#endif
158
159 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, dsa, &dsa->ex_data)) 134 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, dsa, &dsa->ex_data))
160 goto err; 135 goto err;
161 if (dsa->meth->init != NULL && !dsa->meth->init(dsa)) 136 if (dsa->meth->init != NULL && !dsa->meth->init(dsa))
@@ -184,9 +159,6 @@ DSA_free(DSA *r)
184 159
185 if (r->meth != NULL && r->meth->finish != NULL) 160 if (r->meth != NULL && r->meth->finish != NULL)
186 r->meth->finish(r); 161 r->meth->finish(r);
187#ifndef OPENSSL_NO_ENGINE
188 ENGINE_finish(r->engine);
189#endif
190 162
191 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); 163 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);
192 164
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index d9ddd5d797..2716db6dd0 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.37 2023/08/03 18:53:56 tb Exp $ */ 1/* $OpenBSD: ec_key.c,v 1.38 2023/11/19 15:46:09 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -65,9 +65,6 @@
65 65
66#include <openssl/opensslconf.h> 66#include <openssl/opensslconf.h>
67 67
68#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71#include <openssl/err.h> 68#include <openssl/err.h>
72 69
73#include "bn_local.h" 70#include "bn_local.h"
@@ -115,9 +112,6 @@ EC_KEY_free(EC_KEY *r)
115 if (r->meth != NULL && r->meth->finish != NULL) 112 if (r->meth != NULL && r->meth->finish != NULL)
116 r->meth->finish(r); 113 r->meth->finish(r);
117 114
118#ifndef OPENSSL_NO_ENGINE
119 ENGINE_finish(r->engine);
120#endif
121 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data); 115 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_EC_KEY, r, &r->ex_data);
122 116
123 EC_GROUP_free(r->group); 117 EC_GROUP_free(r->group);
@@ -138,11 +132,6 @@ EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
138 if (src->meth != dest->meth) { 132 if (src->meth != dest->meth) {
139 if (dest->meth != NULL && dest->meth->finish != NULL) 133 if (dest->meth != NULL && dest->meth->finish != NULL)
140 dest->meth->finish(dest); 134 dest->meth->finish(dest);
141#ifndef OPENSSL_NO_ENGINE
142 if (ENGINE_finish(dest->engine) == 0)
143 return 0;
144 dest->engine = NULL;
145#endif
146 } 135 }
147 /* copy the parameters */ 136 /* copy the parameters */
148 if (src->group) { 137 if (src->group) {
@@ -186,11 +175,6 @@ EC_KEY_copy(EC_KEY *dest, const EC_KEY *src)
186 return NULL; 175 return NULL;
187 176
188 if (src->meth != dest->meth) { 177 if (src->meth != dest->meth) {
189#ifndef OPENSSL_NO_ENGINE
190 if (src->engine != NULL && ENGINE_init(src->engine) == 0)
191 return 0;
192 dest->engine = src->engine;
193#endif
194 dest->meth = src->meth; 178 dest->meth = src->meth;
195 } 179 }
196 180
diff --git a/src/lib/libcrypto/ec/ec_kmeth.c b/src/lib/libcrypto/ec/ec_kmeth.c
index 38aca0028e..856afc89dc 100644
--- a/src/lib/libcrypto/ec/ec_kmeth.c
+++ b/src/lib/libcrypto/ec/ec_kmeth.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ec_kmeth.c,v 1.12 2023/07/28 09:28:37 tb Exp $ */ 1/* $OpenBSD: ec_kmeth.c,v 1.13 2023/11/19 15:46:09 tb Exp $ */
2/* 2/*
3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 3 * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
4 * project. 4 * project.
@@ -53,9 +53,6 @@
53 */ 53 */
54 54
55#include <openssl/ec.h> 55#include <openssl/ec.h>
56#ifndef OPENSSL_NO_ENGINE
57#include <openssl/engine.h>
58#endif
59#include <openssl/err.h> 56#include <openssl/err.h>
60 57
61#include "bn_local.h" 58#include "bn_local.h"
@@ -126,11 +123,6 @@ EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth)
126 if (finish != NULL) 123 if (finish != NULL)
127 finish(key); 124 finish(key);
128 125
129#ifndef OPENSSL_NO_ENGINE
130 ENGINE_finish(key->engine);
131 key->engine = NULL;
132#endif
133
134 key->meth = meth; 126 key->meth = meth;
135 if (meth->init != NULL) 127 if (meth->init != NULL)
136 return meth->init(key); 128 return meth->init(key);
@@ -148,23 +140,6 @@ EC_KEY_new_method(ENGINE *engine)
148 return NULL; 140 return NULL;
149 } 141 }
150 ret->meth = EC_KEY_get_default_method(); 142 ret->meth = EC_KEY_get_default_method();
151#ifndef OPENSSL_NO_ENGINE
152 if (engine != NULL) {
153 if (!ENGINE_init(engine)) {
154 ECerror(ERR_R_ENGINE_LIB);
155 goto err;
156 }
157 ret->engine = engine;
158 } else
159 ret->engine = ENGINE_get_default_EC();
160 if (ret->engine) {
161 ret->meth = ENGINE_get_EC(ret->engine);
162 if (ret->meth == NULL) {
163 ECerror(ERR_R_ENGINE_LIB);
164 goto err;
165 }
166 }
167#endif
168 ret->version = 1; 143 ret->version = 1;
169 ret->flags = 0; 144 ret->flags = 0;
170 ret->group = NULL; 145 ret->group = NULL;
diff --git a/src/lib/libcrypto/engine/engine_stubs.c b/src/lib/libcrypto/engine/engine_stubs.c
index 3621da80ef..b2bd8f007a 100644
--- a/src/lib/libcrypto/engine/engine_stubs.c
+++ b/src/lib/libcrypto/engine/engine_stubs.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: engine_stubs.c,v 1.1 2023/07/21 09:04:23 tb Exp $ */ 1/* $OpenBSD: engine_stubs.c,v 1.2 2023/11/19 15:46:09 tb Exp $ */
2 2
3/* 3/*
4 * Written by Theo Buehler. Public domain. 4 * Written by Theo Buehler. Public domain.
@@ -6,8 +6,6 @@
6 6
7#include <openssl/engine.h> 7#include <openssl/engine.h>
8 8
9#ifdef OPENSSL_NO_ENGINE
10
11void 9void
12ENGINE_load_builtin_engines(void) 10ENGINE_load_builtin_engines(void)
13{ 11{
@@ -121,5 +119,3 @@ ENGINE_load_public_key(ENGINE *engine, const char *key_id,
121{ 119{
122 return NULL; 120 return NULL;
123} 121}
124
125#endif
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
index 2c8a273f17..4829e46a1a 100644
--- a/src/lib/libcrypto/err/err_all.c
+++ b/src/lib/libcrypto/err/err_all.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: err_all.c,v 1.32 2023/07/28 09:46:36 tb Exp $ */ 1/* $OpenBSD: err_all.c,v 1.33 2023/11/19 15:46:09 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 *
@@ -91,9 +91,6 @@
91#ifndef OPENSSL_NO_EC 91#ifndef OPENSSL_NO_EC
92#include <openssl/ec.h> 92#include <openssl/ec.h>
93#endif 93#endif
94#ifndef OPENSSL_NO_ENGINE
95#include <openssl/engine.h>
96#endif
97#ifndef OPENSSL_NO_RSA 94#ifndef OPENSSL_NO_RSA
98#include <openssl/rsa.h> 95#include <openssl/rsa.h>
99#endif 96#endif
@@ -130,9 +127,6 @@ ERR_load_crypto_strings_internal(void)
130#ifndef OPENSSL_NO_EC 127#ifndef OPENSSL_NO_EC
131 ERR_load_EC_strings(); 128 ERR_load_EC_strings();
132#endif 129#endif
133#ifndef OPENSSL_NO_ENGINE
134 ERR_load_ENGINE_strings();
135#endif
136 ERR_load_EVP_strings(); 130 ERR_load_EVP_strings();
137#ifndef OPENSSL_NO_GOST 131#ifndef OPENSSL_NO_GOST
138 ERR_load_GOST_strings(); 132 ERR_load_GOST_strings();
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
index ca3fb219cd..9a2a304250 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.38 2023/07/07 19:37:53 beck Exp $ */ 1/* $OpenBSD: digest.c,v 1.39 2023/11/19 15:46:09 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 *
@@ -118,10 +118,6 @@
118#include <openssl/evp.h> 118#include <openssl/evp.h>
119#include <openssl/objects.h> 119#include <openssl/objects.h>
120 120
121#ifndef OPENSSL_NO_ENGINE
122#include <openssl/engine.h>
123#endif
124
125#include "evp_local.h" 121#include "evp_local.h"
126 122
127int 123int
@@ -136,49 +132,6 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
136{ 132{
137 EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED); 133 EVP_MD_CTX_clear_flags(ctx, EVP_MD_CTX_FLAG_CLEANED);
138 134
139#ifndef OPENSSL_NO_ENGINE
140 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
141 * so this context may already have an ENGINE! Try to avoid releasing
142 * the previous handle, re-querying for an ENGINE, and having a
143 * reinitialisation, when it may all be unnecessary. */
144 if (ctx->engine && ctx->digest && (!type ||
145 (type && (type->type == ctx->digest->type))))
146 goto skip_to_init;
147 if (type) {
148 /* Ensure an ENGINE left lying around from last time is cleared
149 * (the previous check attempted to avoid this if the same
150 * ENGINE and EVP_MD could be used). */
151 ENGINE_finish(ctx->engine);
152 if (impl != NULL) {
153 if (!ENGINE_init(impl)) {
154 EVPerror(EVP_R_INITIALIZATION_ERROR);
155 return 0;
156 }
157 } else
158 /* Ask if an ENGINE is reserved for this job */
159 impl = ENGINE_get_digest_engine(type->type);
160 if (impl != NULL) {
161 /* There's an ENGINE for this job ... (apparently) */
162 const EVP_MD *d = ENGINE_get_digest(impl, type->type);
163 if (d == NULL) {
164 /* Same comment from evp_enc.c */
165 EVPerror(EVP_R_INITIALIZATION_ERROR);
166 ENGINE_finish(impl);
167 return 0;
168 }
169 /* We'll use the ENGINE's private digest definition */
170 type = d;
171 /* Store the ENGINE functional reference so we know
172 * 'type' came from an ENGINE and we need to release
173 * it when done. */
174 ctx->engine = impl;
175 } else
176 ctx->engine = NULL;
177 } else if (!ctx->digest) {
178 EVPerror(EVP_R_NO_DIGEST_SET);
179 return 0;
180 }
181#endif
182 if (ctx->digest != type) { 135 if (ctx->digest != type) {
183 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data && 136 if (ctx->digest && ctx->digest->ctx_size && ctx->md_data &&
184 !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) { 137 !EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_REUSE)) {
@@ -197,9 +150,6 @@ EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
197 } 150 }
198 } 151 }
199 } 152 }
200#ifndef OPENSSL_NO_ENGINE
201skip_to_init:
202#endif
203 if (ctx->pctx) { 153 if (ctx->pctx) {
204 int r; 154 int r;
205 r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG, 155 r = EVP_PKEY_CTX_ctrl(ctx->pctx, -1, EVP_PKEY_OP_TYPE_SIG,
@@ -266,13 +216,6 @@ EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
266 EVPerror(EVP_R_INPUT_NOT_INITIALIZED); 216 EVPerror(EVP_R_INPUT_NOT_INITIALIZED);
267 return 0; 217 return 0;
268 } 218 }
269#ifndef OPENSSL_NO_ENGINE
270 /* Make sure it's safe to copy a digest context using an ENGINE */
271 if (in->engine && !ENGINE_init(in->engine)) {
272 EVPerror(ERR_R_ENGINE_LIB);
273 return 0;
274 }
275#endif
276 219
277 if (out->digest == in->digest) { 220 if (out->digest == in->digest) {
278 tmp_buf = out->md_data; 221 tmp_buf = out->md_data;
@@ -397,9 +340,6 @@ EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
397 */ 340 */
398 if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX)) 341 if (!EVP_MD_CTX_test_flags(ctx, EVP_MD_CTX_FLAG_KEEP_PKEY_CTX))
399 EVP_PKEY_CTX_free(ctx->pctx); 342 EVP_PKEY_CTX_free(ctx->pctx);
400#ifndef OPENSSL_NO_ENGINE
401 ENGINE_finish(ctx->engine);
402#endif
403 memset(ctx, 0, sizeof(*ctx)); 343 memset(ctx, 0, sizeof(*ctx));
404 344
405 return 1; 345 return 1;
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index eb279b2378..172d8b4019 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.54 2023/11/18 09:37:15 tb Exp $ */ 1/* $OpenBSD: evp_enc.c,v 1.55 2023/11/19 15:46:09 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 *
@@ -68,10 +68,6 @@
68#include <openssl/err.h> 68#include <openssl/err.h>
69#include <openssl/evp.h> 69#include <openssl/evp.h>
70 70
71#ifndef OPENSSL_NO_ENGINE
72#include <openssl/engine.h>
73#endif
74
75#include "evp_local.h" 71#include "evp_local.h"
76 72
77int 73int
@@ -94,15 +90,6 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
94 enc = 1; 90 enc = 1;
95 ctx->encrypt = enc; 91 ctx->encrypt = enc;
96 } 92 }
97#ifndef OPENSSL_NO_ENGINE
98 /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts
99 * so this context may already have an ENGINE! Try to avoid releasing
100 * the previous handle, re-querying for an ENGINE, and having a
101 * reinitialisation, when it may all be unnecessary. */
102 if (ctx->engine && ctx->cipher &&
103 (!cipher || (cipher && (cipher->nid == ctx->cipher->nid))))
104 goto skip_to_init;
105#endif
106 if (cipher) { 93 if (cipher) {
107 /* Ensure a context left lying around from last time is cleared 94 /* Ensure a context left lying around from last time is cleared
108 * (the previous check attempted to avoid this if the same 95 * (the previous check attempted to avoid this if the same
@@ -114,32 +101,6 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
114 ctx->encrypt = enc; 101 ctx->encrypt = enc;
115 ctx->flags = flags; 102 ctx->flags = flags;
116 } 103 }
117#ifndef OPENSSL_NO_ENGINE
118 if (impl) {
119 if (!ENGINE_init(impl)) {
120 EVPerror(EVP_R_INITIALIZATION_ERROR);
121 return 0;
122 }
123 } else
124 /* Ask if an ENGINE is reserved for this job */
125 impl = ENGINE_get_cipher_engine(cipher->nid);
126 if (impl) {
127 /* There's an ENGINE for this job ... (apparently) */
128 const EVP_CIPHER *c =
129 ENGINE_get_cipher(impl, cipher->nid);
130 if (!c) {
131 EVPerror(EVP_R_INITIALIZATION_ERROR);
132 return 0;
133 }
134 /* We'll use the ENGINE's private cipher definition */
135 cipher = c;
136 /* Store the ENGINE functional reference so we know
137 * 'cipher' came from an ENGINE and we need to release
138 * it when done. */
139 ctx->engine = impl;
140 } else
141 ctx->engine = NULL;
142#endif
143 104
144 ctx->cipher = cipher; 105 ctx->cipher = cipher;
145 if (ctx->cipher->ctx_size) { 106 if (ctx->cipher->ctx_size) {
@@ -163,9 +124,6 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
163 EVPerror(EVP_R_NO_CIPHER_SET); 124 EVPerror(EVP_R_NO_CIPHER_SET);
164 return 0; 125 return 0;
165 } 126 }
166#ifndef OPENSSL_NO_ENGINE
167skip_to_init:
168#endif
169 /* we assume block size is a power of 2 in *cryptUpdate */ 127 /* we assume block size is a power of 2 in *cryptUpdate */
170 if (ctx->cipher->block_size != 1 && 128 if (ctx->cipher->block_size != 1 &&
171 ctx->cipher->block_size != 8 && 129 ctx->cipher->block_size != 8 &&
@@ -614,10 +572,6 @@ EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
614 /* XXX - store size of cipher_data so we can always freezero(). */ 572 /* XXX - store size of cipher_data so we can always freezero(). */
615 free(c->cipher_data); 573 free(c->cipher_data);
616 574
617#ifndef OPENSSL_NO_ENGINE
618 ENGINE_finish(c->engine);
619#endif
620
621 explicit_bzero(c, sizeof(EVP_CIPHER_CTX)); 575 explicit_bzero(c, sizeof(EVP_CIPHER_CTX));
622 576
623 return 1; 577 return 1;
@@ -688,13 +642,6 @@ EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in)
688 EVPerror(EVP_R_INPUT_NOT_INITIALIZED); 642 EVPerror(EVP_R_INPUT_NOT_INITIALIZED);
689 return 0; 643 return 0;
690 } 644 }
691#ifndef OPENSSL_NO_ENGINE
692 /* Make sure it's safe to copy a cipher context using an ENGINE */
693 if (in->engine && !ENGINE_init(in->engine)) {
694 EVPerror(ERR_R_ENGINE_LIB);
695 return 0;
696 }
697#endif
698 645
699 EVP_CIPHER_CTX_cleanup(out); 646 EVP_CIPHER_CTX_cleanup(out);
700 memcpy(out, in, sizeof *out); 647 memcpy(out, in, sizeof *out);
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 23ec8e6031..eaeb456cbb 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.37 2023/09/10 17:32:17 tb Exp $ */ 1/* $OpenBSD: p_lib.c,v 1.38 2023/11/19 15:46:10 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 *
@@ -77,10 +77,6 @@
77#include <openssl/rsa.h> 77#include <openssl/rsa.h>
78#endif 78#endif
79 79
80#ifndef OPENSSL_NO_ENGINE
81#include <openssl/engine.h>
82#endif
83
84#include "asn1_local.h" 80#include "asn1_local.h"
85#include "evp_local.h" 81#include "evp_local.h"
86 82
@@ -245,19 +241,11 @@ pkey_set_type(EVP_PKEY *pkey, ENGINE *e, int type, const char *str, int len)
245 */ 241 */
246 if ((type == pkey->save_type) && pkey->ameth) 242 if ((type == pkey->save_type) && pkey->ameth)
247 return 1; 243 return 1;
248#ifndef OPENSSL_NO_ENGINE
249 ENGINE_finish(pkey->engine);
250 pkey->engine = NULL;
251#endif
252 } 244 }
253 if (str) 245 if (str)
254 ameth = EVP_PKEY_asn1_find_str(eptr, str, len); 246 ameth = EVP_PKEY_asn1_find_str(eptr, str, len);
255 else 247 else
256 ameth = EVP_PKEY_asn1_find(eptr, type); 248 ameth = EVP_PKEY_asn1_find(eptr, type);
257#ifndef OPENSSL_NO_ENGINE
258 if (pkey == NULL && eptr != NULL)
259 ENGINE_finish(e);
260#endif
261 if (!ameth) { 249 if (!ameth) {
262 EVPerror(EVP_R_UNSUPPORTED_ALGORITHM); 250 EVPerror(EVP_R_UNSUPPORTED_ALGORITHM);
263 return 0; 251 return 0;
@@ -583,9 +571,6 @@ EVP_PKEY_type(int type)
583 ret = ameth->pkey_id; 571 ret = ameth->pkey_id;
584 else 572 else
585 ret = NID_undef; 573 ret = NID_undef;
586#ifndef OPENSSL_NO_ENGINE
587 ENGINE_finish(e);
588#endif
589 return ret; 574 return ret;
590} 575}
591 576
@@ -626,10 +611,6 @@ EVP_PKEY_free_it(EVP_PKEY *x)
626 x->ameth->pkey_free(x); 611 x->ameth->pkey_free(x);
627 x->pkey.ptr = NULL; 612 x->pkey.ptr = NULL;
628 } 613 }
629#ifndef OPENSSL_NO_ENGINE
630 ENGINE_finish(x->engine);
631 x->engine = NULL;
632#endif
633} 614}
634 615
635static int 616static int
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 3f23a0131b..db0e75518b 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.53 2023/07/07 13:40:44 beck Exp $ */ 1/* $OpenBSD: pem_lib.c,v 1.54 2023/11/19 15:46:10 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 *
@@ -74,9 +74,6 @@
74#ifndef OPENSSL_NO_DES 74#ifndef OPENSSL_NO_DES
75#include <openssl/des.h> 75#include <openssl/des.h>
76#endif 76#endif
77#ifndef OPENSSL_NO_ENGINE
78#include <openssl/engine.h>
79#endif
80 77
81#include "asn1_local.h" 78#include "asn1_local.h"
82#include "evp_local.h" 79#include "evp_local.h"
@@ -231,9 +228,6 @@ check_pem(const char *nm, const char *name)
231 r = 1; 228 r = 1;
232 else 229 else
233 r = 0; 230 r = 0;
234#ifndef OPENSSL_NO_ENGINE
235 ENGINE_finish(e);
236#endif
237 return r; 231 return r;
238 } 232 }
239 } 233 }
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
index 2961952139..d7001c83cc 100644
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ b/src/lib/libcrypto/pem/pem_pkey.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pem_pkey.c,v 1.27 2023/07/07 13:40:44 beck Exp $ */ 1/* $OpenBSD: pem_pkey.c,v 1.28 2023/11/19 15:46:10 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 *
@@ -69,10 +69,6 @@
69#include <openssl/pkcs12.h> 69#include <openssl/pkcs12.h>
70#include <openssl/x509.h> 70#include <openssl/x509.h>
71 71
72#ifndef OPENSSL_NO_ENGINE
73#include <openssl/engine.h>
74#endif
75
76#include "asn1_local.h" 72#include "asn1_local.h"
77#include "evp_local.h" 73#include "evp_local.h"
78 74
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h
index a0e9b47969..d66d71579c 100644
--- a/src/lib/libcrypto/rand/rand.h
+++ b/src/lib/libcrypto/rand/rand.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: rand.h,v 1.23 2022/07/12 14:42:50 kn Exp $ */ 1/* $OpenBSD: rand.h,v 1.24 2023/11/19 15:46:10 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 *
@@ -83,9 +83,6 @@ struct rand_meth_st {
83 83
84int RAND_set_rand_method(const RAND_METHOD *meth); 84int RAND_set_rand_method(const RAND_METHOD *meth);
85const RAND_METHOD *RAND_get_rand_method(void); 85const RAND_METHOD *RAND_get_rand_method(void);
86#ifndef OPENSSL_NO_ENGINE
87int RAND_set_rand_engine(ENGINE *engine);
88#endif
89RAND_METHOD *RAND_SSLeay(void); 86RAND_METHOD *RAND_SSLeay(void);
90 87
91#ifndef LIBRESSL_INTERNAL 88#ifndef LIBRESSL_INTERNAL
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
index 5c5df98c98..b9ef0deebe 100644
--- a/src/lib/libcrypto/rand/rand_lib.c
+++ b/src/lib/libcrypto/rand/rand_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rand_lib.c,v 1.22 2023/07/07 19:37:54 beck Exp $ */ 1/* $OpenBSD: rand_lib.c,v 1.23 2023/11/19 15:46:10 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org> 3 * Copyright (c) 2014 Ted Unangst <tedu@openbsd.org>
4 * 4 *
@@ -45,15 +45,6 @@ RAND_SSLeay(void)
45} 45}
46LCRYPTO_ALIAS(RAND_SSLeay); 46LCRYPTO_ALIAS(RAND_SSLeay);
47 47
48#ifndef OPENSSL_NO_ENGINE
49int
50RAND_set_rand_engine(ENGINE *engine)
51{
52 return 1;
53}
54LCRYPTO_ALIAS(RAND_set_rand_engine);
55#endif
56
57void 48void
58RAND_cleanup(void) 49RAND_cleanup(void)
59{ 50{
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index fbd2c2274c..b379cddc07 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_lib.c,v 1.48 2023/07/28 10:05:16 tb Exp $ */ 1/* $OpenBSD: rsa_lib.c,v 1.49 2023/11/19 15:46:10 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 *
@@ -71,10 +71,6 @@
71#include "evp_local.h" 71#include "evp_local.h"
72#include "rsa_local.h" 72#include "rsa_local.h"
73 73
74#ifndef OPENSSL_NO_ENGINE
75#include <openssl/engine.h>
76#endif
77
78static const RSA_METHOD *default_RSA_meth = NULL; 74static const RSA_METHOD *default_RSA_meth = NULL;
79 75
80RSA * 76RSA *
@@ -122,10 +118,6 @@ RSA_set_method(RSA *rsa, const RSA_METHOD *meth)
122 mtmp = rsa->meth; 118 mtmp = rsa->meth;
123 if (mtmp->finish) 119 if (mtmp->finish)
124 mtmp->finish(rsa); 120 mtmp->finish(rsa);
125#ifndef OPENSSL_NO_ENGINE
126 ENGINE_finish(rsa->engine);
127 rsa->engine = NULL;
128#endif
129 rsa->meth = meth; 121 rsa->meth = meth;
130 if (meth->init) 122 if (meth->init)
131 meth->init(rsa); 123 meth->init(rsa);
@@ -145,25 +137,6 @@ RSA_new_method(ENGINE *engine)
145 137
146 ret->meth = RSA_get_default_method(); 138 ret->meth = RSA_get_default_method();
147 139
148#ifndef OPENSSL_NO_ENGINE
149 if (engine != NULL) {
150 if (!ENGINE_init(engine)) {
151 RSAerror(ERR_R_ENGINE_LIB);
152 goto err;
153 }
154 ret->engine = engine;
155 } else {
156 ret->engine = ENGINE_get_default_RSA();
157 }
158
159 if (ret->engine != NULL) {
160 if ((ret->meth = ENGINE_get_RSA(ret->engine)) == NULL) {
161 RSAerror(ERR_R_ENGINE_LIB);
162 goto err;
163 }
164 }
165#endif
166
167 ret->references = 1; 140 ret->references = 1;
168 ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW; 141 ret->flags = ret->meth->flags & ~RSA_FLAG_NON_FIPS_ALLOW;
169 142
@@ -178,9 +151,6 @@ RSA_new_method(ENGINE *engine)
178 return ret; 151 return ret;
179 152
180 err: 153 err:
181#ifndef OPENSSL_NO_ENGINE
182 ENGINE_finish(ret->engine);
183#endif
184 free(ret); 154 free(ret);
185 155
186 return NULL; 156 return NULL;
@@ -201,9 +171,6 @@ RSA_free(RSA *r)
201 171
202 if (r->meth->finish) 172 if (r->meth->finish)
203 r->meth->finish(r); 173 r->meth->finish(r);
204#ifndef OPENSSL_NO_ENGINE
205 ENGINE_finish(r->engine);
206#endif
207 174
208 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); 175 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data);
209 176
diff --git a/src/lib/libcrypto/ts/ts.h b/src/lib/libcrypto/ts/ts.h
index 0d5de6223c..5215fc0583 100644
--- a/src/lib/libcrypto/ts/ts.h
+++ b/src/lib/libcrypto/ts/ts.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts.h,v 1.22 2023/07/28 09:53:55 tb Exp $ */ 1/* $OpenBSD: ts.h,v 1.23 2023/11/19 15:46:10 tb Exp $ */
2/* Written by Zoltan Glozik (zglozik@opentsa.org) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@opentsa.org) for the OpenSSL
3 * project 2002, 2003, 2004. 3 * project 2002, 2003, 2004.
4 */ 4 */
@@ -542,11 +542,6 @@ EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass);
542const char *TS_CONF_get_tsa_section(CONF *conf, const char *section); 542const char *TS_CONF_get_tsa_section(CONF *conf, const char *section);
543int TS_CONF_set_serial(CONF *conf, const char *section, TS_serial_cb cb, 543int TS_CONF_set_serial(CONF *conf, const char *section, TS_serial_cb cb,
544 TS_RESP_CTX *ctx); 544 TS_RESP_CTX *ctx);
545#ifndef OPENSSL_NO_ENGINE
546int TS_CONF_set_crypto_device(CONF *conf, const char *section,
547 const char *device);
548int TS_CONF_set_default_engine(const char *name);
549#endif
550int TS_CONF_set_signer_cert(CONF *conf, const char *section, 545int TS_CONF_set_signer_cert(CONF *conf, const char *section,
551 const char *cert, TS_RESP_CTX *ctx); 546 const char *cert, TS_RESP_CTX *ctx);
552int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs, 547int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs,
diff --git a/src/lib/libcrypto/ts/ts_conf.c b/src/lib/libcrypto/ts/ts_conf.c
index 103d430272..5d27a8bbc3 100644
--- a/src/lib/libcrypto/ts/ts_conf.c
+++ b/src/lib/libcrypto/ts/ts_conf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ts_conf.c,v 1.12 2023/07/07 07:25:21 beck Exp $ */ 1/* $OpenBSD: ts_conf.c,v 1.13 2023/11/19 15:46:10 tb Exp $ */
2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL 2/* Written by Zoltan Glozik (zglozik@stones.com) for the OpenSSL
3 * project 2002. 3 * project 2002.
4 */ 4 */
@@ -65,10 +65,6 @@
65#include <openssl/pem.h> 65#include <openssl/pem.h>
66#include <openssl/ts.h> 66#include <openssl/ts.h>
67 67
68#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71
72/* Macro definitions for the configuration file. */ 68/* Macro definitions for the configuration file. */
73 69
74#define BASE_SECTION "tsa" 70#define BASE_SECTION "tsa"
@@ -211,56 +207,6 @@ err:
211} 207}
212LCRYPTO_ALIAS(TS_CONF_set_serial); 208LCRYPTO_ALIAS(TS_CONF_set_serial);
213 209
214#ifndef OPENSSL_NO_ENGINE
215
216int
217TS_CONF_set_crypto_device(CONF *conf, const char *section, const char *device)
218{
219 int ret = 0;
220
221 if (!device)
222 device = NCONF_get_string(conf, section, ENV_CRYPTO_DEVICE);
223
224 if (device && !TS_CONF_set_default_engine(device)) {
225 TS_CONF_invalid(section, ENV_CRYPTO_DEVICE);
226 goto err;
227 }
228 ret = 1;
229
230err:
231 return ret;
232}
233LCRYPTO_ALIAS(TS_CONF_set_crypto_device);
234
235int
236TS_CONF_set_default_engine(const char *name)
237{
238 ENGINE *e = NULL;
239 int ret = 0;
240
241 /* Leave the default if builtin specified. */
242 if (strcmp(name, "builtin") == 0)
243 return 1;
244
245 if (!(e = ENGINE_by_id(name)))
246 goto err;
247 /* All the operations are going to be carried out by the engine. */
248 if (!ENGINE_set_default(e, ENGINE_METHOD_ALL))
249 goto err;
250 ret = 1;
251
252err:
253 if (!ret) {
254 TSerror(TS_R_COULD_NOT_SET_ENGINE);
255 ERR_asprintf_error_data("engine:%s", name);
256 }
257 ENGINE_free(e);
258 return ret;
259}
260LCRYPTO_ALIAS(TS_CONF_set_default_engine);
261
262#endif
263
264int 210int
265TS_CONF_set_signer_cert(CONF *conf, const char *section, const char *cert, 211TS_CONF_set_signer_cert(CONF *conf, const char *section, const char *cert,
266 TS_RESP_CTX *ctx) 212 TS_RESP_CTX *ctx)