]>
Commit | Line | Data |
---|---|---|
8a73348b | 1 | /* |
a28d06f3 | 2 | * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved. |
8a73348b MC |
3 | * |
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8 | */ | |
9 | ||
10 | #include <string.h> | |
11 | #include <stdio.h> | |
55a0a117 | 12 | #include <openssl/opensslconf.h> |
8a73348b | 13 | #include <openssl/core.h> |
23c48d94 | 14 | #include <openssl/core_dispatch.h> |
8a73348b MC |
15 | #include <openssl/core_names.h> |
16 | #include <openssl/params.h> | |
63665fff | 17 | #include "prov/bio.h" |
fdaad3f1 | 18 | #include "prov/provider_ctx.h" |
0d2bfe52 | 19 | #include "prov/providercommon.h" |
af3e7e1b | 20 | #include "prov/implementations.h" |
e2f5df36 | 21 | #include "prov/names.h" |
0d2bfe52 | 22 | #include "prov/provider_util.h" |
08edd447 | 23 | #include "prov/seeding.h" |
0d2bfe52 SL |
24 | #include "internal/nelem.h" |
25 | ||
fdaad3f1 RL |
26 | /* |
27 | * Forward declarations to ensure that interface functions are correctly | |
28 | * defined. | |
29 | */ | |
363b1e5d DMSP |
30 | static OSSL_FUNC_provider_gettable_params_fn deflt_gettable_params; |
31 | static OSSL_FUNC_provider_get_params_fn deflt_get_params; | |
32 | static OSSL_FUNC_provider_query_operation_fn deflt_query; | |
fdaad3f1 | 33 | |
745fc918 | 34 | #define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK } |
0d2bfe52 | 35 | #define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL) |
8a73348b MC |
36 | |
37 | /* Functions provided by the core */ | |
363b1e5d DMSP |
38 | static OSSL_FUNC_core_gettable_params_fn *c_gettable_params = NULL; |
39 | static OSSL_FUNC_core_get_params_fn *c_get_params = NULL; | |
8a73348b MC |
40 | |
41 | /* Parameters we provide to the core */ | |
26175013 RL |
42 | static const OSSL_PARAM deflt_param_types[] = { |
43 | OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0), | |
44 | OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0), | |
45 | OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0), | |
eab7b424 | 46 | OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0), |
26175013 | 47 | OSSL_PARAM_END |
8a73348b MC |
48 | }; |
49 | ||
fdaad3f1 | 50 | static const OSSL_PARAM *deflt_gettable_params(void *provctx) |
8a73348b MC |
51 | { |
52 | return deflt_param_types; | |
53 | } | |
54 | ||
fdaad3f1 | 55 | static int deflt_get_params(void *provctx, OSSL_PARAM params[]) |
8a73348b | 56 | { |
4e7991b4 | 57 | OSSL_PARAM *p; |
8a73348b MC |
58 | |
59 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME); | |
60 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider")) | |
61 | return 0; | |
62 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION); | |
63 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR)) | |
64 | return 0; | |
65 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO); | |
66 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR)) | |
67 | return 0; | |
04cb5ec0 | 68 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS); |
eab7b424 | 69 | if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running())) |
04cb5ec0 | 70 | return 0; |
8a73348b MC |
71 | return 1; |
72 | } | |
73 | ||
df553b79 RL |
74 | /* |
75 | * For the algorithm names, we use the following formula for our primary | |
76 | * names: | |
77 | * | |
78 | * ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?] | |
79 | * | |
80 | * VERSION is only present if there are multiple versions of | |
81 | * an alg (MD2, MD4, MD5). It may be omitted if there is only | |
82 | * one version (if a subsequent version is released in the future, | |
83 | * we can always change the canonical name, and add the old name | |
84 | * as an alias). | |
85 | * | |
86 | * SUBNAME may be present where we are combining multiple | |
87 | * algorithms together, e.g. MD5-SHA1. | |
88 | * | |
89 | * SIZE is only present if multiple versions of an algorithm exist | |
90 | * with different sizes (e.g. AES-128-CBC, AES-256-CBC) | |
91 | * | |
92 | * MODE is only present where applicable. | |
93 | * | |
94 | * We add diverse other names where applicable, such as the names that | |
95 | * NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names | |
96 | * we have used historically. | |
cc35c3ed MC |
97 | * |
98 | * Algorithm names are case insensitive, but we use all caps in our "canonical" | |
99 | * names for consistency. | |
df553b79 | 100 | */ |
de29ff17 | 101 | static const OSSL_ALGORITHM deflt_digests[] = { |
df553b79 | 102 | /* Our primary name:NIST name[:our older names] */ |
e2f5df36 RL |
103 | { PROV_NAMES_SHA1, "provider=default", ossl_sha1_functions }, |
104 | { PROV_NAMES_SHA2_224, "provider=default", ossl_sha224_functions }, | |
105 | { PROV_NAMES_SHA2_256, "provider=default", ossl_sha256_functions }, | |
106 | { PROV_NAMES_SHA2_384, "provider=default", ossl_sha384_functions }, | |
107 | { PROV_NAMES_SHA2_512, "provider=default", ossl_sha512_functions }, | |
108 | { PROV_NAMES_SHA2_512_224, "provider=default", ossl_sha512_224_functions }, | |
109 | { PROV_NAMES_SHA2_512_256, "provider=default", ossl_sha512_256_functions }, | |
d5e5e2ff | 110 | |
df553b79 | 111 | /* We agree with NIST here, so one name only */ |
e2f5df36 RL |
112 | { PROV_NAMES_SHA3_224, "provider=default", ossl_sha3_224_functions }, |
113 | { PROV_NAMES_SHA3_256, "provider=default", ossl_sha3_256_functions }, | |
114 | { PROV_NAMES_SHA3_384, "provider=default", ossl_sha3_384_functions }, | |
115 | { PROV_NAMES_SHA3_512, "provider=default", ossl_sha3_512_functions }, | |
d5e5e2ff | 116 | |
524f1261 UM |
117 | { PROV_NAMES_KECCAK_224, "provider=default", ossl_keccak_224_functions }, |
118 | { PROV_NAMES_KECCAK_256, "provider=default", ossl_keccak_256_functions }, | |
119 | { PROV_NAMES_KECCAK_384, "provider=default", ossl_keccak_384_functions }, | |
120 | { PROV_NAMES_KECCAK_512, "provider=default", ossl_keccak_512_functions }, | |
121 | ||
e23cda00 | 122 | /* |
cc35c3ed MC |
123 | * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for |
124 | * the KMAC-128 and KMAC-256. | |
e23cda00 | 125 | */ |
e2f5df36 | 126 | { PROV_NAMES_KECCAK_KMAC_128, "provider=default", |
1be63951 | 127 | ossl_keccak_kmac_128_functions }, |
e2f5df36 | 128 | { PROV_NAMES_KECCAK_KMAC_256, "provider=default", |
1be63951 | 129 | ossl_keccak_kmac_256_functions }, |
d5e5e2ff | 130 | |
df553b79 | 131 | /* Our primary name:NIST name */ |
e2f5df36 RL |
132 | { PROV_NAMES_SHAKE_128, "provider=default", ossl_shake_128_functions }, |
133 | { PROV_NAMES_SHAKE_256, "provider=default", ossl_shake_256_functions }, | |
d5e5e2ff SL |
134 | |
135 | #ifndef OPENSSL_NO_BLAKE2 | |
df553b79 RL |
136 | /* |
137 | * https://blake2.net/ doesn't specify size variants, | |
138 | * but mentions that Bouncy Castle uses the names | |
139 | * BLAKE2b-160, BLAKE2b-256, BLAKE2b-384, and BLAKE2b-512 | |
140 | * If we assume that "2b" and "2s" are versions, that pattern | |
141 | * fits with ours. We also add our historical names. | |
142 | */ | |
e2f5df36 RL |
143 | { PROV_NAMES_BLAKE2S_256, "provider=default", ossl_blake2s256_functions }, |
144 | { PROV_NAMES_BLAKE2B_512, "provider=default", ossl_blake2b512_functions }, | |
d5e5e2ff SL |
145 | #endif /* OPENSSL_NO_BLAKE2 */ |
146 | ||
147 | #ifndef OPENSSL_NO_SM3 | |
e2f5df36 | 148 | { PROV_NAMES_SM3, "provider=default", ossl_sm3_functions }, |
d5e5e2ff SL |
149 | #endif /* OPENSSL_NO_SM3 */ |
150 | ||
151 | #ifndef OPENSSL_NO_MD5 | |
e2f5df36 RL |
152 | { PROV_NAMES_MD5, "provider=default", ossl_md5_functions }, |
153 | { PROV_NAMES_MD5_SHA1, "provider=default", ossl_md5_sha1_functions }, | |
d5e5e2ff SL |
154 | #endif /* OPENSSL_NO_MD5 */ |
155 | ||
ecd83146 P |
156 | #ifndef OPENSSL_NO_RMD160 |
157 | { PROV_NAMES_RIPEMD_160, "provider=default", ossl_ripemd160_functions }, | |
158 | #endif /* OPENSSL_NO_RMD160 */ | |
159 | ||
bef9b48e | 160 | { PROV_NAMES_NULL, "provider=default", ossl_nullmd_functions }, |
de29ff17 MC |
161 | { NULL, NULL, NULL } |
162 | }; | |
163 | ||
0d2bfe52 | 164 | static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = { |
e2f5df36 RL |
165 | ALG(PROV_NAMES_NULL, ossl_null_functions), |
166 | ALG(PROV_NAMES_AES_256_ECB, ossl_aes256ecb_functions), | |
167 | ALG(PROV_NAMES_AES_192_ECB, ossl_aes192ecb_functions), | |
168 | ALG(PROV_NAMES_AES_128_ECB, ossl_aes128ecb_functions), | |
169 | ALG(PROV_NAMES_AES_256_CBC, ossl_aes256cbc_functions), | |
170 | ALG(PROV_NAMES_AES_192_CBC, ossl_aes192cbc_functions), | |
171 | ALG(PROV_NAMES_AES_128_CBC, ossl_aes128cbc_functions), | |
172 | ALG(PROV_NAMES_AES_128_CBC_CTS, ossl_aes128cbc_cts_functions), | |
173 | ALG(PROV_NAMES_AES_192_CBC_CTS, ossl_aes192cbc_cts_functions), | |
174 | ALG(PROV_NAMES_AES_256_CBC_CTS, ossl_aes256cbc_cts_functions), | |
175 | ALG(PROV_NAMES_AES_256_OFB, ossl_aes256ofb_functions), | |
176 | ALG(PROV_NAMES_AES_192_OFB, ossl_aes192ofb_functions), | |
177 | ALG(PROV_NAMES_AES_128_OFB, ossl_aes128ofb_functions), | |
178 | ALG(PROV_NAMES_AES_256_CFB, ossl_aes256cfb_functions), | |
179 | ALG(PROV_NAMES_AES_192_CFB, ossl_aes192cfb_functions), | |
180 | ALG(PROV_NAMES_AES_128_CFB, ossl_aes128cfb_functions), | |
181 | ALG(PROV_NAMES_AES_256_CFB1, ossl_aes256cfb1_functions), | |
182 | ALG(PROV_NAMES_AES_192_CFB1, ossl_aes192cfb1_functions), | |
183 | ALG(PROV_NAMES_AES_128_CFB1, ossl_aes128cfb1_functions), | |
184 | ALG(PROV_NAMES_AES_256_CFB8, ossl_aes256cfb8_functions), | |
185 | ALG(PROV_NAMES_AES_192_CFB8, ossl_aes192cfb8_functions), | |
186 | ALG(PROV_NAMES_AES_128_CFB8, ossl_aes128cfb8_functions), | |
187 | ALG(PROV_NAMES_AES_256_CTR, ossl_aes256ctr_functions), | |
188 | ALG(PROV_NAMES_AES_192_CTR, ossl_aes192ctr_functions), | |
189 | ALG(PROV_NAMES_AES_128_CTR, ossl_aes128ctr_functions), | |
190 | ALG(PROV_NAMES_AES_256_XTS, ossl_aes256xts_functions), | |
191 | ALG(PROV_NAMES_AES_128_XTS, ossl_aes128xts_functions), | |
3837c202 | 192 | #ifndef OPENSSL_NO_OCB |
e2f5df36 RL |
193 | ALG(PROV_NAMES_AES_256_OCB, ossl_aes256ocb_functions), |
194 | ALG(PROV_NAMES_AES_192_OCB, ossl_aes192ocb_functions), | |
195 | ALG(PROV_NAMES_AES_128_OCB, ossl_aes128ocb_functions), | |
3837c202 | 196 | #endif /* OPENSSL_NO_OCB */ |
eb173822 | 197 | #ifndef OPENSSL_NO_SIV |
e2f5df36 RL |
198 | ALG(PROV_NAMES_AES_128_SIV, ossl_aes128siv_functions), |
199 | ALG(PROV_NAMES_AES_192_SIV, ossl_aes192siv_functions), | |
200 | ALG(PROV_NAMES_AES_256_SIV, ossl_aes256siv_functions), | |
0113ec84 TS |
201 | ALG(PROV_NAMES_AES_128_GCM_SIV, ossl_aes128gcm_siv_functions), |
202 | ALG(PROV_NAMES_AES_192_GCM_SIV, ossl_aes192gcm_siv_functions), | |
203 | ALG(PROV_NAMES_AES_256_GCM_SIV, ossl_aes256gcm_siv_functions), | |
eb173822 | 204 | #endif /* OPENSSL_NO_SIV */ |
e2f5df36 RL |
205 | ALG(PROV_NAMES_AES_256_GCM, ossl_aes256gcm_functions), |
206 | ALG(PROV_NAMES_AES_192_GCM, ossl_aes192gcm_functions), | |
207 | ALG(PROV_NAMES_AES_128_GCM, ossl_aes128gcm_functions), | |
208 | ALG(PROV_NAMES_AES_256_CCM, ossl_aes256ccm_functions), | |
209 | ALG(PROV_NAMES_AES_192_CCM, ossl_aes192ccm_functions), | |
210 | ALG(PROV_NAMES_AES_128_CCM, ossl_aes128ccm_functions), | |
211 | ALG(PROV_NAMES_AES_256_WRAP, ossl_aes256wrap_functions), | |
212 | ALG(PROV_NAMES_AES_192_WRAP, ossl_aes192wrap_functions), | |
213 | ALG(PROV_NAMES_AES_128_WRAP, ossl_aes128wrap_functions), | |
214 | ALG(PROV_NAMES_AES_256_WRAP_PAD, ossl_aes256wrappad_functions), | |
215 | ALG(PROV_NAMES_AES_192_WRAP_PAD, ossl_aes192wrappad_functions), | |
216 | ALG(PROV_NAMES_AES_128_WRAP_PAD, ossl_aes128wrappad_functions), | |
217 | ALG(PROV_NAMES_AES_256_WRAP_INV, ossl_aes256wrapinv_functions), | |
218 | ALG(PROV_NAMES_AES_192_WRAP_INV, ossl_aes192wrapinv_functions), | |
219 | ALG(PROV_NAMES_AES_128_WRAP_INV, ossl_aes128wrapinv_functions), | |
220 | ALG(PROV_NAMES_AES_256_WRAP_PAD_INV, ossl_aes256wrappadinv_functions), | |
221 | ALG(PROV_NAMES_AES_192_WRAP_PAD_INV, ossl_aes192wrappadinv_functions), | |
222 | ALG(PROV_NAMES_AES_128_WRAP_PAD_INV, ossl_aes128wrappadinv_functions), | |
223 | ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA1, ossl_aes128cbc_hmac_sha1_functions, | |
592dcfd3 | 224 | ossl_cipher_capable_aes_cbc_hmac_sha1), |
e2f5df36 | 225 | ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA1, ossl_aes256cbc_hmac_sha1_functions, |
592dcfd3 | 226 | ossl_cipher_capable_aes_cbc_hmac_sha1), |
e2f5df36 | 227 | ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA256, ossl_aes128cbc_hmac_sha256_functions, |
592dcfd3 | 228 | ossl_cipher_capable_aes_cbc_hmac_sha256), |
e2f5df36 | 229 | ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA256, ossl_aes256cbc_hmac_sha256_functions, |
592dcfd3 | 230 | ossl_cipher_capable_aes_cbc_hmac_sha256), |
a672a02a | 231 | #ifndef OPENSSL_NO_ARIA |
e2f5df36 RL |
232 | ALG(PROV_NAMES_ARIA_256_GCM, ossl_aria256gcm_functions), |
233 | ALG(PROV_NAMES_ARIA_192_GCM, ossl_aria192gcm_functions), | |
234 | ALG(PROV_NAMES_ARIA_128_GCM, ossl_aria128gcm_functions), | |
235 | ALG(PROV_NAMES_ARIA_256_CCM, ossl_aria256ccm_functions), | |
236 | ALG(PROV_NAMES_ARIA_192_CCM, ossl_aria192ccm_functions), | |
237 | ALG(PROV_NAMES_ARIA_128_CCM, ossl_aria128ccm_functions), | |
238 | ALG(PROV_NAMES_ARIA_256_ECB, ossl_aria256ecb_functions), | |
239 | ALG(PROV_NAMES_ARIA_192_ECB, ossl_aria192ecb_functions), | |
240 | ALG(PROV_NAMES_ARIA_128_ECB, ossl_aria128ecb_functions), | |
241 | ALG(PROV_NAMES_ARIA_256_CBC, ossl_aria256cbc_functions), | |
242 | ALG(PROV_NAMES_ARIA_192_CBC, ossl_aria192cbc_functions), | |
243 | ALG(PROV_NAMES_ARIA_128_CBC, ossl_aria128cbc_functions), | |
244 | ALG(PROV_NAMES_ARIA_256_OFB, ossl_aria256ofb_functions), | |
245 | ALG(PROV_NAMES_ARIA_192_OFB, ossl_aria192ofb_functions), | |
246 | ALG(PROV_NAMES_ARIA_128_OFB, ossl_aria128ofb_functions), | |
247 | ALG(PROV_NAMES_ARIA_256_CFB, ossl_aria256cfb_functions), | |
248 | ALG(PROV_NAMES_ARIA_192_CFB, ossl_aria192cfb_functions), | |
249 | ALG(PROV_NAMES_ARIA_128_CFB, ossl_aria128cfb_functions), | |
250 | ALG(PROV_NAMES_ARIA_256_CFB1, ossl_aria256cfb1_functions), | |
251 | ALG(PROV_NAMES_ARIA_192_CFB1, ossl_aria192cfb1_functions), | |
252 | ALG(PROV_NAMES_ARIA_128_CFB1, ossl_aria128cfb1_functions), | |
253 | ALG(PROV_NAMES_ARIA_256_CFB8, ossl_aria256cfb8_functions), | |
254 | ALG(PROV_NAMES_ARIA_192_CFB8, ossl_aria192cfb8_functions), | |
255 | ALG(PROV_NAMES_ARIA_128_CFB8, ossl_aria128cfb8_functions), | |
256 | ALG(PROV_NAMES_ARIA_256_CTR, ossl_aria256ctr_functions), | |
257 | ALG(PROV_NAMES_ARIA_192_CTR, ossl_aria192ctr_functions), | |
258 | ALG(PROV_NAMES_ARIA_128_CTR, ossl_aria128ctr_functions), | |
a672a02a | 259 | #endif /* OPENSSL_NO_ARIA */ |
e1178600 | 260 | #ifndef OPENSSL_NO_CAMELLIA |
e2f5df36 RL |
261 | ALG(PROV_NAMES_CAMELLIA_256_ECB, ossl_camellia256ecb_functions), |
262 | ALG(PROV_NAMES_CAMELLIA_192_ECB, ossl_camellia192ecb_functions), | |
263 | ALG(PROV_NAMES_CAMELLIA_128_ECB, ossl_camellia128ecb_functions), | |
264 | ALG(PROV_NAMES_CAMELLIA_256_CBC, ossl_camellia256cbc_functions), | |
265 | ALG(PROV_NAMES_CAMELLIA_192_CBC, ossl_camellia192cbc_functions), | |
266 | ALG(PROV_NAMES_CAMELLIA_128_CBC, ossl_camellia128cbc_functions), | |
7f5a9399 SL |
267 | ALG(PROV_NAMES_CAMELLIA_128_CBC_CTS, ossl_camellia128cbc_cts_functions), |
268 | ALG(PROV_NAMES_CAMELLIA_192_CBC_CTS, ossl_camellia192cbc_cts_functions), | |
269 | ALG(PROV_NAMES_CAMELLIA_256_CBC_CTS, ossl_camellia256cbc_cts_functions), | |
e2f5df36 RL |
270 | ALG(PROV_NAMES_CAMELLIA_256_OFB, ossl_camellia256ofb_functions), |
271 | ALG(PROV_NAMES_CAMELLIA_192_OFB, ossl_camellia192ofb_functions), | |
272 | ALG(PROV_NAMES_CAMELLIA_128_OFB, ossl_camellia128ofb_functions), | |
273 | ALG(PROV_NAMES_CAMELLIA_256_CFB, ossl_camellia256cfb_functions), | |
274 | ALG(PROV_NAMES_CAMELLIA_192_CFB, ossl_camellia192cfb_functions), | |
275 | ALG(PROV_NAMES_CAMELLIA_128_CFB, ossl_camellia128cfb_functions), | |
276 | ALG(PROV_NAMES_CAMELLIA_256_CFB1, ossl_camellia256cfb1_functions), | |
277 | ALG(PROV_NAMES_CAMELLIA_192_CFB1, ossl_camellia192cfb1_functions), | |
278 | ALG(PROV_NAMES_CAMELLIA_128_CFB1, ossl_camellia128cfb1_functions), | |
279 | ALG(PROV_NAMES_CAMELLIA_256_CFB8, ossl_camellia256cfb8_functions), | |
280 | ALG(PROV_NAMES_CAMELLIA_192_CFB8, ossl_camellia192cfb8_functions), | |
281 | ALG(PROV_NAMES_CAMELLIA_128_CFB8, ossl_camellia128cfb8_functions), | |
282 | ALG(PROV_NAMES_CAMELLIA_256_CTR, ossl_camellia256ctr_functions), | |
283 | ALG(PROV_NAMES_CAMELLIA_192_CTR, ossl_camellia192ctr_functions), | |
284 | ALG(PROV_NAMES_CAMELLIA_128_CTR, ossl_camellia128ctr_functions), | |
e1178600 | 285 | #endif /* OPENSSL_NO_CAMELLIA */ |
cb1548bc | 286 | #ifndef OPENSSL_NO_DES |
e2f5df36 RL |
287 | ALG(PROV_NAMES_DES_EDE3_ECB, ossl_tdes_ede3_ecb_functions), |
288 | ALG(PROV_NAMES_DES_EDE3_CBC, ossl_tdes_ede3_cbc_functions), | |
289 | ALG(PROV_NAMES_DES_EDE3_OFB, ossl_tdes_ede3_ofb_functions), | |
290 | ALG(PROV_NAMES_DES_EDE3_CFB, ossl_tdes_ede3_cfb_functions), | |
291 | ALG(PROV_NAMES_DES_EDE3_CFB8, ossl_tdes_ede3_cfb8_functions), | |
292 | ALG(PROV_NAMES_DES_EDE3_CFB1, ossl_tdes_ede3_cfb1_functions), | |
293 | ALG(PROV_NAMES_DES3_WRAP, ossl_tdes_wrap_cbc_functions), | |
294 | ALG(PROV_NAMES_DES_EDE_ECB, ossl_tdes_ede2_ecb_functions), | |
295 | ALG(PROV_NAMES_DES_EDE_CBC, ossl_tdes_ede2_cbc_functions), | |
296 | ALG(PROV_NAMES_DES_EDE_OFB, ossl_tdes_ede2_ofb_functions), | |
297 | ALG(PROV_NAMES_DES_EDE_CFB, ossl_tdes_ede2_cfb_functions), | |
cb1548bc | 298 | #endif /* OPENSSL_NO_DES */ |
105dde25 | 299 | #ifndef OPENSSL_NO_SM4 |
c2ee608a TZ |
300 | ALG(PROV_NAMES_SM4_GCM, ossl_sm4128gcm_functions), |
301 | ALG(PROV_NAMES_SM4_CCM, ossl_sm4128ccm_functions), | |
e2f5df36 RL |
302 | ALG(PROV_NAMES_SM4_ECB, ossl_sm4128ecb_functions), |
303 | ALG(PROV_NAMES_SM4_CBC, ossl_sm4128cbc_functions), | |
304 | ALG(PROV_NAMES_SM4_CTR, ossl_sm4128ctr_functions), | |
305 | ALG(PROV_NAMES_SM4_OFB, ossl_sm4128ofb128_functions), | |
306 | ALG(PROV_NAMES_SM4_CFB, ossl_sm4128cfb128_functions), | |
2788b56f | 307 | ALG(PROV_NAMES_SM4_XTS, ossl_sm4128xts_functions), |
105dde25 | 308 | #endif /* OPENSSL_NO_SM4 */ |
3d5a7578 | 309 | #ifndef OPENSSL_NO_CHACHA |
e2f5df36 | 310 | ALG(PROV_NAMES_ChaCha20, ossl_chacha20_functions), |
3d5a7578 | 311 | # ifndef OPENSSL_NO_POLY1305 |
e2f5df36 | 312 | ALG(PROV_NAMES_ChaCha20_Poly1305, ossl_chacha20_ossl_poly1305_functions), |
3d5a7578 SL |
313 | # endif /* OPENSSL_NO_POLY1305 */ |
314 | #endif /* OPENSSL_NO_CHACHA */ | |
0d2bfe52 | 315 | { { NULL, NULL, NULL }, NULL } |
aab26e6f | 316 | }; |
0d2bfe52 | 317 | static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)]; |
aab26e6f | 318 | |
55a0a117 RL |
319 | static const OSSL_ALGORITHM deflt_macs[] = { |
320 | #ifndef OPENSSL_NO_BLAKE2 | |
e2f5df36 RL |
321 | { PROV_NAMES_BLAKE2BMAC, "provider=default", ossl_blake2bmac_functions }, |
322 | { PROV_NAMES_BLAKE2SMAC, "provider=default", ossl_blake2smac_functions }, | |
2e5db6ad RL |
323 | #endif |
324 | #ifndef OPENSSL_NO_CMAC | |
e2f5df36 | 325 | { PROV_NAMES_CMAC, "provider=default", ossl_cmac_functions }, |
55a0a117 | 326 | #endif |
e2f5df36 RL |
327 | { PROV_NAMES_GMAC, "provider=default", ossl_gmac_functions }, |
328 | { PROV_NAMES_HMAC, "provider=default", ossl_hmac_functions }, | |
329 | { PROV_NAMES_KMAC_128, "provider=default", ossl_kmac128_functions }, | |
330 | { PROV_NAMES_KMAC_256, "provider=default", ossl_kmac256_functions }, | |
4657693d | 331 | #ifndef OPENSSL_NO_SIPHASH |
e2f5df36 | 332 | { PROV_NAMES_SIPHASH, "provider=default", ossl_siphash_functions }, |
ae0b6b92 RL |
333 | #endif |
334 | #ifndef OPENSSL_NO_POLY1305 | |
e2f5df36 | 335 | { PROV_NAMES_POLY1305, "provider=default", ossl_poly1305_functions }, |
4657693d | 336 | #endif |
55a0a117 RL |
337 | { NULL, NULL, NULL } |
338 | }; | |
339 | ||
e3405a4a | 340 | static const OSSL_ALGORITHM deflt_kdfs[] = { |
e2f5df36 | 341 | { PROV_NAMES_HKDF, "provider=default", ossl_kdf_hkdf_functions }, |
736dba01 P |
342 | { PROV_NAMES_TLS1_3_KDF, "provider=default", |
343 | ossl_kdf_tls1_3_kdf_functions }, | |
e2f5df36 RL |
344 | { PROV_NAMES_SSKDF, "provider=default", ossl_kdf_sskdf_functions }, |
345 | { PROV_NAMES_PBKDF2, "provider=default", ossl_kdf_pbkdf2_functions }, | |
346 | { PROV_NAMES_PKCS12KDF, "provider=default", ossl_kdf_pkcs12_functions }, | |
347 | { PROV_NAMES_SSHKDF, "provider=default", ossl_kdf_sshkdf_functions }, | |
348 | { PROV_NAMES_X963KDF, "provider=default", ossl_kdf_x963_kdf_functions }, | |
349 | { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_tls1_prf_functions }, | |
350 | { PROV_NAMES_KBKDF, "provider=default", ossl_kdf_kbkdf_functions }, | |
351 | { PROV_NAMES_X942KDF_ASN1, "provider=default", ossl_kdf_x942_kdf_functions }, | |
e3405a4a | 352 | #ifndef OPENSSL_NO_SCRYPT |
e2f5df36 | 353 | { PROV_NAMES_SCRYPT, "provider=default", ossl_kdf_scrypt_functions }, |
e3405a4a | 354 | #endif |
e2f5df36 | 355 | { PROV_NAMES_KRB5KDF, "provider=default", ossl_kdf_krb5kdf_functions }, |
0fee1dff | 356 | { NULL, NULL, NULL } |
e3405a4a P |
357 | }; |
358 | ||
89e29174 | 359 | static const OSSL_ALGORITHM deflt_keyexch[] = { |
76ca35e7 | 360 | #ifndef OPENSSL_NO_DH |
e2f5df36 | 361 | { PROV_NAMES_DH, "provider=default", ossl_dh_keyexch_functions }, |
6f7d2135 MC |
362 | #endif |
363 | #ifndef OPENSSL_NO_EC | |
e2f5df36 RL |
364 | { PROV_NAMES_ECDH, "provider=default", ossl_ecdh_keyexch_functions }, |
365 | { PROV_NAMES_X25519, "provider=default", ossl_x25519_keyexch_functions }, | |
366 | { PROV_NAMES_X448, "provider=default", ossl_x448_keyexch_functions }, | |
8b84b075 | 367 | #endif |
e2f5df36 RL |
368 | { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_tls1_prf_keyexch_functions }, |
369 | { PROV_NAMES_HKDF, "provider=default", ossl_kdf_hkdf_keyexch_functions }, | |
370 | { PROV_NAMES_SCRYPT, "provider=default", | |
1be63951 | 371 | ossl_kdf_scrypt_keyexch_functions }, |
8b84b075 RL |
372 | { NULL, NULL, NULL } |
373 | }; | |
374 | ||
bcc4ae67 | 375 | static const OSSL_ALGORITHM deflt_rands[] = { |
e2f5df36 RL |
376 | { PROV_NAMES_CTR_DRBG, "provider=default", ossl_drbg_ctr_functions }, |
377 | { PROV_NAMES_HASH_DRBG, "provider=default", ossl_drbg_hash_functions }, | |
378 | { PROV_NAMES_HMAC_DRBG, "provider=default", ossl_drbg_ossl_hmac_functions }, | |
379 | { PROV_NAMES_SEED_SRC, "provider=default", ossl_seed_src_functions }, | |
380 | { PROV_NAMES_TEST_RAND, "provider=default", ossl_test_rng_functions }, | |
bcc4ae67 P |
381 | { NULL, NULL, NULL } |
382 | }; | |
383 | ||
4889dadc MC |
384 | static const OSSL_ALGORITHM deflt_signature[] = { |
385 | #ifndef OPENSSL_NO_DSA | |
e2f5df36 | 386 | { PROV_NAMES_DSA, "provider=default", ossl_dsa_signature_functions }, |
4889dadc | 387 | #endif |
e2f5df36 | 388 | { PROV_NAMES_RSA, "provider=default", ossl_rsa_signature_functions }, |
3965480c | 389 | #ifndef OPENSSL_NO_EC |
e2f5df36 RL |
390 | { PROV_NAMES_ED25519, "provider=default", ossl_ed25519_signature_functions }, |
391 | { PROV_NAMES_ED448, "provider=default", ossl_ed448_signature_functions }, | |
392 | { PROV_NAMES_ECDSA, "provider=default", ossl_ecdsa_signature_functions }, | |
d0b79f86 | 393 | # ifndef OPENSSL_NO_SM2 |
e2f5df36 | 394 | { PROV_NAMES_SM2, "provider=default", ossl_sm2_signature_functions }, |
d0b79f86 | 395 | # endif |
3965480c | 396 | #endif |
e2f5df36 RL |
397 | { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_hmac_signature_functions }, |
398 | { PROV_NAMES_SIPHASH, "provider=default", | |
1be63951 | 399 | ossl_mac_legacy_siphash_signature_functions }, |
4db71d01 | 400 | #ifndef OPENSSL_NO_POLY1305 |
e2f5df36 | 401 | { PROV_NAMES_POLY1305, "provider=default", |
1be63951 | 402 | ossl_mac_legacy_poly1305_signature_functions }, |
a540ef90 MC |
403 | #endif |
404 | #ifndef OPENSSL_NO_CMAC | |
e2f5df36 | 405 | { PROV_NAMES_CMAC, "provider=default", ossl_mac_legacy_cmac_signature_functions }, |
4db71d01 | 406 | #endif |
4889dadc MC |
407 | { NULL, NULL, NULL } |
408 | }; | |
409 | ||
89abd1b6 | 410 | static const OSSL_ALGORITHM deflt_asym_cipher[] = { |
e2f5df36 | 411 | { PROV_NAMES_RSA, "provider=default", ossl_rsa_asym_cipher_functions }, |
ce64d3ee | 412 | #ifndef OPENSSL_NO_SM2 |
e2f5df36 | 413 | { PROV_NAMES_SM2, "provider=default", ossl_sm2_asym_cipher_functions }, |
ce64d3ee | 414 | #endif |
89abd1b6 MC |
415 | { NULL, NULL, NULL } |
416 | }; | |
4889dadc | 417 | |
80f4fd18 | 418 | static const OSSL_ALGORITHM deflt_asym_kem[] = { |
e2f5df36 | 419 | { PROV_NAMES_RSA, "provider=default", ossl_rsa_asym_kem_functions }, |
78c44b05 | 420 | #ifndef OPENSSL_NO_EC |
421 | { PROV_NAMES_X25519, "provider=default", ossl_ecx_asym_kem_functions }, | |
422 | { PROV_NAMES_X448, "provider=default", ossl_ecx_asym_kem_functions }, | |
423 | { PROV_NAMES_EC, "provider=default", ossl_ec_asym_kem_functions }, | |
424 | #endif | |
80f4fd18 SL |
425 | { NULL, NULL, NULL } |
426 | }; | |
427 | ||
8b84b075 RL |
428 | static const OSSL_ALGORITHM deflt_keymgmt[] = { |
429 | #ifndef OPENSSL_NO_DH | |
e2f5df36 RL |
430 | { PROV_NAMES_DH, "provider=default", ossl_dh_keymgmt_functions, |
431 | PROV_DESCS_DH }, | |
432 | { PROV_NAMES_DHX, "provider=default", ossl_dhx_keymgmt_functions, | |
433 | PROV_DESCS_DHX }, | |
4889dadc MC |
434 | #endif |
435 | #ifndef OPENSSL_NO_DSA | |
e2f5df36 RL |
436 | { PROV_NAMES_DSA, "provider=default", ossl_dsa_keymgmt_functions, |
437 | PROV_DESCS_DSA}, | |
76ca35e7 | 438 | #endif |
e2f5df36 RL |
439 | { PROV_NAMES_RSA, "provider=default", ossl_rsa_keymgmt_functions, |
440 | PROV_DESCS_RSA }, | |
441 | { PROV_NAMES_RSA_PSS, "provider=default", ossl_rsapss_keymgmt_functions, | |
442 | PROV_DESCS_RSA_PSS }, | |
90d3cb57 | 443 | #ifndef OPENSSL_NO_EC |
e2f5df36 RL |
444 | { PROV_NAMES_EC, "provider=default", ossl_ec_keymgmt_functions, |
445 | PROV_DESCS_EC }, | |
446 | { PROV_NAMES_X25519, "provider=default", ossl_x25519_keymgmt_functions, | |
447 | PROV_DESCS_X25519 }, | |
448 | { PROV_NAMES_X448, "provider=default", ossl_x448_keymgmt_functions, | |
449 | PROV_DESCS_X448 }, | |
450 | { PROV_NAMES_ED25519, "provider=default", ossl_ed25519_keymgmt_functions, | |
451 | PROV_DESCS_ED25519 }, | |
452 | { PROV_NAMES_ED448, "provider=default", ossl_ed448_keymgmt_functions, | |
453 | PROV_DESCS_ED448 }, | |
90d3cb57 | 454 | #endif |
e2f5df36 RL |
455 | { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_keymgmt_functions, |
456 | PROV_DESCS_TLS1_PRF_SIGN }, | |
457 | { PROV_NAMES_HKDF, "provider=default", ossl_kdf_keymgmt_functions, | |
458 | PROV_DESCS_HKDF_SIGN }, | |
459 | { PROV_NAMES_SCRYPT, "provider=default", ossl_kdf_keymgmt_functions, | |
460 | PROV_DESCS_SCRYPT_SIGN }, | |
461 | { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_keymgmt_functions, | |
462 | PROV_DESCS_HMAC_SIGN }, | |
463 | { PROV_NAMES_SIPHASH, "provider=default", ossl_mac_legacy_keymgmt_functions, | |
464 | PROV_DESCS_SIPHASH_SIGN }, | |
4db71d01 | 465 | #ifndef OPENSSL_NO_POLY1305 |
e2f5df36 RL |
466 | { PROV_NAMES_POLY1305, "provider=default", ossl_mac_legacy_keymgmt_functions, |
467 | PROV_DESCS_POLY1305_SIGN }, | |
a540ef90 MC |
468 | #endif |
469 | #ifndef OPENSSL_NO_CMAC | |
e2f5df36 RL |
470 | { PROV_NAMES_CMAC, "provider=default", ossl_cmac_legacy_keymgmt_functions, |
471 | PROV_DESCS_CMAC_SIGN }, | |
d0b79f86 | 472 | #endif |
7ee511d0 | 473 | #ifndef OPENSSL_NO_SM2 |
e2f5df36 RL |
474 | { PROV_NAMES_SM2, "provider=default", ossl_sm2_keymgmt_functions, |
475 | PROV_DESCS_SM2 }, | |
4db71d01 | 476 | #endif |
89e29174 MC |
477 | { NULL, NULL, NULL } |
478 | }; | |
479 | ||
ece9304c | 480 | static const OSSL_ALGORITHM deflt_encoder[] = { |
c319b627 | 481 | #define ENCODER_PROVIDER "default" |
ece9304c | 482 | #include "encoders.inc" |
1017b8e4 | 483 | { NULL, NULL, NULL } |
c319b627 | 484 | #undef ENCODER_PROVIDER |
1017b8e4 RL |
485 | }; |
486 | ||
ece9304c | 487 | static const OSSL_ALGORITHM deflt_decoder[] = { |
2c090c1d | 488 | #define DECODER_PROVIDER "default" |
ece9304c | 489 | #include "decoders.inc" |
677add38 | 490 | { NULL, NULL, NULL } |
2c090c1d | 491 | #undef DECODER_PROVIDER |
677add38 RL |
492 | }; |
493 | ||
63f187cf | 494 | static const OSSL_ALGORITHM deflt_store[] = { |
ce43db7a JS |
495 | #define STORE(name, _fips, func_table) \ |
496 | { name, "provider=default,fips=" _fips, (func_table) }, | |
63f187cf RL |
497 | |
498 | #include "stores.inc" | |
499 | { NULL, NULL, NULL } | |
500 | #undef STORE | |
501 | }; | |
502 | ||
fdaad3f1 | 503 | static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id, |
de29ff17 MC |
504 | int *no_cache) |
505 | { | |
506 | *no_cache = 0; | |
507 | switch (operation_id) { | |
508 | case OSSL_OP_DIGEST: | |
509 | return deflt_digests; | |
aab26e6f | 510 | case OSSL_OP_CIPHER: |
0d2bfe52 | 511 | return exported_ciphers; |
55a0a117 RL |
512 | case OSSL_OP_MAC: |
513 | return deflt_macs; | |
e3405a4a P |
514 | case OSSL_OP_KDF: |
515 | return deflt_kdfs; | |
bcc4ae67 P |
516 | case OSSL_OP_RAND: |
517 | return deflt_rands; | |
8b84b075 RL |
518 | case OSSL_OP_KEYMGMT: |
519 | return deflt_keymgmt; | |
89e29174 MC |
520 | case OSSL_OP_KEYEXCH: |
521 | return deflt_keyexch; | |
4889dadc MC |
522 | case OSSL_OP_SIGNATURE: |
523 | return deflt_signature; | |
89abd1b6 MC |
524 | case OSSL_OP_ASYM_CIPHER: |
525 | return deflt_asym_cipher; | |
80f4fd18 SL |
526 | case OSSL_OP_KEM: |
527 | return deflt_asym_kem; | |
ece9304c RL |
528 | case OSSL_OP_ENCODER: |
529 | return deflt_encoder; | |
530 | case OSSL_OP_DECODER: | |
531 | return deflt_decoder; | |
63f187cf RL |
532 | case OSSL_OP_STORE: |
533 | return deflt_store; | |
de29ff17 MC |
534 | } |
535 | return NULL; | |
536 | } | |
537 | ||
72bfc958 | 538 | |
78906fff RL |
539 | static void deflt_teardown(void *provctx) |
540 | { | |
7d6766cb P |
541 | BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(provctx)); |
542 | ossl_prov_ctx_free(provctx); | |
78906fff RL |
543 | } |
544 | ||
8a73348b MC |
545 | /* Functions we provide to the core */ |
546 | static const OSSL_DISPATCH deflt_dispatch_table[] = { | |
78906fff | 547 | { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown }, |
dca97d00 | 548 | { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params }, |
8a73348b | 549 | { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params }, |
de29ff17 | 550 | { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query }, |
c8830891 SL |
551 | { OSSL_FUNC_PROVIDER_GET_CAPABILITIES, |
552 | (void (*)(void))ossl_prov_get_capabilities }, | |
8a73348b MC |
553 | { 0, NULL } |
554 | }; | |
555 | ||
556 | OSSL_provider_init_fn ossl_default_provider_init; | |
557 | ||
d40b42ab | 558 | int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle, |
8a73348b | 559 | const OSSL_DISPATCH *in, |
a39eb840 RL |
560 | const OSSL_DISPATCH **out, |
561 | void **provctx) | |
8a73348b | 562 | { |
a829b735 | 563 | OSSL_FUNC_core_get_libctx_fn *c_get_libctx = NULL; |
d40b42ab | 564 | BIO_METHOD *corebiometh; |
8013a933 | 565 | |
08edd447 P |
566 | if (!ossl_prov_bio_from_dispatch(in) |
567 | || !ossl_prov_seeding_from_dispatch(in)) | |
63665fff | 568 | return 0; |
8a73348b MC |
569 | for (; in->function_id != 0; in++) { |
570 | switch (in->function_id) { | |
dca97d00 | 571 | case OSSL_FUNC_CORE_GETTABLE_PARAMS: |
363b1e5d | 572 | c_gettable_params = OSSL_FUNC_core_gettable_params(in); |
8a73348b MC |
573 | break; |
574 | case OSSL_FUNC_CORE_GET_PARAMS: | |
363b1e5d | 575 | c_get_params = OSSL_FUNC_core_get_params(in); |
8a73348b | 576 | break; |
a829b735 DMSP |
577 | case OSSL_FUNC_CORE_GET_LIBCTX: |
578 | c_get_libctx = OSSL_FUNC_core_get_libctx(in); | |
8013a933 | 579 | break; |
8a73348b MC |
580 | default: |
581 | /* Just ignore anything we don't understand */ | |
582 | break; | |
583 | } | |
584 | } | |
585 | ||
8013a933 RL |
586 | if (c_get_libctx == NULL) |
587 | return 0; | |
588 | ||
8013a933 RL |
589 | /* |
590 | * We want to make sure that all calls from this provider that requires | |
591 | * a library context use the same context as the one used to call our | |
d40b42ab | 592 | * functions. We do that by passing it along in the provider context. |
78906fff | 593 | * |
d40b42ab | 594 | * This only works for built-in providers. Most providers should |
78906fff | 595 | * create their own library context. |
8013a933 | 596 | */ |
7d6766cb | 597 | if ((*provctx = ossl_prov_ctx_new()) == NULL |
9500c823 | 598 | || (corebiometh = ossl_bio_prov_init_bio_method()) == NULL) { |
7d6766cb | 599 | ossl_prov_ctx_free(*provctx); |
d40b42ab | 600 | *provctx = NULL; |
78906fff | 601 | return 0; |
d40b42ab | 602 | } |
a829b735 | 603 | ossl_prov_ctx_set0_libctx(*provctx, |
b4250010 | 604 | (OSSL_LIB_CTX *)c_get_libctx(handle)); |
7d6766cb P |
605 | ossl_prov_ctx_set0_handle(*provctx, handle); |
606 | ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh); | |
78906fff RL |
607 | |
608 | *out = deflt_dispatch_table; | |
b233ea82 | 609 | ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers); |
78906fff | 610 | |
8a73348b MC |
611 | return 1; |
612 | } |