Move legacy ciphers into the legacy provider
[openssl.git] / providers / defltprov.c
1 /*
2  * Copyright 2019 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_numbers.h>
15 #include <openssl/core_names.h>
16 #include <openssl/params.h>
17 #include "prov/bio.h"
18 #include "prov/providercommon.h"
19 #include "prov/implementations.h"
20 #include "prov/provider_util.h"
21 #include "internal/nelem.h"
22
23 #define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK }
24 #define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
25
26 /* Functions provided by the core */
27 static OSSL_core_gettable_params_fn *c_gettable_params = NULL;
28 static OSSL_core_get_params_fn *c_get_params = NULL;
29
30 /* Parameters we provide to the core */
31 static const OSSL_PARAM deflt_param_types[] = {
32     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
33     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
34     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
35     OSSL_PARAM_END
36 };
37
38 static const OSSL_PARAM *deflt_gettable_params(const OSSL_PROVIDER *prov)
39 {
40     return deflt_param_types;
41 }
42
43 static int deflt_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
44 {
45     OSSL_PARAM *p;
46
47     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
48     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider"))
49         return 0;
50     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
51     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
52         return 0;
53     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
54     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
55         return 0;
56
57     return 1;
58 }
59
60 /*
61  * For the algorithm names, we use the following formula for our primary
62  * names:
63  *
64  *     ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
65  *
66  *     VERSION is only present if there are multiple versions of
67  *     an alg (MD2, MD4, MD5).  It may be omitted if there is only
68  *     one version (if a subsequent version is released in the future,
69  *     we can always change the canonical name, and add the old name
70  *     as an alias).
71  *
72  *     SUBNAME may be present where we are combining multiple
73  *     algorithms together, e.g. MD5-SHA1.
74  *
75  *     SIZE is only present if multiple versions of an algorithm exist
76  *     with different sizes (e.g. AES-128-CBC, AES-256-CBC)
77  *
78  *     MODE is only present where applicable.
79  *
80  * We add diverse other names where applicable, such as the names that
81  * NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names
82  * we have used historically.
83  *
84  * Algorithm names are case insensitive, but we use all caps in our "canonical"
85  * names for consistency.
86  */
87 static const OSSL_ALGORITHM deflt_digests[] = {
88     /* Our primary name:NIST name[:our older names] */
89     { "SHA1:SHA-1", "provider=default", sha1_functions },
90     { "SHA2-224:SHA-224:SHA224", "provider=default", sha224_functions },
91     { "SHA2-256:SHA-256:SHA256", "provider=default", sha256_functions },
92     { "SHA2-384:SHA-384:SHA384", "provider=default", sha384_functions },
93     { "SHA2-512:SHA-512:SHA512", "provider=default", sha512_functions },
94     { "SHA2-512/224:SHA-512/224:SHA512-224", "provider=default",
95       sha512_224_functions },
96     { "SHA2-512/256:SHA-512/256:SHA512-256", "provider=default",
97       sha512_256_functions },
98
99     /* We agree with NIST here, so one name only */
100     { "SHA3-224", "provider=default", sha3_224_functions },
101     { "SHA3-256", "provider=default", sha3_256_functions },
102     { "SHA3-384", "provider=default", sha3_384_functions },
103     { "SHA3-512", "provider=default", sha3_512_functions },
104
105     /*
106      * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for
107      * the KMAC-128 and KMAC-256.
108      */
109     { "KECCAK-KMAC-128:KECCAK-KMAC128", "provider=default", keccak_kmac_128_functions },
110     { "KECCAK-KMAC-256:KECCAK-KMAC256", "provider=default", keccak_kmac_256_functions },
111
112     /* Our primary name:NIST name */
113     { "SHAKE-128:SHAKE128", "provider=default", shake_128_functions },
114     { "SHAKE-256:SHAKE256", "provider=default", shake_256_functions },
115
116 #ifndef OPENSSL_NO_BLAKE2
117     /*
118      * https://blake2.net/ doesn't specify size variants,
119      * but mentions that Bouncy Castle uses the names
120      * BLAKE2b-160, BLAKE2b-256, BLAKE2b-384, and BLAKE2b-512
121      * If we assume that "2b" and "2s" are versions, that pattern
122      * fits with ours.  We also add our historical names.
123      */
124     { "BLAKE2S-256:BLAKE2s256", "provider=default", blake2s256_functions },
125     { "BLAKE2B-512:BLAKE2b512", "provider=default", blake2b512_functions },
126 #endif /* OPENSSL_NO_BLAKE2 */
127
128 #ifndef OPENSSL_NO_SM3
129     { "SM3", "provider=default", sm3_functions },
130 #endif /* OPENSSL_NO_SM3 */
131
132 #ifndef OPENSSL_NO_MD5
133     { "MD5", "provider=default", md5_functions },
134     { "MD5-SHA1", "provider=default", md5_sha1_functions },
135 #endif /* OPENSSL_NO_MD5 */
136
137     { NULL, NULL, NULL }
138 };
139
140 static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
141     ALG("NULL", null_functions),
142     ALG("AES-256-ECB", aes256ecb_functions),
143     ALG("AES-192-ECB", aes192ecb_functions),
144     ALG("AES-128-ECB", aes128ecb_functions),
145     ALG("AES-256-CBC", aes256cbc_functions),
146     ALG("AES-192-CBC", aes192cbc_functions),
147     ALG("AES-128-CBC", aes128cbc_functions),
148     ALG("AES-256-OFB", aes256ofb_functions),
149     ALG("AES-192-OFB", aes192ofb_functions),
150     ALG("AES-128-OFB", aes128ofb_functions),
151     ALG("AES-256-CFB", aes256cfb_functions),
152     ALG("AES-192-CFB", aes192cfb_functions),
153     ALG("AES-128-CFB", aes128cfb_functions),
154     ALG("AES-256-CFB1", aes256cfb1_functions),
155     ALG("AES-192-CFB1", aes192cfb1_functions),
156     ALG("AES-128-CFB1", aes128cfb1_functions),
157     ALG("AES-256-CFB8", aes256cfb8_functions),
158     ALG("AES-192-CFB8", aes192cfb8_functions),
159     ALG("AES-128-CFB8", aes128cfb8_functions),
160     ALG("AES-256-CTR", aes256ctr_functions),
161     ALG("AES-192-CTR", aes192ctr_functions),
162     ALG("AES-128-CTR", aes128ctr_functions),
163     ALG("AES-256-XTS", aes256xts_functions),
164     ALG("AES-128-XTS", aes128xts_functions),
165 #ifndef OPENSSL_NO_OCB
166     ALG("AES-256-OCB", aes256ocb_functions),
167     ALG("AES-192-OCB", aes192ocb_functions),
168     ALG("AES-128-OCB", aes128ocb_functions),
169 #endif /* OPENSSL_NO_OCB */
170 #ifndef OPENSSL_NO_SIV
171     ALG("AES-128-SIV", aes128siv_functions),
172     ALG("AES-192-SIV", aes192siv_functions),
173     ALG("AES-256-SIV", aes256siv_functions),
174 #endif /* OPENSSL_NO_SIV */
175     ALG("AES-256-GCM:id-aes256-GCM", aes256gcm_functions),
176     ALG("AES-192-GCM:id-aes192-GCM", aes192gcm_functions),
177     ALG("AES-128-GCM:id-aes128-GCM", aes128gcm_functions),
178     ALG("AES-256-CCM:id-aes256-CCM", aes256ccm_functions),
179     ALG("AES-192-CCM:id-aes192-CCM", aes192ccm_functions),
180     ALG("AES-128-CCM:id-aes128-CCM", aes128ccm_functions),
181     ALG("AES-256-WRAP:id-aes256-wrap:AES256-WRAP", aes256wrap_functions),
182     ALG("AES-192-WRAP:id-aes192-wrap:AES192-WRAP", aes192wrap_functions),
183     ALG("AES-128-WRAP:id-aes128-wrap:AES128-WRAP", aes128wrap_functions),
184     ALG("AES-256-WRAP-PAD:id-aes256-wrap-pad:AES256-WRAP-PAD",
185         aes256wrappad_functions),
186     ALG("AES-192-WRAP-PAD:id-aes192-wrap-pad:AES192-WRAP-PAD",
187         aes192wrappad_functions),
188     ALG("AES-128-WRAP-PAD:id-aes128-wrap-pad:AES128-WRAP-PAD",
189         aes128wrappad_functions),
190     ALGC("AES-128-CBC-HMAC-SHA1", aes128cbc_hmac_sha1_functions,
191          cipher_capable_aes_cbc_hmac_sha1),
192     ALGC("AES-256-CBC-HMAC-SHA1", aes256cbc_hmac_sha1_functions,
193          cipher_capable_aes_cbc_hmac_sha1),
194     ALGC("AES-128-CBC-HMAC-SHA256", aes128cbc_hmac_sha256_functions,
195         cipher_capable_aes_cbc_hmac_sha256),
196     ALGC("AES-256-CBC-HMAC-SHA256", aes256cbc_hmac_sha256_functions,
197          cipher_capable_aes_cbc_hmac_sha256),
198 #ifndef OPENSSL_NO_ARIA
199     ALG("ARIA-256-GCM", aria256gcm_functions),
200     ALG("ARIA-192-GCM", aria192gcm_functions),
201     ALG("ARIA-128-GCM", aria128gcm_functions),
202     ALG("ARIA-256-CCM", aria256ccm_functions),
203     ALG("ARIA-192-CCM", aria192ccm_functions),
204     ALG("ARIA-128-CCM", aria128ccm_functions),
205     ALG("ARIA-256-ECB", aria256ecb_functions),
206     ALG("ARIA-192-ECB", aria192ecb_functions),
207     ALG("ARIA-128-ECB", aria128ecb_functions),
208     ALG("ARIA-256-CBC:ARIA256", aria256cbc_functions),
209     ALG("ARIA-192-CBC:ARIA192", aria192cbc_functions),
210     ALG("ARIA-128-CBC:ARIA128", aria128cbc_functions),
211     ALG("ARIA-256-OFB", aria256ofb_functions),
212     ALG("ARIA-192-OFB", aria192ofb_functions),
213     ALG("ARIA-128-OFB", aria128ofb_functions),
214     ALG("ARIA-256-CFB", aria256cfb_functions),
215     ALG("ARIA-192-CFB", aria192cfb_functions),
216     ALG("ARIA-128-CFB", aria128cfb_functions),
217     ALG("ARIA-256-CFB1", aria256cfb1_functions),
218     ALG("ARIA-192-CFB1", aria192cfb1_functions),
219     ALG("ARIA-128-CFB1", aria128cfb1_functions),
220     ALG("ARIA-256-CFB8", aria256cfb8_functions),
221     ALG("ARIA-192-CFB8", aria192cfb8_functions),
222     ALG("ARIA-128-CFB8", aria128cfb8_functions),
223     ALG("ARIA-256-CTR", aria256ctr_functions),
224     ALG("ARIA-192-CTR", aria192ctr_functions),
225     ALG("ARIA-128-CTR", aria128ctr_functions),
226 #endif /* OPENSSL_NO_ARIA */
227 #ifndef OPENSSL_NO_CAMELLIA
228     ALG("CAMELLIA-256-ECB", camellia256ecb_functions),
229     ALG("CAMELLIA-192-ECB", camellia192ecb_functions),
230     ALG("CAMELLIA-128-ECB", camellia128ecb_functions),
231     ALG("CAMELLIA-256-CBC:CAMELLIA256", camellia256cbc_functions),
232     ALG("CAMELLIA-192-CBC:CAMELLIA192", camellia192cbc_functions),
233     ALG("CAMELLIA-128-CBC:CAMELLIA128", camellia128cbc_functions),
234     ALG("CAMELLIA-256-OFB", camellia256ofb_functions),
235     ALG("CAMELLIA-192-OFB", camellia192ofb_functions),
236     ALG("CAMELLIA-128-OFB", camellia128ofb_functions),
237     ALG("CAMELLIA-256-CFB", camellia256cfb_functions),
238     ALG("CAMELLIA-192-CFB", camellia192cfb_functions),
239     ALG("CAMELLIA-128-CFB", camellia128cfb_functions),
240     ALG("CAMELLIA-256-CFB1", camellia256cfb1_functions),
241     ALG("CAMELLIA-192-CFB1", camellia192cfb1_functions),
242     ALG("CAMELLIA-128-CFB1", camellia128cfb1_functions),
243     ALG("CAMELLIA-256-CFB8", camellia256cfb8_functions),
244     ALG("CAMELLIA-192-CFB8", camellia192cfb8_functions),
245     ALG("CAMELLIA-128-CFB8", camellia128cfb8_functions),
246     ALG("CAMELLIA-256-CTR", camellia256ctr_functions),
247     ALG("CAMELLIA-192-CTR", camellia192ctr_functions),
248     ALG("CAMELLIA-128-CTR", camellia128ctr_functions),
249 #endif /* OPENSSL_NO_CAMELLIA */
250 #ifndef OPENSSL_NO_DES
251     ALG("DES-EDE3-ECB:DES-EDE3", tdes_ede3_ecb_functions),
252     ALG("DES-EDE3-CBC:DES3", tdes_ede3_cbc_functions),
253     ALG("DES-EDE3-OFB", tdes_ede3_ofb_functions),
254     ALG("DES-EDE3-CFB", tdes_ede3_cfb_functions),
255     ALG("DES-EDE3-CFB8", tdes_ede3_cfb8_functions),
256     ALG("DES-EDE3-CFB1", tdes_ede3_cfb1_functions),
257     ALG("DES3-WRAP:id-smime-alg-CMS3DESwrap", tdes_wrap_cbc_functions),
258     ALG("DES-EDE-ECB:DES-EDE", tdes_ede2_ecb_functions),
259     ALG("DES-EDE-CBC", tdes_ede2_cbc_functions),
260     ALG("DES-EDE-OFB", tdes_ede2_ofb_functions),
261     ALG("DES-EDE-CFB", tdes_ede2_cfb_functions),
262 #endif /* OPENSSL_NO_DES */
263 #ifndef OPENSSL_NO_SM4
264     ALG("SM4-ECB", sm4128ecb_functions),
265     ALG("SM4-CBC:SM4", sm4128cbc_functions),
266     ALG("SM4-CTR", sm4128ctr_functions),
267     ALG("SM4-OFB:SM4-OFB128", sm4128ofb128_functions),
268     ALG("SM4-CFB:SM4-CFB128", sm4128cfb128_functions),
269 #endif /* OPENSSL_NO_SM4 */
270 #ifndef OPENSSL_NO_CHACHA
271     ALG("ChaCha20", chacha20_functions),
272 # ifndef OPENSSL_NO_POLY1305
273     ALG("ChaCha20-Poly1305", chacha20_poly1305_functions),
274 # endif /* OPENSSL_NO_POLY1305 */
275 #endif /* OPENSSL_NO_CHACHA */
276     { { NULL, NULL, NULL }, NULL }
277 };
278 static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)];
279
280 static const OSSL_ALGORITHM deflt_macs[] = {
281 #ifndef OPENSSL_NO_BLAKE2
282     { "BLAKE2BMAC", "provider=default", blake2bmac_functions },
283     { "BLAKE2SMAC", "provider=default", blake2smac_functions },
284 #endif
285 #ifndef OPENSSL_NO_CMAC
286     { "CMAC", "provider=default", cmac_functions },
287 #endif
288     { "GMAC", "provider=default", gmac_functions },
289     { "HMAC", "provider=default", hmac_functions },
290     { "KMAC-128:KMAC128", "provider=default", kmac128_functions },
291     { "KMAC-256:KMAC256", "provider=default", kmac256_functions },
292 #ifndef OPENSSL_NO_SIPHASH
293     { "SIPHASH", "provider=default", siphash_functions },
294 #endif
295 #ifndef OPENSSL_NO_POLY1305
296     { "POLY1305", "provider=default", poly1305_functions },
297 #endif
298     { NULL, NULL, NULL }
299 };
300
301 static const OSSL_ALGORITHM deflt_kdfs[] = {
302     { "HKDF", "provider=default", kdf_hkdf_functions },
303     { "SSKDF", "provider=default", kdf_sskdf_functions },
304     { "PBKDF2", "provider=default", kdf_pbkdf2_functions },
305     { "SSHKDF", "provider=default", kdf_sshkdf_functions },
306     { "X963KDF", "provider=default", kdf_x963_kdf_functions },
307     { "TLS1-PRF", "provider=default", kdf_tls1_prf_functions },
308     { "KBKDF", "provider=default", kdf_kbkdf_functions },
309 #ifndef OPENSSL_NO_CMS
310     { "X942KDF", "provider=default", kdf_x942_kdf_functions },
311 #endif
312 #ifndef OPENSSL_NO_SCRYPT
313     { "SCRYPT:id-scrypt", "provider=default", kdf_scrypt_functions },
314 #endif
315     { "KRB5KDF", "provider=default", kdf_krb5kdf_functions },
316     { NULL, NULL, NULL }
317 };
318
319 static const OSSL_ALGORITHM deflt_keyexch[] = {
320 #ifndef OPENSSL_NO_DH
321     { "DH:dhKeyAgreement", "provider=default", dh_keyexch_functions },
322 #endif
323 #ifndef OPENSSL_NO_EC
324     { "ECDH", "provider=default", ecdh_keyexch_functions },
325     { "X25519", "provider=default", x25519_keyexch_functions },
326     { "X448", "provider=default", x448_keyexch_functions },
327 #endif
328     { NULL, NULL, NULL }
329 };
330
331 static const OSSL_ALGORITHM deflt_signature[] = {
332 #ifndef OPENSSL_NO_DSA
333     { "DSA:dsaEncryption", "provider=default", dsa_signature_functions },
334 #endif
335     { "RSA:rsaEncryption", "provider=default", rsa_signature_functions },
336 #ifndef OPENSSL_NO_EC
337     { "ED25519:Ed25519", "provider=default", ed25519_signature_functions },
338     { "ED448:Ed448", "provider=default", ed448_signature_functions },
339     { "ECDSA", "provider=default", ecdsa_signature_functions },
340 #endif
341     { NULL, NULL, NULL }
342 };
343
344 static const OSSL_ALGORITHM deflt_asym_cipher[] = {
345     { "RSA:rsaEncryption", "provider=default", rsa_asym_cipher_functions },
346     { NULL, NULL, NULL }
347 };
348
349 static const OSSL_ALGORITHM deflt_keymgmt[] = {
350 #ifndef OPENSSL_NO_DH
351     { "DH:dhKeyAgreement", "provider=default", dh_keymgmt_functions },
352 #endif
353 #ifndef OPENSSL_NO_DSA
354     { "DSA:dsaEncryption", "provider=default", dsa_keymgmt_functions },
355 #endif
356     { "RSA:rsaEncryption", "provider=default", rsa_keymgmt_functions },
357 #ifndef OPENSSL_NO_EC
358     { "EC:id-ecPublicKey", "provider=default", ec_keymgmt_functions },
359     { "X25519", "provider=default", x25519_keymgmt_functions },
360     { "X448", "provider=default", x448_keymgmt_functions },
361     { "ED25519", "provider=default", ed25519_keymgmt_functions },
362     { "ED448", "provider=default", ed448_keymgmt_functions },
363 #endif
364     { NULL, NULL, NULL }
365 };
366
367 /*
368  * Unlike most algorithms in the default provider, the serializers are allowed
369  * for use in FIPS mode because they are not FIPS relevant, and therefore have
370  * the "fips=yes" property.
371  */
372 static const OSSL_ALGORITHM deflt_serializer[] = {
373     { "RSA", "provider=default,fips=yes,format=text,type=private",
374       rsa_priv_text_serializer_functions },
375     { "RSA", "provider=default,fips=yes,format=text,type=public",
376       rsa_pub_text_serializer_functions },
377     { "RSA", "provider=default,fips=yes,format=der,type=private",
378       rsa_priv_der_serializer_functions },
379     { "RSA", "provider=default,fips=yes,format=der,type=public",
380       rsa_pub_der_serializer_functions },
381     { "RSA", "provider=default,fips=yes,format=pem,type=private",
382       rsa_priv_pem_serializer_functions },
383     { "RSA", "provider=default,fips=yes,format=pem,type=public",
384       rsa_pub_pem_serializer_functions },
385
386 #ifndef OPENSSL_NO_DH
387     { "DH", "provider=default,fips=yes,format=text,type=private",
388       dh_priv_text_serializer_functions },
389     { "DH", "provider=default,fips=yes,format=text,type=public",
390       dh_pub_text_serializer_functions },
391     { "DH", "provider=default,fips=yes,format=text,type=parameters",
392       dh_param_text_serializer_functions },
393     { "DH", "provider=default,fips=yes,format=der,type=private",
394       dh_priv_der_serializer_functions },
395     { "DH", "provider=default,fips=yes,format=der,type=public",
396       dh_pub_der_serializer_functions },
397     { "DH", "provider=default,fips=yes,format=der,type=parameters",
398       dh_param_der_serializer_functions },
399     { "DH", "provider=default,fips=yes,format=pem,type=private",
400       dh_priv_pem_serializer_functions },
401     { "DH", "provider=default,fips=yes,format=pem,type=public",
402       dh_pub_pem_serializer_functions },
403     { "DH", "provider=default,fips=yes,format=pem,type=parameters",
404       dh_param_pem_serializer_functions },
405 #endif
406
407 #ifndef OPENSSL_NO_DSA
408     { "DSA", "provider=default,fips=yes,format=text,type=private",
409       dsa_priv_text_serializer_functions },
410     { "DSA", "provider=default,fips=yes,format=text,type=public",
411       dsa_pub_text_serializer_functions },
412     { "DSA", "provider=default,fips=yes,format=text,type=parameters",
413       dsa_param_text_serializer_functions },
414     { "DSA", "provider=default,fips=yes,format=der,type=private",
415       dsa_priv_der_serializer_functions },
416     { "DSA", "provider=default,fips=yes,format=der,type=public",
417       dsa_pub_der_serializer_functions },
418     { "DSA", "provider=default,fips=yes,format=der,type=parameters",
419       dsa_param_der_serializer_functions },
420     { "DSA", "provider=default,fips=yes,format=pem,type=private",
421       dsa_priv_pem_serializer_functions },
422     { "DSA", "provider=default,fips=yes,format=pem,type=public",
423       dsa_pub_pem_serializer_functions },
424     { "DSA", "provider=default,fips=yes,format=pem,type=parameters",
425       dsa_param_pem_serializer_functions },
426 #endif
427
428 #ifndef OPENSSL_NO_EC
429     { "X25519", "provider=default,fips=yes,format=text,type=private",
430       x25519_priv_print_serializer_functions },
431     { "X25519", "provider=default,fips=yes,format=text,type=public",
432       x25519_pub_print_serializer_functions },
433     { "X25519", "provider=default,fips=yes,format=der,type=private",
434       x25519_priv_der_serializer_functions },
435     { "X25519", "provider=default,fips=yes,format=der,type=public",
436       x25519_pub_der_serializer_functions },
437     { "X25519", "provider=default,fips=yes,format=pem,type=private",
438       x25519_priv_pem_serializer_functions },
439     { "X25519", "provider=default,fips=yes,format=pem,type=public",
440       x25519_pub_pem_serializer_functions },
441
442     { "X448", "provider=default,format=text,type=private",
443       x448_priv_print_serializer_functions },
444     { "X448", "provider=default,format=text,type=public",
445       x448_pub_print_serializer_functions },
446     { "X448", "provider=default,format=der,type=private",
447       x448_priv_der_serializer_functions },
448     { "X448", "provider=default,format=der,type=public",
449       x448_pub_der_serializer_functions },
450     { "X448", "provider=default,format=pem,type=private",
451       x448_priv_pem_serializer_functions },
452     { "X448", "provider=default,format=pem,type=public",
453       x448_pub_pem_serializer_functions },
454
455     { "ED25519", "provider=default,fips=yes,format=text,type=private",
456       ed25519_priv_print_serializer_functions },
457     { "ED25519", "provider=default,fips=yes,format=text,type=public",
458       ed25519_pub_print_serializer_functions },
459     { "ED25519", "provider=default,fips=yes,format=der,type=private",
460       ed25519_priv_der_serializer_functions },
461     { "ED25519", "provider=default,fips=yes,format=der,type=public",
462       ed25519_pub_der_serializer_functions },
463     { "ED25519", "provider=default,fips=yes,format=pem,type=private",
464       ed25519_priv_pem_serializer_functions },
465     { "ED25519", "provider=default,fips=yes,format=pem,type=public",
466       ed25519_pub_pem_serializer_functions },
467
468     { "ED448", "provider=default,format=text,type=private",
469       ed448_priv_print_serializer_functions },
470     { "ED448", "provider=default,format=text,type=public",
471       ed448_pub_print_serializer_functions },
472     { "ED448", "provider=default,format=der,type=private",
473       ed448_priv_der_serializer_functions },
474     { "ED448", "provider=default,format=der,type=public",
475       ed448_pub_der_serializer_functions },
476     { "ED448", "provider=default,format=pem,type=private",
477       ed448_priv_pem_serializer_functions },
478     { "ED448", "provider=default,format=pem,type=public",
479       ed448_pub_pem_serializer_functions },
480
481     { "EC", "provider=default,fips=yes,format=text,type=private",
482       ec_priv_text_serializer_functions },
483     { "EC", "provider=default,fips=yes,format=text,type=public",
484       ec_pub_text_serializer_functions },
485     { "EC", "provider=default,fips=yes,format=text,type=parameters",
486       ec_param_text_serializer_functions },
487     { "EC", "provider=default,fips=yes,format=der,type=private",
488       ec_priv_der_serializer_functions },
489     { "EC", "provider=default,fips=yes,format=der,type=public",
490       ec_pub_der_serializer_functions },
491     { "EC", "provider=default,fips=yes,format=der,type=parameters",
492       ec_param_der_serializer_functions },
493     { "EC", "provider=default,fips=yes,format=pem,type=private",
494       ec_priv_pem_serializer_functions },
495     { "EC", "provider=default,fips=yes,format=pem,type=public",
496       ec_pub_pem_serializer_functions },
497     { "EC", "provider=default,fips=yes,format=pem,type=parameters",
498       ec_param_pem_serializer_functions },
499 #endif
500     { NULL, NULL, NULL }
501 };
502
503 static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov,
504                                          int operation_id,
505                                          int *no_cache)
506 {
507     *no_cache = 0;
508     switch (operation_id) {
509     case OSSL_OP_DIGEST:
510         return deflt_digests;
511     case OSSL_OP_CIPHER:
512         ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers);
513         return exported_ciphers;
514     case OSSL_OP_MAC:
515         return deflt_macs;
516     case OSSL_OP_KDF:
517         return deflt_kdfs;
518     case OSSL_OP_KEYMGMT:
519         return deflt_keymgmt;
520     case OSSL_OP_KEYEXCH:
521         return deflt_keyexch;
522     case OSSL_OP_SIGNATURE:
523         return deflt_signature;
524     case OSSL_OP_ASYM_CIPHER:
525         return deflt_asym_cipher;
526     case OSSL_OP_SERIALIZER:
527         return deflt_serializer;
528     }
529     return NULL;
530 }
531
532 /* Functions we provide to the core */
533 static const OSSL_DISPATCH deflt_dispatch_table[] = {
534     { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params },
535     { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params },
536     { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query },
537     { 0, NULL }
538 };
539
540 OSSL_provider_init_fn ossl_default_provider_init;
541
542 int ossl_default_provider_init(const OSSL_PROVIDER *provider,
543                                const OSSL_DISPATCH *in,
544                                const OSSL_DISPATCH **out,
545                                void **provctx)
546 {
547     OSSL_core_get_library_context_fn *c_get_libctx = NULL;
548
549     if (!ossl_prov_bio_from_dispatch(in))
550         return 0;
551     for (; in->function_id != 0; in++) {
552         switch (in->function_id) {
553         case OSSL_FUNC_CORE_GETTABLE_PARAMS:
554             c_gettable_params = OSSL_get_core_gettable_params(in);
555             break;
556         case OSSL_FUNC_CORE_GET_PARAMS:
557             c_get_params = OSSL_get_core_get_params(in);
558             break;
559         case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT:
560             c_get_libctx = OSSL_get_core_get_library_context(in);
561             break;
562         default:
563             /* Just ignore anything we don't understand */
564             break;
565         }
566     }
567
568     if (c_get_libctx == NULL)
569         return 0;
570
571     *out = deflt_dispatch_table;
572
573     /*
574      * We want to make sure that all calls from this provider that requires
575      * a library context use the same context as the one used to call our
576      * functions.  We do that by passing it along as the provider context.
577      */
578     *provctx = c_get_libctx(provider);
579     return 1;
580 }