]> git.ipfire.org Git - thirdparty/openssl.git/blob - providers/defltprov.c
Implement provider-side keymgmt_dup function
[thirdparty/openssl.git] / providers / defltprov.c
1 /*
2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
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>
12 #include <openssl/opensslconf.h>
13 #include <openssl/core.h>
14 #include <openssl/core_dispatch.h>
15 #include <openssl/core_names.h>
16 #include <openssl/params.h>
17 #include "prov/bio.h"
18 #include "prov/provider_ctx.h"
19 #include "prov/providercommon.h"
20 #include "prov/implementations.h"
21 #include "prov/provider_util.h"
22 #include "prov/seeding.h"
23 #include "internal/nelem.h"
24
25 /*
26 * Forward declarations to ensure that interface functions are correctly
27 * defined.
28 */
29 static OSSL_FUNC_provider_gettable_params_fn deflt_gettable_params;
30 static OSSL_FUNC_provider_get_params_fn deflt_get_params;
31 static OSSL_FUNC_provider_query_operation_fn deflt_query;
32
33 #define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK }
34 #define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
35
36 /* Functions provided by the core */
37 static OSSL_FUNC_core_gettable_params_fn *c_gettable_params = NULL;
38 static OSSL_FUNC_core_get_params_fn *c_get_params = NULL;
39
40 /* Parameters we provide to the core */
41 static const OSSL_PARAM deflt_param_types[] = {
42 OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
43 OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
44 OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
45 OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
46 OSSL_PARAM_END
47 };
48
49 static const OSSL_PARAM *deflt_gettable_params(void *provctx)
50 {
51 return deflt_param_types;
52 }
53
54 static int deflt_get_params(void *provctx, OSSL_PARAM params[])
55 {
56 OSSL_PARAM *p;
57
58 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
59 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider"))
60 return 0;
61 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
62 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
63 return 0;
64 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
65 if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
66 return 0;
67 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
68 if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
69 return 0;
70 return 1;
71 }
72
73 /*
74 * For the algorithm names, we use the following formula for our primary
75 * names:
76 *
77 * ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
78 *
79 * VERSION is only present if there are multiple versions of
80 * an alg (MD2, MD4, MD5). It may be omitted if there is only
81 * one version (if a subsequent version is released in the future,
82 * we can always change the canonical name, and add the old name
83 * as an alias).
84 *
85 * SUBNAME may be present where we are combining multiple
86 * algorithms together, e.g. MD5-SHA1.
87 *
88 * SIZE is only present if multiple versions of an algorithm exist
89 * with different sizes (e.g. AES-128-CBC, AES-256-CBC)
90 *
91 * MODE is only present where applicable.
92 *
93 * We add diverse other names where applicable, such as the names that
94 * NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names
95 * we have used historically.
96 *
97 * Algorithm names are case insensitive, but we use all caps in our "canonical"
98 * names for consistency.
99 */
100 static const OSSL_ALGORITHM deflt_digests[] = {
101 /* Our primary name:NIST name[:our older names] */
102 { "SHA1:SHA-1:SSL3-SHA1", "provider=default", ossl_sha1_functions },
103 { "SHA2-224:SHA-224:SHA224", "provider=default", ossl_sha224_functions },
104 { "SHA2-256:SHA-256:SHA256", "provider=default", ossl_sha256_functions },
105 { "SHA2-384:SHA-384:SHA384", "provider=default", ossl_sha384_functions },
106 { "SHA2-512:SHA-512:SHA512", "provider=default", ossl_sha512_functions },
107 { "SHA2-512/224:SHA-512/224:SHA512-224", "provider=default",
108 ossl_sha512_224_functions },
109 { "SHA2-512/256:SHA-512/256:SHA512-256", "provider=default",
110 ossl_sha512_256_functions },
111
112 /* We agree with NIST here, so one name only */
113 { "SHA3-224", "provider=default", ossl_sha3_224_functions },
114 { "SHA3-256", "provider=default", ossl_sha3_256_functions },
115 { "SHA3-384", "provider=default", ossl_sha3_384_functions },
116 { "SHA3-512", "provider=default", ossl_sha3_512_functions },
117
118 /*
119 * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for
120 * the KMAC-128 and KMAC-256.
121 */
122 { "KECCAK-KMAC-128:KECCAK-KMAC128", "provider=default",
123 ossl_keccak_kmac_128_functions },
124 { "KECCAK-KMAC-256:KECCAK-KMAC256", "provider=default",
125 ossl_keccak_kmac_256_functions },
126
127 /* Our primary name:NIST name */
128 { "SHAKE-128:SHAKE128", "provider=default", ossl_shake_128_functions },
129 { "SHAKE-256:SHAKE256", "provider=default", ossl_shake_256_functions },
130
131 #ifndef OPENSSL_NO_BLAKE2
132 /*
133 * https://blake2.net/ doesn't specify size variants,
134 * but mentions that Bouncy Castle uses the names
135 * BLAKE2b-160, BLAKE2b-256, BLAKE2b-384, and BLAKE2b-512
136 * If we assume that "2b" and "2s" are versions, that pattern
137 * fits with ours. We also add our historical names.
138 */
139 { "BLAKE2S-256:BLAKE2s256", "provider=default", ossl_blake2s256_functions },
140 { "BLAKE2B-512:BLAKE2b512", "provider=default", ossl_blake2b512_functions },
141 #endif /* OPENSSL_NO_BLAKE2 */
142
143 #ifndef OPENSSL_NO_SM3
144 { "SM3", "provider=default", ossl_sm3_functions },
145 #endif /* OPENSSL_NO_SM3 */
146
147 #ifndef OPENSSL_NO_MD5
148 { "MD5:SSL3-MD5", "provider=default", ossl_md5_functions },
149 { "MD5-SHA1", "provider=default", ossl_md5_sha1_functions },
150 #endif /* OPENSSL_NO_MD5 */
151
152 { NULL, NULL, NULL }
153 };
154
155 static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
156 ALG("NULL", ossl_null_functions),
157 ALG("AES-256-ECB", ossl_aes256ecb_functions),
158 ALG("AES-192-ECB", ossl_aes192ecb_functions),
159 ALG("AES-128-ECB", ossl_aes128ecb_functions),
160 ALG("AES-256-CBC:AES256", ossl_aes256cbc_functions),
161 ALG("AES-192-CBC:AES192", ossl_aes192cbc_functions),
162 ALG("AES-128-CBC:AES128", ossl_aes128cbc_functions),
163 ALG("AES-128-CBC-CTS", ossl_aes128cbc_cts_functions),
164 ALG("AES-192-CBC-CTS", ossl_aes192cbc_cts_functions),
165 ALG("AES-256-CBC-CTS", ossl_aes256cbc_cts_functions),
166 ALG("AES-256-OFB", ossl_aes256ofb_functions),
167 ALG("AES-192-OFB", ossl_aes192ofb_functions),
168 ALG("AES-128-OFB", ossl_aes128ofb_functions),
169 ALG("AES-256-CFB", ossl_aes256cfb_functions),
170 ALG("AES-192-CFB", ossl_aes192cfb_functions),
171 ALG("AES-128-CFB", ossl_aes128cfb_functions),
172 ALG("AES-256-CFB1", ossl_aes256cfb1_functions),
173 ALG("AES-192-CFB1", ossl_aes192cfb1_functions),
174 ALG("AES-128-CFB1", ossl_aes128cfb1_functions),
175 ALG("AES-256-CFB8", ossl_aes256cfb8_functions),
176 ALG("AES-192-CFB8", ossl_aes192cfb8_functions),
177 ALG("AES-128-CFB8", ossl_aes128cfb8_functions),
178 ALG("AES-256-CTR", ossl_aes256ctr_functions),
179 ALG("AES-192-CTR", ossl_aes192ctr_functions),
180 ALG("AES-128-CTR", ossl_aes128ctr_functions),
181 ALG("AES-256-XTS", ossl_aes256xts_functions),
182 ALG("AES-128-XTS", ossl_aes128xts_functions),
183 #ifndef OPENSSL_NO_OCB
184 ALG("AES-256-OCB", ossl_aes256ocb_functions),
185 ALG("AES-192-OCB", ossl_aes192ocb_functions),
186 ALG("AES-128-OCB", ossl_aes128ocb_functions),
187 #endif /* OPENSSL_NO_OCB */
188 #ifndef OPENSSL_NO_SIV
189 ALG("AES-128-SIV", ossl_aes128siv_functions),
190 ALG("AES-192-SIV", ossl_aes192siv_functions),
191 ALG("AES-256-SIV", ossl_aes256siv_functions),
192 #endif /* OPENSSL_NO_SIV */
193 ALG("AES-256-GCM:id-aes256-GCM", ossl_aes256gcm_functions),
194 ALG("AES-192-GCM:id-aes192-GCM", ossl_aes192gcm_functions),
195 ALG("AES-128-GCM:id-aes128-GCM", ossl_aes128gcm_functions),
196 ALG("AES-256-CCM:id-aes256-CCM", ossl_aes256ccm_functions),
197 ALG("AES-192-CCM:id-aes192-CCM", ossl_aes192ccm_functions),
198 ALG("AES-128-CCM:id-aes128-CCM", ossl_aes128ccm_functions),
199 ALG("AES-256-WRAP:id-aes256-wrap:AES256-WRAP", ossl_aes256wrap_functions),
200 ALG("AES-192-WRAP:id-aes192-wrap:AES192-WRAP", ossl_aes192wrap_functions),
201 ALG("AES-128-WRAP:id-aes128-wrap:AES128-WRAP", ossl_aes128wrap_functions),
202 ALG("AES-256-WRAP-PAD:id-aes256-wrap-pad:AES256-WRAP-PAD",
203 ossl_aes256wrappad_functions),
204 ALG("AES-192-WRAP-PAD:id-aes192-wrap-pad:AES192-WRAP-PAD",
205 ossl_aes192wrappad_functions),
206 ALG("AES-128-WRAP-PAD:id-aes128-wrap-pad:AES128-WRAP-PAD",
207 ossl_aes128wrappad_functions),
208 ALG("AES-256-WRAP-INV:AES256-WRAP-INV", ossl_aes256wrapinv_functions),
209 ALG("AES-192-WRAP-INV:AES192-WRAP-INV", ossl_aes192wrapinv_functions),
210 ALG("AES-128-WRAP-INV:AES128-WRAP-INV", ossl_aes128wrapinv_functions),
211 ALG("AES-256-WRAP-PAD-INV:AES256-WRAP-PAD-INV",
212 ossl_aes256wrappadinv_functions),
213 ALG("AES-192-WRAP-PAD-INV:AES192-WRAP-PAD-INV",
214 ossl_aes192wrappadinv_functions),
215 ALG("AES-128-WRAP-PAD-INV:AES128-WRAP-PAD-INV",
216 ossl_aes128wrappadinv_functions),
217 ALGC("AES-128-CBC-HMAC-SHA1", ossl_aes128cbc_hmac_sha1_functions,
218 ossl_cipher_capable_aes_cbc_hmac_sha1),
219 ALGC("AES-256-CBC-HMAC-SHA1", ossl_aes256cbc_hmac_sha1_functions,
220 ossl_cipher_capable_aes_cbc_hmac_sha1),
221 ALGC("AES-128-CBC-HMAC-SHA256", ossl_aes128cbc_hmac_sha256_functions,
222 ossl_cipher_capable_aes_cbc_hmac_sha256),
223 ALGC("AES-256-CBC-HMAC-SHA256", ossl_aes256cbc_hmac_sha256_functions,
224 ossl_cipher_capable_aes_cbc_hmac_sha256),
225 #ifndef OPENSSL_NO_ARIA
226 ALG("ARIA-256-GCM", ossl_aria256gcm_functions),
227 ALG("ARIA-192-GCM", ossl_aria192gcm_functions),
228 ALG("ARIA-128-GCM", ossl_aria128gcm_functions),
229 ALG("ARIA-256-CCM", ossl_aria256ccm_functions),
230 ALG("ARIA-192-CCM", ossl_aria192ccm_functions),
231 ALG("ARIA-128-CCM", ossl_aria128ccm_functions),
232 ALG("ARIA-256-ECB", ossl_aria256ecb_functions),
233 ALG("ARIA-192-ECB", ossl_aria192ecb_functions),
234 ALG("ARIA-128-ECB", ossl_aria128ecb_functions),
235 ALG("ARIA-256-CBC:ARIA256", ossl_aria256cbc_functions),
236 ALG("ARIA-192-CBC:ARIA192", ossl_aria192cbc_functions),
237 ALG("ARIA-128-CBC:ARIA128", ossl_aria128cbc_functions),
238 ALG("ARIA-256-OFB", ossl_aria256ofb_functions),
239 ALG("ARIA-192-OFB", ossl_aria192ofb_functions),
240 ALG("ARIA-128-OFB", ossl_aria128ofb_functions),
241 ALG("ARIA-256-CFB", ossl_aria256cfb_functions),
242 ALG("ARIA-192-CFB", ossl_aria192cfb_functions),
243 ALG("ARIA-128-CFB", ossl_aria128cfb_functions),
244 ALG("ARIA-256-CFB1", ossl_aria256cfb1_functions),
245 ALG("ARIA-192-CFB1", ossl_aria192cfb1_functions),
246 ALG("ARIA-128-CFB1", ossl_aria128cfb1_functions),
247 ALG("ARIA-256-CFB8", ossl_aria256cfb8_functions),
248 ALG("ARIA-192-CFB8", ossl_aria192cfb8_functions),
249 ALG("ARIA-128-CFB8", ossl_aria128cfb8_functions),
250 ALG("ARIA-256-CTR", ossl_aria256ctr_functions),
251 ALG("ARIA-192-CTR", ossl_aria192ctr_functions),
252 ALG("ARIA-128-CTR", ossl_aria128ctr_functions),
253 #endif /* OPENSSL_NO_ARIA */
254 #ifndef OPENSSL_NO_CAMELLIA
255 ALG("CAMELLIA-256-ECB", ossl_camellia256ecb_functions),
256 ALG("CAMELLIA-192-ECB", ossl_camellia192ecb_functions),
257 ALG("CAMELLIA-128-ECB", ossl_camellia128ecb_functions),
258 ALG("CAMELLIA-256-CBC:CAMELLIA256", ossl_camellia256cbc_functions),
259 ALG("CAMELLIA-192-CBC:CAMELLIA192", ossl_camellia192cbc_functions),
260 ALG("CAMELLIA-128-CBC:CAMELLIA128", ossl_camellia128cbc_functions),
261 ALG("CAMELLIA-256-OFB", ossl_camellia256ofb_functions),
262 ALG("CAMELLIA-192-OFB", ossl_camellia192ofb_functions),
263 ALG("CAMELLIA-128-OFB", ossl_camellia128ofb_functions),
264 ALG("CAMELLIA-256-CFB", ossl_camellia256cfb_functions),
265 ALG("CAMELLIA-192-CFB", ossl_camellia192cfb_functions),
266 ALG("CAMELLIA-128-CFB", ossl_camellia128cfb_functions),
267 ALG("CAMELLIA-256-CFB1", ossl_camellia256cfb1_functions),
268 ALG("CAMELLIA-192-CFB1", ossl_camellia192cfb1_functions),
269 ALG("CAMELLIA-128-CFB1", ossl_camellia128cfb1_functions),
270 ALG("CAMELLIA-256-CFB8", ossl_camellia256cfb8_functions),
271 ALG("CAMELLIA-192-CFB8", ossl_camellia192cfb8_functions),
272 ALG("CAMELLIA-128-CFB8", ossl_camellia128cfb8_functions),
273 ALG("CAMELLIA-256-CTR", ossl_camellia256ctr_functions),
274 ALG("CAMELLIA-192-CTR", ossl_camellia192ctr_functions),
275 ALG("CAMELLIA-128-CTR", ossl_camellia128ctr_functions),
276 #endif /* OPENSSL_NO_CAMELLIA */
277 #ifndef OPENSSL_NO_DES
278 ALG("DES-EDE3-ECB:DES-EDE3", ossl_tdes_ede3_ecb_functions),
279 ALG("DES-EDE3-CBC:DES3", ossl_tdes_ede3_cbc_functions),
280 ALG("DES-EDE3-OFB", ossl_tdes_ede3_ofb_functions),
281 ALG("DES-EDE3-CFB", ossl_tdes_ede3_cfb_functions),
282 ALG("DES-EDE3-CFB8", ossl_tdes_ede3_cfb8_functions),
283 ALG("DES-EDE3-CFB1", ossl_tdes_ede3_cfb1_functions),
284 ALG("DES3-WRAP:id-smime-alg-CMS3DESwrap", ossl_tdes_wrap_cbc_functions),
285 ALG("DES-EDE-ECB:DES-EDE", ossl_tdes_ede2_ecb_functions),
286 ALG("DES-EDE-CBC", ossl_tdes_ede2_cbc_functions),
287 ALG("DES-EDE-OFB", ossl_tdes_ede2_ofb_functions),
288 ALG("DES-EDE-CFB", ossl_tdes_ede2_cfb_functions),
289 #endif /* OPENSSL_NO_DES */
290 #ifndef OPENSSL_NO_SM4
291 ALG("SM4-ECB", ossl_sm4128ecb_functions),
292 ALG("SM4-CBC:SM4", ossl_sm4128cbc_functions),
293 ALG("SM4-CTR", ossl_sm4128ctr_functions),
294 ALG("SM4-OFB:SM4-OFB128", ossl_sm4128ofb128_functions),
295 ALG("SM4-CFB:SM4-CFB128", ossl_sm4128cfb128_functions),
296 #endif /* OPENSSL_NO_SM4 */
297 #ifndef OPENSSL_NO_CHACHA
298 ALG("ChaCha20", ossl_chacha20_functions),
299 # ifndef OPENSSL_NO_POLY1305
300 ALG("ChaCha20-Poly1305", ossl_chacha20_ossl_poly1305_functions),
301 # endif /* OPENSSL_NO_POLY1305 */
302 #endif /* OPENSSL_NO_CHACHA */
303 { { NULL, NULL, NULL }, NULL }
304 };
305 static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)];
306
307 static const OSSL_ALGORITHM deflt_macs[] = {
308 #ifndef OPENSSL_NO_BLAKE2
309 { "BLAKE2BMAC", "provider=default", ossl_blake2bmac_functions },
310 { "BLAKE2SMAC", "provider=default", ossl_blake2smac_functions },
311 #endif
312 #ifndef OPENSSL_NO_CMAC
313 { "CMAC", "provider=default", ossl_cmac_functions },
314 #endif
315 { "GMAC", "provider=default", ossl_gmac_functions },
316 { "HMAC", "provider=default", ossl_hmac_functions },
317 { "KMAC-128:KMAC128", "provider=default", ossl_kmac128_functions },
318 { "KMAC-256:KMAC256", "provider=default", ossl_kmac256_functions },
319 #ifndef OPENSSL_NO_SIPHASH
320 { "SIPHASH", "provider=default", ossl_siphash_functions },
321 #endif
322 #ifndef OPENSSL_NO_POLY1305
323 { "POLY1305", "provider=default", ossl_poly1305_functions },
324 #endif
325 { NULL, NULL, NULL }
326 };
327
328 static const OSSL_ALGORITHM deflt_kdfs[] = {
329 { "HKDF", "provider=default", ossl_kdf_hkdf_functions },
330 { "SSKDF", "provider=default", ossl_kdf_sskdf_functions },
331 { "PBKDF2", "provider=default", ossl_kdf_pbkdf2_functions },
332 { "PKCS12KDF", "provider=default", ossl_kdf_pkcs12_functions },
333 { "SSHKDF", "provider=default", ossl_kdf_sshkdf_functions },
334 { "X963KDF:X942KDF-CONCAT", "provider=default", ossl_kdf_x963_kdf_functions },
335 { "TLS1-PRF", "provider=default", ossl_kdf_tls1_prf_functions },
336 { "KBKDF", "provider=default", ossl_kdf_kbkdf_functions },
337 { "X942KDF-ASN1:X942KDF", "provider=default", ossl_kdf_x942_kdf_functions },
338 #ifndef OPENSSL_NO_SCRYPT
339 { "SCRYPT:id-scrypt", "provider=default", ossl_kdf_scrypt_functions },
340 #endif
341 { "KRB5KDF", "provider=default", ossl_kdf_krb5kdf_functions },
342 { NULL, NULL, NULL }
343 };
344
345 static const OSSL_ALGORITHM deflt_keyexch[] = {
346 #ifndef OPENSSL_NO_DH
347 { "DH:dhKeyAgreement", "provider=default", ossl_dh_keyexch_functions },
348 #endif
349 #ifndef OPENSSL_NO_EC
350 { "ECDH", "provider=default", ossl_ecdh_keyexch_functions },
351 { "X25519", "provider=default", ossl_x25519_keyexch_functions },
352 { "X448", "provider=default", ossl_x448_keyexch_functions },
353 #endif
354 { "TLS1-PRF", "provider=default", ossl_kdf_tls1_prf_keyexch_functions },
355 { "HKDF", "provider=default", ossl_kdf_hkdf_keyexch_functions },
356 { "SCRYPT:id-scrypt", "provider=default",
357 ossl_kdf_scrypt_keyexch_functions },
358 { NULL, NULL, NULL }
359 };
360
361 static const OSSL_ALGORITHM deflt_rands[] = {
362 { "CTR-DRBG", "provider=default", ossl_drbg_ctr_functions },
363 { "HASH-DRBG", "provider=default", ossl_drbg_hash_functions },
364 { "HMAC-DRBG", "provider=default", ossl_drbg_ossl_hmac_functions },
365 { "SEED-SRC", "provider=default", ossl_seed_src_functions },
366 { "TEST-RAND", "provider=default", ossl_test_rng_functions },
367 { NULL, NULL, NULL }
368 };
369
370 static const OSSL_ALGORITHM deflt_signature[] = {
371 #ifndef OPENSSL_NO_DSA
372 { "DSA:dsaEncryption", "provider=default", ossl_dsa_signature_functions },
373 #endif
374 { "RSA:rsaEncryption", "provider=default", ossl_rsa_signature_functions },
375 #ifndef OPENSSL_NO_EC
376 { "ED25519", "provider=default", ossl_ed25519_signature_functions },
377 { "ED448", "provider=default", ossl_ed448_signature_functions },
378 { "ECDSA", "provider=default", ossl_ecdsa_signature_functions },
379 # ifndef OPENSSL_NO_SM2
380 { "SM2", "provider=default", ossl_sm2_signature_functions },
381 # endif
382 #endif
383 { "HMAC", "provider=default", ossl_mac_legacy_hmac_signature_functions },
384 { "SIPHASH", "provider=default",
385 ossl_mac_legacy_siphash_signature_functions },
386 #ifndef OPENSSL_NO_POLY1305
387 { "POLY1305", "provider=default",
388 ossl_mac_legacy_poly1305_signature_functions },
389 #endif
390 #ifndef OPENSSL_NO_CMAC
391 { "CMAC", "provider=default", ossl_mac_legacy_cmac_signature_functions },
392 #endif
393 { NULL, NULL, NULL }
394 };
395
396 static const OSSL_ALGORITHM deflt_asym_cipher[] = {
397 { "RSA:rsaEncryption", "provider=default", ossl_rsa_asym_cipher_functions },
398 #ifndef OPENSSL_NO_SM2
399 { "SM2", "provider=default", ossl_sm2_asym_cipher_functions },
400 #endif
401 { NULL, NULL, NULL }
402 };
403
404 static const OSSL_ALGORITHM deflt_asym_kem[] = {
405 { "RSA", "provider=default", ossl_rsa_asym_kem_functions },
406 { NULL, NULL, NULL }
407 };
408
409 static const OSSL_ALGORITHM deflt_keymgmt[] = {
410 #ifndef OPENSSL_NO_DH
411 { "DH:dhKeyAgreement", "provider=default", ossl_dh_keymgmt_functions,
412 "OpenSSL PKCS#3 DH implementation" },
413 { "DHX:X9.42 DH:dhpublicnumber", "provider=default",
414 ossl_dhx_keymgmt_functions, "OpenSSL X9.42 DH implementation" },
415 #endif
416 #ifndef OPENSSL_NO_DSA
417 { "DSA:dsaEncryption", "provider=default", ossl_dsa_keymgmt_functions,
418 "OpenSSL DSA implementation" },
419 #endif
420 { "RSA:rsaEncryption", "provider=default", ossl_rsa_keymgmt_functions,
421 "OpenSSL RSA implementation" },
422 { "RSA-PSS:RSASSA-PSS", "provider=default", ossl_rsapss_keymgmt_functions,
423 "OpenSSL RSA-PSS implementation" },
424 #ifndef OPENSSL_NO_EC
425 { "EC:id-ecPublicKey", "provider=default", ossl_ec_keymgmt_functions,
426 "OpenSSL EC implementation" },
427 { "X25519", "provider=default", ossl_x25519_keymgmt_functions,
428 "OpenSSL X25519 implementation" },
429 { "X448", "provider=default", ossl_x448_keymgmt_functions,
430 "OpenSSL X448 implementation" },
431 { "ED25519", "provider=default", ossl_ed25519_keymgmt_functions,
432 "OpenSSL ED25519 implementation" },
433 { "ED448", "provider=default", ossl_ed448_keymgmt_functions,
434 "OpenSSL ED448 implementation" },
435 #endif
436 { "TLS1-PRF", "provider=default", ossl_kdf_keymgmt_functions,
437 "OpenSSL TLS1-PRF via EVP_PKEY implementation" },
438 { "HKDF", "provider=default", ossl_kdf_keymgmt_functions,
439 "OpenSSL HKDF via EVP_PKEY implementation" },
440 { "SCRYPT:id-scrypt", "provider=default", ossl_kdf_keymgmt_functions,
441 "OpenSSL SCRYPT via EVP_PKEY implementation" },
442 { "HMAC", "provider=default", ossl_mac_legacy_keymgmt_functions,
443 "OpenSSL HMAC via EVP_PKEY implementation" },
444 { "SIPHASH", "provider=default", ossl_mac_legacy_keymgmt_functions,
445 "OpenSSL SIPHASH via EVP_PKEY implementation" },
446 #ifndef OPENSSL_NO_POLY1305
447 { "POLY1305", "provider=default", ossl_mac_legacy_keymgmt_functions,
448 "OpenSSL POLY1305 via EVP_PKEY implementation" },
449 #endif
450 #ifndef OPENSSL_NO_CMAC
451 { "CMAC", "provider=default", ossl_cossl_mac_legacy_keymgmt_functions,
452 "OpenSSL CMAC via EVP_PKEY implementation" },
453 #endif
454 #ifndef OPENSSL_NO_SM2
455 { "SM2", "provider=default", ossl_sm2_keymgmt_functions,
456 "OpenSSL SM2 implementation" },
457 #endif
458 { NULL, NULL, NULL }
459 };
460
461 static const OSSL_ALGORITHM deflt_encoder[] = {
462 #define ENCODER_PROVIDER "default"
463 #include "encoders.inc"
464 { NULL, NULL, NULL }
465 #undef ENCODER_PROVIDER
466 };
467
468 static const OSSL_ALGORITHM deflt_decoder[] = {
469 #define DECODER_PROVIDER "default"
470 #include "decoders.inc"
471 { NULL, NULL, NULL }
472 #undef DECODER_PROVIDER
473 };
474
475 static const OSSL_ALGORITHM deflt_store[] = {
476 #define STORE(name, _fips, func_table) \
477 { name, "provider=default,fips=" _fips, (func_table) },
478
479 #include "stores.inc"
480 { NULL, NULL, NULL }
481 #undef STORE
482 };
483
484 static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id,
485 int *no_cache)
486 {
487 *no_cache = 0;
488 switch (operation_id) {
489 case OSSL_OP_DIGEST:
490 return deflt_digests;
491 case OSSL_OP_CIPHER:
492 return exported_ciphers;
493 case OSSL_OP_MAC:
494 return deflt_macs;
495 case OSSL_OP_KDF:
496 return deflt_kdfs;
497 case OSSL_OP_RAND:
498 return deflt_rands;
499 case OSSL_OP_KEYMGMT:
500 return deflt_keymgmt;
501 case OSSL_OP_KEYEXCH:
502 return deflt_keyexch;
503 case OSSL_OP_SIGNATURE:
504 return deflt_signature;
505 case OSSL_OP_ASYM_CIPHER:
506 return deflt_asym_cipher;
507 case OSSL_OP_KEM:
508 return deflt_asym_kem;
509 case OSSL_OP_ENCODER:
510 return deflt_encoder;
511 case OSSL_OP_DECODER:
512 return deflt_decoder;
513 case OSSL_OP_STORE:
514 return deflt_store;
515 }
516 return NULL;
517 }
518
519
520 static void deflt_teardown(void *provctx)
521 {
522 BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(provctx));
523 ossl_prov_ctx_free(provctx);
524 }
525
526 /* Functions we provide to the core */
527 static const OSSL_DISPATCH deflt_dispatch_table[] = {
528 { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown },
529 { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params },
530 { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params },
531 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query },
532 { OSSL_FUNC_PROVIDER_GET_CAPABILITIES,
533 (void (*)(void))ossl_prov_get_capabilities },
534 { 0, NULL }
535 };
536
537 OSSL_provider_init_fn ossl_default_provider_init;
538
539 int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle,
540 const OSSL_DISPATCH *in,
541 const OSSL_DISPATCH **out,
542 void **provctx)
543 {
544 OSSL_FUNC_core_get_libctx_fn *c_get_libctx = NULL;
545 BIO_METHOD *corebiometh;
546
547 if (!ossl_prov_bio_from_dispatch(in)
548 || !ossl_prov_seeding_from_dispatch(in))
549 return 0;
550 for (; in->function_id != 0; in++) {
551 switch (in->function_id) {
552 case OSSL_FUNC_CORE_GETTABLE_PARAMS:
553 c_gettable_params = OSSL_FUNC_core_gettable_params(in);
554 break;
555 case OSSL_FUNC_CORE_GET_PARAMS:
556 c_get_params = OSSL_FUNC_core_get_params(in);
557 break;
558 case OSSL_FUNC_CORE_GET_LIBCTX:
559 c_get_libctx = OSSL_FUNC_core_get_libctx(in);
560 break;
561 default:
562 /* Just ignore anything we don't understand */
563 break;
564 }
565 }
566
567 if (c_get_libctx == NULL)
568 return 0;
569
570 /*
571 * We want to make sure that all calls from this provider that requires
572 * a library context use the same context as the one used to call our
573 * functions. We do that by passing it along in the provider context.
574 *
575 * This only works for built-in providers. Most providers should
576 * create their own library context.
577 */
578 if ((*provctx = ossl_prov_ctx_new()) == NULL
579 || (corebiometh = ossl_bio_prov_init_bio_method()) == NULL) {
580 ossl_prov_ctx_free(*provctx);
581 *provctx = NULL;
582 return 0;
583 }
584 ossl_prov_ctx_set0_libctx(*provctx,
585 (OSSL_LIB_CTX *)c_get_libctx(handle));
586 ossl_prov_ctx_set0_handle(*provctx, handle);
587 ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh);
588
589 *out = deflt_dispatch_table;
590 ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers);
591
592 return 1;
593 }