diff options
Diffstat (limited to 'src/lib')
33 files changed, 9 insertions, 4967 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index 9067c5673e..d44a18846f 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.145 2023/07/28 09:46:36 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.146 2023/07/28 09:53:55 tb Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
@@ -28,9 +28,6 @@ CFLAGS+= -DLIBRESSL_NAMESPACE -DLIBRESSL_CRYPTO_NAMESPACE | |||
28 | CFLAGS+= -DHAVE_FUNOPEN | 28 | CFLAGS+= -DHAVE_FUNOPEN |
29 | .endif | 29 | .endif |
30 | 30 | ||
31 | # Hardware engines | ||
32 | CFLAGS+= -DOPENSSL_NO_HW_PADLOCK # XXX enable this? | ||
33 | |||
34 | CFLAGS+= -I${LCRYPTO_SRC} | 31 | CFLAGS+= -I${LCRYPTO_SRC} |
35 | CFLAGS+= -I${LCRYPTO_SRC}/arch/${MACHINE_CPU} | 32 | CFLAGS+= -I${LCRYPTO_SRC}/arch/${MACHINE_CPU} |
36 | CFLAGS+= -I${LCRYPTO_SRC}/asn1 | 33 | CFLAGS+= -I${LCRYPTO_SRC}/asn1 |
@@ -346,28 +343,6 @@ SRCS+= ecdsa.c | |||
346 | 343 | ||
347 | # engine/ | 344 | # engine/ |
348 | SRCS+= engine_stubs.c | 345 | SRCS+= engine_stubs.c |
349 | SRCS+= eng_all.c | ||
350 | SRCS+= eng_cnf.c | ||
351 | SRCS+= eng_ctrl.c | ||
352 | SRCS+= eng_dyn.c | ||
353 | SRCS+= eng_err.c | ||
354 | SRCS+= eng_fat.c | ||
355 | SRCS+= eng_init.c | ||
356 | SRCS+= eng_lib.c | ||
357 | SRCS+= eng_list.c | ||
358 | SRCS+= eng_openssl.c | ||
359 | SRCS+= eng_pkey.c | ||
360 | SRCS+= eng_table.c | ||
361 | SRCS+= tb_asnmth.c | ||
362 | SRCS+= tb_cipher.c | ||
363 | SRCS+= tb_dh.c | ||
364 | SRCS+= tb_digest.c | ||
365 | SRCS+= tb_dsa.c | ||
366 | SRCS+= tb_eckey.c | ||
367 | SRCS+= tb_pkmeth.c | ||
368 | SRCS+= tb_rand.c | ||
369 | SRCS+= tb_rsa.c | ||
370 | SRCS+= tb_store.c | ||
371 | 346 | ||
372 | # err/ | 347 | # err/ |
373 | SRCS+= err.c | 348 | SRCS+= err.c |
diff --git a/src/lib/libcrypto/Symbols.list b/src/lib/libcrypto/Symbols.list index 8b35d5ca44..d0484a5d4c 100644 --- a/src/lib/libcrypto/Symbols.list +++ b/src/lib/libcrypto/Symbols.list | |||
@@ -1129,136 +1129,25 @@ ED25519_verify | |||
1129 | EDIPARTYNAME_free | 1129 | EDIPARTYNAME_free |
1130 | EDIPARTYNAME_it | 1130 | EDIPARTYNAME_it |
1131 | EDIPARTYNAME_new | 1131 | EDIPARTYNAME_new |
1132 | ENGINE_add | ||
1133 | ENGINE_add_conf_module | ||
1134 | ENGINE_by_id | 1132 | ENGINE_by_id |
1135 | ENGINE_cleanup | 1133 | ENGINE_cleanup |
1136 | ENGINE_cmd_is_executable | ||
1137 | ENGINE_ctrl | ||
1138 | ENGINE_ctrl_cmd | 1134 | ENGINE_ctrl_cmd |
1139 | ENGINE_ctrl_cmd_string | 1135 | ENGINE_ctrl_cmd_string |
1140 | ENGINE_finish | 1136 | ENGINE_finish |
1141 | ENGINE_free | 1137 | ENGINE_free |
1142 | ENGINE_get_DH | ||
1143 | ENGINE_get_DSA | ||
1144 | ENGINE_get_EC | ||
1145 | ENGINE_get_RAND | ||
1146 | ENGINE_get_RSA | ||
1147 | ENGINE_get_STORE | ||
1148 | ENGINE_get_cipher | ||
1149 | ENGINE_get_cipher_engine | ||
1150 | ENGINE_get_ciphers | ||
1151 | ENGINE_get_cmd_defns | ||
1152 | ENGINE_get_ctrl_function | ||
1153 | ENGINE_get_default_DH | ||
1154 | ENGINE_get_default_DSA | ||
1155 | ENGINE_get_default_EC | ||
1156 | ENGINE_get_default_RAND | ||
1157 | ENGINE_get_default_RSA | 1138 | ENGINE_get_default_RSA |
1158 | ENGINE_get_destroy_function | ||
1159 | ENGINE_get_digest | ||
1160 | ENGINE_get_digest_engine | ||
1161 | ENGINE_get_digests | ||
1162 | ENGINE_get_ex_data | ||
1163 | ENGINE_get_ex_new_index | ||
1164 | ENGINE_get_finish_function | ||
1165 | ENGINE_get_first | ||
1166 | ENGINE_get_flags | ||
1167 | ENGINE_get_id | 1139 | ENGINE_get_id |
1168 | ENGINE_get_init_function | ||
1169 | ENGINE_get_last | ||
1170 | ENGINE_get_load_privkey_function | ||
1171 | ENGINE_get_load_pubkey_function | ||
1172 | ENGINE_get_name | 1140 | ENGINE_get_name |
1173 | ENGINE_get_next | ||
1174 | ENGINE_get_pkey_asn1_meth | ||
1175 | ENGINE_get_pkey_asn1_meth_engine | ||
1176 | ENGINE_get_pkey_asn1_meth_str | ||
1177 | ENGINE_get_pkey_asn1_meths | ||
1178 | ENGINE_get_pkey_meth | ||
1179 | ENGINE_get_pkey_meth_engine | ||
1180 | ENGINE_get_pkey_meths | ||
1181 | ENGINE_get_prev | ||
1182 | ENGINE_get_ssl_client_cert_function | ||
1183 | ENGINE_get_static_state | ||
1184 | ENGINE_get_table_flags | ||
1185 | ENGINE_init | 1141 | ENGINE_init |
1186 | ENGINE_load_builtin_engines | 1142 | ENGINE_load_builtin_engines |
1187 | ENGINE_load_dynamic | 1143 | ENGINE_load_dynamic |
1188 | ENGINE_load_openssl | 1144 | ENGINE_load_openssl |
1189 | ENGINE_load_private_key | 1145 | ENGINE_load_private_key |
1190 | ENGINE_load_public_key | 1146 | ENGINE_load_public_key |
1191 | ENGINE_load_ssl_client_cert | ||
1192 | ENGINE_new | 1147 | ENGINE_new |
1193 | ENGINE_pkey_asn1_find_str | ||
1194 | ENGINE_register_DH | ||
1195 | ENGINE_register_DSA | ||
1196 | ENGINE_register_EC | ||
1197 | ENGINE_register_RAND | ||
1198 | ENGINE_register_RSA | ||
1199 | ENGINE_register_STORE | ||
1200 | ENGINE_register_all_DH | ||
1201 | ENGINE_register_all_DSA | ||
1202 | ENGINE_register_all_EC | ||
1203 | ENGINE_register_all_RAND | ||
1204 | ENGINE_register_all_RSA | ||
1205 | ENGINE_register_all_STORE | ||
1206 | ENGINE_register_all_ciphers | ||
1207 | ENGINE_register_all_complete | 1148 | ENGINE_register_all_complete |
1208 | ENGINE_register_all_digests | ||
1209 | ENGINE_register_all_pkey_asn1_meths | ||
1210 | ENGINE_register_all_pkey_meths | ||
1211 | ENGINE_register_ciphers | ||
1212 | ENGINE_register_complete | ||
1213 | ENGINE_register_digests | ||
1214 | ENGINE_register_pkey_asn1_meths | ||
1215 | ENGINE_register_pkey_meths | ||
1216 | ENGINE_remove | ||
1217 | ENGINE_set_DH | ||
1218 | ENGINE_set_DSA | ||
1219 | ENGINE_set_EC | ||
1220 | ENGINE_set_RAND | ||
1221 | ENGINE_set_RSA | ||
1222 | ENGINE_set_STORE | ||
1223 | ENGINE_set_ciphers | ||
1224 | ENGINE_set_cmd_defns | ||
1225 | ENGINE_set_ctrl_function | ||
1226 | ENGINE_set_default | 1149 | ENGINE_set_default |
1227 | ENGINE_set_default_DH | ||
1228 | ENGINE_set_default_DSA | ||
1229 | ENGINE_set_default_EC | ||
1230 | ENGINE_set_default_RAND | ||
1231 | ENGINE_set_default_RSA | 1150 | ENGINE_set_default_RSA |
1232 | ENGINE_set_default_ciphers | ||
1233 | ENGINE_set_default_digests | ||
1234 | ENGINE_set_default_pkey_asn1_meths | ||
1235 | ENGINE_set_default_pkey_meths | ||
1236 | ENGINE_set_default_string | ||
1237 | ENGINE_set_destroy_function | ||
1238 | ENGINE_set_digests | ||
1239 | ENGINE_set_ex_data | ||
1240 | ENGINE_set_finish_function | ||
1241 | ENGINE_set_flags | ||
1242 | ENGINE_set_id | ||
1243 | ENGINE_set_init_function | ||
1244 | ENGINE_set_load_privkey_function | ||
1245 | ENGINE_set_load_pubkey_function | ||
1246 | ENGINE_set_load_ssl_client_cert_function | ||
1247 | ENGINE_set_name | ||
1248 | ENGINE_set_pkey_asn1_meths | ||
1249 | ENGINE_set_pkey_meths | ||
1250 | ENGINE_set_table_flags | ||
1251 | ENGINE_unregister_DH | ||
1252 | ENGINE_unregister_DSA | ||
1253 | ENGINE_unregister_EC | ||
1254 | ENGINE_unregister_RAND | ||
1255 | ENGINE_unregister_RSA | ||
1256 | ENGINE_unregister_STORE | ||
1257 | ENGINE_unregister_ciphers | ||
1258 | ENGINE_unregister_digests | ||
1259 | ENGINE_unregister_pkey_asn1_meths | ||
1260 | ENGINE_unregister_pkey_meths | ||
1261 | ENGINE_up_ref | ||
1262 | ERR_add_error_data | 1151 | ERR_add_error_data |
1263 | ERR_add_error_vdata | 1152 | ERR_add_error_vdata |
1264 | ERR_asprintf_error_data | 1153 | ERR_asprintf_error_data |
@@ -1286,7 +1175,6 @@ ERR_load_CRYPTO_strings | |||
1286 | ERR_load_DH_strings | 1175 | ERR_load_DH_strings |
1287 | ERR_load_DSA_strings | 1176 | ERR_load_DSA_strings |
1288 | ERR_load_EC_strings | 1177 | ERR_load_EC_strings |
1289 | ERR_load_ENGINE_strings | ||
1290 | ERR_load_ERR_strings | 1178 | ERR_load_ERR_strings |
1291 | ERR_load_EVP_strings | 1179 | ERR_load_EVP_strings |
1292 | ERR_load_GOST_strings | 1180 | ERR_load_GOST_strings |
@@ -2387,7 +2275,6 @@ RAND_load_file | |||
2387 | RAND_poll | 2275 | RAND_poll |
2388 | RAND_pseudo_bytes | 2276 | RAND_pseudo_bytes |
2389 | RAND_seed | 2277 | RAND_seed |
2390 | RAND_set_rand_engine | ||
2391 | RAND_set_rand_method | 2278 | RAND_set_rand_method |
2392 | RAND_status | 2279 | RAND_status |
2393 | RAND_write_file | 2280 | RAND_write_file |
@@ -2606,9 +2493,7 @@ TS_CONF_load_key | |||
2606 | TS_CONF_set_accuracy | 2493 | TS_CONF_set_accuracy |
2607 | TS_CONF_set_certs | 2494 | TS_CONF_set_certs |
2608 | TS_CONF_set_clock_precision_digits | 2495 | TS_CONF_set_clock_precision_digits |
2609 | TS_CONF_set_crypto_device | ||
2610 | TS_CONF_set_def_policy | 2496 | TS_CONF_set_def_policy |
2611 | TS_CONF_set_default_engine | ||
2612 | TS_CONF_set_digests | 2497 | TS_CONF_set_digests |
2613 | TS_CONF_set_ess_cert_id_chain | 2498 | TS_CONF_set_ess_cert_id_chain |
2614 | TS_CONF_set_ordering | 2499 | TS_CONF_set_ordering |
diff --git a/src/lib/libcrypto/Symbols.namespace b/src/lib/libcrypto/Symbols.namespace index adaac43146..b8ca3539ec 100644 --- a/src/lib/libcrypto/Symbols.namespace +++ b/src/lib/libcrypto/Symbols.namespace | |||
@@ -1417,7 +1417,6 @@ _libre_ERR_get_implementation | |||
1417 | _libre_ERR_set_implementation | 1417 | _libre_ERR_set_implementation |
1418 | _libre_RAND_set_rand_method | 1418 | _libre_RAND_set_rand_method |
1419 | _libre_RAND_get_rand_method | 1419 | _libre_RAND_get_rand_method |
1420 | _libre_RAND_set_rand_engine | ||
1421 | _libre_RAND_SSLeay | 1420 | _libre_RAND_SSLeay |
1422 | _libre_ERR_load_RAND_strings | 1421 | _libre_ERR_load_RAND_strings |
1423 | _libre_ECDSA_SIG_new | 1422 | _libre_ECDSA_SIG_new |
@@ -1616,8 +1615,6 @@ _libre_TS_CONF_load_certs | |||
1616 | _libre_TS_CONF_load_key | 1615 | _libre_TS_CONF_load_key |
1617 | _libre_TS_CONF_get_tsa_section | 1616 | _libre_TS_CONF_get_tsa_section |
1618 | _libre_TS_CONF_set_serial | 1617 | _libre_TS_CONF_set_serial |
1619 | _libre_TS_CONF_set_crypto_device | ||
1620 | _libre_TS_CONF_set_default_engine | ||
1621 | _libre_TS_CONF_set_signer_cert | 1618 | _libre_TS_CONF_set_signer_cert |
1622 | _libre_TS_CONF_set_certs | 1619 | _libre_TS_CONF_set_certs |
1623 | _libre_TS_CONF_set_signer_key | 1620 | _libre_TS_CONF_set_signer_key |
diff --git a/src/lib/libcrypto/engine/README b/src/lib/libcrypto/engine/README deleted file mode 100644 index bc4a9041ff..0000000000 --- a/src/lib/libcrypto/engine/README +++ /dev/null | |||
@@ -1,211 +0,0 @@ | |||
1 | Notes: 2001-09-24 | ||
2 | ----------------- | ||
3 | |||
4 | This "description" (if one chooses to call it that) needed some major updating | ||
5 | so here goes. This update addresses a change being made at the same time to | ||
6 | OpenSSL, and it pretty much completely restructures the underlying mechanics of | ||
7 | the "ENGINE" code. So it serves a double purpose of being a "ENGINE internals | ||
8 | for masochists" document *and* a rather extensive commit log message. (I'd get | ||
9 | lynched for sticking all this in CHANGES or the commit mails :-). | ||
10 | |||
11 | ENGINE_TABLE underlies this restructuring, as described in the internal header | ||
12 | "eng_int.h", implemented in eng_table.c, and used in each of the "class" files; | ||
13 | tb_rsa.c, tb_dsa.c, etc. | ||
14 | |||
15 | However, "EVP_CIPHER" underlies the motivation and design of ENGINE_TABLE so | ||
16 | I'll mention a bit about that first. EVP_CIPHER (and most of this applies | ||
17 | equally to EVP_MD for digests) is both a "method" and a algorithm/mode | ||
18 | identifier that, in the current API, "lingers". These cipher description + | ||
19 | implementation structures can be defined or obtained directly by applications, | ||
20 | or can be loaded "en masse" into EVP storage so that they can be catalogued and | ||
21 | searched in various ways, ie. two ways of encrypting with the "des_cbc" | ||
22 | algorithm/mode pair are; | ||
23 | |||
24 | (i) directly; | ||
25 | const EVP_CIPHER *cipher = EVP_des_cbc(); | ||
26 | EVP_EncryptInit(&ctx, cipher, key, iv); | ||
27 | [ ... use EVP_EncryptUpdate() and EVP_EncryptFinal() ...] | ||
28 | |||
29 | (ii) indirectly; | ||
30 | OpenSSL_add_all_ciphers(); | ||
31 | cipher = EVP_get_cipherbyname("des_cbc"); | ||
32 | EVP_EncryptInit(&ctx, cipher, key, iv); | ||
33 | [ ... etc ... ] | ||
34 | |||
35 | The latter is more generally used because it also allows ciphers/digests to be | ||
36 | looked up based on other identifiers which can be useful for automatic cipher | ||
37 | selection, eg. in SSL/TLS, or by user-controllable configuration. | ||
38 | |||
39 | The important point about this is that EVP_CIPHER definitions and structures are | ||
40 | passed around with impunity and there is no safe way, without requiring massive | ||
41 | rewrites of many applications, to assume that EVP_CIPHERs can be reference | ||
42 | counted. One an EVP_CIPHER is exposed to the caller, neither it nor anything it | ||
43 | comes from can "safely" be destroyed. Unless of course the way of getting to | ||
44 | such ciphers is via entirely distinct API calls that didn't exist before. | ||
45 | However existing API usage cannot be made to understand when an EVP_CIPHER | ||
46 | pointer, that has been passed to the caller, is no longer being used. | ||
47 | |||
48 | The other problem with the existing API w.r.t. to hooking EVP_CIPHER support | ||
49 | into ENGINE is storage - the OBJ_NAME-based storage used by EVP to register | ||
50 | ciphers simultaneously registers cipher *types* and cipher *implementations* - | ||
51 | they are effectively the same thing, an "EVP_CIPHER" pointer. The problem with | ||
52 | hooking in ENGINEs is that multiple ENGINEs may implement the same ciphers. The | ||
53 | solution is necessarily that ENGINE-provided ciphers simply are not registered, | ||
54 | stored, or exposed to the caller in the same manner as existing ciphers. This is | ||
55 | especially necessary considering the fact ENGINE uses reference counts to allow | ||
56 | for cleanup, modularity, and DSO support - yet EVP_CIPHERs, as exposed to | ||
57 | callers in the current API, support no such controls. | ||
58 | |||
59 | Another sticking point for integrating cipher support into ENGINE is linkage. | ||
60 | Already there is a problem with the way ENGINE supports RSA, DSA, etc whereby | ||
61 | they are available *because* they're part of a giant ENGINE called "openssl". | ||
62 | Ie. all implementations *have* to come from an ENGINE, but we get round that by | ||
63 | having a giant ENGINE with all the software support encapsulated. This creates | ||
64 | linker hassles if nothing else - linking a 1-line application that calls 2 basic | ||
65 | RSA functions (eg. "RSA_free(RSA_new());") will result in large quantities of | ||
66 | ENGINE code being linked in *and* because of that DSA, DH, and RAND also. If we | ||
67 | continue with this approach for EVP_CIPHER support (even if it *was* possible) | ||
68 | we would lose our ability to link selectively by selectively loading certain | ||
69 | implementations of certain functionality. Touching any part of any kind of | ||
70 | crypto would result in massive static linkage of everything else. So the | ||
71 | solution is to change the way ENGINE feeds existing "classes", ie. how the | ||
72 | hooking to ENGINE works from RSA, DSA, DH, RAND, as well as adding new hooking | ||
73 | for EVP_CIPHER, and EVP_MD. | ||
74 | |||
75 | The way this is now being done is by mostly reverting back to how things used to | ||
76 | work prior to ENGINE :-). Ie. RSA now has a "RSA_METHOD" pointer again - this | ||
77 | was previously replaced by an "ENGINE" pointer and all RSA code that required | ||
78 | the RSA_METHOD would call ENGINE_get_RSA() each time on its ENGINE handle to | ||
79 | temporarily get and use the ENGINE's RSA implementation. Apart from being more | ||
80 | efficient, switching back to each RSA having an RSA_METHOD pointer also allows | ||
81 | us to conceivably operate with *no* ENGINE. As we'll see, this removes any need | ||
82 | for a fallback ENGINE that encapsulates default implementations - we can simply | ||
83 | have our RSA structure pointing its RSA_METHOD pointer to the software | ||
84 | implementation and have its ENGINE pointer set to NULL. | ||
85 | |||
86 | A look at the EVP_CIPHER hooking is most explanatory, the RSA, DSA (etc) cases | ||
87 | turn out to be degenerate forms of the same thing. The EVP storage of ciphers, | ||
88 | and the existing EVP API functions that return "software" implementations and | ||
89 | descriptions remain untouched. However, the storage takes more meaning in terms | ||
90 | of "cipher description" and less meaning in terms of "implementation". When an | ||
91 | EVP_CIPHER_CTX is actually initialised with an EVP_CIPHER method and is about to | ||
92 | begin en/decryption, the hooking to ENGINE comes into play. What happens is that | ||
93 | cipher-specific ENGINE code is asked for an ENGINE pointer (a functional | ||
94 | reference) for any ENGINE that is registered to perform the algo/mode that the | ||
95 | provided EVP_CIPHER structure represents. Under normal circumstances, that | ||
96 | ENGINE code will return NULL because no ENGINEs will have had any cipher | ||
97 | implementations *registered*. As such, a NULL ENGINE pointer is stored in the | ||
98 | EVP_CIPHER_CTX context, and the EVP_CIPHER structure is left hooked into the | ||
99 | context and so is used as the implementation. Pretty much how things work now | ||
100 | except we'd have a redundant ENGINE pointer set to NULL and doing nothing. | ||
101 | |||
102 | Conversely, if an ENGINE *has* been registered to perform the algorithm/mode | ||
103 | combination represented by the provided EVP_CIPHER, then a functional reference | ||
104 | to that ENGINE will be returned to the EVP_CIPHER_CTX during initialisation. | ||
105 | That functional reference will be stored in the context (and released on | ||
106 | cleanup) - and having that reference provides a *safe* way to use an EVP_CIPHER | ||
107 | definition that is private to the ENGINE. Ie. the EVP_CIPHER provided by the | ||
108 | application will actually be replaced by an EVP_CIPHER from the registered | ||
109 | ENGINE - it will support the same algorithm/mode as the original but will be a | ||
110 | completely different implementation. Because this EVP_CIPHER isn't stored in the | ||
111 | EVP storage, nor is it returned to applications from traditional API functions, | ||
112 | there is no associated problem with it not having reference counts. And of | ||
113 | course, when one of these "private" cipher implementations is hooked into | ||
114 | EVP_CIPHER_CTX, it is done whilst the EVP_CIPHER_CTX holds a functional | ||
115 | reference to the ENGINE that owns it, thus the use of the ENGINE's EVP_CIPHER is | ||
116 | safe. | ||
117 | |||
118 | The "cipher-specific ENGINE code" I mentioned is implemented in tb_cipher.c but | ||
119 | in essence it is simply an instantiation of "ENGINE_TABLE" code for use by | ||
120 | EVP_CIPHER code. tb_digest.c is virtually identical but, of course, it is for | ||
121 | use by EVP_MD code. Ditto for tb_rsa.c, tb_dsa.c, etc. These instantiations of | ||
122 | ENGINE_TABLE essentially provide linker-separation of the classes so that even | ||
123 | if ENGINEs implement *all* possible algorithms, an application using only | ||
124 | EVP_CIPHER code will link at most code relating to EVP_CIPHER, tb_cipher.c, core | ||
125 | ENGINE code that is independent of class, and of course the ENGINE | ||
126 | implementation that the application loaded. It will *not* however link any | ||
127 | class-specific ENGINE code for digests, RSA, etc nor will it bleed over into | ||
128 | other APIs, such as the RSA/DSA/etc library code. | ||
129 | |||
130 | ENGINE_TABLE is a little more complicated than may seem necessary but this is | ||
131 | mostly to avoid a lot of "init()"-thrashing on ENGINEs (that may have to load | ||
132 | DSOs, and other expensive setup that shouldn't be thrashed unnecessarily) *and* | ||
133 | to duplicate "default" behaviour. Basically an ENGINE_TABLE instantiation, for | ||
134 | example tb_cipher.c, implements a hash-table keyed by integer "nid" values. | ||
135 | These nids provide the uniquenness of an algorithm/mode - and each nid will hash | ||
136 | to a potentially NULL "ENGINE_PILE". An ENGINE_PILE is essentially a list of | ||
137 | pointers to ENGINEs that implement that particular 'nid'. Each "pile" uses some | ||
138 | caching tricks such that requests on that 'nid' will be cached and all future | ||
139 | requests will return immediately (well, at least with minimal operation) unless | ||
140 | a change is made to the pile, eg. perhaps an ENGINE was unloaded. The reason is | ||
141 | that an application could have support for 10 ENGINEs statically linked | ||
142 | in, and the machine in question may not have any of the hardware those 10 | ||
143 | ENGINEs support. If each of those ENGINEs has a "des_cbc" implementation, we | ||
144 | want to avoid every EVP_CIPHER_CTX setup from trying (and failing) to initialise | ||
145 | each of those 10 ENGINEs. Instead, the first such request will try to do that | ||
146 | and will either return (and cache) a NULL ENGINE pointer or will return a | ||
147 | functional reference to the first that successfully initialised. In the latter | ||
148 | case it will also cache an extra functional reference to the ENGINE as a | ||
149 | "default" for that 'nid'. The caching is acknowledged by a 'uptodate' variable | ||
150 | that is unset only if un/registration takes place on that pile. Ie. if | ||
151 | implementations of "des_cbc" are added or removed. This behaviour can be | ||
152 | tweaked; the ENGINE_TABLE_FLAG_NOINIT value can be passed to | ||
153 | ENGINE_set_table_flags(), in which case the only ENGINEs that tb_cipher.c will | ||
154 | try to initialise from the "pile" will be those that are already initialised | ||
155 | (ie. it's simply an increment of the functional reference count, and no real | ||
156 | "initialisation" will take place). | ||
157 | |||
158 | RSA, DSA, DH, and RAND all have their own ENGINE_TABLE code as well, and the | ||
159 | difference is that they all use an implicit 'nid' of 1. Whereas EVP_CIPHERs are | ||
160 | actually qualitatively different depending on 'nid' (the "des_cbc" EVP_CIPHER is | ||
161 | not an interoperable implementation of "aes_256_cbc"), RSA_METHODs are | ||
162 | necessarily interoperable and don't have different flavours, only different | ||
163 | implementations. In other words, the ENGINE_TABLE for RSA will either be empty, | ||
164 | or will have a single ENGING_PILE hashed to by the 'nid' 1 and that pile | ||
165 | represents ENGINEs that implement the single "type" of RSA there is. | ||
166 | |||
167 | Cleanup - the registration and unregistration may pose questions about how | ||
168 | cleanup works with the ENGINE_PILE doing all this caching nonsense (ie. when the | ||
169 | application or EVP_CIPHER code releases its last reference to an ENGINE, the | ||
170 | ENGINE_PILE code may still have references and thus those ENGINEs will stay | ||
171 | hooked in forever). The way this is handled is via "unregistration". With these | ||
172 | new ENGINE changes, an abstract ENGINE can be loaded and initialised, but that | ||
173 | is an algorithm-agnostic process. Even if initialised, it will not have | ||
174 | registered any of its implementations (to do so would link all class "table" | ||
175 | code despite the fact the application may use only ciphers, for example). This | ||
176 | is deliberately a distinct step. Moreover, registration and unregistration has | ||
177 | nothing to do with whether an ENGINE is *functional* or not (ie. you can even | ||
178 | register an ENGINE and its implementations without it being operational, you may | ||
179 | not even have the drivers to make it operate). What actually happens with | ||
180 | respect to cleanup is managed inside eng_lib.c with the "engine_cleanup_***" | ||
181 | functions. These functions are internal-only and each part of ENGINE code that | ||
182 | could require cleanup will, upon performing its first allocation, register a | ||
183 | callback with the "engine_cleanup" code. The other part of this that makes it | ||
184 | tick is that the ENGINE_TABLE instantiations (tb_***.c) use NULL as their | ||
185 | initialised state. So if RSA code asks for an ENGINE and no ENGINE has | ||
186 | registered an implementation, the code will simply return NULL and the tb_rsa.c | ||
187 | state will be unchanged. Thus, no cleanup is required unless registration takes | ||
188 | place. ENGINE_cleanup() will simply iterate across a list of registered cleanup | ||
189 | callbacks calling each in turn, and will then internally delete its own storage | ||
190 | (a STACK). When a cleanup callback is next registered (eg. if the cleanup() is | ||
191 | part of a graceful restart and the application wants to cleanup all state then | ||
192 | start again), the internal STACK storage will be freshly allocated. This is much | ||
193 | the same as the situation in the ENGINE_TABLE instantiations ... NULL is the | ||
194 | initialised state, so only modification operations (not queries) will cause that | ||
195 | code to have to register a cleanup. | ||
196 | |||
197 | What else? The bignum callbacks and associated ENGINE functions have been | ||
198 | removed for two obvious reasons; (i) there was no way to generalise them to the | ||
199 | mechanism now used by RSA/DSA/..., because there's no such thing as a BIGNUM | ||
200 | method, and (ii) because of (i), there was no meaningful way for library or | ||
201 | application code to automatically hook and use ENGINE supplied bignum functions | ||
202 | anyway. Also, ENGINE_cpy() has been removed (although an internal-only version | ||
203 | exists) - the idea of providing an ENGINE_cpy() function probably wasn't a good | ||
204 | one and now certainly doesn't make sense in any generalised way. Some of the | ||
205 | RSA, DSA, DH, and RAND functions that were fiddled during the original ENGINE | ||
206 | changes have now, as a consequence, been reverted back. This is because the | ||
207 | hooking of ENGINE is now automatic (and passive, it can interally use a NULL | ||
208 | ENGINE pointer to simply ignore ENGINE from then on). | ||
209 | |||
210 | Hell, that should be enough for now ... comments welcome: geoff@openssl.org | ||
211 | |||
diff --git a/src/lib/libcrypto/engine/eng_all.c b/src/lib/libcrypto/engine/eng_all.c deleted file mode 100644 index 403ca6865d..0000000000 --- a/src/lib/libcrypto/engine/eng_all.c +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | /* $OpenBSD: eng_all.c,v 1.30 2018/03/17 16:20:01 beck Exp $ */ | ||
2 | /* Written by Richard Levitte <richard@levitte.org> for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <pthread.h> | ||
60 | |||
61 | #include <openssl/opensslconf.h> | ||
62 | |||
63 | #include "cryptlib.h" | ||
64 | #include "eng_int.h" | ||
65 | |||
66 | void | ||
67 | ENGINE_load_builtin_engines_internal(void) | ||
68 | { | ||
69 | #ifndef OPENSSL_NO_STATIC_ENGINE | ||
70 | #ifndef OPENSSL_NO_HW | ||
71 | #ifndef OPENSSL_NO_HW_PADLOCK | ||
72 | ENGINE_load_padlock(); | ||
73 | #endif | ||
74 | #endif | ||
75 | #endif | ||
76 | ENGINE_register_all_complete(); | ||
77 | } | ||
78 | |||
79 | void | ||
80 | ENGINE_load_builtin_engines(void) | ||
81 | { | ||
82 | static pthread_once_t once = PTHREAD_ONCE_INIT; | ||
83 | |||
84 | /* Prayer and clean living lets you ignore errors, OpenSSL style */ | ||
85 | (void) OPENSSL_init_crypto(0, NULL); | ||
86 | |||
87 | (void) pthread_once(&once, ENGINE_load_builtin_engines_internal); | ||
88 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c deleted file mode 100644 index 24358af8cd..0000000000 --- a/src/lib/libcrypto/engine/eng_cnf.c +++ /dev/null | |||
@@ -1,252 +0,0 @@ | |||
1 | /* $OpenBSD: eng_cnf.c,v 1.15 2018/04/14 07:18:37 tb Exp $ */ | ||
2 | /* Written by Stephen Henson (steve@openssl.org) for the OpenSSL | ||
3 | * project 2001. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <string.h> | ||
60 | |||
61 | #include <openssl/err.h> | ||
62 | |||
63 | #include "eng_int.h" | ||
64 | #include <openssl/conf.h> | ||
65 | |||
66 | /* #define ENGINE_CONF_DEBUG */ | ||
67 | |||
68 | /* ENGINE config module */ | ||
69 | |||
70 | static char * | ||
71 | skip_dot(char *name) | ||
72 | { | ||
73 | char *p; | ||
74 | |||
75 | p = strchr(name, '.'); | ||
76 | if (p) | ||
77 | return p + 1; | ||
78 | return name; | ||
79 | } | ||
80 | |||
81 | static STACK_OF(ENGINE) *initialized_engines = NULL; | ||
82 | |||
83 | static int | ||
84 | int_engine_init(ENGINE *e) | ||
85 | { | ||
86 | if (!ENGINE_init(e)) | ||
87 | return 0; | ||
88 | if (!initialized_engines) | ||
89 | initialized_engines = sk_ENGINE_new_null(); | ||
90 | if (!initialized_engines || !sk_ENGINE_push(initialized_engines, e)) { | ||
91 | ENGINE_finish(e); | ||
92 | return 0; | ||
93 | } | ||
94 | return 1; | ||
95 | } | ||
96 | |||
97 | |||
98 | static int | ||
99 | int_engine_configure(char *name, char *value, const CONF *cnf) | ||
100 | { | ||
101 | int i; | ||
102 | int ret = 0; | ||
103 | long do_init = -1; | ||
104 | STACK_OF(CONF_VALUE) *ecmds; | ||
105 | CONF_VALUE *ecmd = NULL; | ||
106 | char *ctrlname, *ctrlvalue; | ||
107 | ENGINE *e = NULL; | ||
108 | int soft = 0; | ||
109 | |||
110 | name = skip_dot(name); | ||
111 | #ifdef ENGINE_CONF_DEBUG | ||
112 | fprintf(stderr, "Configuring engine %s\n", name); | ||
113 | #endif | ||
114 | /* Value is a section containing ENGINE commands */ | ||
115 | ecmds = NCONF_get_section(cnf, value); | ||
116 | |||
117 | if (!ecmds) { | ||
118 | ENGINEerror(ENGINE_R_ENGINE_SECTION_ERROR); | ||
119 | return 0; | ||
120 | } | ||
121 | |||
122 | for (i = 0; i < sk_CONF_VALUE_num(ecmds); i++) { | ||
123 | ecmd = sk_CONF_VALUE_value(ecmds, i); | ||
124 | ctrlname = skip_dot(ecmd->name); | ||
125 | ctrlvalue = ecmd->value; | ||
126 | #ifdef ENGINE_CONF_DEBUG | ||
127 | fprintf(stderr, "ENGINE conf: doing ctrl(%s,%s)\n", | ||
128 | ctrlname, ctrlvalue); | ||
129 | #endif | ||
130 | |||
131 | /* First handle some special pseudo ctrls */ | ||
132 | |||
133 | /* Override engine name to use */ | ||
134 | if (!strcmp(ctrlname, "engine_id")) | ||
135 | name = ctrlvalue; | ||
136 | else if (!strcmp(ctrlname, "soft_load")) | ||
137 | soft = 1; | ||
138 | /* Load a dynamic ENGINE */ | ||
139 | else if (!strcmp(ctrlname, "dynamic_path")) { | ||
140 | e = ENGINE_by_id("dynamic"); | ||
141 | if (!e) | ||
142 | goto err; | ||
143 | if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", ctrlvalue, 0)) | ||
144 | goto err; | ||
145 | if (!ENGINE_ctrl_cmd_string(e, "LIST_ADD", "2", 0)) | ||
146 | goto err; | ||
147 | if (!ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) | ||
148 | goto err; | ||
149 | } | ||
150 | /* ... add other pseudos here ... */ | ||
151 | else { | ||
152 | /* At this point we need an ENGINE structural reference | ||
153 | * if we don't already have one. | ||
154 | */ | ||
155 | if (!e) { | ||
156 | e = ENGINE_by_id(name); | ||
157 | if (!e && soft) { | ||
158 | ERR_clear_error(); | ||
159 | return 1; | ||
160 | } | ||
161 | if (!e) | ||
162 | goto err; | ||
163 | } | ||
164 | /* Allow "EMPTY" to mean no value: this allows a valid | ||
165 | * "value" to be passed to ctrls of type NO_INPUT | ||
166 | */ | ||
167 | if (!strcmp(ctrlvalue, "EMPTY")) | ||
168 | ctrlvalue = NULL; | ||
169 | if (!strcmp(ctrlname, "init")) { | ||
170 | if (!NCONF_get_number_e(cnf, value, "init", | ||
171 | &do_init)) | ||
172 | goto err; | ||
173 | if (do_init == 1) { | ||
174 | if (!int_engine_init(e)) | ||
175 | goto err; | ||
176 | } else if (do_init != 0) { | ||
177 | ENGINEerror(ENGINE_R_INVALID_INIT_VALUE); | ||
178 | goto err; | ||
179 | } | ||
180 | } | ||
181 | else if (!strcmp(ctrlname, "default_algorithms")) { | ||
182 | if (!ENGINE_set_default_string(e, ctrlvalue)) | ||
183 | goto err; | ||
184 | } else if (!ENGINE_ctrl_cmd_string(e, | ||
185 | ctrlname, ctrlvalue, 0)) | ||
186 | goto err; | ||
187 | } | ||
188 | } | ||
189 | if (e && (do_init == -1) && !int_engine_init(e)) { | ||
190 | ecmd = NULL; | ||
191 | goto err; | ||
192 | } | ||
193 | ret = 1; | ||
194 | |||
195 | err: | ||
196 | if (ret != 1) { | ||
197 | ENGINEerror(ENGINE_R_ENGINE_CONFIGURATION_ERROR); | ||
198 | if (ecmd) | ||
199 | ERR_asprintf_error_data( | ||
200 | "section=%s, name=%s, value=%s", | ||
201 | ecmd->section, ecmd->name, ecmd->value); | ||
202 | } | ||
203 | ENGINE_free(e); | ||
204 | return ret; | ||
205 | } | ||
206 | |||
207 | |||
208 | static int | ||
209 | int_engine_module_init(CONF_IMODULE *md, const CONF *cnf) | ||
210 | { | ||
211 | STACK_OF(CONF_VALUE) *elist; | ||
212 | CONF_VALUE *cval; | ||
213 | int i; | ||
214 | |||
215 | #ifdef ENGINE_CONF_DEBUG | ||
216 | fprintf(stderr, "Called engine module: name %s, value %s\n", | ||
217 | CONF_imodule_get_name(md), CONF_imodule_get_value(md)); | ||
218 | #endif | ||
219 | /* Value is a section containing ENGINEs to configure */ | ||
220 | elist = NCONF_get_section(cnf, CONF_imodule_get_value(md)); | ||
221 | |||
222 | if (!elist) { | ||
223 | ENGINEerror(ENGINE_R_ENGINES_SECTION_ERROR); | ||
224 | return 0; | ||
225 | } | ||
226 | |||
227 | for (i = 0; i < sk_CONF_VALUE_num(elist); i++) { | ||
228 | cval = sk_CONF_VALUE_value(elist, i); | ||
229 | if (!int_engine_configure(cval->name, cval->value, cnf)) | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | return 1; | ||
234 | } | ||
235 | |||
236 | static void | ||
237 | int_engine_module_finish(CONF_IMODULE *md) | ||
238 | { | ||
239 | ENGINE *e; | ||
240 | |||
241 | while ((e = sk_ENGINE_pop(initialized_engines))) | ||
242 | ENGINE_finish(e); | ||
243 | sk_ENGINE_free(initialized_engines); | ||
244 | initialized_engines = NULL; | ||
245 | } | ||
246 | |||
247 | void | ||
248 | ENGINE_add_conf_module(void) | ||
249 | { | ||
250 | CONF_module_add("engines", int_engine_module_init, | ||
251 | int_engine_module_finish); | ||
252 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c deleted file mode 100644 index 1a3c25fbae..0000000000 --- a/src/lib/libcrypto/engine/eng_ctrl.c +++ /dev/null | |||
@@ -1,379 +0,0 @@ | |||
1 | /* $OpenBSD: eng_ctrl.c,v 1.11 2017/01/29 17:49:23 beck Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <string.h> | ||
57 | |||
58 | #include <openssl/err.h> | ||
59 | |||
60 | #include "eng_int.h" | ||
61 | |||
62 | /* When querying a ENGINE-specific control command's 'description', this string | ||
63 | * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */ | ||
64 | static const char *int_no_description = ""; | ||
65 | |||
66 | /* These internal functions handle 'CMD'-related control commands when the | ||
67 | * ENGINE in question has asked us to take care of it (ie. the ENGINE did not | ||
68 | * set the ENGINE_FLAGS_MANUAL_CMD_CTRL flag. */ | ||
69 | |||
70 | static int | ||
71 | int_ctrl_cmd_is_null(const ENGINE_CMD_DEFN *defn) | ||
72 | { | ||
73 | if ((defn->cmd_num == 0) || (defn->cmd_name == NULL)) | ||
74 | return 1; | ||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static int | ||
79 | int_ctrl_cmd_by_name(const ENGINE_CMD_DEFN *defn, const char *s) | ||
80 | { | ||
81 | int idx = 0; | ||
82 | while (!int_ctrl_cmd_is_null(defn) && | ||
83 | (strcmp(defn->cmd_name, s) != 0)) { | ||
84 | idx++; | ||
85 | defn++; | ||
86 | } | ||
87 | if (int_ctrl_cmd_is_null(defn)) | ||
88 | /* The given name wasn't found */ | ||
89 | return -1; | ||
90 | return idx; | ||
91 | } | ||
92 | |||
93 | static int | ||
94 | int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num) | ||
95 | { | ||
96 | int idx = 0; | ||
97 | /* NB: It is stipulated that 'cmd_defn' lists are ordered by cmd_num. So | ||
98 | * our searches don't need to take any longer than necessary. */ | ||
99 | while (!int_ctrl_cmd_is_null(defn) && (defn->cmd_num < num)) { | ||
100 | idx++; | ||
101 | defn++; | ||
102 | } | ||
103 | if (defn->cmd_num == num) | ||
104 | return idx; | ||
105 | /* The given cmd_num wasn't found */ | ||
106 | return -1; | ||
107 | } | ||
108 | |||
109 | static int | ||
110 | int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | ||
111 | { | ||
112 | int idx; | ||
113 | int ret; | ||
114 | char *s = (char *)p; | ||
115 | |||
116 | /* Take care of the easy one first (eg. it requires no searches) */ | ||
117 | if (cmd == ENGINE_CTRL_GET_FIRST_CMD_TYPE) { | ||
118 | if ((e->cmd_defns == NULL) || | ||
119 | int_ctrl_cmd_is_null(e->cmd_defns)) | ||
120 | return 0; | ||
121 | return e->cmd_defns->cmd_num; | ||
122 | } | ||
123 | /* One or two commands require that "p" be a valid string buffer */ | ||
124 | if ((cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) || | ||
125 | (cmd == ENGINE_CTRL_GET_NAME_FROM_CMD) || | ||
126 | (cmd == ENGINE_CTRL_GET_DESC_FROM_CMD)) { | ||
127 | if (s == NULL) { | ||
128 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
129 | return -1; | ||
130 | } | ||
131 | } | ||
132 | /* Now handle cmd_name -> cmd_num conversion */ | ||
133 | if (cmd == ENGINE_CTRL_GET_CMD_FROM_NAME) { | ||
134 | if ((e->cmd_defns == NULL) || | ||
135 | ((idx = int_ctrl_cmd_by_name(e->cmd_defns, s)) < 0)) { | ||
136 | ENGINEerror(ENGINE_R_INVALID_CMD_NAME); | ||
137 | return -1; | ||
138 | } | ||
139 | return e->cmd_defns[idx].cmd_num; | ||
140 | } | ||
141 | /* For the rest of the commands, the 'long' argument must specify a | ||
142 | * valie command number - so we need to conduct a search. */ | ||
143 | if ((e->cmd_defns == NULL) || | ||
144 | ((idx = int_ctrl_cmd_by_num(e->cmd_defns, (unsigned int)i)) < 0)) { | ||
145 | ENGINEerror(ENGINE_R_INVALID_CMD_NUMBER); | ||
146 | return -1; | ||
147 | } | ||
148 | /* Now the logic splits depending on command type */ | ||
149 | switch (cmd) { | ||
150 | case ENGINE_CTRL_GET_NEXT_CMD_TYPE: | ||
151 | idx++; | ||
152 | if (int_ctrl_cmd_is_null(e->cmd_defns + idx)) | ||
153 | /* end-of-list */ | ||
154 | return 0; | ||
155 | else | ||
156 | return e->cmd_defns[idx].cmd_num; | ||
157 | case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD: | ||
158 | return strlen(e->cmd_defns[idx].cmd_name); | ||
159 | case ENGINE_CTRL_GET_NAME_FROM_CMD: | ||
160 | ret = snprintf(s, strlen(e->cmd_defns[idx].cmd_name) + 1, | ||
161 | "%s", e->cmd_defns[idx].cmd_name); | ||
162 | if (ret >= (strlen(e->cmd_defns[idx].cmd_name) + 1)) | ||
163 | ret = -1; | ||
164 | return ret; | ||
165 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: | ||
166 | if (e->cmd_defns[idx].cmd_desc) | ||
167 | return strlen(e->cmd_defns[idx].cmd_desc); | ||
168 | return strlen(int_no_description); | ||
169 | case ENGINE_CTRL_GET_DESC_FROM_CMD: | ||
170 | if (e->cmd_defns[idx].cmd_desc) { | ||
171 | ret = snprintf(s, | ||
172 | strlen(e->cmd_defns[idx].cmd_desc) + 1, | ||
173 | "%s", e->cmd_defns[idx].cmd_desc); | ||
174 | if (ret >= strlen(e->cmd_defns[idx].cmd_desc) + 1) | ||
175 | ret = -1; | ||
176 | return ret; | ||
177 | } | ||
178 | ret = snprintf(s, strlen(int_no_description) + 1, "%s", | ||
179 | int_no_description); | ||
180 | if (ret >= strlen(int_no_description) + 1) | ||
181 | ret = -1; | ||
182 | return ret; | ||
183 | case ENGINE_CTRL_GET_CMD_FLAGS: | ||
184 | return e->cmd_defns[idx].cmd_flags; | ||
185 | } | ||
186 | |||
187 | /* Shouldn't really be here ... */ | ||
188 | ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR); | ||
189 | return -1; | ||
190 | } | ||
191 | |||
192 | int | ||
193 | ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | ||
194 | { | ||
195 | int ctrl_exists, ref_exists; | ||
196 | |||
197 | if (e == NULL) { | ||
198 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
199 | return 0; | ||
200 | } | ||
201 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
202 | ref_exists = ((e->struct_ref > 0) ? 1 : 0); | ||
203 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
204 | ctrl_exists = ((e->ctrl == NULL) ? 0 : 1); | ||
205 | if (!ref_exists) { | ||
206 | ENGINEerror(ENGINE_R_NO_REFERENCE); | ||
207 | return 0; | ||
208 | } | ||
209 | /* Intercept any "root-level" commands before trying to hand them on to | ||
210 | * ctrl() handlers. */ | ||
211 | switch (cmd) { | ||
212 | case ENGINE_CTRL_HAS_CTRL_FUNCTION: | ||
213 | return ctrl_exists; | ||
214 | case ENGINE_CTRL_GET_FIRST_CMD_TYPE: | ||
215 | case ENGINE_CTRL_GET_NEXT_CMD_TYPE: | ||
216 | case ENGINE_CTRL_GET_CMD_FROM_NAME: | ||
217 | case ENGINE_CTRL_GET_NAME_LEN_FROM_CMD: | ||
218 | case ENGINE_CTRL_GET_NAME_FROM_CMD: | ||
219 | case ENGINE_CTRL_GET_DESC_LEN_FROM_CMD: | ||
220 | case ENGINE_CTRL_GET_DESC_FROM_CMD: | ||
221 | case ENGINE_CTRL_GET_CMD_FLAGS: | ||
222 | if (ctrl_exists && !(e->flags & ENGINE_FLAGS_MANUAL_CMD_CTRL)) | ||
223 | return int_ctrl_helper(e, cmd, i, p, f); | ||
224 | if (!ctrl_exists) { | ||
225 | ENGINEerror(ENGINE_R_NO_CONTROL_FUNCTION); | ||
226 | /* For these cmd-related functions, failure is indicated | ||
227 | * by a -1 return value (because 0 is used as a valid | ||
228 | * return in some places). */ | ||
229 | return -1; | ||
230 | } | ||
231 | default: | ||
232 | break; | ||
233 | } | ||
234 | /* Anything else requires a ctrl() handler to exist. */ | ||
235 | if (!ctrl_exists) { | ||
236 | ENGINEerror(ENGINE_R_NO_CONTROL_FUNCTION); | ||
237 | return 0; | ||
238 | } | ||
239 | return e->ctrl(e, cmd, i, p, f); | ||
240 | } | ||
241 | |||
242 | int | ||
243 | ENGINE_cmd_is_executable(ENGINE *e, int cmd) | ||
244 | { | ||
245 | int flags; | ||
246 | |||
247 | if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, cmd, | ||
248 | NULL, NULL)) < 0) { | ||
249 | ENGINEerror(ENGINE_R_INVALID_CMD_NUMBER); | ||
250 | return 0; | ||
251 | } | ||
252 | if (!(flags & ENGINE_CMD_FLAG_NO_INPUT) && | ||
253 | !(flags & ENGINE_CMD_FLAG_NUMERIC) && | ||
254 | !(flags & ENGINE_CMD_FLAG_STRING)) | ||
255 | return 0; | ||
256 | return 1; | ||
257 | } | ||
258 | |||
259 | int | ||
260 | ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, long i, void *p, | ||
261 | void (*f)(void), int cmd_optional) | ||
262 | { | ||
263 | int num; | ||
264 | |||
265 | if ((e == NULL) || (cmd_name == NULL)) { | ||
266 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
267 | return 0; | ||
268 | } | ||
269 | if ((e->ctrl == NULL) || | ||
270 | ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME, | ||
271 | 0, (void *)cmd_name, NULL)) <= 0)) { | ||
272 | /* If the command didn't *have* to be supported, we fake | ||
273 | * success. This allows certain settings to be specified for | ||
274 | * multiple ENGINEs and only require a change of ENGINE id | ||
275 | * (without having to selectively apply settings). Eg. changing | ||
276 | * from a hardware device back to the regular software ENGINE | ||
277 | * without editing the config file, etc. */ | ||
278 | if (cmd_optional) { | ||
279 | ERR_clear_error(); | ||
280 | return 1; | ||
281 | } | ||
282 | ENGINEerror(ENGINE_R_INVALID_CMD_NAME); | ||
283 | return 0; | ||
284 | } | ||
285 | |||
286 | /* Force the result of the control command to 0 or 1, for the reasons | ||
287 | * mentioned before. */ | ||
288 | if (ENGINE_ctrl(e, num, i, p, f) > 0) | ||
289 | return 1; | ||
290 | |||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | int | ||
295 | ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, | ||
296 | int cmd_optional) | ||
297 | { | ||
298 | int num, flags; | ||
299 | long l; | ||
300 | char *ptr; | ||
301 | |||
302 | if ((e == NULL) || (cmd_name == NULL)) { | ||
303 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
304 | return 0; | ||
305 | } | ||
306 | if ((e->ctrl == NULL) || | ||
307 | ((num = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FROM_NAME, 0, | ||
308 | (void *)cmd_name, NULL)) <= 0)) { | ||
309 | /* If the command didn't *have* to be supported, we fake | ||
310 | * success. This allows certain settings to be specified for | ||
311 | * multiple ENGINEs and only require a change of ENGINE id | ||
312 | * (without having to selectively apply settings). Eg. changing | ||
313 | * from a hardware device back to the regular software ENGINE | ||
314 | * without editing the config file, etc. */ | ||
315 | if (cmd_optional) { | ||
316 | ERR_clear_error(); | ||
317 | return 1; | ||
318 | } | ||
319 | ENGINEerror(ENGINE_R_INVALID_CMD_NAME); | ||
320 | return 0; | ||
321 | } | ||
322 | if (!ENGINE_cmd_is_executable(e, num)) { | ||
323 | ENGINEerror(ENGINE_R_CMD_NOT_EXECUTABLE); | ||
324 | return 0; | ||
325 | } | ||
326 | if ((flags = ENGINE_ctrl(e, ENGINE_CTRL_GET_CMD_FLAGS, num, | ||
327 | NULL, NULL)) < 0) { | ||
328 | /* Shouldn't happen, given that ENGINE_cmd_is_executable() | ||
329 | * returned success. */ | ||
330 | ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR); | ||
331 | return 0; | ||
332 | } | ||
333 | /* If the command takes no input, there must be no input. And vice | ||
334 | * versa. */ | ||
335 | if (flags & ENGINE_CMD_FLAG_NO_INPUT) { | ||
336 | if (arg != NULL) { | ||
337 | ENGINEerror(ENGINE_R_COMMAND_TAKES_NO_INPUT); | ||
338 | return 0; | ||
339 | } | ||
340 | /* We deliberately force the result of ENGINE_ctrl() to 0 or 1 | ||
341 | * rather than returning it as "return data". This is to ensure | ||
342 | * usage of these commands is consistent across applications and | ||
343 | * that certain applications don't understand it one way, and | ||
344 | * others another. */ | ||
345 | if (ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) | ||
346 | return 1; | ||
347 | return 0; | ||
348 | } | ||
349 | /* So, we require input */ | ||
350 | if (arg == NULL) { | ||
351 | ENGINEerror(ENGINE_R_COMMAND_TAKES_INPUT); | ||
352 | return 0; | ||
353 | } | ||
354 | /* If it takes string input, that's easy */ | ||
355 | if (flags & ENGINE_CMD_FLAG_STRING) { | ||
356 | /* Same explanation as above */ | ||
357 | if (ENGINE_ctrl(e, num, 0, (void *)arg, NULL) > 0) | ||
358 | return 1; | ||
359 | return 0; | ||
360 | } | ||
361 | /* If it doesn't take numeric either, then it is unsupported for use in | ||
362 | * a config-setting situation, which is what this function is for. This | ||
363 | * should never happen though, because ENGINE_cmd_is_executable() was | ||
364 | * used. */ | ||
365 | if (!(flags & ENGINE_CMD_FLAG_NUMERIC)) { | ||
366 | ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR); | ||
367 | return 0; | ||
368 | } | ||
369 | l = strtol(arg, &ptr, 10); | ||
370 | if ((arg == ptr) || (*ptr != '\0')) { | ||
371 | ENGINEerror(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER); | ||
372 | return 0; | ||
373 | } | ||
374 | /* Force the result of the control command to 0 or 1, for the reasons | ||
375 | * mentioned before. */ | ||
376 | if (ENGINE_ctrl(e, num, l, NULL, NULL) > 0) | ||
377 | return 1; | ||
378 | return 0; | ||
379 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_dyn.c b/src/lib/libcrypto/engine/eng_dyn.c deleted file mode 100644 index 400ce72681..0000000000 --- a/src/lib/libcrypto/engine/eng_dyn.c +++ /dev/null | |||
@@ -1,64 +0,0 @@ | |||
1 | /* $OpenBSD: eng_dyn.c,v 1.14 2015/06/19 06:05:11 bcook Exp $ */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2001. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <openssl/engine.h> | ||
60 | |||
61 | void | ||
62 | ENGINE_load_dynamic(void) | ||
63 | { | ||
64 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c deleted file mode 100644 index 5f86a41540..0000000000 --- a/src/lib/libcrypto/engine/eng_err.c +++ /dev/null | |||
@@ -1,129 +0,0 @@ | |||
1 | /* $OpenBSD: eng_err.c,v 1.12 2022/07/12 14:42:49 kn Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2010 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <stdio.h> | ||
57 | |||
58 | #include <openssl/opensslconf.h> | ||
59 | |||
60 | #include <openssl/err.h> | ||
61 | #include <openssl/engine.h> | ||
62 | |||
63 | #ifndef OPENSSL_NO_ERR | ||
64 | |||
65 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_ENGINE,func,0) | ||
66 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_ENGINE,0,reason) | ||
67 | |||
68 | static ERR_STRING_DATA ENGINE_str_functs[] = { | ||
69 | {ERR_FUNC(0xfff), "CRYPTO_internal"}, | ||
70 | {0, NULL} | ||
71 | }; | ||
72 | |||
73 | static ERR_STRING_DATA ENGINE_str_reasons[] = { | ||
74 | {ERR_REASON(ENGINE_R_ALREADY_LOADED) , "already loaded"}, | ||
75 | {ERR_REASON(ENGINE_R_ARGUMENT_IS_NOT_A_NUMBER), "argument is not a number"}, | ||
76 | {ERR_REASON(ENGINE_R_CMD_NOT_EXECUTABLE) , "cmd not executable"}, | ||
77 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_INPUT), "command takes input"}, | ||
78 | {ERR_REASON(ENGINE_R_COMMAND_TAKES_NO_INPUT), "command takes no input"}, | ||
79 | {ERR_REASON(ENGINE_R_CONFLICTING_ENGINE_ID), "conflicting engine id"}, | ||
80 | {ERR_REASON(ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED), "ctrl command not implemented"}, | ||
81 | {ERR_REASON(ENGINE_R_DH_NOT_IMPLEMENTED) , "dh not implemented"}, | ||
82 | {ERR_REASON(ENGINE_R_DSA_NOT_IMPLEMENTED), "dsa not implemented"}, | ||
83 | {ERR_REASON(ENGINE_R_DSO_FAILURE) , "DSO failure"}, | ||
84 | {ERR_REASON(ENGINE_R_DSO_NOT_FOUND) , "dso not found"}, | ||
85 | {ERR_REASON(ENGINE_R_ENGINES_SECTION_ERROR), "engines section error"}, | ||
86 | {ERR_REASON(ENGINE_R_ENGINE_CONFIGURATION_ERROR), "engine configuration error"}, | ||
87 | {ERR_REASON(ENGINE_R_ENGINE_IS_NOT_IN_LIST), "engine is not in the list"}, | ||
88 | {ERR_REASON(ENGINE_R_ENGINE_SECTION_ERROR), "engine section error"}, | ||
89 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PRIVATE_KEY), "failed loading private key"}, | ||
90 | {ERR_REASON(ENGINE_R_FAILED_LOADING_PUBLIC_KEY), "failed loading public key"}, | ||
91 | {ERR_REASON(ENGINE_R_FINISH_FAILED) , "finish failed"}, | ||
92 | {ERR_REASON(ENGINE_R_GET_HANDLE_FAILED) , "could not obtain hardware handle"}, | ||
93 | {ERR_REASON(ENGINE_R_ID_OR_NAME_MISSING) , "'id' or 'name' missing"}, | ||
94 | {ERR_REASON(ENGINE_R_INIT_FAILED) , "init failed"}, | ||
95 | {ERR_REASON(ENGINE_R_INTERNAL_LIST_ERROR), "internal list error"}, | ||
96 | {ERR_REASON(ENGINE_R_INVALID_ARGUMENT) , "invalid argument"}, | ||
97 | {ERR_REASON(ENGINE_R_INVALID_CMD_NAME) , "invalid cmd name"}, | ||
98 | {ERR_REASON(ENGINE_R_INVALID_CMD_NUMBER) , "invalid cmd number"}, | ||
99 | {ERR_REASON(ENGINE_R_INVALID_INIT_VALUE) , "invalid init value"}, | ||
100 | {ERR_REASON(ENGINE_R_INVALID_STRING) , "invalid string"}, | ||
101 | {ERR_REASON(ENGINE_R_NOT_INITIALISED) , "not initialised"}, | ||
102 | {ERR_REASON(ENGINE_R_NOT_LOADED) , "not loaded"}, | ||
103 | {ERR_REASON(ENGINE_R_NO_CONTROL_FUNCTION), "no control function"}, | ||
104 | {ERR_REASON(ENGINE_R_NO_INDEX) , "no index"}, | ||
105 | {ERR_REASON(ENGINE_R_NO_LOAD_FUNCTION) , "no load function"}, | ||
106 | {ERR_REASON(ENGINE_R_NO_REFERENCE) , "no reference"}, | ||
107 | {ERR_REASON(ENGINE_R_NO_SUCH_ENGINE) , "no such engine"}, | ||
108 | {ERR_REASON(ENGINE_R_NO_UNLOAD_FUNCTION) , "no unload function"}, | ||
109 | {ERR_REASON(ENGINE_R_PROVIDE_PARAMETERS) , "provide parameters"}, | ||
110 | {ERR_REASON(ENGINE_R_RSA_NOT_IMPLEMENTED), "rsa not implemented"}, | ||
111 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_CIPHER), "unimplemented cipher"}, | ||
112 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_DIGEST), "unimplemented digest"}, | ||
113 | {ERR_REASON(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD), "unimplemented public key method"}, | ||
114 | {ERR_REASON(ENGINE_R_VERSION_INCOMPATIBILITY), "version incompatibility"}, | ||
115 | {0, NULL} | ||
116 | }; | ||
117 | |||
118 | #endif | ||
119 | |||
120 | void | ||
121 | ERR_load_ENGINE_strings(void) | ||
122 | { | ||
123 | #ifndef OPENSSL_NO_ERR | ||
124 | if (ERR_func_error_string(ENGINE_str_functs[0].error) == NULL) { | ||
125 | ERR_load_strings(0, ENGINE_str_functs); | ||
126 | ERR_load_strings(0, ENGINE_str_reasons); | ||
127 | } | ||
128 | #endif | ||
129 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c deleted file mode 100644 index f0b57722ff..0000000000 --- a/src/lib/libcrypto/engine/eng_fat.c +++ /dev/null | |||
@@ -1,182 +0,0 @@ | |||
1 | /* $OpenBSD: eng_fat.c,v 1.19 2023/07/28 09:22:26 tb Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | /* ==================================================================== | ||
56 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
57 | * ECDH support in OpenSSL originally developed by | ||
58 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
59 | */ | ||
60 | |||
61 | #include <string.h> | ||
62 | |||
63 | #include <openssl/opensslconf.h> | ||
64 | |||
65 | #include <openssl/err.h> | ||
66 | #include "eng_int.h" | ||
67 | #include <openssl/conf.h> | ||
68 | |||
69 | int | ||
70 | ENGINE_set_default(ENGINE *e, unsigned int flags) | ||
71 | { | ||
72 | if ((flags & ENGINE_METHOD_CIPHERS) && !ENGINE_set_default_ciphers(e)) | ||
73 | return 0; | ||
74 | if ((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e)) | ||
75 | return 0; | ||
76 | #ifndef OPENSSL_NO_RSA | ||
77 | if ((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e)) | ||
78 | return 0; | ||
79 | #endif | ||
80 | #ifndef OPENSSL_NO_DSA | ||
81 | if ((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e)) | ||
82 | return 0; | ||
83 | #endif | ||
84 | #ifndef OPENSSL_NO_DH | ||
85 | if ((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) | ||
86 | return 0; | ||
87 | #endif | ||
88 | #ifndef OPENSSL_NO_EC | ||
89 | if ((flags & ENGINE_METHOD_EC) && !ENGINE_set_default_EC(e)) | ||
90 | return 0; | ||
91 | #endif | ||
92 | if ((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) | ||
93 | return 0; | ||
94 | if ((flags & ENGINE_METHOD_PKEY_METHS) && | ||
95 | !ENGINE_set_default_pkey_meths(e)) | ||
96 | return 0; | ||
97 | if ((flags & ENGINE_METHOD_PKEY_ASN1_METHS) && | ||
98 | !ENGINE_set_default_pkey_asn1_meths(e)) | ||
99 | return 0; | ||
100 | return 1; | ||
101 | } | ||
102 | |||
103 | /* Set default algorithms using a string */ | ||
104 | |||
105 | static int | ||
106 | int_def_cb(const char *alg, int len, void *arg) | ||
107 | { | ||
108 | unsigned int *pflags = arg; | ||
109 | |||
110 | if (!strncmp(alg, "ALL", len)) | ||
111 | *pflags |= ENGINE_METHOD_ALL; | ||
112 | else if (!strncmp(alg, "RSA", len)) | ||
113 | *pflags |= ENGINE_METHOD_RSA; | ||
114 | else if (!strncmp(alg, "DSA", len)) | ||
115 | *pflags |= ENGINE_METHOD_DSA; | ||
116 | else if (!strncmp(alg, "DH", len)) | ||
117 | *pflags |= ENGINE_METHOD_DH; | ||
118 | else if (strncmp(alg, "EC", len) == 0) | ||
119 | *pflags |= ENGINE_METHOD_EC; | ||
120 | else if (!strncmp(alg, "RAND", len)) | ||
121 | *pflags |= ENGINE_METHOD_RAND; | ||
122 | else if (!strncmp(alg, "CIPHERS", len)) | ||
123 | *pflags |= ENGINE_METHOD_CIPHERS; | ||
124 | else if (!strncmp(alg, "DIGESTS", len)) | ||
125 | *pflags |= ENGINE_METHOD_DIGESTS; | ||
126 | else if (!strncmp(alg, "PKEY", len)) | ||
127 | *pflags |= ENGINE_METHOD_PKEY_METHS | | ||
128 | ENGINE_METHOD_PKEY_ASN1_METHS; | ||
129 | else if (!strncmp(alg, "PKEY_CRYPTO", len)) | ||
130 | *pflags |= ENGINE_METHOD_PKEY_METHS; | ||
131 | else if (!strncmp(alg, "PKEY_ASN1", len)) | ||
132 | *pflags |= ENGINE_METHOD_PKEY_ASN1_METHS; | ||
133 | else | ||
134 | return 0; | ||
135 | return 1; | ||
136 | } | ||
137 | |||
138 | int | ||
139 | ENGINE_set_default_string(ENGINE *e, const char *def_list) | ||
140 | { | ||
141 | unsigned int flags = 0; | ||
142 | |||
143 | if (!CONF_parse_list(def_list, ',', 1, int_def_cb, &flags)) { | ||
144 | ENGINEerror(ENGINE_R_INVALID_STRING); | ||
145 | ERR_asprintf_error_data("str=%s",def_list); | ||
146 | return 0; | ||
147 | } | ||
148 | return ENGINE_set_default(e, flags); | ||
149 | } | ||
150 | |||
151 | int | ||
152 | ENGINE_register_complete(ENGINE *e) | ||
153 | { | ||
154 | ENGINE_register_ciphers(e); | ||
155 | ENGINE_register_digests(e); | ||
156 | #ifndef OPENSSL_NO_RSA | ||
157 | ENGINE_register_RSA(e); | ||
158 | #endif | ||
159 | #ifndef OPENSSL_NO_DSA | ||
160 | ENGINE_register_DSA(e); | ||
161 | #endif | ||
162 | #ifndef OPENSSL_NO_DH | ||
163 | ENGINE_register_DH(e); | ||
164 | #endif | ||
165 | #ifndef OPENSSL_NO_EC | ||
166 | ENGINE_register_EC(e); | ||
167 | #endif | ||
168 | ENGINE_register_RAND(e); | ||
169 | ENGINE_register_pkey_meths(e); | ||
170 | return 1; | ||
171 | } | ||
172 | |||
173 | int | ||
174 | ENGINE_register_all_complete(void) | ||
175 | { | ||
176 | ENGINE *e; | ||
177 | |||
178 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
179 | if (!(e->flags & ENGINE_FLAGS_NO_REGISTER_ALL)) | ||
180 | ENGINE_register_complete(e); | ||
181 | return 1; | ||
182 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_init.c b/src/lib/libcrypto/engine/eng_init.c deleted file mode 100644 index 793adba8be..0000000000 --- a/src/lib/libcrypto/engine/eng_init.c +++ /dev/null | |||
@@ -1,147 +0,0 @@ | |||
1 | /* $OpenBSD: eng_init.c,v 1.9 2018/04/14 07:09:21 tb Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <openssl/err.h> | ||
57 | |||
58 | #include "eng_int.h" | ||
59 | |||
60 | /* Initialise a engine type for use (or up its functional reference count | ||
61 | * if it's already in use). This version is only used internally. */ | ||
62 | int | ||
63 | engine_unlocked_init(ENGINE *e) | ||
64 | { | ||
65 | int to_return = 1; | ||
66 | |||
67 | if ((e->funct_ref == 0) && e->init) | ||
68 | /* This is the first functional reference and the engine | ||
69 | * requires initialisation so we do it now. */ | ||
70 | to_return = e->init(e); | ||
71 | if (to_return) { | ||
72 | /* OK, we return a functional reference which is also a | ||
73 | * structural reference. */ | ||
74 | e->struct_ref++; | ||
75 | e->funct_ref++; | ||
76 | engine_ref_debug(e, 0, 1) | ||
77 | engine_ref_debug(e, 1, 1) | ||
78 | } | ||
79 | return to_return; | ||
80 | } | ||
81 | |||
82 | /* Free a functional reference to a engine type. This version is only used | ||
83 | * internally. */ | ||
84 | int | ||
85 | engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) | ||
86 | { | ||
87 | int to_return = 1; | ||
88 | |||
89 | /* Reduce the functional reference count here so if it's the terminating | ||
90 | * case, we can release the lock safely and call the finish() handler | ||
91 | * without risk of a race. We get a race if we leave the count until | ||
92 | * after and something else is calling "finish" at the same time - | ||
93 | * there's a chance that both threads will together take the count from | ||
94 | * 2 to 0 without either calling finish(). */ | ||
95 | e->funct_ref--; | ||
96 | engine_ref_debug(e, 1, -1); | ||
97 | if ((e->funct_ref == 0) && e->finish) { | ||
98 | if (unlock_for_handlers) | ||
99 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
100 | to_return = e->finish(e); | ||
101 | if (unlock_for_handlers) | ||
102 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
103 | if (!to_return) | ||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | /* Release the structural reference too */ | ||
108 | if (!engine_free_util(e, 0)) { | ||
109 | ENGINEerror(ENGINE_R_FINISH_FAILED); | ||
110 | return 0; | ||
111 | } | ||
112 | return to_return; | ||
113 | } | ||
114 | |||
115 | /* The API (locked) version of "init" */ | ||
116 | int | ||
117 | ENGINE_init(ENGINE *e) | ||
118 | { | ||
119 | int ret; | ||
120 | |||
121 | if (e == NULL) { | ||
122 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
123 | return 0; | ||
124 | } | ||
125 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
126 | ret = engine_unlocked_init(e); | ||
127 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
128 | return ret; | ||
129 | } | ||
130 | |||
131 | /* The API (locked) version of "finish" */ | ||
132 | int | ||
133 | ENGINE_finish(ENGINE *e) | ||
134 | { | ||
135 | int to_return = 1; | ||
136 | |||
137 | if (e == NULL) | ||
138 | return 1; | ||
139 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
140 | to_return = engine_unlocked_finish(e, 1); | ||
141 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
142 | if (!to_return) { | ||
143 | ENGINEerror(ENGINE_R_FINISH_FAILED); | ||
144 | return 0; | ||
145 | } | ||
146 | return to_return; | ||
147 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_int.h b/src/lib/libcrypto/engine/eng_int.h deleted file mode 100644 index 2b0ba22aaf..0000000000 --- a/src/lib/libcrypto/engine/eng_int.h +++ /dev/null | |||
@@ -1,201 +0,0 @@ | |||
1 | /* $OpenBSD: eng_int.h,v 1.12 2023/07/28 09:22:26 tb Exp $ */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | /* ==================================================================== | ||
59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
60 | * ECDH support in OpenSSL originally developed by | ||
61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
62 | */ | ||
63 | |||
64 | #ifndef HEADER_ENGINE_INT_H | ||
65 | #define HEADER_ENGINE_INT_H | ||
66 | |||
67 | /* Take public definitions from engine.h */ | ||
68 | #include <openssl/engine.h> | ||
69 | |||
70 | __BEGIN_HIDDEN_DECLS | ||
71 | |||
72 | /* If we compile with this symbol defined, then both reference counts in the | ||
73 | * ENGINE structure will be monitored with a line of output on stderr for each | ||
74 | * change. This prints the engine's pointer address (truncated to unsigned int), | ||
75 | * "struct" or "funct" to indicate the reference type, the before and after | ||
76 | * reference count, and the file:line-number pair. The "engine_ref_debug" | ||
77 | * statements must come *after* the change. */ | ||
78 | #ifdef ENGINE_REF_COUNT_DEBUG | ||
79 | |||
80 | #define engine_ref_debug(e, isfunct, diff) \ | ||
81 | fprintf(stderr, "engine: %08x %s from %d to %d (%s:%d)\n", \ | ||
82 | (unsigned int)(e), (isfunct ? "funct" : "struct"), \ | ||
83 | ((isfunct) ? ((e)->funct_ref - (diff)) : ((e)->struct_ref - (diff))), \ | ||
84 | ((isfunct) ? (e)->funct_ref : (e)->struct_ref), \ | ||
85 | (__FILE__), (__LINE__)); | ||
86 | |||
87 | #else | ||
88 | |||
89 | #define engine_ref_debug(e, isfunct, diff) | ||
90 | |||
91 | #endif | ||
92 | |||
93 | /* Any code that will need cleanup operations should use these functions to | ||
94 | * register callbacks. ENGINE_cleanup() will call all registered callbacks in | ||
95 | * order. NB: both the "add" functions assume CRYPTO_LOCK_ENGINE to already be | ||
96 | * held (in "write" mode). */ | ||
97 | typedef void (ENGINE_CLEANUP_CB)(void); | ||
98 | typedef struct st_engine_cleanup_item { | ||
99 | ENGINE_CLEANUP_CB *cb; | ||
100 | } ENGINE_CLEANUP_ITEM; | ||
101 | DECLARE_STACK_OF(ENGINE_CLEANUP_ITEM) | ||
102 | void engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb); | ||
103 | void engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb); | ||
104 | |||
105 | /* We need stacks of ENGINEs for use in eng_table.c */ | ||
106 | DECLARE_STACK_OF(ENGINE) | ||
107 | |||
108 | /* If this symbol is defined then engine_table_select(), the function that is | ||
109 | * used by RSA, DSA (etc) code to select registered ENGINEs, cache defaults and | ||
110 | * functional references (etc), will display debugging summaries to stderr. */ | ||
111 | /* #define ENGINE_TABLE_DEBUG */ | ||
112 | |||
113 | /* This represents an implementation table. Dependent code should instantiate it | ||
114 | * as a (ENGINE_TABLE *) pointer value set initially to NULL. */ | ||
115 | typedef struct st_engine_table ENGINE_TABLE; | ||
116 | int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup, | ||
117 | ENGINE *e, const int *nids, int num_nids, int setdefault); | ||
118 | void engine_table_unregister(ENGINE_TABLE **table, ENGINE *e); | ||
119 | void engine_table_cleanup(ENGINE_TABLE **table); | ||
120 | #ifndef ENGINE_TABLE_DEBUG | ||
121 | ENGINE *engine_table_select(ENGINE_TABLE **table, int nid); | ||
122 | #else | ||
123 | ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, | ||
124 | int l); | ||
125 | #define engine_table_select(t,n) engine_table_select_tmp(t,n,__FILE__,__LINE__) | ||
126 | #endif | ||
127 | typedef void (engine_table_doall_cb)(int nid, STACK_OF(ENGINE) *sk, | ||
128 | ENGINE *def, void *arg); | ||
129 | void engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb, | ||
130 | void *arg); | ||
131 | |||
132 | /* Internal versions of API functions that have control over locking. These are | ||
133 | * used between C files when functionality needs to be shared but the caller may | ||
134 | * already be controlling of the CRYPTO_LOCK_ENGINE lock. */ | ||
135 | int engine_unlocked_init(ENGINE *e); | ||
136 | int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers); | ||
137 | int engine_free_util(ENGINE *e, int locked); | ||
138 | |||
139 | /* This function will reset all "set"able values in an ENGINE to NULL. This | ||
140 | * won't touch reference counts or ex_data, but is equivalent to calling all the | ||
141 | * ENGINE_set_***() functions with a NULL value. */ | ||
142 | void engine_set_all_null(ENGINE *e); | ||
143 | |||
144 | /* NB: Bitwise OR-able values for the "flags" variable in ENGINE are now exposed | ||
145 | * in engine.h. */ | ||
146 | |||
147 | /* Free up dynamically allocated public key methods associated with ENGINE */ | ||
148 | |||
149 | void engine_pkey_meths_free(ENGINE *e); | ||
150 | void engine_pkey_asn1_meths_free(ENGINE *e); | ||
151 | |||
152 | /* This is a structure for storing implementations of various crypto | ||
153 | * algorithms and functions. */ | ||
154 | struct engine_st { | ||
155 | const char *id; | ||
156 | const char *name; | ||
157 | const RSA_METHOD *rsa_meth; | ||
158 | const DSA_METHOD *dsa_meth; | ||
159 | const DH_METHOD *dh_meth; | ||
160 | const EC_KEY_METHOD *ec_meth; | ||
161 | const RAND_METHOD *rand_meth; | ||
162 | const STORE_METHOD *store_meth; | ||
163 | /* Cipher handling is via this callback */ | ||
164 | ENGINE_CIPHERS_PTR ciphers; | ||
165 | /* Digest handling is via this callback */ | ||
166 | ENGINE_DIGESTS_PTR digests; | ||
167 | /* Public key handling via this callback */ | ||
168 | ENGINE_PKEY_METHS_PTR pkey_meths; | ||
169 | /* ASN1 public key handling via this callback */ | ||
170 | ENGINE_PKEY_ASN1_METHS_PTR pkey_asn1_meths; | ||
171 | |||
172 | ENGINE_GEN_INT_FUNC_PTR destroy; | ||
173 | |||
174 | ENGINE_GEN_INT_FUNC_PTR init; | ||
175 | ENGINE_GEN_INT_FUNC_PTR finish; | ||
176 | ENGINE_CTRL_FUNC_PTR ctrl; | ||
177 | ENGINE_LOAD_KEY_PTR load_privkey; | ||
178 | ENGINE_LOAD_KEY_PTR load_pubkey; | ||
179 | |||
180 | ENGINE_SSL_CLIENT_CERT_PTR load_ssl_client_cert; | ||
181 | |||
182 | const ENGINE_CMD_DEFN *cmd_defns; | ||
183 | int flags; | ||
184 | /* reference count on the structure itself */ | ||
185 | int struct_ref; | ||
186 | /* reference count on usability of the engine type. NB: This | ||
187 | * controls the loading and initialisation of any functionlity | ||
188 | * required by this engine, whereas the previous count is | ||
189 | * simply to cope with (de)allocation of this structure. Hence, | ||
190 | * running_ref <= struct_ref at all times. */ | ||
191 | int funct_ref; | ||
192 | /* A place to store per-ENGINE data */ | ||
193 | CRYPTO_EX_DATA ex_data; | ||
194 | /* Used to maintain the linked-list of engines. */ | ||
195 | struct engine_st *prev; | ||
196 | struct engine_st *next; | ||
197 | }; | ||
198 | |||
199 | __END_HIDDEN_DECLS | ||
200 | |||
201 | #endif /* HEADER_ENGINE_INT_H */ | ||
diff --git a/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c deleted file mode 100644 index 1aedcb18c6..0000000000 --- a/src/lib/libcrypto/engine/eng_lib.c +++ /dev/null | |||
@@ -1,365 +0,0 @@ | |||
1 | /* $OpenBSD: eng_lib.c,v 1.14 2018/04/14 07:18:37 tb Exp $ */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | |||
59 | #include <string.h> | ||
60 | |||
61 | #include <openssl/err.h> | ||
62 | #include <openssl/rand.h> | ||
63 | |||
64 | #include "eng_int.h" | ||
65 | |||
66 | /* The "new"/"free" stuff first */ | ||
67 | |||
68 | ENGINE * | ||
69 | ENGINE_new(void) | ||
70 | { | ||
71 | ENGINE *ret; | ||
72 | |||
73 | if (!OPENSSL_init_crypto(0, NULL)) | ||
74 | return NULL; | ||
75 | |||
76 | ret = malloc(sizeof(ENGINE)); | ||
77 | if (ret == NULL) { | ||
78 | ENGINEerror(ERR_R_MALLOC_FAILURE); | ||
79 | return NULL; | ||
80 | } | ||
81 | memset(ret, 0, sizeof(ENGINE)); | ||
82 | ret->struct_ref = 1; | ||
83 | engine_ref_debug(ret, 0, 1) | ||
84 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_ENGINE, ret, &ret->ex_data); | ||
85 | return ret; | ||
86 | } | ||
87 | |||
88 | /* Placed here (close proximity to ENGINE_new) so that modifications to the | ||
89 | * elements of the ENGINE structure are more likely to be caught and changed | ||
90 | * here. */ | ||
91 | void | ||
92 | engine_set_all_null(ENGINE *e) | ||
93 | { | ||
94 | e->id = NULL; | ||
95 | e->name = NULL; | ||
96 | e->rsa_meth = NULL; | ||
97 | e->dsa_meth = NULL; | ||
98 | e->dh_meth = NULL; | ||
99 | e->rand_meth = NULL; | ||
100 | e->store_meth = NULL; | ||
101 | e->ciphers = NULL; | ||
102 | e->digests = NULL; | ||
103 | e->destroy = NULL; | ||
104 | e->init = NULL; | ||
105 | e->finish = NULL; | ||
106 | e->ctrl = NULL; | ||
107 | e->load_privkey = NULL; | ||
108 | e->load_pubkey = NULL; | ||
109 | e->cmd_defns = NULL; | ||
110 | e->flags = 0; | ||
111 | } | ||
112 | |||
113 | int | ||
114 | engine_free_util(ENGINE *e, int locked) | ||
115 | { | ||
116 | int i; | ||
117 | |||
118 | if (e == NULL) | ||
119 | return 1; | ||
120 | if (locked) | ||
121 | i = CRYPTO_add(&e->struct_ref, -1, CRYPTO_LOCK_ENGINE); | ||
122 | else | ||
123 | i = --e->struct_ref; | ||
124 | engine_ref_debug(e, 0, -1) | ||
125 | if (i > 0) | ||
126 | return 1; | ||
127 | |||
128 | /* Free up any dynamically allocated public key methods */ | ||
129 | engine_pkey_meths_free(e); | ||
130 | engine_pkey_asn1_meths_free(e); | ||
131 | /* Give the ENGINE a chance to do any structural cleanup corresponding | ||
132 | * to allocation it did in its constructor (eg. unload error strings) */ | ||
133 | if (e->destroy) | ||
134 | e->destroy(e); | ||
135 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_ENGINE, e, &e->ex_data); | ||
136 | free(e); | ||
137 | return 1; | ||
138 | } | ||
139 | |||
140 | int | ||
141 | ENGINE_free(ENGINE *e) | ||
142 | { | ||
143 | return engine_free_util(e, 1); | ||
144 | } | ||
145 | |||
146 | /* Cleanup stuff */ | ||
147 | |||
148 | /* ENGINE_cleanup() is coded such that anything that does work that will need | ||
149 | * cleanup can register a "cleanup" callback here. That way we don't get linker | ||
150 | * bloat by referring to all *possible* cleanups, but any linker bloat into code | ||
151 | * "X" will cause X's cleanup function to end up here. */ | ||
152 | static STACK_OF(ENGINE_CLEANUP_ITEM) *cleanup_stack = NULL; | ||
153 | static int | ||
154 | int_cleanup_check(int create) | ||
155 | { | ||
156 | if (cleanup_stack) | ||
157 | return 1; | ||
158 | if (!create) | ||
159 | return 0; | ||
160 | cleanup_stack = sk_ENGINE_CLEANUP_ITEM_new_null(); | ||
161 | return (cleanup_stack ? 1 : 0); | ||
162 | } | ||
163 | |||
164 | static ENGINE_CLEANUP_ITEM * | ||
165 | int_cleanup_item(ENGINE_CLEANUP_CB *cb) | ||
166 | { | ||
167 | ENGINE_CLEANUP_ITEM *item = malloc(sizeof(ENGINE_CLEANUP_ITEM)); | ||
168 | |||
169 | if (!item) | ||
170 | return NULL; | ||
171 | item->cb = cb; | ||
172 | return item; | ||
173 | } | ||
174 | |||
175 | void | ||
176 | engine_cleanup_add_first(ENGINE_CLEANUP_CB *cb) | ||
177 | { | ||
178 | ENGINE_CLEANUP_ITEM *item; | ||
179 | |||
180 | if (!int_cleanup_check(1)) | ||
181 | return; | ||
182 | item = int_cleanup_item(cb); | ||
183 | if (item) | ||
184 | sk_ENGINE_CLEANUP_ITEM_insert(cleanup_stack, item, 0); | ||
185 | } | ||
186 | |||
187 | void | ||
188 | engine_cleanup_add_last(ENGINE_CLEANUP_CB *cb) | ||
189 | { | ||
190 | ENGINE_CLEANUP_ITEM *item; | ||
191 | |||
192 | if (!int_cleanup_check(1)) | ||
193 | return; | ||
194 | item = int_cleanup_item(cb); | ||
195 | if (item) | ||
196 | sk_ENGINE_CLEANUP_ITEM_push(cleanup_stack, item); | ||
197 | } | ||
198 | /* The API function that performs all cleanup */ | ||
199 | static void | ||
200 | engine_cleanup_cb_free(ENGINE_CLEANUP_ITEM *item) | ||
201 | { | ||
202 | (*(item->cb))(); | ||
203 | free(item); | ||
204 | } | ||
205 | |||
206 | void | ||
207 | ENGINE_cleanup(void) | ||
208 | { | ||
209 | if (int_cleanup_check(0)) { | ||
210 | sk_ENGINE_CLEANUP_ITEM_pop_free(cleanup_stack, | ||
211 | engine_cleanup_cb_free); | ||
212 | cleanup_stack = NULL; | ||
213 | } | ||
214 | /* FIXME: This should be handled (somehow) through RAND, eg. by it | ||
215 | * registering a cleanup callback. */ | ||
216 | RAND_set_rand_method(NULL); | ||
217 | } | ||
218 | |||
219 | /* Now the "ex_data" support */ | ||
220 | |||
221 | int | ||
222 | ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
223 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
224 | { | ||
225 | return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_ENGINE, argl, argp, | ||
226 | new_func, dup_func, free_func); | ||
227 | } | ||
228 | |||
229 | int | ||
230 | ENGINE_set_ex_data(ENGINE *e, int idx, void *arg) | ||
231 | { | ||
232 | return (CRYPTO_set_ex_data(&e->ex_data, idx, arg)); | ||
233 | } | ||
234 | |||
235 | void * | ||
236 | ENGINE_get_ex_data(const ENGINE *e, int idx) | ||
237 | { | ||
238 | return (CRYPTO_get_ex_data(&e->ex_data, idx)); | ||
239 | } | ||
240 | |||
241 | /* Functions to get/set an ENGINE's elements - mainly to avoid exposing the | ||
242 | * ENGINE structure itself. */ | ||
243 | |||
244 | int | ||
245 | ENGINE_set_id(ENGINE *e, const char *id) | ||
246 | { | ||
247 | if (id == NULL) { | ||
248 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
249 | return 0; | ||
250 | } | ||
251 | e->id = id; | ||
252 | return 1; | ||
253 | } | ||
254 | |||
255 | int | ||
256 | ENGINE_set_name(ENGINE *e, const char *name) | ||
257 | { | ||
258 | if (name == NULL) { | ||
259 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
260 | return 0; | ||
261 | } | ||
262 | e->name = name; | ||
263 | return 1; | ||
264 | } | ||
265 | |||
266 | int | ||
267 | ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f) | ||
268 | { | ||
269 | e->destroy = destroy_f; | ||
270 | return 1; | ||
271 | } | ||
272 | |||
273 | int | ||
274 | ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f) | ||
275 | { | ||
276 | e->init = init_f; | ||
277 | return 1; | ||
278 | } | ||
279 | |||
280 | int | ||
281 | ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f) | ||
282 | { | ||
283 | e->finish = finish_f; | ||
284 | return 1; | ||
285 | } | ||
286 | |||
287 | int | ||
288 | ENGINE_set_ctrl_function(ENGINE *e, ENGINE_CTRL_FUNC_PTR ctrl_f) | ||
289 | { | ||
290 | e->ctrl = ctrl_f; | ||
291 | return 1; | ||
292 | } | ||
293 | |||
294 | int | ||
295 | ENGINE_set_flags(ENGINE *e, int flags) | ||
296 | { | ||
297 | e->flags = flags; | ||
298 | return 1; | ||
299 | } | ||
300 | |||
301 | int | ||
302 | ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns) | ||
303 | { | ||
304 | e->cmd_defns = defns; | ||
305 | return 1; | ||
306 | } | ||
307 | |||
308 | const char * | ||
309 | ENGINE_get_id(const ENGINE *e) | ||
310 | { | ||
311 | return e->id; | ||
312 | } | ||
313 | |||
314 | const char * | ||
315 | ENGINE_get_name(const ENGINE *e) | ||
316 | { | ||
317 | return e->name; | ||
318 | } | ||
319 | |||
320 | ENGINE_GEN_INT_FUNC_PTR | ||
321 | ENGINE_get_destroy_function(const ENGINE *e) | ||
322 | { | ||
323 | return e->destroy; | ||
324 | } | ||
325 | |||
326 | ENGINE_GEN_INT_FUNC_PTR | ||
327 | ENGINE_get_init_function(const ENGINE *e) | ||
328 | { | ||
329 | return e->init; | ||
330 | } | ||
331 | |||
332 | ENGINE_GEN_INT_FUNC_PTR | ||
333 | ENGINE_get_finish_function(const ENGINE *e) | ||
334 | { | ||
335 | return e->finish; | ||
336 | } | ||
337 | |||
338 | ENGINE_CTRL_FUNC_PTR | ||
339 | ENGINE_get_ctrl_function(const ENGINE *e) | ||
340 | { | ||
341 | return e->ctrl; | ||
342 | } | ||
343 | |||
344 | int | ||
345 | ENGINE_get_flags(const ENGINE *e) | ||
346 | { | ||
347 | return e->flags; | ||
348 | } | ||
349 | |||
350 | const ENGINE_CMD_DEFN * | ||
351 | ENGINE_get_cmd_defns(const ENGINE *e) | ||
352 | { | ||
353 | return e->cmd_defns; | ||
354 | } | ||
355 | |||
356 | /* eng_lib.o is pretty much linked into anything that touches ENGINE already, so | ||
357 | * put the "static_state" hack here. */ | ||
358 | |||
359 | static int internal_static_hack = 0; | ||
360 | |||
361 | void * | ||
362 | ENGINE_get_static_state(void) | ||
363 | { | ||
364 | return &internal_static_hack; | ||
365 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c deleted file mode 100644 index eaa0d228f9..0000000000 --- a/src/lib/libcrypto/engine/eng_list.c +++ /dev/null | |||
@@ -1,381 +0,0 @@ | |||
1 | /* $OpenBSD: eng_list.c,v 1.27 2023/07/28 09:22:26 tb Exp $ */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | /* ==================================================================== | ||
59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
60 | * ECDH support in OpenSSL originally developed by | ||
61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
62 | */ | ||
63 | |||
64 | #include <string.h> | ||
65 | #include <unistd.h> | ||
66 | |||
67 | #include <openssl/opensslconf.h> | ||
68 | |||
69 | #include <openssl/err.h> | ||
70 | |||
71 | #include "cryptlib.h" | ||
72 | #include "eng_int.h" | ||
73 | |||
74 | /* The linked-list of pointers to engine types. engine_list_head | ||
75 | * incorporates an implicit structural reference but engine_list_tail | ||
76 | * does not - the latter is a computational niceity and only points | ||
77 | * to something that is already pointed to by its predecessor in the | ||
78 | * list (or engine_list_head itself). In the same way, the use of the | ||
79 | * "prev" pointer in each ENGINE is to save excessive list iteration, | ||
80 | * it doesn't correspond to an extra structural reference. Hence, | ||
81 | * engine_list_head, and each non-null "next" pointer account for | ||
82 | * the list itself assuming exactly 1 structural reference on each | ||
83 | * list member. */ | ||
84 | static ENGINE *engine_list_head = NULL; | ||
85 | static ENGINE *engine_list_tail = NULL; | ||
86 | |||
87 | /* This cleanup function is only needed internally. If it should be called, we | ||
88 | * register it with the "ENGINE_cleanup()" stack to be called during cleanup. */ | ||
89 | |||
90 | static void | ||
91 | engine_list_cleanup(void) | ||
92 | { | ||
93 | ENGINE *iterator = engine_list_head; | ||
94 | |||
95 | while (iterator != NULL && ENGINE_remove(iterator)) | ||
96 | iterator = engine_list_head; | ||
97 | } | ||
98 | |||
99 | /* These static functions starting with a lower case "engine_" always | ||
100 | * take place when CRYPTO_LOCK_ENGINE has been locked up. */ | ||
101 | static int | ||
102 | engine_list_add(ENGINE *e) | ||
103 | { | ||
104 | int conflict = 0; | ||
105 | ENGINE *iterator = NULL; | ||
106 | |||
107 | if (e == NULL) { | ||
108 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
109 | return 0; | ||
110 | } | ||
111 | iterator = engine_list_head; | ||
112 | while (iterator && !conflict) { | ||
113 | conflict = (strcmp(iterator->id, e->id) == 0); | ||
114 | iterator = iterator->next; | ||
115 | } | ||
116 | if (conflict) { | ||
117 | ENGINEerror(ENGINE_R_CONFLICTING_ENGINE_ID); | ||
118 | return 0; | ||
119 | } | ||
120 | if (engine_list_head == NULL) { | ||
121 | /* We are adding to an empty list. */ | ||
122 | if (engine_list_tail) { | ||
123 | ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR); | ||
124 | return 0; | ||
125 | } | ||
126 | engine_list_head = e; | ||
127 | e->prev = NULL; | ||
128 | /* The first time the list allocates, we should register the | ||
129 | * cleanup. */ | ||
130 | engine_cleanup_add_last(engine_list_cleanup); | ||
131 | } else { | ||
132 | /* We are adding to the tail of an existing list. */ | ||
133 | if ((engine_list_tail == NULL) || | ||
134 | (engine_list_tail->next != NULL)) { | ||
135 | ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR); | ||
136 | return 0; | ||
137 | } | ||
138 | engine_list_tail->next = e; | ||
139 | e->prev = engine_list_tail; | ||
140 | } | ||
141 | /* Having the engine in the list assumes a structural | ||
142 | * reference. */ | ||
143 | e->struct_ref++; | ||
144 | engine_ref_debug(e, 0, 1) | ||
145 | /* However it came to be, e is the last item in the list. */ | ||
146 | engine_list_tail = e; | ||
147 | e->next = NULL; | ||
148 | return 1; | ||
149 | } | ||
150 | |||
151 | static int | ||
152 | engine_list_remove(ENGINE *e) | ||
153 | { | ||
154 | ENGINE *iterator; | ||
155 | |||
156 | if (e == NULL) { | ||
157 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
158 | return 0; | ||
159 | } | ||
160 | /* We need to check that e is in our linked list! */ | ||
161 | iterator = engine_list_head; | ||
162 | while (iterator && (iterator != e)) | ||
163 | iterator = iterator->next; | ||
164 | if (iterator == NULL) { | ||
165 | ENGINEerror(ENGINE_R_ENGINE_IS_NOT_IN_LIST); | ||
166 | return 0; | ||
167 | } | ||
168 | /* un-link e from the chain. */ | ||
169 | if (e->next) | ||
170 | e->next->prev = e->prev; | ||
171 | if (e->prev) | ||
172 | e->prev->next = e->next; | ||
173 | /* Correct our head/tail if necessary. */ | ||
174 | if (engine_list_head == e) | ||
175 | engine_list_head = e->next; | ||
176 | if (engine_list_tail == e) | ||
177 | engine_list_tail = e->prev; | ||
178 | engine_free_util(e, 0); | ||
179 | return 1; | ||
180 | } | ||
181 | |||
182 | /* Get the first/last "ENGINE" type available. */ | ||
183 | ENGINE * | ||
184 | ENGINE_get_first(void) | ||
185 | { | ||
186 | ENGINE *ret; | ||
187 | |||
188 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
189 | ret = engine_list_head; | ||
190 | if (ret) { | ||
191 | ret->struct_ref++; | ||
192 | engine_ref_debug(ret, 0, 1) | ||
193 | } | ||
194 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
195 | return ret; | ||
196 | } | ||
197 | |||
198 | ENGINE * | ||
199 | ENGINE_get_last(void) | ||
200 | { | ||
201 | ENGINE *ret; | ||
202 | |||
203 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
204 | ret = engine_list_tail; | ||
205 | if (ret) { | ||
206 | ret->struct_ref++; | ||
207 | engine_ref_debug(ret, 0, 1) | ||
208 | } | ||
209 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
210 | return ret; | ||
211 | } | ||
212 | |||
213 | /* Iterate to the next/previous "ENGINE" type (NULL = end of the list). */ | ||
214 | ENGINE * | ||
215 | ENGINE_get_next(ENGINE *e) | ||
216 | { | ||
217 | ENGINE *ret = NULL; | ||
218 | |||
219 | if (e == NULL) { | ||
220 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
221 | return 0; | ||
222 | } | ||
223 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
224 | ret = e->next; | ||
225 | if (ret) { | ||
226 | /* Return a valid structural reference to the next ENGINE */ | ||
227 | ret->struct_ref++; | ||
228 | engine_ref_debug(ret, 0, 1) | ||
229 | } | ||
230 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
231 | /* Release the structural reference to the previous ENGINE */ | ||
232 | ENGINE_free(e); | ||
233 | return ret; | ||
234 | } | ||
235 | |||
236 | ENGINE * | ||
237 | ENGINE_get_prev(ENGINE *e) | ||
238 | { | ||
239 | ENGINE *ret = NULL; | ||
240 | |||
241 | if (e == NULL) { | ||
242 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
243 | return 0; | ||
244 | } | ||
245 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
246 | ret = e->prev; | ||
247 | if (ret) { | ||
248 | /* Return a valid structural reference to the next ENGINE */ | ||
249 | ret->struct_ref++; | ||
250 | engine_ref_debug(ret, 0, 1) | ||
251 | } | ||
252 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
253 | /* Release the structural reference to the previous ENGINE */ | ||
254 | ENGINE_free(e); | ||
255 | return ret; | ||
256 | } | ||
257 | |||
258 | /* Add another "ENGINE" type into the list. */ | ||
259 | int | ||
260 | ENGINE_add(ENGINE *e) | ||
261 | { | ||
262 | int to_return = 1; | ||
263 | |||
264 | if (e == NULL) { | ||
265 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
266 | return 0; | ||
267 | } | ||
268 | if ((e->id == NULL) || (e->name == NULL)) { | ||
269 | ENGINEerror(ENGINE_R_ID_OR_NAME_MISSING); | ||
270 | } | ||
271 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
272 | if (!engine_list_add(e)) { | ||
273 | ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR); | ||
274 | to_return = 0; | ||
275 | } | ||
276 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
277 | return to_return; | ||
278 | } | ||
279 | |||
280 | /* Remove an existing "ENGINE" type from the array. */ | ||
281 | int | ||
282 | ENGINE_remove(ENGINE *e) | ||
283 | { | ||
284 | int to_return = 1; | ||
285 | |||
286 | if (e == NULL) { | ||
287 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
288 | return 0; | ||
289 | } | ||
290 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
291 | if (!engine_list_remove(e)) { | ||
292 | ENGINEerror(ENGINE_R_INTERNAL_LIST_ERROR); | ||
293 | to_return = 0; | ||
294 | } | ||
295 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
296 | return to_return; | ||
297 | } | ||
298 | |||
299 | static void | ||
300 | engine_cpy(ENGINE *dest, const ENGINE *src) | ||
301 | { | ||
302 | dest->id = src->id; | ||
303 | dest->name = src->name; | ||
304 | #ifndef OPENSSL_NO_RSA | ||
305 | dest->rsa_meth = src->rsa_meth; | ||
306 | #endif | ||
307 | #ifndef OPENSSL_NO_DSA | ||
308 | dest->dsa_meth = src->dsa_meth; | ||
309 | #endif | ||
310 | #ifndef OPENSSL_NO_DH | ||
311 | dest->dh_meth = src->dh_meth; | ||
312 | #endif | ||
313 | #ifndef OPENSSL_NO_EC | ||
314 | dest->ec_meth = src->ec_meth; | ||
315 | #endif | ||
316 | dest->rand_meth = src->rand_meth; | ||
317 | dest->store_meth = src->store_meth; | ||
318 | dest->ciphers = src->ciphers; | ||
319 | dest->digests = src->digests; | ||
320 | dest->pkey_meths = src->pkey_meths; | ||
321 | dest->destroy = src->destroy; | ||
322 | dest->init = src->init; | ||
323 | dest->finish = src->finish; | ||
324 | dest->ctrl = src->ctrl; | ||
325 | dest->load_privkey = src->load_privkey; | ||
326 | dest->load_pubkey = src->load_pubkey; | ||
327 | dest->cmd_defns = src->cmd_defns; | ||
328 | dest->flags = src->flags; | ||
329 | } | ||
330 | |||
331 | ENGINE * | ||
332 | ENGINE_by_id(const char *id) | ||
333 | { | ||
334 | ENGINE *iterator; | ||
335 | |||
336 | if (id == NULL) { | ||
337 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
338 | return NULL; | ||
339 | } | ||
340 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
341 | iterator = engine_list_head; | ||
342 | while (iterator && (strcmp(id, iterator->id) != 0)) | ||
343 | iterator = iterator->next; | ||
344 | if (iterator) { | ||
345 | /* We need to return a structural reference. If this is an | ||
346 | * ENGINE type that returns copies, make a duplicate - otherwise | ||
347 | * increment the existing ENGINE's reference count. */ | ||
348 | if (iterator->flags & ENGINE_FLAGS_BY_ID_COPY) { | ||
349 | ENGINE *cp = ENGINE_new(); | ||
350 | if (!cp) | ||
351 | iterator = NULL; | ||
352 | else { | ||
353 | engine_cpy(cp, iterator); | ||
354 | iterator = cp; | ||
355 | } | ||
356 | } else { | ||
357 | iterator->struct_ref++; | ||
358 | engine_ref_debug(iterator, 0, 1) | ||
359 | } | ||
360 | } | ||
361 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
362 | |||
363 | if (iterator == NULL) { | ||
364 | ENGINEerror(ENGINE_R_NO_SUCH_ENGINE); | ||
365 | ERR_asprintf_error_data("id=%s", id); | ||
366 | } | ||
367 | return iterator; | ||
368 | } | ||
369 | |||
370 | int | ||
371 | ENGINE_up_ref(ENGINE *e) | ||
372 | { | ||
373 | int refs; | ||
374 | |||
375 | if (e == NULL) { | ||
376 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
377 | return 0; | ||
378 | } | ||
379 | refs = CRYPTO_add(&e->struct_ref, 1, CRYPTO_LOCK_ENGINE); | ||
380 | return refs > 1 ? 1 : 0; | ||
381 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_openssl.c b/src/lib/libcrypto/engine/eng_openssl.c deleted file mode 100644 index 6162b715f0..0000000000 --- a/src/lib/libcrypto/engine/eng_openssl.c +++ /dev/null | |||
@@ -1,400 +0,0 @@ | |||
1 | /* $OpenBSD: eng_openssl.c,v 1.19 2023/07/28 09:22:26 tb Exp $ */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2000. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | /* ==================================================================== | ||
59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
60 | * ECDH support in OpenSSL originally developed by | ||
61 | * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project. | ||
62 | */ | ||
63 | |||
64 | #include <stdio.h> | ||
65 | #include <string.h> | ||
66 | |||
67 | #include <openssl/opensslconf.h> | ||
68 | |||
69 | #include <openssl/crypto.h> | ||
70 | #include <openssl/engine.h> | ||
71 | #include <openssl/err.h> | ||
72 | #include <openssl/evp.h> | ||
73 | #include <openssl/pem.h> | ||
74 | #include <openssl/rand.h> | ||
75 | |||
76 | #ifndef OPENSSL_NO_DH | ||
77 | #include <openssl/dh.h> | ||
78 | #endif | ||
79 | #ifndef OPENSSL_NO_DSA | ||
80 | #include <openssl/dsa.h> | ||
81 | #endif | ||
82 | #ifndef OPENSSL_NO_RSA | ||
83 | #include <openssl/rsa.h> | ||
84 | #endif | ||
85 | |||
86 | #include "evp_local.h" | ||
87 | |||
88 | /* This testing gunk is implemented (and explained) lower down. It also assumes | ||
89 | * the application explicitly calls "ENGINE_load_openssl()" because this is no | ||
90 | * longer automatic in ENGINE_load_builtin_engines(). */ | ||
91 | #define TEST_ENG_OPENSSL_RC4 | ||
92 | #define TEST_ENG_OPENSSL_PKEY | ||
93 | /* #define TEST_ENG_OPENSSL_RC4_OTHERS */ | ||
94 | #define TEST_ENG_OPENSSL_RC4_P_INIT | ||
95 | /* #define TEST_ENG_OPENSSL_RC4_P_CIPHER */ | ||
96 | #define TEST_ENG_OPENSSL_SHA | ||
97 | /* #define TEST_ENG_OPENSSL_SHA_OTHERS */ | ||
98 | /* #define TEST_ENG_OPENSSL_SHA_P_INIT */ | ||
99 | /* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */ | ||
100 | /* #define TEST_ENG_OPENSSL_SHA_P_FINAL */ | ||
101 | |||
102 | /* Now check what of those algorithms are actually enabled */ | ||
103 | #ifdef OPENSSL_NO_RC4 | ||
104 | #undef TEST_ENG_OPENSSL_RC4 | ||
105 | #undef TEST_ENG_OPENSSL_RC4_OTHERS | ||
106 | #undef TEST_ENG_OPENSSL_RC4_P_INIT | ||
107 | #undef TEST_ENG_OPENSSL_RC4_P_CIPHER | ||
108 | #endif | ||
109 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA1) | ||
110 | #undef TEST_ENG_OPENSSL_SHA | ||
111 | #undef TEST_ENG_OPENSSL_SHA_OTHERS | ||
112 | #undef TEST_ENG_OPENSSL_SHA_P_INIT | ||
113 | #undef TEST_ENG_OPENSSL_SHA_P_UPDATE | ||
114 | #undef TEST_ENG_OPENSSL_SHA_P_FINAL | ||
115 | #endif | ||
116 | |||
117 | #ifdef TEST_ENG_OPENSSL_RC4 | ||
118 | static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | ||
119 | const int **nids, int nid); | ||
120 | #endif | ||
121 | #ifdef TEST_ENG_OPENSSL_SHA | ||
122 | static int openssl_digests(ENGINE *e, const EVP_MD **digest, | ||
123 | const int **nids, int nid); | ||
124 | #endif | ||
125 | |||
126 | #ifdef TEST_ENG_OPENSSL_PKEY | ||
127 | static EVP_PKEY *openssl_load_privkey(ENGINE *eng, const char *key_id, | ||
128 | UI_METHOD *ui_method, void *callback_data); | ||
129 | #endif | ||
130 | |||
131 | /* The constants used when creating the ENGINE */ | ||
132 | static const char *engine_openssl_id = "openssl"; | ||
133 | static const char *engine_openssl_name = "Software engine support"; | ||
134 | |||
135 | /* This internal function is used by ENGINE_openssl() and possibly by the | ||
136 | * "dynamic" ENGINE support too */ | ||
137 | static int | ||
138 | bind_helper(ENGINE *e) | ||
139 | { | ||
140 | if (!ENGINE_set_id(e, engine_openssl_id) || | ||
141 | !ENGINE_set_name(e, engine_openssl_name) | ||
142 | #ifndef TEST_ENG_OPENSSL_NO_ALGORITHMS | ||
143 | #ifndef OPENSSL_NO_RSA | ||
144 | || !ENGINE_set_RSA(e, RSA_get_default_method()) | ||
145 | #endif | ||
146 | #ifndef OPENSSL_NO_DSA | ||
147 | || !ENGINE_set_DSA(e, DSA_get_default_method()) | ||
148 | #endif | ||
149 | #ifndef OPENSSL_NO_DH | ||
150 | || !ENGINE_set_DH(e, DH_get_default_method()) | ||
151 | #endif | ||
152 | || !ENGINE_set_RAND(e, RAND_SSLeay()) | ||
153 | #ifdef TEST_ENG_OPENSSL_RC4 | ||
154 | || !ENGINE_set_ciphers(e, openssl_ciphers) | ||
155 | #endif | ||
156 | #ifdef TEST_ENG_OPENSSL_SHA | ||
157 | || !ENGINE_set_digests(e, openssl_digests) | ||
158 | #endif | ||
159 | #endif | ||
160 | #ifdef TEST_ENG_OPENSSL_PKEY | ||
161 | || !ENGINE_set_load_privkey_function(e, openssl_load_privkey) | ||
162 | #endif | ||
163 | ) | ||
164 | return 0; | ||
165 | /* If we add errors to this ENGINE, ensure the error handling is setup here */ | ||
166 | /* openssl_load_error_strings(); */ | ||
167 | return 1; | ||
168 | } | ||
169 | |||
170 | static ENGINE * | ||
171 | engine_openssl(void) | ||
172 | { | ||
173 | ENGINE *ret = ENGINE_new(); | ||
174 | |||
175 | if (ret == NULL) | ||
176 | return NULL; | ||
177 | if (!bind_helper(ret)) { | ||
178 | ENGINE_free(ret); | ||
179 | return NULL; | ||
180 | } | ||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | void | ||
185 | ENGINE_load_openssl(void) | ||
186 | { | ||
187 | ENGINE *toadd = engine_openssl(); | ||
188 | |||
189 | if (toadd == NULL) | ||
190 | return; | ||
191 | (void) ENGINE_add(toadd); | ||
192 | /* If the "add" worked, it gets a structural reference. So either way, | ||
193 | * we release our just-created reference. */ | ||
194 | ENGINE_free(toadd); | ||
195 | ERR_clear_error(); | ||
196 | } | ||
197 | |||
198 | /* This stuff is needed if this ENGINE is being compiled into a self-contained | ||
199 | * shared-library. */ | ||
200 | #ifdef ENGINE_DYNAMIC_SUPPORT | ||
201 | static int | ||
202 | bind_fn(ENGINE *e, const char *id) | ||
203 | { | ||
204 | if (id && (strcmp(id, engine_openssl_id) != 0)) | ||
205 | return 0; | ||
206 | if (!bind_helper(e)) | ||
207 | return 0; | ||
208 | return 1; | ||
209 | } | ||
210 | IMPLEMENT_DYNAMIC_CHECK_FN() | ||
211 | IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | ||
212 | #endif /* ENGINE_DYNAMIC_SUPPORT */ | ||
213 | |||
214 | #ifdef TEST_ENG_OPENSSL_RC4 | ||
215 | /* This section of code compiles an "alternative implementation" of two modes of | ||
216 | * RC4 into this ENGINE. The result is that EVP_CIPHER operation for "rc4" | ||
217 | * should under normal circumstances go via this support rather than the default | ||
218 | * EVP support. There are other symbols to tweak the testing; | ||
219 | * TEST_ENC_OPENSSL_RC4_OTHERS - print a one line message to stderr each time | ||
220 | * we're asked for a cipher we don't support (should not happen). | ||
221 | * TEST_ENG_OPENSSL_RC4_P_INIT - print a one line message to stderr each time | ||
222 | * the "init_key" handler is called. | ||
223 | * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler. | ||
224 | */ | ||
225 | #include <openssl/rc4.h> | ||
226 | #define TEST_RC4_KEY_SIZE 16 | ||
227 | static int test_cipher_nids[] = {NID_rc4, NID_rc4_40}; | ||
228 | static int test_cipher_nids_number = 2; | ||
229 | |||
230 | typedef struct { | ||
231 | unsigned char key[TEST_RC4_KEY_SIZE]; | ||
232 | RC4_KEY ks; | ||
233 | } TEST_RC4_KEY; | ||
234 | |||
235 | #define test(ctx) ((TEST_RC4_KEY *)(ctx)->cipher_data) | ||
236 | static int | ||
237 | test_rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | ||
238 | const unsigned char *iv, int enc) | ||
239 | { | ||
240 | #ifdef TEST_ENG_OPENSSL_RC4_P_INIT | ||
241 | fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_init_key() called\n"); | ||
242 | #endif | ||
243 | memcpy(&test(ctx)->key[0], key, EVP_CIPHER_CTX_key_length(ctx)); | ||
244 | RC4_set_key(&test(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), | ||
245 | test(ctx)->key); | ||
246 | return 1; | ||
247 | } | ||
248 | |||
249 | static int | ||
250 | test_rc4_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | ||
251 | const unsigned char *in, size_t inl) | ||
252 | { | ||
253 | #ifdef TEST_ENG_OPENSSL_RC4_P_CIPHER | ||
254 | fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) test_cipher() called\n"); | ||
255 | #endif | ||
256 | RC4(&test(ctx)->ks, inl, in, out); | ||
257 | return 1; | ||
258 | } | ||
259 | |||
260 | static const EVP_CIPHER test_r4_cipher = { | ||
261 | NID_rc4, | ||
262 | 1, TEST_RC4_KEY_SIZE, 0, | ||
263 | EVP_CIPH_VARIABLE_LENGTH, | ||
264 | test_rc4_init_key, | ||
265 | test_rc4_cipher, | ||
266 | NULL, | ||
267 | sizeof(TEST_RC4_KEY), | ||
268 | NULL, | ||
269 | NULL, | ||
270 | NULL, | ||
271 | NULL | ||
272 | }; | ||
273 | |||
274 | static const EVP_CIPHER test_r4_40_cipher = { | ||
275 | NID_rc4_40, | ||
276 | 1,5 /* 40 bit */,0, | ||
277 | EVP_CIPH_VARIABLE_LENGTH, | ||
278 | test_rc4_init_key, | ||
279 | test_rc4_cipher, | ||
280 | NULL, | ||
281 | sizeof(TEST_RC4_KEY), | ||
282 | NULL, | ||
283 | NULL, | ||
284 | NULL, | ||
285 | NULL | ||
286 | }; | ||
287 | |||
288 | static int | ||
289 | openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, const int **nids, int nid) | ||
290 | { | ||
291 | if (!cipher) { | ||
292 | /* We are returning a list of supported nids */ | ||
293 | *nids = test_cipher_nids; | ||
294 | return test_cipher_nids_number; | ||
295 | } | ||
296 | /* We are being asked for a specific cipher */ | ||
297 | if (nid == NID_rc4) | ||
298 | *cipher = &test_r4_cipher; | ||
299 | else if (nid == NID_rc4_40) | ||
300 | *cipher = &test_r4_40_cipher; | ||
301 | else { | ||
302 | #ifdef TEST_ENG_OPENSSL_RC4_OTHERS | ||
303 | fprintf(stderr, "(TEST_ENG_OPENSSL_RC4) returning NULL for " | ||
304 | "nid %d\n", nid); | ||
305 | #endif | ||
306 | *cipher = NULL; | ||
307 | return 0; | ||
308 | } | ||
309 | return 1; | ||
310 | } | ||
311 | #endif | ||
312 | |||
313 | #ifdef TEST_ENG_OPENSSL_SHA | ||
314 | /* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */ | ||
315 | #include <openssl/sha.h> | ||
316 | static int test_digest_nids[] = {NID_sha1}; | ||
317 | static int test_digest_nids_number = 1; | ||
318 | |||
319 | static int | ||
320 | test_sha1_init(EVP_MD_CTX *ctx) | ||
321 | { | ||
322 | #ifdef TEST_ENG_OPENSSL_SHA_P_INIT | ||
323 | fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_init() called\n"); | ||
324 | #endif | ||
325 | return SHA1_Init(ctx->md_data); | ||
326 | } | ||
327 | |||
328 | static int | ||
329 | test_sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
330 | { | ||
331 | #ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE | ||
332 | fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n"); | ||
333 | #endif | ||
334 | return SHA1_Update(ctx->md_data, data, count); | ||
335 | } | ||
336 | |||
337 | static int | ||
338 | test_sha1_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
339 | { | ||
340 | #ifdef TEST_ENG_OPENSSL_SHA_P_FINAL | ||
341 | fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_final() called\n"); | ||
342 | #endif | ||
343 | return SHA1_Final(md, ctx->md_data); | ||
344 | } | ||
345 | |||
346 | static const EVP_MD test_sha_md = { | ||
347 | .type = NID_sha1, | ||
348 | .pkey_type = NID_sha1WithRSAEncryption, | ||
349 | .md_size = SHA_DIGEST_LENGTH, | ||
350 | .flags = 0, | ||
351 | .init = test_sha1_init, | ||
352 | .update = test_sha1_update, | ||
353 | .final = test_sha1_final, | ||
354 | .copy = NULL, | ||
355 | .cleanup = NULL, | ||
356 | .block_size = SHA_CBLOCK, | ||
357 | .ctx_size = sizeof(EVP_MD *) + sizeof(SHA_CTX), | ||
358 | }; | ||
359 | |||
360 | static int | ||
361 | openssl_digests(ENGINE *e, const EVP_MD **digest, const int **nids, int nid) | ||
362 | { | ||
363 | if (!digest) { | ||
364 | /* We are returning a list of supported nids */ | ||
365 | *nids = test_digest_nids; | ||
366 | return test_digest_nids_number; | ||
367 | } | ||
368 | /* We are being asked for a specific digest */ | ||
369 | if (nid == NID_sha1) | ||
370 | *digest = &test_sha_md; | ||
371 | else { | ||
372 | #ifdef TEST_ENG_OPENSSL_SHA_OTHERS | ||
373 | fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) returning NULL for " | ||
374 | "nid %d\n", nid); | ||
375 | #endif | ||
376 | *digest = NULL; | ||
377 | return 0; | ||
378 | } | ||
379 | return 1; | ||
380 | } | ||
381 | #endif | ||
382 | |||
383 | #ifdef TEST_ENG_OPENSSL_PKEY | ||
384 | static EVP_PKEY * | ||
385 | openssl_load_privkey(ENGINE *eng, const char *key_id, UI_METHOD *ui_method, | ||
386 | void *callback_data) | ||
387 | { | ||
388 | BIO *in; | ||
389 | EVP_PKEY *key; | ||
390 | |||
391 | fprintf(stderr, "(TEST_ENG_OPENSSL_PKEY)Loading Private key %s\n", | ||
392 | key_id); | ||
393 | in = BIO_new_file(key_id, "r"); | ||
394 | if (!in) | ||
395 | return NULL; | ||
396 | key = PEM_read_bio_PrivateKey(in, NULL, 0, NULL); | ||
397 | BIO_free(in); | ||
398 | return key; | ||
399 | } | ||
400 | #endif | ||
diff --git a/src/lib/libcrypto/engine/eng_pkey.c b/src/lib/libcrypto/engine/eng_pkey.c deleted file mode 100644 index a0320e973f..0000000000 --- a/src/lib/libcrypto/engine/eng_pkey.c +++ /dev/null | |||
@@ -1,184 +0,0 @@ | |||
1 | /* $OpenBSD: eng_pkey.c,v 1.7 2017/01/29 17:49:23 beck Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <openssl/err.h> | ||
57 | |||
58 | #include "eng_int.h" | ||
59 | |||
60 | /* Basic get/set stuff */ | ||
61 | |||
62 | int | ||
63 | ENGINE_set_load_privkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpriv_f) | ||
64 | { | ||
65 | e->load_privkey = loadpriv_f; | ||
66 | return 1; | ||
67 | } | ||
68 | |||
69 | int | ||
70 | ENGINE_set_load_pubkey_function(ENGINE *e, ENGINE_LOAD_KEY_PTR loadpub_f) | ||
71 | { | ||
72 | e->load_pubkey = loadpub_f; | ||
73 | return 1; | ||
74 | } | ||
75 | |||
76 | int | ||
77 | ENGINE_set_load_ssl_client_cert_function(ENGINE *e, | ||
78 | ENGINE_SSL_CLIENT_CERT_PTR loadssl_f) | ||
79 | { | ||
80 | e->load_ssl_client_cert = loadssl_f; | ||
81 | return 1; | ||
82 | } | ||
83 | |||
84 | ENGINE_LOAD_KEY_PTR | ||
85 | ENGINE_get_load_privkey_function(const ENGINE *e) | ||
86 | { | ||
87 | return e->load_privkey; | ||
88 | } | ||
89 | |||
90 | ENGINE_LOAD_KEY_PTR | ||
91 | ENGINE_get_load_pubkey_function(const ENGINE *e) | ||
92 | { | ||
93 | return e->load_pubkey; | ||
94 | } | ||
95 | |||
96 | ENGINE_SSL_CLIENT_CERT_PTR | ||
97 | ENGINE_get_ssl_client_cert_function(const ENGINE *e) | ||
98 | { | ||
99 | return e->load_ssl_client_cert; | ||
100 | } | ||
101 | |||
102 | /* API functions to load public/private keys */ | ||
103 | |||
104 | EVP_PKEY * | ||
105 | ENGINE_load_private_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method, | ||
106 | void *callback_data) | ||
107 | { | ||
108 | EVP_PKEY *pkey; | ||
109 | |||
110 | if (e == NULL) { | ||
111 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
112 | return 0; | ||
113 | } | ||
114 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
115 | if (e->funct_ref == 0) { | ||
116 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
117 | ENGINEerror(ENGINE_R_NOT_INITIALISED); | ||
118 | return 0; | ||
119 | } | ||
120 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
121 | if (!e->load_privkey) { | ||
122 | ENGINEerror(ENGINE_R_NO_LOAD_FUNCTION); | ||
123 | return 0; | ||
124 | } | ||
125 | pkey = e->load_privkey(e, key_id, ui_method, callback_data); | ||
126 | if (!pkey) { | ||
127 | ENGINEerror(ENGINE_R_FAILED_LOADING_PRIVATE_KEY); | ||
128 | return 0; | ||
129 | } | ||
130 | return pkey; | ||
131 | } | ||
132 | |||
133 | EVP_PKEY * | ||
134 | ENGINE_load_public_key(ENGINE *e, const char *key_id, UI_METHOD *ui_method, | ||
135 | void *callback_data) | ||
136 | { | ||
137 | EVP_PKEY *pkey; | ||
138 | |||
139 | if (e == NULL) { | ||
140 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
141 | return 0; | ||
142 | } | ||
143 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
144 | if (e->funct_ref == 0) { | ||
145 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
146 | ENGINEerror(ENGINE_R_NOT_INITIALISED); | ||
147 | return 0; | ||
148 | } | ||
149 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
150 | if (!e->load_pubkey) { | ||
151 | ENGINEerror(ENGINE_R_NO_LOAD_FUNCTION); | ||
152 | return 0; | ||
153 | } | ||
154 | pkey = e->load_pubkey(e, key_id, ui_method, callback_data); | ||
155 | if (!pkey) { | ||
156 | ENGINEerror(ENGINE_R_FAILED_LOADING_PUBLIC_KEY); | ||
157 | return 0; | ||
158 | } | ||
159 | return pkey; | ||
160 | } | ||
161 | |||
162 | int | ||
163 | ENGINE_load_ssl_client_cert(ENGINE *e, SSL *s, STACK_OF(X509_NAME) *ca_dn, | ||
164 | X509 **pcert, EVP_PKEY **ppkey, STACK_OF(X509) **pother, | ||
165 | UI_METHOD *ui_method, void *callback_data) | ||
166 | { | ||
167 | if (e == NULL) { | ||
168 | ENGINEerror(ERR_R_PASSED_NULL_PARAMETER); | ||
169 | return 0; | ||
170 | } | ||
171 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
172 | if (e->funct_ref == 0) { | ||
173 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
174 | ENGINEerror(ENGINE_R_NOT_INITIALISED); | ||
175 | return 0; | ||
176 | } | ||
177 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
178 | if (!e->load_ssl_client_cert) { | ||
179 | ENGINEerror(ENGINE_R_NO_LOAD_FUNCTION); | ||
180 | return 0; | ||
181 | } | ||
182 | return e->load_ssl_client_cert(e, s, ca_dn, pcert, ppkey, pother, | ||
183 | ui_method, callback_data); | ||
184 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_table.c b/src/lib/libcrypto/engine/eng_table.c deleted file mode 100644 index 0e7ea3b698..0000000000 --- a/src/lib/libcrypto/engine/eng_table.c +++ /dev/null | |||
@@ -1,354 +0,0 @@ | |||
1 | /* $OpenBSD: eng_table.c,v 1.10 2022/12/26 07:18:52 jmc Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2001 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <openssl/err.h> | ||
57 | #include <openssl/evp.h> | ||
58 | #include <openssl/lhash.h> | ||
59 | |||
60 | #include "eng_int.h" | ||
61 | |||
62 | /* The type of the items in the table */ | ||
63 | typedef struct st_engine_pile { | ||
64 | /* The 'nid' of this algorithm/mode */ | ||
65 | int nid; | ||
66 | /* ENGINEs that implement this algorithm/mode. */ | ||
67 | STACK_OF(ENGINE) *sk; | ||
68 | /* The default ENGINE to perform this algorithm/mode. */ | ||
69 | ENGINE *funct; | ||
70 | /* Zero if 'sk' is newer than the cached 'funct', non-zero otherwise */ | ||
71 | int uptodate; | ||
72 | } ENGINE_PILE; | ||
73 | |||
74 | DECLARE_LHASH_OF(ENGINE_PILE); | ||
75 | |||
76 | /* The type exposed in eng_int.h */ | ||
77 | struct st_engine_table { | ||
78 | LHASH_OF(ENGINE_PILE) piles; | ||
79 | }; /* ENGINE_TABLE */ | ||
80 | |||
81 | typedef struct st_engine_pile_doall { | ||
82 | engine_table_doall_cb *cb; | ||
83 | void *arg; | ||
84 | } ENGINE_PILE_DOALL; | ||
85 | |||
86 | /* Global flags (ENGINE_TABLE_FLAG_***). */ | ||
87 | static unsigned int table_flags = 0; | ||
88 | |||
89 | /* API function manipulating 'table_flags' */ | ||
90 | unsigned int | ||
91 | ENGINE_get_table_flags(void) | ||
92 | { | ||
93 | return table_flags; | ||
94 | } | ||
95 | |||
96 | void | ||
97 | ENGINE_set_table_flags(unsigned int flags) | ||
98 | { | ||
99 | table_flags = flags; | ||
100 | } | ||
101 | |||
102 | /* Internal functions for the "piles" hash table */ | ||
103 | static unsigned long | ||
104 | engine_pile_hash(const ENGINE_PILE *c) | ||
105 | { | ||
106 | return c->nid; | ||
107 | } | ||
108 | |||
109 | static int | ||
110 | engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b) | ||
111 | { | ||
112 | return a->nid - b->nid; | ||
113 | } | ||
114 | static IMPLEMENT_LHASH_HASH_FN(engine_pile, ENGINE_PILE) | ||
115 | static IMPLEMENT_LHASH_COMP_FN(engine_pile, ENGINE_PILE) | ||
116 | |||
117 | static int | ||
118 | int_table_check(ENGINE_TABLE **t, int create) | ||
119 | { | ||
120 | LHASH_OF(ENGINE_PILE) *lh; | ||
121 | |||
122 | if (*t) | ||
123 | return 1; | ||
124 | if (!create) | ||
125 | return 0; | ||
126 | if ((lh = lh_ENGINE_PILE_new()) == NULL) | ||
127 | return 0; | ||
128 | *t = (ENGINE_TABLE *)lh; | ||
129 | return 1; | ||
130 | } | ||
131 | |||
132 | /* Privately exposed (via eng_int.h) functions for adding and/or removing | ||
133 | * ENGINEs from the implementation table */ | ||
134 | int | ||
135 | engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup, | ||
136 | ENGINE *e, const int *nids, int num_nids, int setdefault) | ||
137 | { | ||
138 | int ret = 0, added = 0; | ||
139 | ENGINE_PILE tmplate, *fnd; | ||
140 | |||
141 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
142 | if (!(*table)) | ||
143 | added = 1; | ||
144 | if (!int_table_check(table, 1)) | ||
145 | goto end; | ||
146 | if (added) | ||
147 | /* The cleanup callback needs to be added */ | ||
148 | engine_cleanup_add_first(cleanup); | ||
149 | while (num_nids--) { | ||
150 | tmplate.nid = *nids; | ||
151 | fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate); | ||
152 | if (!fnd) { | ||
153 | fnd = malloc(sizeof(ENGINE_PILE)); | ||
154 | if (!fnd) | ||
155 | goto end; | ||
156 | fnd->uptodate = 1; | ||
157 | fnd->nid = *nids; | ||
158 | fnd->sk = sk_ENGINE_new_null(); | ||
159 | if (!fnd->sk) { | ||
160 | free(fnd); | ||
161 | goto end; | ||
162 | } | ||
163 | fnd->funct = NULL; | ||
164 | (void)lh_ENGINE_PILE_insert(&(*table)->piles, fnd); | ||
165 | } | ||
166 | /* A registration shouldn't add duplicate entries */ | ||
167 | (void)sk_ENGINE_delete_ptr(fnd->sk, e); | ||
168 | /* if 'setdefault', this ENGINE goes to the head of the list */ | ||
169 | if (!sk_ENGINE_push(fnd->sk, e)) | ||
170 | goto end; | ||
171 | /* "touch" this ENGINE_PILE */ | ||
172 | fnd->uptodate = 0; | ||
173 | if (setdefault) { | ||
174 | if (!engine_unlocked_init(e)) { | ||
175 | ENGINEerror(ENGINE_R_INIT_FAILED); | ||
176 | goto end; | ||
177 | } | ||
178 | if (fnd->funct) | ||
179 | engine_unlocked_finish(fnd->funct, 0); | ||
180 | fnd->funct = e; | ||
181 | fnd->uptodate = 1; | ||
182 | } | ||
183 | nids++; | ||
184 | } | ||
185 | ret = 1; | ||
186 | end: | ||
187 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
188 | return ret; | ||
189 | } | ||
190 | |||
191 | static void | ||
192 | int_unregister_cb_doall_arg(ENGINE_PILE *pile, ENGINE *e) | ||
193 | { | ||
194 | int n; | ||
195 | |||
196 | /* Iterate the 'c->sk' stack removing any occurrence of 'e' */ | ||
197 | while ((n = sk_ENGINE_find(pile->sk, e)) >= 0) { | ||
198 | (void)sk_ENGINE_delete(pile->sk, n); | ||
199 | pile->uptodate = 0; | ||
200 | } | ||
201 | if (pile->funct == e) { | ||
202 | engine_unlocked_finish(e, 0); | ||
203 | pile->funct = NULL; | ||
204 | } | ||
205 | } | ||
206 | static IMPLEMENT_LHASH_DOALL_ARG_FN(int_unregister_cb, ENGINE_PILE, ENGINE) | ||
207 | |||
208 | void | ||
209 | engine_table_unregister(ENGINE_TABLE **table, ENGINE *e) | ||
210 | { | ||
211 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
212 | if (int_table_check(table, 0)) | ||
213 | lh_ENGINE_PILE_doall_arg(&(*table)->piles, | ||
214 | LHASH_DOALL_ARG_FN(int_unregister_cb), ENGINE, e); | ||
215 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
216 | } | ||
217 | |||
218 | static void | ||
219 | int_cleanup_cb_doall(ENGINE_PILE *p) | ||
220 | { | ||
221 | sk_ENGINE_free(p->sk); | ||
222 | if (p->funct) | ||
223 | engine_unlocked_finish(p->funct, 0); | ||
224 | free(p); | ||
225 | } | ||
226 | static IMPLEMENT_LHASH_DOALL_FN(int_cleanup_cb, ENGINE_PILE) | ||
227 | |||
228 | void | ||
229 | engine_table_cleanup(ENGINE_TABLE **table) | ||
230 | { | ||
231 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
232 | if (*table) { | ||
233 | lh_ENGINE_PILE_doall(&(*table)->piles, | ||
234 | LHASH_DOALL_FN(int_cleanup_cb)); | ||
235 | lh_ENGINE_PILE_free(&(*table)->piles); | ||
236 | *table = NULL; | ||
237 | } | ||
238 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
239 | } | ||
240 | |||
241 | /* return a functional reference for a given 'nid' */ | ||
242 | #ifndef ENGINE_TABLE_DEBUG | ||
243 | ENGINE * | ||
244 | engine_table_select(ENGINE_TABLE **table, int nid) | ||
245 | #else | ||
246 | ENGINE * | ||
247 | engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, int l) | ||
248 | #endif | ||
249 | { | ||
250 | ENGINE *ret = NULL; | ||
251 | ENGINE_PILE tmplate, *fnd = NULL; | ||
252 | int initres, loop = 0; | ||
253 | |||
254 | if (!(*table)) { | ||
255 | #ifdef ENGINE_TABLE_DEBUG | ||
256 | fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing " | ||
257 | "registered!\n", f, l, nid); | ||
258 | #endif | ||
259 | return NULL; | ||
260 | } | ||
261 | ERR_set_mark(); | ||
262 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
263 | /* Check again inside the lock otherwise we could race against cleanup | ||
264 | * operations. But don't worry about a fprintf(stderr). */ | ||
265 | if (!int_table_check(table, 0)) | ||
266 | goto end; | ||
267 | tmplate.nid = nid; | ||
268 | fnd = lh_ENGINE_PILE_retrieve(&(*table)->piles, &tmplate); | ||
269 | if (!fnd) | ||
270 | goto end; | ||
271 | if (fnd->funct && engine_unlocked_init(fnd->funct)) { | ||
272 | #ifdef ENGINE_TABLE_DEBUG | ||
273 | fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using " | ||
274 | "ENGINE '%s' cached\n", f, l, nid, fnd->funct->id); | ||
275 | #endif | ||
276 | ret = fnd->funct; | ||
277 | goto end; | ||
278 | } | ||
279 | if (fnd->uptodate) { | ||
280 | ret = fnd->funct; | ||
281 | goto end; | ||
282 | } | ||
283 | trynext: | ||
284 | ret = sk_ENGINE_value(fnd->sk, loop++); | ||
285 | if (!ret) { | ||
286 | #ifdef ENGINE_TABLE_DEBUG | ||
287 | fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no " | ||
288 | "registered implementations would initialise\n", f, l, nid); | ||
289 | #endif | ||
290 | goto end; | ||
291 | } | ||
292 | /* Try to initialise the ENGINE? */ | ||
293 | if ((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT)) | ||
294 | initres = engine_unlocked_init(ret); | ||
295 | else | ||
296 | initres = 0; | ||
297 | if (initres) { | ||
298 | /* Update 'funct' */ | ||
299 | if ((fnd->funct != ret) && engine_unlocked_init(ret)) { | ||
300 | /* If there was a previous default we release it. */ | ||
301 | if (fnd->funct) | ||
302 | engine_unlocked_finish(fnd->funct, 0); | ||
303 | fnd->funct = ret; | ||
304 | #ifdef ENGINE_TABLE_DEBUG | ||
305 | fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, " | ||
306 | "setting default to '%s'\n", f, l, nid, ret->id); | ||
307 | #endif | ||
308 | } | ||
309 | #ifdef ENGINE_TABLE_DEBUG | ||
310 | fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, using " | ||
311 | "newly initialised '%s'\n", f, l, nid, ret->id); | ||
312 | #endif | ||
313 | goto end; | ||
314 | } | ||
315 | goto trynext; | ||
316 | end: | ||
317 | /* If it failed, it is unlikely to succeed again until some future | ||
318 | * registrations have taken place. In all cases, we cache. */ | ||
319 | if (fnd) | ||
320 | fnd->uptodate = 1; | ||
321 | #ifdef ENGINE_TABLE_DEBUG | ||
322 | if (ret) | ||
323 | fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching " | ||
324 | "ENGINE '%s'\n", f, l, nid, ret->id); | ||
325 | else | ||
326 | fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching " | ||
327 | "'no matching ENGINE'\n", f, l, nid); | ||
328 | #endif | ||
329 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
330 | /* Whatever happened, any failed init()s are not failures in this | ||
331 | * context, so clear our error state. */ | ||
332 | ERR_pop_to_mark(); | ||
333 | return ret; | ||
334 | } | ||
335 | |||
336 | /* Table enumeration */ | ||
337 | |||
338 | static void | ||
339 | int_cb_doall_arg(ENGINE_PILE *pile, ENGINE_PILE_DOALL *dall) | ||
340 | { | ||
341 | dall->cb(pile->nid, pile->sk, pile->funct, dall->arg); | ||
342 | } | ||
343 | static IMPLEMENT_LHASH_DOALL_ARG_FN(int_cb, ENGINE_PILE, ENGINE_PILE_DOALL) | ||
344 | |||
345 | void | ||
346 | engine_table_doall(ENGINE_TABLE *table, engine_table_doall_cb *cb, void *arg) | ||
347 | { | ||
348 | ENGINE_PILE_DOALL dall; | ||
349 | |||
350 | dall.cb = cb; | ||
351 | dall.arg = arg; | ||
352 | lh_ENGINE_PILE_doall_arg(&table->piles, LHASH_DOALL_ARG_FN(int_cb), | ||
353 | ENGINE_PILE_DOALL, &dall); | ||
354 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_asnmth.c b/src/lib/libcrypto/engine/tb_asnmth.c deleted file mode 100644 index 913230f696..0000000000 --- a/src/lib/libcrypto/engine/tb_asnmth.c +++ /dev/null | |||
@@ -1,255 +0,0 @@ | |||
1 | /* $OpenBSD: tb_asnmth.c,v 1.7 2022/11/26 16:08:52 tb Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <string.h> | ||
57 | |||
58 | #include <openssl/err.h> | ||
59 | |||
60 | #include "eng_int.h" | ||
61 | #include "asn1_local.h" | ||
62 | #include <openssl/evp.h> | ||
63 | |||
64 | /* If this symbol is defined then ENGINE_get_pkey_asn1_meth_engine(), the | ||
65 | * function that is used by EVP to hook in pkey_asn1_meth code and cache | ||
66 | * defaults (etc), will display brief debugging summaries to stderr with the | ||
67 | * 'nid'. */ | ||
68 | /* #define ENGINE_PKEY_ASN1_METH_DEBUG */ | ||
69 | |||
70 | static ENGINE_TABLE *pkey_asn1_meth_table = NULL; | ||
71 | |||
72 | void | ||
73 | ENGINE_unregister_pkey_asn1_meths(ENGINE *e) | ||
74 | { | ||
75 | engine_table_unregister(&pkey_asn1_meth_table, e); | ||
76 | } | ||
77 | |||
78 | static void | ||
79 | engine_unregister_all_pkey_asn1_meths(void) | ||
80 | { | ||
81 | engine_table_cleanup(&pkey_asn1_meth_table); | ||
82 | } | ||
83 | |||
84 | int | ||
85 | ENGINE_register_pkey_asn1_meths(ENGINE *e) | ||
86 | { | ||
87 | if (e->pkey_asn1_meths) { | ||
88 | const int *nids; | ||
89 | int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0); | ||
90 | if (num_nids > 0) | ||
91 | return engine_table_register(&pkey_asn1_meth_table, | ||
92 | engine_unregister_all_pkey_asn1_meths, e, nids, | ||
93 | num_nids, 0); | ||
94 | } | ||
95 | return 1; | ||
96 | } | ||
97 | |||
98 | void | ||
99 | ENGINE_register_all_pkey_asn1_meths(void) | ||
100 | { | ||
101 | ENGINE *e; | ||
102 | |||
103 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
104 | ENGINE_register_pkey_asn1_meths(e); | ||
105 | } | ||
106 | |||
107 | int | ||
108 | ENGINE_set_default_pkey_asn1_meths(ENGINE *e) | ||
109 | { | ||
110 | if (e->pkey_asn1_meths) { | ||
111 | const int *nids; | ||
112 | int num_nids = e->pkey_asn1_meths(e, NULL, &nids, 0); | ||
113 | if (num_nids > 0) | ||
114 | return engine_table_register(&pkey_asn1_meth_table, | ||
115 | engine_unregister_all_pkey_asn1_meths, e, nids, | ||
116 | num_nids, 1); | ||
117 | } | ||
118 | return 1; | ||
119 | } | ||
120 | |||
121 | /* Exposed API function to get a functional reference from the implementation | ||
122 | * table (ie. try to get a functional reference from the tabled structural | ||
123 | * references) for a given pkey_asn1_meth 'nid' */ | ||
124 | ENGINE * | ||
125 | ENGINE_get_pkey_asn1_meth_engine(int nid) | ||
126 | { | ||
127 | return engine_table_select(&pkey_asn1_meth_table, nid); | ||
128 | } | ||
129 | |||
130 | /* Obtains a pkey_asn1_meth implementation from an ENGINE functional reference */ | ||
131 | const EVP_PKEY_ASN1_METHOD * | ||
132 | ENGINE_get_pkey_asn1_meth(ENGINE *e, int nid) | ||
133 | { | ||
134 | EVP_PKEY_ASN1_METHOD *ret; | ||
135 | ENGINE_PKEY_ASN1_METHS_PTR fn = ENGINE_get_pkey_asn1_meths(e); | ||
136 | |||
137 | if (!fn || !fn(e, &ret, NULL, nid)) { | ||
138 | ENGINEerror(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD); | ||
139 | return NULL; | ||
140 | } | ||
141 | return ret; | ||
142 | } | ||
143 | |||
144 | /* Gets the pkey_asn1_meth callback from an ENGINE structure */ | ||
145 | ENGINE_PKEY_ASN1_METHS_PTR | ||
146 | ENGINE_get_pkey_asn1_meths(const ENGINE *e) | ||
147 | { | ||
148 | return e->pkey_asn1_meths; | ||
149 | } | ||
150 | |||
151 | /* Sets the pkey_asn1_meth callback in an ENGINE structure */ | ||
152 | int | ||
153 | ENGINE_set_pkey_asn1_meths(ENGINE *e, ENGINE_PKEY_ASN1_METHS_PTR f) | ||
154 | { | ||
155 | e->pkey_asn1_meths = f; | ||
156 | return 1; | ||
157 | } | ||
158 | |||
159 | /* Internal function to free up EVP_PKEY_ASN1_METHOD structures before an | ||
160 | * ENGINE is destroyed | ||
161 | */ | ||
162 | |||
163 | void | ||
164 | engine_pkey_asn1_meths_free(ENGINE *e) | ||
165 | { | ||
166 | int i; | ||
167 | EVP_PKEY_ASN1_METHOD *pkm; | ||
168 | |||
169 | if (e->pkey_asn1_meths) { | ||
170 | const int *pknids; | ||
171 | int npknids; | ||
172 | npknids = e->pkey_asn1_meths(e, NULL, &pknids, 0); | ||
173 | for (i = 0; i < npknids; i++) { | ||
174 | if (e->pkey_asn1_meths(e, &pkm, NULL, pknids[i])) { | ||
175 | EVP_PKEY_asn1_free(pkm); | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | |||
181 | /* Find a method based on a string. This does a linear search through | ||
182 | * all implemented algorithms. This is OK in practice because only | ||
183 | * a small number of algorithms are likely to be implemented in an engine | ||
184 | * and it is not used for speed critical operations. | ||
185 | */ | ||
186 | |||
187 | const EVP_PKEY_ASN1_METHOD * | ||
188 | ENGINE_get_pkey_asn1_meth_str(ENGINE *e, const char *str, int len) | ||
189 | { | ||
190 | int i, nidcount; | ||
191 | const int *nids; | ||
192 | EVP_PKEY_ASN1_METHOD *ameth; | ||
193 | |||
194 | if (!e->pkey_asn1_meths) | ||
195 | return NULL; | ||
196 | if (len == -1) | ||
197 | len = strlen(str); | ||
198 | nidcount = e->pkey_asn1_meths(e, NULL, &nids, 0); | ||
199 | for (i = 0; i < nidcount; i++) { | ||
200 | e->pkey_asn1_meths(e, &ameth, NULL, nids[i]); | ||
201 | if (((int)strlen(ameth->pem_str) == len) && | ||
202 | !strncasecmp(ameth->pem_str, str, len)) | ||
203 | return ameth; | ||
204 | } | ||
205 | return NULL; | ||
206 | } | ||
207 | |||
208 | typedef struct { | ||
209 | ENGINE *e; | ||
210 | const EVP_PKEY_ASN1_METHOD *ameth; | ||
211 | const char *str; | ||
212 | int len; | ||
213 | } ENGINE_FIND_STR; | ||
214 | |||
215 | static void | ||
216 | look_str_cb(int nid, STACK_OF(ENGINE) *sk, ENGINE *def, void *arg) | ||
217 | { | ||
218 | ENGINE_FIND_STR *lk = arg; | ||
219 | int i; | ||
220 | |||
221 | if (lk->ameth) | ||
222 | return; | ||
223 | for (i = 0; i < sk_ENGINE_num(sk); i++) { | ||
224 | ENGINE *e = sk_ENGINE_value(sk, i); | ||
225 | EVP_PKEY_ASN1_METHOD *ameth; | ||
226 | e->pkey_asn1_meths(e, &ameth, NULL, nid); | ||
227 | if (((int)strlen(ameth->pem_str) == lk->len) && | ||
228 | !strncasecmp(ameth->pem_str, lk->str, lk->len)) { | ||
229 | lk->e = e; | ||
230 | lk->ameth = ameth; | ||
231 | return; | ||
232 | } | ||
233 | } | ||
234 | } | ||
235 | |||
236 | const EVP_PKEY_ASN1_METHOD * | ||
237 | ENGINE_pkey_asn1_find_str(ENGINE **pe, const char *str, int len) | ||
238 | { | ||
239 | ENGINE_FIND_STR fstr; | ||
240 | |||
241 | fstr.e = NULL; | ||
242 | fstr.ameth = NULL; | ||
243 | fstr.str = str; | ||
244 | fstr.len = len; | ||
245 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); | ||
246 | engine_table_doall(pkey_asn1_meth_table, look_str_cb, &fstr); | ||
247 | /* If found obtain a structural reference to engine */ | ||
248 | if (fstr.e) { | ||
249 | fstr.e->struct_ref++; | ||
250 | engine_ref_debug(fstr.e, 0, 1) | ||
251 | } | ||
252 | *pe = fstr.e; | ||
253 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); | ||
254 | return fstr.ameth; | ||
255 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c deleted file mode 100644 index ed87ff199e..0000000000 --- a/src/lib/libcrypto/engine/tb_cipher.c +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | /* $OpenBSD: tb_cipher.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <openssl/err.h> | ||
57 | |||
58 | #include "eng_int.h" | ||
59 | |||
60 | /* If this symbol is defined then ENGINE_get_cipher_engine(), the function that | ||
61 | * is used by EVP to hook in cipher code and cache defaults (etc), will display | ||
62 | * brief debugging summaries to stderr with the 'nid'. */ | ||
63 | /* #define ENGINE_CIPHER_DEBUG */ | ||
64 | |||
65 | static ENGINE_TABLE *cipher_table = NULL; | ||
66 | |||
67 | void | ||
68 | ENGINE_unregister_ciphers(ENGINE *e) | ||
69 | { | ||
70 | engine_table_unregister(&cipher_table, e); | ||
71 | } | ||
72 | |||
73 | static void | ||
74 | engine_unregister_all_ciphers(void) | ||
75 | { | ||
76 | engine_table_cleanup(&cipher_table); | ||
77 | } | ||
78 | |||
79 | int | ||
80 | ENGINE_register_ciphers(ENGINE *e) | ||
81 | { | ||
82 | if (e->ciphers) { | ||
83 | const int *nids; | ||
84 | int num_nids = e->ciphers(e, NULL, &nids, 0); | ||
85 | if (num_nids > 0) | ||
86 | return engine_table_register(&cipher_table, | ||
87 | engine_unregister_all_ciphers, e, nids, | ||
88 | num_nids, 0); | ||
89 | } | ||
90 | return 1; | ||
91 | } | ||
92 | |||
93 | void | ||
94 | ENGINE_register_all_ciphers(void) | ||
95 | { | ||
96 | ENGINE *e; | ||
97 | |||
98 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
99 | ENGINE_register_ciphers(e); | ||
100 | } | ||
101 | |||
102 | int | ||
103 | ENGINE_set_default_ciphers(ENGINE *e) | ||
104 | { | ||
105 | if (e->ciphers) { | ||
106 | const int *nids; | ||
107 | int num_nids = e->ciphers(e, NULL, &nids, 0); | ||
108 | if (num_nids > 0) | ||
109 | return engine_table_register(&cipher_table, | ||
110 | engine_unregister_all_ciphers, e, nids, | ||
111 | num_nids, 1); | ||
112 | } | ||
113 | return 1; | ||
114 | } | ||
115 | |||
116 | /* Exposed API function to get a functional reference from the implementation | ||
117 | * table (ie. try to get a functional reference from the tabled structural | ||
118 | * references) for a given cipher 'nid' */ | ||
119 | ENGINE * | ||
120 | ENGINE_get_cipher_engine(int nid) | ||
121 | { | ||
122 | return engine_table_select(&cipher_table, nid); | ||
123 | } | ||
124 | |||
125 | /* Obtains a cipher implementation from an ENGINE functional reference */ | ||
126 | const EVP_CIPHER * | ||
127 | ENGINE_get_cipher(ENGINE *e, int nid) | ||
128 | { | ||
129 | const EVP_CIPHER *ret; | ||
130 | ENGINE_CIPHERS_PTR fn = ENGINE_get_ciphers(e); | ||
131 | |||
132 | if (!fn || !fn(e, &ret, NULL, nid)) { | ||
133 | ENGINEerror(ENGINE_R_UNIMPLEMENTED_CIPHER); | ||
134 | return NULL; | ||
135 | } | ||
136 | return ret; | ||
137 | } | ||
138 | |||
139 | /* Gets the cipher callback from an ENGINE structure */ | ||
140 | ENGINE_CIPHERS_PTR | ||
141 | ENGINE_get_ciphers(const ENGINE *e) | ||
142 | { | ||
143 | return e->ciphers; | ||
144 | } | ||
145 | |||
146 | /* Sets the cipher callback in an ENGINE structure */ | ||
147 | int | ||
148 | ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f) | ||
149 | { | ||
150 | e->ciphers = f; | ||
151 | return 1; | ||
152 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_dh.c b/src/lib/libcrypto/engine/tb_dh.c deleted file mode 100644 index 4f200424e5..0000000000 --- a/src/lib/libcrypto/engine/tb_dh.c +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | /* $OpenBSD: tb_dh.c,v 1.6 2014/06/12 15:49:29 deraadt Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include "eng_int.h" | ||
57 | |||
58 | /* If this symbol is defined then ENGINE_get_default_DH(), the function that is | ||
59 | * used by DH to hook in implementation code and cache defaults (etc), will | ||
60 | * display brief debugging summaries to stderr with the 'nid'. */ | ||
61 | /* #define ENGINE_DH_DEBUG */ | ||
62 | |||
63 | static ENGINE_TABLE *dh_table = NULL; | ||
64 | static const int dummy_nid = 1; | ||
65 | |||
66 | void | ||
67 | ENGINE_unregister_DH(ENGINE *e) | ||
68 | { | ||
69 | engine_table_unregister(&dh_table, e); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | engine_unregister_all_DH(void) | ||
74 | { | ||
75 | engine_table_cleanup(&dh_table); | ||
76 | } | ||
77 | |||
78 | int | ||
79 | ENGINE_register_DH(ENGINE *e) | ||
80 | { | ||
81 | if (e->dh_meth) | ||
82 | return engine_table_register(&dh_table, | ||
83 | engine_unregister_all_DH, e, &dummy_nid, 1, 0); | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | void | ||
88 | ENGINE_register_all_DH(void) | ||
89 | { | ||
90 | ENGINE *e; | ||
91 | |||
92 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
93 | ENGINE_register_DH(e); | ||
94 | } | ||
95 | |||
96 | int | ||
97 | ENGINE_set_default_DH(ENGINE *e) | ||
98 | { | ||
99 | if (e->dh_meth) | ||
100 | return engine_table_register(&dh_table, | ||
101 | engine_unregister_all_DH, e, &dummy_nid, 1, 1); | ||
102 | return 1; | ||
103 | } | ||
104 | |||
105 | /* Exposed API function to get a functional reference from the implementation | ||
106 | * table (ie. try to get a functional reference from the tabled structural | ||
107 | * references). */ | ||
108 | ENGINE * | ||
109 | ENGINE_get_default_DH(void) | ||
110 | { | ||
111 | return engine_table_select(&dh_table, dummy_nid); | ||
112 | } | ||
113 | |||
114 | /* Obtains an DH implementation from an ENGINE functional reference */ | ||
115 | const DH_METHOD * | ||
116 | ENGINE_get_DH(const ENGINE *e) | ||
117 | { | ||
118 | return e->dh_meth; | ||
119 | } | ||
120 | |||
121 | /* Sets an DH implementation in an ENGINE structure */ | ||
122 | int | ||
123 | ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth) | ||
124 | { | ||
125 | e->dh_meth = dh_meth; | ||
126 | return 1; | ||
127 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_digest.c b/src/lib/libcrypto/engine/tb_digest.c deleted file mode 100644 index f1a2e8a6b3..0000000000 --- a/src/lib/libcrypto/engine/tb_digest.c +++ /dev/null | |||
@@ -1,152 +0,0 @@ | |||
1 | /* $OpenBSD: tb_digest.c,v 1.8 2017/01/29 17:49:23 beck Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <openssl/err.h> | ||
57 | |||
58 | #include "eng_int.h" | ||
59 | |||
60 | /* If this symbol is defined then ENGINE_get_digest_engine(), the function that | ||
61 | * is used by EVP to hook in digest code and cache defaults (etc), will display | ||
62 | * brief debugging summaries to stderr with the 'nid'. */ | ||
63 | /* #define ENGINE_DIGEST_DEBUG */ | ||
64 | |||
65 | static ENGINE_TABLE *digest_table = NULL; | ||
66 | |||
67 | void | ||
68 | ENGINE_unregister_digests(ENGINE *e) | ||
69 | { | ||
70 | engine_table_unregister(&digest_table, e); | ||
71 | } | ||
72 | |||
73 | static void | ||
74 | engine_unregister_all_digests(void) | ||
75 | { | ||
76 | engine_table_cleanup(&digest_table); | ||
77 | } | ||
78 | |||
79 | int | ||
80 | ENGINE_register_digests(ENGINE *e) | ||
81 | { | ||
82 | if (e->digests) { | ||
83 | const int *nids; | ||
84 | int num_nids = e->digests(e, NULL, &nids, 0); | ||
85 | if (num_nids > 0) | ||
86 | return engine_table_register(&digest_table, | ||
87 | engine_unregister_all_digests, e, nids, | ||
88 | num_nids, 0); | ||
89 | } | ||
90 | return 1; | ||
91 | } | ||
92 | |||
93 | void | ||
94 | ENGINE_register_all_digests(void) | ||
95 | { | ||
96 | ENGINE *e; | ||
97 | |||
98 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
99 | ENGINE_register_digests(e); | ||
100 | } | ||
101 | |||
102 | int | ||
103 | ENGINE_set_default_digests(ENGINE *e) | ||
104 | { | ||
105 | if (e->digests) { | ||
106 | const int *nids; | ||
107 | int num_nids = e->digests(e, NULL, &nids, 0); | ||
108 | if (num_nids > 0) | ||
109 | return engine_table_register(&digest_table, | ||
110 | engine_unregister_all_digests, e, nids, | ||
111 | num_nids, 1); | ||
112 | } | ||
113 | return 1; | ||
114 | } | ||
115 | |||
116 | /* Exposed API function to get a functional reference from the implementation | ||
117 | * table (ie. try to get a functional reference from the tabled structural | ||
118 | * references) for a given digest 'nid' */ | ||
119 | ENGINE * | ||
120 | ENGINE_get_digest_engine(int nid) | ||
121 | { | ||
122 | return engine_table_select(&digest_table, nid); | ||
123 | } | ||
124 | |||
125 | /* Obtains a digest implementation from an ENGINE functional reference */ | ||
126 | const EVP_MD * | ||
127 | ENGINE_get_digest(ENGINE *e, int nid) | ||
128 | { | ||
129 | const EVP_MD *ret; | ||
130 | ENGINE_DIGESTS_PTR fn = ENGINE_get_digests(e); | ||
131 | |||
132 | if (!fn || !fn(e, &ret, NULL, nid)) { | ||
133 | ENGINEerror(ENGINE_R_UNIMPLEMENTED_DIGEST); | ||
134 | return NULL; | ||
135 | } | ||
136 | return ret; | ||
137 | } | ||
138 | |||
139 | /* Gets the digest callback from an ENGINE structure */ | ||
140 | ENGINE_DIGESTS_PTR | ||
141 | ENGINE_get_digests(const ENGINE *e) | ||
142 | { | ||
143 | return e->digests; | ||
144 | } | ||
145 | |||
146 | /* Sets the digest callback in an ENGINE structure */ | ||
147 | int | ||
148 | ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f) | ||
149 | { | ||
150 | e->digests = f; | ||
151 | return 1; | ||
152 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c deleted file mode 100644 index 23e9236107..0000000000 --- a/src/lib/libcrypto/engine/tb_dsa.c +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | /* $OpenBSD: tb_dsa.c,v 1.7 2014/06/12 15:49:29 deraadt Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include "eng_int.h" | ||
57 | |||
58 | /* If this symbol is defined then ENGINE_get_default_DSA(), the function that is | ||
59 | * used by DSA to hook in implementation code and cache defaults (etc), will | ||
60 | * display brief debugging summaries to stderr with the 'nid'. */ | ||
61 | /* #define ENGINE_DSA_DEBUG */ | ||
62 | |||
63 | static ENGINE_TABLE *dsa_table = NULL; | ||
64 | static const int dummy_nid = 1; | ||
65 | |||
66 | void | ||
67 | ENGINE_unregister_DSA(ENGINE *e) | ||
68 | { | ||
69 | engine_table_unregister(&dsa_table, e); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | engine_unregister_all_DSA(void) | ||
74 | { | ||
75 | engine_table_cleanup(&dsa_table); | ||
76 | } | ||
77 | |||
78 | int | ||
79 | ENGINE_register_DSA(ENGINE *e) | ||
80 | { | ||
81 | if (e->dsa_meth) | ||
82 | return engine_table_register(&dsa_table, | ||
83 | engine_unregister_all_DSA, e, &dummy_nid, 1, 0); | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | void | ||
88 | ENGINE_register_all_DSA(void) | ||
89 | { | ||
90 | ENGINE *e; | ||
91 | |||
92 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
93 | ENGINE_register_DSA(e); | ||
94 | } | ||
95 | |||
96 | int | ||
97 | ENGINE_set_default_DSA(ENGINE *e) | ||
98 | { | ||
99 | if (e->dsa_meth) | ||
100 | return engine_table_register(&dsa_table, | ||
101 | engine_unregister_all_DSA, e, &dummy_nid, 1, 1); | ||
102 | return 1; | ||
103 | } | ||
104 | |||
105 | /* Exposed API function to get a functional reference from the implementation | ||
106 | * table (ie. try to get a functional reference from the tabled structural | ||
107 | * references). */ | ||
108 | ENGINE * | ||
109 | ENGINE_get_default_DSA(void) | ||
110 | { | ||
111 | return engine_table_select(&dsa_table, dummy_nid); | ||
112 | } | ||
113 | |||
114 | /* Obtains an DSA implementation from an ENGINE functional reference */ | ||
115 | const DSA_METHOD * | ||
116 | ENGINE_get_DSA(const ENGINE *e) | ||
117 | { | ||
118 | return e->dsa_meth; | ||
119 | } | ||
120 | |||
121 | /* Sets an DSA implementation in an ENGINE structure */ | ||
122 | int | ||
123 | ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth) | ||
124 | { | ||
125 | e->dsa_meth = dsa_meth; | ||
126 | return 1; | ||
127 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_eckey.c b/src/lib/libcrypto/engine/tb_eckey.c deleted file mode 100644 index 464156aefa..0000000000 --- a/src/lib/libcrypto/engine/tb_eckey.c +++ /dev/null | |||
@@ -1,124 +0,0 @@ | |||
1 | /* $OpenBSD: tb_eckey.c,v 1.2 2019/01/19 01:18:56 tb Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include "eng_int.h" | ||
57 | |||
58 | static ENGINE_TABLE *ec_table = NULL; | ||
59 | static const int dummy_nid = 1; | ||
60 | |||
61 | void | ||
62 | ENGINE_unregister_EC(ENGINE *e) | ||
63 | { | ||
64 | engine_table_unregister(&ec_table, e); | ||
65 | } | ||
66 | |||
67 | static void | ||
68 | engine_unregister_all_EC(void) | ||
69 | { | ||
70 | engine_table_cleanup(&ec_table); | ||
71 | } | ||
72 | |||
73 | int | ||
74 | ENGINE_register_EC(ENGINE *e) | ||
75 | { | ||
76 | if (e->ec_meth) | ||
77 | return engine_table_register(&ec_table, | ||
78 | engine_unregister_all_EC, e, &dummy_nid, 1, 0); | ||
79 | return 1; | ||
80 | } | ||
81 | |||
82 | void | ||
83 | ENGINE_register_all_EC(void) | ||
84 | { | ||
85 | ENGINE *e; | ||
86 | |||
87 | for (e = ENGINE_get_first(); e != NULL; e = ENGINE_get_next(e)) | ||
88 | ENGINE_register_EC(e); | ||
89 | } | ||
90 | |||
91 | int | ||
92 | ENGINE_set_default_EC(ENGINE *e) | ||
93 | { | ||
94 | if (e->ec_meth != NULL) | ||
95 | return engine_table_register(&ec_table, | ||
96 | engine_unregister_all_EC, e, &dummy_nid, 1, 1); | ||
97 | return 1; | ||
98 | } | ||
99 | |||
100 | /* | ||
101 | * Exposed API function to get a functional reference from the implementation | ||
102 | * table (ie. try to get a functional reference from the tabled structural | ||
103 | * references). | ||
104 | */ | ||
105 | ENGINE * | ||
106 | ENGINE_get_default_EC(void) | ||
107 | { | ||
108 | return engine_table_select(&ec_table, dummy_nid); | ||
109 | } | ||
110 | |||
111 | /* Obtains an EC_KEY implementation from an ENGINE functional reference */ | ||
112 | const EC_KEY_METHOD * | ||
113 | ENGINE_get_EC(const ENGINE *e) | ||
114 | { | ||
115 | return e->ec_meth; | ||
116 | } | ||
117 | |||
118 | /* Sets an EC_KEY implementation in an ENGINE structure */ | ||
119 | int | ||
120 | ENGINE_set_EC(ENGINE *e, const EC_KEY_METHOD *ec_meth) | ||
121 | { | ||
122 | e->ec_meth = ec_meth; | ||
123 | return 1; | ||
124 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_pkmeth.c b/src/lib/libcrypto/engine/tb_pkmeth.c deleted file mode 100644 index 05566a3464..0000000000 --- a/src/lib/libcrypto/engine/tb_pkmeth.c +++ /dev/null | |||
@@ -1,175 +0,0 @@ | |||
1 | /* $OpenBSD: tb_pkmeth.c,v 1.6 2017/01/29 17:49:23 beck Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2006 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <openssl/err.h> | ||
57 | |||
58 | #include "eng_int.h" | ||
59 | #include <openssl/evp.h> | ||
60 | |||
61 | /* If this symbol is defined then ENGINE_get_pkey_meth_engine(), the function | ||
62 | * that is used by EVP to hook in pkey_meth code and cache defaults (etc), will | ||
63 | * display brief debugging summaries to stderr with the 'nid'. */ | ||
64 | /* #define ENGINE_PKEY_METH_DEBUG */ | ||
65 | |||
66 | static ENGINE_TABLE *pkey_meth_table = NULL; | ||
67 | |||
68 | void | ||
69 | ENGINE_unregister_pkey_meths(ENGINE *e) | ||
70 | { | ||
71 | engine_table_unregister(&pkey_meth_table, e); | ||
72 | } | ||
73 | |||
74 | static void | ||
75 | engine_unregister_all_pkey_meths(void) | ||
76 | { | ||
77 | engine_table_cleanup(&pkey_meth_table); | ||
78 | } | ||
79 | |||
80 | int | ||
81 | ENGINE_register_pkey_meths(ENGINE *e) | ||
82 | { | ||
83 | if (e->pkey_meths) { | ||
84 | const int *nids; | ||
85 | int num_nids = e->pkey_meths(e, NULL, &nids, 0); | ||
86 | if (num_nids > 0) | ||
87 | return engine_table_register(&pkey_meth_table, | ||
88 | engine_unregister_all_pkey_meths, e, nids, | ||
89 | num_nids, 0); | ||
90 | } | ||
91 | return 1; | ||
92 | } | ||
93 | |||
94 | void | ||
95 | ENGINE_register_all_pkey_meths(void) | ||
96 | { | ||
97 | ENGINE *e; | ||
98 | |||
99 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
100 | ENGINE_register_pkey_meths(e); | ||
101 | } | ||
102 | |||
103 | int | ||
104 | ENGINE_set_default_pkey_meths(ENGINE *e) | ||
105 | { | ||
106 | if (e->pkey_meths) { | ||
107 | const int *nids; | ||
108 | int num_nids = e->pkey_meths(e, NULL, &nids, 0); | ||
109 | if (num_nids > 0) | ||
110 | return engine_table_register(&pkey_meth_table, | ||
111 | engine_unregister_all_pkey_meths, e, nids, | ||
112 | num_nids, 1); | ||
113 | } | ||
114 | return 1; | ||
115 | } | ||
116 | |||
117 | /* Exposed API function to get a functional reference from the implementation | ||
118 | * table (ie. try to get a functional reference from the tabled structural | ||
119 | * references) for a given pkey_meth 'nid' */ | ||
120 | ENGINE * | ||
121 | ENGINE_get_pkey_meth_engine(int nid) | ||
122 | { | ||
123 | return engine_table_select(&pkey_meth_table, nid); | ||
124 | } | ||
125 | |||
126 | /* Obtains a pkey_meth implementation from an ENGINE functional reference */ | ||
127 | const EVP_PKEY_METHOD * | ||
128 | ENGINE_get_pkey_meth(ENGINE *e, int nid) | ||
129 | { | ||
130 | EVP_PKEY_METHOD *ret; | ||
131 | ENGINE_PKEY_METHS_PTR fn = ENGINE_get_pkey_meths(e); | ||
132 | |||
133 | if (!fn || !fn(e, &ret, NULL, nid)) { | ||
134 | ENGINEerror(ENGINE_R_UNIMPLEMENTED_PUBLIC_KEY_METHOD); | ||
135 | return NULL; | ||
136 | } | ||
137 | return ret; | ||
138 | } | ||
139 | |||
140 | /* Gets the pkey_meth callback from an ENGINE structure */ | ||
141 | ENGINE_PKEY_METHS_PTR | ||
142 | ENGINE_get_pkey_meths(const ENGINE *e) | ||
143 | { | ||
144 | return e->pkey_meths; | ||
145 | } | ||
146 | |||
147 | /* Sets the pkey_meth callback in an ENGINE structure */ | ||
148 | int | ||
149 | ENGINE_set_pkey_meths(ENGINE *e, ENGINE_PKEY_METHS_PTR f) | ||
150 | { | ||
151 | e->pkey_meths = f; | ||
152 | return 1; | ||
153 | } | ||
154 | |||
155 | /* Internal function to free up EVP_PKEY_METHOD structures before an | ||
156 | * ENGINE is destroyed | ||
157 | */ | ||
158 | |||
159 | void | ||
160 | engine_pkey_meths_free(ENGINE *e) | ||
161 | { | ||
162 | int i; | ||
163 | EVP_PKEY_METHOD *pkm; | ||
164 | |||
165 | if (e->pkey_meths) { | ||
166 | const int *pknids; | ||
167 | int npknids; | ||
168 | npknids = e->pkey_meths(e, NULL, &pknids, 0); | ||
169 | for (i = 0; i < npknids; i++) { | ||
170 | if (e->pkey_meths(e, &pkm, NULL, pknids[i])) { | ||
171 | EVP_PKEY_meth_free(pkm); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_rand.c b/src/lib/libcrypto/engine/tb_rand.c deleted file mode 100644 index cc61da747c..0000000000 --- a/src/lib/libcrypto/engine/tb_rand.c +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | /* $OpenBSD: tb_rand.c,v 1.6 2014/06/12 15:49:29 deraadt Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include "eng_int.h" | ||
57 | |||
58 | /* If this symbol is defined then ENGINE_get_default_RAND(), the function that is | ||
59 | * used by RAND to hook in implementation code and cache defaults (etc), will | ||
60 | * display brief debugging summaries to stderr with the 'nid'. */ | ||
61 | /* #define ENGINE_RAND_DEBUG */ | ||
62 | |||
63 | static ENGINE_TABLE *rand_table = NULL; | ||
64 | static const int dummy_nid = 1; | ||
65 | |||
66 | void | ||
67 | ENGINE_unregister_RAND(ENGINE *e) | ||
68 | { | ||
69 | engine_table_unregister(&rand_table, e); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | engine_unregister_all_RAND(void) | ||
74 | { | ||
75 | engine_table_cleanup(&rand_table); | ||
76 | } | ||
77 | |||
78 | int | ||
79 | ENGINE_register_RAND(ENGINE *e) | ||
80 | { | ||
81 | if (e->rand_meth) | ||
82 | return engine_table_register(&rand_table, | ||
83 | engine_unregister_all_RAND, e, &dummy_nid, 1, 0); | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | void | ||
88 | ENGINE_register_all_RAND(void) | ||
89 | { | ||
90 | ENGINE *e; | ||
91 | |||
92 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
93 | ENGINE_register_RAND(e); | ||
94 | } | ||
95 | |||
96 | int | ||
97 | ENGINE_set_default_RAND(ENGINE *e) | ||
98 | { | ||
99 | if (e->rand_meth) | ||
100 | return engine_table_register(&rand_table, | ||
101 | engine_unregister_all_RAND, e, &dummy_nid, 1, 1); | ||
102 | return 1; | ||
103 | } | ||
104 | |||
105 | /* Exposed API function to get a functional reference from the implementation | ||
106 | * table (ie. try to get a functional reference from the tabled structural | ||
107 | * references). */ | ||
108 | ENGINE * | ||
109 | ENGINE_get_default_RAND(void) | ||
110 | { | ||
111 | return engine_table_select(&rand_table, dummy_nid); | ||
112 | } | ||
113 | |||
114 | /* Obtains an RAND implementation from an ENGINE functional reference */ | ||
115 | const RAND_METHOD * | ||
116 | ENGINE_get_RAND(const ENGINE *e) | ||
117 | { | ||
118 | return e->rand_meth; | ||
119 | } | ||
120 | |||
121 | /* Sets an RAND implementation in an ENGINE structure */ | ||
122 | int | ||
123 | ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth) | ||
124 | { | ||
125 | e->rand_meth = rand_meth; | ||
126 | return 1; | ||
127 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_rsa.c b/src/lib/libcrypto/engine/tb_rsa.c deleted file mode 100644 index 52ee8889a0..0000000000 --- a/src/lib/libcrypto/engine/tb_rsa.c +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | /* $OpenBSD: tb_rsa.c,v 1.6 2014/06/12 15:49:29 deraadt Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2000 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include "eng_int.h" | ||
57 | |||
58 | /* If this symbol is defined then ENGINE_get_default_RSA(), the function that is | ||
59 | * used by RSA to hook in implementation code and cache defaults (etc), will | ||
60 | * display brief debugging summaries to stderr with the 'nid'. */ | ||
61 | /* #define ENGINE_RSA_DEBUG */ | ||
62 | |||
63 | static ENGINE_TABLE *rsa_table = NULL; | ||
64 | static const int dummy_nid = 1; | ||
65 | |||
66 | void | ||
67 | ENGINE_unregister_RSA(ENGINE *e) | ||
68 | { | ||
69 | engine_table_unregister(&rsa_table, e); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | engine_unregister_all_RSA(void) | ||
74 | { | ||
75 | engine_table_cleanup(&rsa_table); | ||
76 | } | ||
77 | |||
78 | int | ||
79 | ENGINE_register_RSA(ENGINE *e) | ||
80 | { | ||
81 | if (e->rsa_meth) | ||
82 | return engine_table_register(&rsa_table, | ||
83 | engine_unregister_all_RSA, e, &dummy_nid, 1, 0); | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | void | ||
88 | ENGINE_register_all_RSA(void) | ||
89 | { | ||
90 | ENGINE *e; | ||
91 | |||
92 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
93 | ENGINE_register_RSA(e); | ||
94 | } | ||
95 | |||
96 | int | ||
97 | ENGINE_set_default_RSA(ENGINE *e) | ||
98 | { | ||
99 | if (e->rsa_meth) | ||
100 | return engine_table_register(&rsa_table, | ||
101 | engine_unregister_all_RSA, e, &dummy_nid, 1, 1); | ||
102 | return 1; | ||
103 | } | ||
104 | |||
105 | /* Exposed API function to get a functional reference from the implementation | ||
106 | * table (ie. try to get a functional reference from the tabled structural | ||
107 | * references). */ | ||
108 | ENGINE * | ||
109 | ENGINE_get_default_RSA(void) | ||
110 | { | ||
111 | return engine_table_select(&rsa_table, dummy_nid); | ||
112 | } | ||
113 | |||
114 | /* Obtains an RSA implementation from an ENGINE functional reference */ | ||
115 | const RSA_METHOD * | ||
116 | ENGINE_get_RSA(const ENGINE *e) | ||
117 | { | ||
118 | return e->rsa_meth; | ||
119 | } | ||
120 | |||
121 | /* Sets an RSA implementation in an ENGINE structure */ | ||
122 | int | ||
123 | ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth) | ||
124 | { | ||
125 | e->rsa_meth = rsa_meth; | ||
126 | return 1; | ||
127 | } | ||
diff --git a/src/lib/libcrypto/engine/tb_store.c b/src/lib/libcrypto/engine/tb_store.c deleted file mode 100644 index e9ad11ab01..0000000000 --- a/src/lib/libcrypto/engine/tb_store.c +++ /dev/null | |||
@@ -1,109 +0,0 @@ | |||
1 | /* $OpenBSD: tb_store.c,v 1.5 2015/02/07 13:19:15 doug Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2003 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include "eng_int.h" | ||
57 | |||
58 | /* If this symbol is defined then ENGINE_get_default_STORE(), the function that is | ||
59 | * used by STORE to hook in implementation code and cache defaults (etc), will | ||
60 | * display brief debugging summaries to stderr with the 'nid'. */ | ||
61 | /* #define ENGINE_STORE_DEBUG */ | ||
62 | |||
63 | static ENGINE_TABLE *store_table = NULL; | ||
64 | static const int dummy_nid = 1; | ||
65 | |||
66 | void | ||
67 | ENGINE_unregister_STORE(ENGINE *e) | ||
68 | { | ||
69 | engine_table_unregister(&store_table, e); | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | engine_unregister_all_STORE(void) | ||
74 | { | ||
75 | engine_table_cleanup(&store_table); | ||
76 | } | ||
77 | |||
78 | int | ||
79 | ENGINE_register_STORE(ENGINE *e) | ||
80 | { | ||
81 | if (e->store_meth) | ||
82 | return engine_table_register(&store_table, | ||
83 | engine_unregister_all_STORE, e, &dummy_nid, 1, 0); | ||
84 | return 1; | ||
85 | } | ||
86 | |||
87 | void | ||
88 | ENGINE_register_all_STORE(void) | ||
89 | { | ||
90 | ENGINE *e; | ||
91 | |||
92 | for (e = ENGINE_get_first(); e; e = ENGINE_get_next(e)) | ||
93 | ENGINE_register_STORE(e); | ||
94 | } | ||
95 | |||
96 | /* Obtains an STORE implementation from an ENGINE functional reference */ | ||
97 | const STORE_METHOD * | ||
98 | ENGINE_get_STORE(const ENGINE *e) | ||
99 | { | ||
100 | return e->store_meth; | ||
101 | } | ||
102 | |||
103 | /* Sets an STORE implementation in an ENGINE structure */ | ||
104 | int | ||
105 | ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth) | ||
106 | { | ||
107 | e->store_meth = store_meth; | ||
108 | return 1; | ||
109 | } | ||
diff --git a/src/lib/libcrypto/hidden/openssl/rand.h b/src/lib/libcrypto/hidden/openssl/rand.h index d94a1bfd5c..978d10f70b 100644 --- a/src/lib/libcrypto/hidden/openssl/rand.h +++ b/src/lib/libcrypto/hidden/openssl/rand.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: rand.h,v 1.2 2023/07/07 19:37:54 beck Exp $ */ | 1 | /* $OpenBSD: rand.h,v 1.3 2023/07/28 09:53:55 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -27,7 +27,6 @@ | |||
27 | 27 | ||
28 | LCRYPTO_USED(RAND_set_rand_method); | 28 | LCRYPTO_USED(RAND_set_rand_method); |
29 | LCRYPTO_USED(RAND_get_rand_method); | 29 | LCRYPTO_USED(RAND_get_rand_method); |
30 | LCRYPTO_USED(RAND_set_rand_engine); | ||
31 | LCRYPTO_USED(RAND_SSLeay); | 30 | LCRYPTO_USED(RAND_SSLeay); |
32 | LCRYPTO_USED(ERR_load_RAND_strings); | 31 | LCRYPTO_USED(ERR_load_RAND_strings); |
33 | 32 | ||
diff --git a/src/lib/libcrypto/hidden/openssl/ts.h b/src/lib/libcrypto/hidden/openssl/ts.h index 638f72f2f1..0acad21373 100644 --- a/src/lib/libcrypto/hidden/openssl/ts.h +++ b/src/lib/libcrypto/hidden/openssl/ts.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ts.h,v 1.2 2023/07/07 19:37:54 beck Exp $ */ | 1 | /* $OpenBSD: ts.h,v 1.3 2023/07/28 09:53:55 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -201,8 +201,6 @@ LCRYPTO_USED(TS_CONF_load_certs); | |||
201 | LCRYPTO_USED(TS_CONF_load_key); | 201 | LCRYPTO_USED(TS_CONF_load_key); |
202 | LCRYPTO_USED(TS_CONF_get_tsa_section); | 202 | LCRYPTO_USED(TS_CONF_get_tsa_section); |
203 | LCRYPTO_USED(TS_CONF_set_serial); | 203 | LCRYPTO_USED(TS_CONF_set_serial); |
204 | LCRYPTO_USED(TS_CONF_set_crypto_device); | ||
205 | LCRYPTO_USED(TS_CONF_set_default_engine); | ||
206 | LCRYPTO_USED(TS_CONF_set_signer_cert); | 204 | LCRYPTO_USED(TS_CONF_set_signer_cert); |
207 | LCRYPTO_USED(TS_CONF_set_certs); | 205 | LCRYPTO_USED(TS_CONF_set_certs); |
208 | LCRYPTO_USED(TS_CONF_set_signer_key); | 206 | LCRYPTO_USED(TS_CONF_set_signer_key); |
diff --git a/src/lib/libcrypto/opensslfeatures.h b/src/lib/libcrypto/opensslfeatures.h index 7b8d40e688..02d5228953 100644 --- a/src/lib/libcrypto/opensslfeatures.h +++ b/src/lib/libcrypto/opensslfeatures.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: opensslfeatures.h,v 1.40 2023/07/28 09:46:36 tb Exp $ */ | 1 | /* $OpenBSD: opensslfeatures.h,v 1.41 2023/07/28 09:53:55 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Feature flags for LibreSSL... so you can actually tell when things | 3 | * Feature flags for LibreSSL... so you can actually tell when things |
4 | * are enabled, rather than not being able to tell when things are | 4 | * are enabled, rather than not being able to tell when things are |
@@ -63,7 +63,7 @@ | |||
63 | /* #define OPENSSL_NO_EC */ | 63 | /* #define OPENSSL_NO_EC */ |
64 | #define OPENSSL_NO_EC_NISTP_64_GCC_128 | 64 | #define OPENSSL_NO_EC_NISTP_64_GCC_128 |
65 | #define OPENSSL_NO_EGD | 65 | #define OPENSSL_NO_EGD |
66 | /* #define OPENSSL_NO_ENGINE */ | 66 | #define OPENSSL_NO_ENGINE |
67 | /* #define OPENSSL_NO_ERR */ | 67 | /* #define OPENSSL_NO_ERR */ |
68 | /* #define OPENSSL_NO_FUZZ_AFL */ | 68 | /* #define OPENSSL_NO_FUZZ_AFL */ |
69 | /* #define OPENSSL_NO_FUZZ_LIBFUZZER */ | 69 | /* #define OPENSSL_NO_FUZZ_LIBFUZZER */ |
diff --git a/src/lib/libcrypto/ts/ts.h b/src/lib/libcrypto/ts/ts.h index 6021a309f7..0d5de6223c 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.21 2023/04/25 17:52:54 tb Exp $ */ | 1 | /* $OpenBSD: ts.h,v 1.22 2023/07/28 09:53:55 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,9 +542,11 @@ EVP_PKEY *TS_CONF_load_key(const char *file, const char *pass); | |||
542 | const char *TS_CONF_get_tsa_section(CONF *conf, const char *section); | 542 | const char *TS_CONF_get_tsa_section(CONF *conf, const char *section); |
543 | int TS_CONF_set_serial(CONF *conf, const char *section, TS_serial_cb cb, | 543 | int 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 | ||
545 | int TS_CONF_set_crypto_device(CONF *conf, const char *section, | 546 | int TS_CONF_set_crypto_device(CONF *conf, const char *section, |
546 | const char *device); | 547 | const char *device); |
547 | int TS_CONF_set_default_engine(const char *name); | 548 | int TS_CONF_set_default_engine(const char *name); |
549 | #endif | ||
548 | int TS_CONF_set_signer_cert(CONF *conf, const char *section, | 550 | int TS_CONF_set_signer_cert(CONF *conf, const char *section, |
549 | const char *cert, TS_RESP_CTX *ctx); | 551 | const char *cert, TS_RESP_CTX *ctx); |
550 | int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs, | 552 | int TS_CONF_set_certs(CONF *conf, const char *section, const char *certs, |
diff --git a/src/lib/libssl/Symbols.list b/src/lib/libssl/Symbols.list index 2b9ec25e14..9f261bb97a 100644 --- a/src/lib/libssl/Symbols.list +++ b/src/lib/libssl/Symbols.list | |||
@@ -95,7 +95,6 @@ SSL_CTX_set_cipher_list | |||
95 | SSL_CTX_set_ciphersuites | 95 | SSL_CTX_set_ciphersuites |
96 | SSL_CTX_set_client_CA_list | 96 | SSL_CTX_set_client_CA_list |
97 | SSL_CTX_set_client_cert_cb | 97 | SSL_CTX_set_client_cert_cb |
98 | SSL_CTX_set_client_cert_engine | ||
99 | SSL_CTX_set_cookie_generate_cb | 98 | SSL_CTX_set_cookie_generate_cb |
100 | SSL_CTX_set_cookie_verify_cb | 99 | SSL_CTX_set_cookie_verify_cb |
101 | SSL_CTX_set_default_passwd_cb | 100 | SSL_CTX_set_default_passwd_cb |
diff --git a/src/lib/libssl/hidden/openssl/ssl.h b/src/lib/libssl/hidden/openssl/ssl.h index acc99fe138..e4ec6d6251 100644 --- a/src/lib/libssl/hidden/openssl/ssl.h +++ b/src/lib/libssl/hidden/openssl/ssl.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ssl.h,v 1.3 2023/07/08 16:40:14 beck Exp $ */ | 1 | /* $OpenBSD: ssl.h,v 1.4 2023/07/28 09:53:55 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2023 Bob Beck <beck@openbsd.org> |
4 | * | 4 | * |
@@ -44,7 +44,6 @@ LSSL_USED(SSL_CTX_set_info_callback); | |||
44 | LSSL_USED(SSL_CTX_get_info_callback); | 44 | LSSL_USED(SSL_CTX_get_info_callback); |
45 | LSSL_USED(SSL_CTX_set_client_cert_cb); | 45 | LSSL_USED(SSL_CTX_set_client_cert_cb); |
46 | LSSL_USED(SSL_CTX_get_client_cert_cb); | 46 | LSSL_USED(SSL_CTX_get_client_cert_cb); |
47 | LSSL_USED(SSL_CTX_set_client_cert_engine); | ||
48 | LSSL_USED(SSL_CTX_set_cookie_generate_cb); | 47 | LSSL_USED(SSL_CTX_set_cookie_generate_cb); |
49 | LSSL_USED(SSL_CTX_set_cookie_verify_cb); | 48 | LSSL_USED(SSL_CTX_set_cookie_verify_cb); |
50 | LSSL_USED(SSL_CTX_set_next_protos_advertised_cb); | 49 | LSSL_USED(SSL_CTX_set_next_protos_advertised_cb); |