Tweak some algorithm naming inconsistencies
[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/implementations.h"
18
19 /* Functions provided by the core */
20 static OSSL_core_gettable_params_fn *c_gettable_params = NULL;
21 static OSSL_core_get_params_fn *c_get_params = NULL;
22
23 /* Parameters we provide to the core */
24 static const OSSL_PARAM deflt_param_types[] = {
25     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
26     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
27     OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
28     OSSL_PARAM_END
29 };
30
31 static const OSSL_PARAM *deflt_gettable_params(const OSSL_PROVIDER *prov)
32 {
33     return deflt_param_types;
34 }
35
36 static int deflt_get_params(const OSSL_PROVIDER *prov, OSSL_PARAM params[])
37 {
38     OSSL_PARAM *p;
39
40     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
41     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider"))
42         return 0;
43     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
44     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
45         return 0;
46     p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
47     if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
48         return 0;
49
50     return 1;
51 }
52
53 /*
54  * For the algorithm names, we use the following formula for our primary
55  * names:
56  *
57  *     ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
58  *
59  *     VERSION is only present if there are multiple versions of
60  *     an alg (MD2, MD4, MD5).  It may be omitted if there is only
61  *     one version (if a subsequent version is released in the future,
62  *     we can always change the canonical name, and add the old name
63  *     as an alias).
64  *
65  *     SUBNAME may be present where we are combining multiple
66  *     algorithms together, e.g. MD5-SHA1.
67  *
68  *     SIZE is only present if multiple versions of an algorithm exist
69  *     with different sizes (e.g. AES-128-CBC, AES-256-CBC)
70  *
71  *     MODE is only present where applicable.
72  *
73  * We add diverse other names where applicable, such as the names that
74  * NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names
75  * we have used historically.
76  *
77  * Algorithm names are case insensitive, but we use all caps in our "canonical"
78  * names for consistency.
79  */
80 static const OSSL_ALGORITHM deflt_digests[] = {
81     /* Our primary name:NIST name[:our older names] */
82     { "SHA1:SHA-1", "default=yes", sha1_functions },
83     { "SHA2-224:SHA-224:SHA224", "default=yes", sha224_functions },
84     { "SHA2-256:SHA-256:SHA256", "default=yes", sha256_functions },
85     { "SHA2-384:SHA-384:SHA384", "default=yes", sha384_functions },
86     { "SHA2-512:SHA-512:SHA512", "default=yes", sha512_functions },
87     { "SHA2-512/224:SHA-512/224:SHA512-224", "default=yes",
88       sha512_224_functions },
89     { "SHA2-512/256:SHA-512/256:SHA512-256", "default=yes",
90       sha512_256_functions },
91
92     /* We agree with NIST here, so one name only */
93     { "SHA3-224", "default=yes", sha3_224_functions },
94     { "SHA3-256", "default=yes", sha3_256_functions },
95     { "SHA3-384", "default=yes", sha3_384_functions },
96     { "SHA3-512", "default=yes", sha3_512_functions },
97
98     /*
99      * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for
100      * the KMAC-128 and KMAC-256.
101      */
102     { "KECCAK-KMAC-128:KECCAK-KMAC128", "default=yes", keccak_kmac_128_functions },
103     { "KECCAK-KMAC-256:KECCAK-KMAC256", "default=yes", keccak_kmac_256_functions },
104
105     /* Our primary name:NIST name */
106     { "SHAKE-128:SHAKE128", "default=yes", shake_128_functions },
107     { "SHAKE-256:SHAKE256", "default=yes", shake_256_functions },
108
109 #ifndef OPENSSL_NO_BLAKE2
110     /*
111      * https://blake2.net/ doesn't specify size variants,
112      * but mentions that Bouncy Castle uses the names
113      * BLAKE2b-160, BLAKE2b-256, BLAKE2b-384, and BLAKE2b-512
114      * If we assume that "2b" and "2s" are versions, that pattern
115      * fits with ours.  We also add our historical names.
116      */
117     { "BLAKE2S-256:BLAKE2s256", "default=yes", blake2s256_functions },
118     { "BLAKE2B-512:BLAKE2b512", "default=yes", blake2b512_functions },
119 #endif /* OPENSSL_NO_BLAKE2 */
120
121 #ifndef OPENSSL_NO_SM3
122     { "SM3", "default=yes", sm3_functions },
123 #endif /* OPENSSL_NO_SM3 */
124
125 #ifndef OPENSSL_NO_MD5
126     { "MD5", "default=yes", md5_functions },
127     { "MD5-SHA1", "default=yes", md5_sha1_functions },
128 #endif /* OPENSSL_NO_MD5 */
129
130     { NULL, NULL, NULL }
131 };
132
133 static const OSSL_ALGORITHM deflt_ciphers[] = {
134     { "AES-256-ECB", "default=yes", aes256ecb_functions },
135     { "AES-192-ECB", "default=yes", aes192ecb_functions },
136     { "AES-128-ECB", "default=yes", aes128ecb_functions },
137     { "AES-256-CBC", "default=yes", aes256cbc_functions },
138     { "AES-192-CBC", "default=yes", aes192cbc_functions },
139     { "AES-128-CBC", "default=yes", aes128cbc_functions },
140     { "AES-256-OFB", "default=yes", aes256ofb_functions },
141     { "AES-192-OFB", "default=yes", aes192ofb_functions },
142     { "AES-128-OFB", "default=yes", aes128ofb_functions },
143     { "AES-256-CFB", "default=yes", aes256cfb_functions },
144     { "AES-192-CFB", "default=yes", aes192cfb_functions },
145     { "AES-128-CFB", "default=yes", aes128cfb_functions },
146     { "AES-256-CFB1", "default=yes", aes256cfb1_functions },
147     { "AES-192-CFB1", "default=yes", aes192cfb1_functions },
148     { "AES-128-CFB1", "default=yes", aes128cfb1_functions },
149     { "AES-256-CFB8", "default=yes", aes256cfb8_functions },
150     { "AES-192-CFB8", "default=yes", aes192cfb8_functions },
151     { "AES-128-CFB8", "default=yes", aes128cfb8_functions },
152     { "AES-256-CTR", "default=yes", aes256ctr_functions },
153     { "AES-192-CTR", "default=yes", aes192ctr_functions },
154     { "AES-128-CTR", "default=yes", aes128ctr_functions },
155     { "AES-256-XTS", "default=yes", aes256xts_functions },
156     { "AES-128-XTS", "default=yes", aes128xts_functions },
157 #ifndef OPENSSL_NO_OCB
158     { "AES-256-OCB", "default=yes", aes256ocb_functions },
159     { "AES-192-OCB", "default=yes", aes192ocb_functions },
160     { "AES-128-OCB", "default=yes", aes128ocb_functions },
161 #endif /* OPENSSL_NO_OCB */
162 #ifndef OPENSSL_NO_SIV
163     { "AES-128-SIV", "default=yes", aes128siv_functions },
164     { "AES-192-SIV", "default=yes", aes192siv_functions },
165     { "AES-256-SIV", "default=yes", aes256siv_functions },
166 #endif /* OPENSSL_NO_SIV */
167     { "AES-256-GCM:id-aes256-GCM", "default=yes", aes256gcm_functions },
168     { "AES-192-GCM:id-aes192-GCM", "default=yes", aes192gcm_functions },
169     { "AES-128-GCM:id-aes128-GCM", "default=yes", aes128gcm_functions },
170     { "AES-256-CCM:id-aes256-CCM", "default=yes", aes256ccm_functions },
171     { "AES-192-CCM:id-aes192-CCM", "default=yes", aes192ccm_functions },
172     { "AES-128-CCM:id-aes128-CCM", "default=yes", aes128ccm_functions },
173     { "AES-256-WRAP:id-aes256-wrap:AES256-WRAP", "default=yes",
174       aes256wrap_functions },
175     { "AES-192-WRAP:id-aes192-wrap:AES192-WRAP", "default=yes",
176       aes192wrap_functions },
177     { "AES-128-WRAP:id-aes128-wrap:AES128-WRAP", "default=yes",
178       aes128wrap_functions },
179     { "AES-256-WRAP-PAD:id-aes256-wrap-pad:AES256-WRAP-PAD", "default=yes",
180       aes256wrappad_functions },
181     { "AES-192-WRAP-PAD:id-aes192-wrap-pad:AES192-WRAP-PAD", "default=yes",
182       aes192wrappad_functions },
183     { "AES-128-WRAP-PAD:id-aes128-wrap-pad:AES128-WRAP-PAD", "default=yes",
184       aes128wrappad_functions },
185 #ifndef OPENSSL_NO_ARIA
186     { "ARIA-256-GCM", "default=yes", aria256gcm_functions },
187     { "ARIA-192-GCM", "default=yes", aria192gcm_functions },
188     { "ARIA-128-GCM", "default=yes", aria128gcm_functions },
189     { "ARIA-256-CCM", "default=yes", aria256ccm_functions },
190     { "ARIA-192-CCM", "default=yes", aria192ccm_functions },
191     { "ARIA-128-CCM", "default=yes", aria128ccm_functions },
192     { "ARIA-256-ECB", "default=yes", aria256ecb_functions },
193     { "ARIA-192-ECB", "default=yes", aria192ecb_functions },
194     { "ARIA-128-ECB", "default=yes", aria128ecb_functions },
195     { "ARIA-256-CBC:ARIA256", "default=yes", aria256cbc_functions },
196     { "ARIA-192-CBC:ARIA192", "default=yes", aria192cbc_functions },
197     { "ARIA-128-CBC:ARIA128", "default=yes", aria128cbc_functions },
198     { "ARIA-256-OFB", "default=yes", aria256ofb_functions },
199     { "ARIA-192-OFB", "default=yes", aria192ofb_functions },
200     { "ARIA-128-OFB", "default=yes", aria128ofb_functions },
201     { "ARIA-256-CFB", "default=yes", aria256cfb_functions },
202     { "ARIA-192-CFB", "default=yes", aria192cfb_functions },
203     { "ARIA-128-CFB", "default=yes", aria128cfb_functions },
204     { "ARIA-256-CFB1", "default=yes", aria256cfb1_functions },
205     { "ARIA-192-CFB1", "default=yes", aria192cfb1_functions },
206     { "ARIA-128-CFB1", "default=yes", aria128cfb1_functions },
207     { "ARIA-256-CFB8", "default=yes", aria256cfb8_functions },
208     { "ARIA-192-CFB8", "default=yes", aria192cfb8_functions },
209     { "ARIA-128-CFB8", "default=yes", aria128cfb8_functions },
210     { "ARIA-256-CTR", "default=yes", aria256ctr_functions },
211     { "ARIA-192-CTR", "default=yes", aria192ctr_functions },
212     { "ARIA-128-CTR", "default=yes", aria128ctr_functions },
213 #endif /* OPENSSL_NO_ARIA */
214 #ifndef OPENSSL_NO_CAMELLIA
215     { "CAMELLIA-256-ECB", "default=yes", camellia256ecb_functions },
216     { "CAMELLIA-192-ECB", "default=yes", camellia192ecb_functions },
217     { "CAMELLIA-128-ECB", "default=yes", camellia128ecb_functions },
218     { "CAMELLIA-256-CBC:CAMELLIA256", "default=yes", camellia256cbc_functions },
219     { "CAMELLIA-192-CBC:CAMELLIA192", "default=yes", camellia192cbc_functions },
220     { "CAMELLIA-128-CBC:CAMELLIA128", "default=yes", camellia128cbc_functions },
221     { "CAMELLIA-256-OFB", "default=yes", camellia256ofb_functions },
222     { "CAMELLIA-192-OFB", "default=yes", camellia192ofb_functions },
223     { "CAMELLIA-128-OFB", "default=yes", camellia128ofb_functions },
224     { "CAMELLIA-256-CFB", "default=yes", camellia256cfb_functions },
225     { "CAMELLIA-192-CFB", "default=yes", camellia192cfb_functions },
226     { "CAMELLIA-128-CFB", "default=yes", camellia128cfb_functions },
227     { "CAMELLIA-256-CFB1", "default=yes", camellia256cfb1_functions },
228     { "CAMELLIA-192-CFB1", "default=yes", camellia192cfb1_functions },
229     { "CAMELLIA-128-CFB1", "default=yes", camellia128cfb1_functions },
230     { "CAMELLIA-256-CFB8", "default=yes", camellia256cfb8_functions },
231     { "CAMELLIA-192-CFB8", "default=yes", camellia192cfb8_functions },
232     { "CAMELLIA-128-CFB8", "default=yes", camellia128cfb8_functions },
233     { "CAMELLIA-256-CTR", "default=yes", camellia256ctr_functions },
234     { "CAMELLIA-192-CTR", "default=yes", camellia192ctr_functions },
235     { "CAMELLIA-128-CTR", "default=yes", camellia128ctr_functions },
236 #endif /* OPENSSL_NO_CAMELLIA */
237 #ifndef OPENSSL_NO_DES
238     { "DES-EDE3-ECB:DES-EDE3", "default=yes", tdes_ede3_ecb_functions },
239     { "DES-EDE3-CBC:DES3", "default=yes", tdes_ede3_cbc_functions },
240     { "DES-EDE3-OFB", "default=yes", tdes_ede3_ofb_functions },
241     { "DES-EDE3-CFB", "default=yes", tdes_ede3_cfb_functions },
242     { "DES-EDE3-CFB8", "default=yes", tdes_ede3_cfb8_functions },
243     { "DES-EDE3-CFB1", "default=yes", tdes_ede3_cfb1_functions },
244     { "DES-EDE-ECB:DES-EDE", "default=yes", tdes_ede2_ecb_functions },
245     { "DES-EDE-CBC", "default=yes", tdes_ede2_cbc_functions },
246     { "DES-EDE-OFB", "default=yes", tdes_ede2_ofb_functions },
247     { "DES-EDE-CFB", "default=yes", tdes_ede2_cfb_functions },
248     { "DESX-CBC:DESX", "default=yes", tdes_desx_cbc_functions },
249     { "DES3-WRAP:id-smime-alg-CMS3DESwrap", "default=yes", tdes_wrap_cbc_functions },
250     { "DES-ECB", "default=yes", des_ecb_functions },
251     { "DES-CBC:DES", "default=yes", des_cbc_functions },
252     { "DES-OFB", "default=yes", des_ofb64_functions },
253     { "DES-CFB", "default=yes", des_cfb64_functions },
254     { "DES-CFB1", "default=yes", des_cfb1_functions },
255     { "DES-CFB8", "default=yes", des_cfb8_functions },
256 #endif /* OPENSSL_NO_DES */
257 #ifndef OPENSSL_NO_BF
258     { "BF-ECB", "default=yes", blowfish128ecb_functions },
259     { "BF-CBC:BF:BLOWFISH", "default=yes", blowfish128cbc_functions },
260     { "BF-OFB", "default=yes", blowfish64ofb64_functions },
261     { "BF-CFB", "default=yes", blowfish64cfb64_functions },
262 #endif /* OPENSSL_NO_BF */
263 #ifndef OPENSSL_NO_IDEA
264     { "IDEA-ECB", "default=yes", idea128ecb_functions },
265     { "IDEA-CBC:IDEA", "default=yes", idea128cbc_functions },
266     { "IDEA-OFB:IDEA-OFB64", "default=yes", idea128ofb64_functions },
267     { "IDEA-CFB:IDEA-CFB64", "default=yes", idea128cfb64_functions },
268 #endif /* OPENSSL_NO_IDEA */
269 #ifndef OPENSSL_NO_CAST
270     { "CAST5-ECB", "default=yes", cast5128ecb_functions },
271     { "CAST5-CBC:CAST-CBC:CAST", "default=yes", cast5128cbc_functions },
272     { "CAST5-OFB", "default=yes", cast564ofb64_functions },
273     { "CAST5-CFB", "default=yes", cast564cfb64_functions },
274 #endif /* OPENSSL_NO_CAST */
275 #ifndef OPENSSL_NO_SEED
276     { "SEED-ECB", "default=yes", seed128ecb_functions },
277     { "SEED-CBC:SEED", "default=yes", seed128cbc_functions },
278     { "SEED-OFB:SEED-OFB128", "default=yes", seed128ofb128_functions },
279     { "SEED-CFB:SEED-CFB128", "default=yes", seed128cfb128_functions },
280 #endif /* OPENSSL_NO_SEED */
281 #ifndef OPENSSL_NO_SM4
282     { "SM4-ECB", "default=yes", sm4128ecb_functions },
283     { "SM4-CBC:SM4", "default=yes", sm4128cbc_functions },
284     { "SM4-CTR", "default=yes", sm4128ctr_functions },
285     { "SM4-OFB:SM4-OFB128", "default=yes", sm4128ofb128_functions },
286     { "SM4-CFB:SM4-CFB128", "default=yes", sm4128cfb128_functions },
287 #endif /* OPENSSL_NO_SM4 */
288 #ifndef OPENSSL_NO_RC4
289     { "RC4", "default=yes", rc4128_functions },
290     { "RC4-40", "default=yes", rc440_functions },
291 # ifndef OPENSSL_NO_MD5
292     { "RC4-HMAC-MD5", "default=yes", rc4_hmac_md5_functions },
293 # endif /* OPENSSL_NO_MD5 */
294 #endif /* OPENSSL_NO_RC4 */
295 #ifndef OPENSSL_NO_RC5
296     { "RC5-ECB", "default=yes", rc5128ecb_functions },
297     { "RC5-CBC", "default=yes", rc5128cbc_functions },
298     { "RC5-OFB", "default=yes", rc5128ofb64_functions },
299     { "RC5-CFB", "default=yes", rc5128cfb64_functions },
300 #endif /* OPENSSL_NO_RC5 */
301 #ifndef OPENSSL_NO_RC2
302     { "RC2-ECB", "default=yes", rc2128ecb_functions },
303     { "RC2-CBC", "default=yes", rc2128cbc_functions },
304     { "RC2-40-CBC", "default=yes", rc240cbc_functions },
305     { "RC2-64-CBC", "default=yes", rc264cbc_functions },
306     { "RC2-CFB", "default=yes", rc2128cfb128_functions },
307     { "RC2-OFB", "default=yes", rc2128ofb128_functions },
308 #endif /* OPENSSL_NO_RC2 */
309 #ifndef OPENSSL_NO_CHACHA
310     { "ChaCha20", "default=yes", chacha20_functions },
311 # ifndef OPENSSL_NO_POLY1305
312     { "ChaCha20-Poly1305", "default=yes", chacha20_poly1305_functions },
313 # endif /* OPENSSL_NO_POLY1305 */
314 #endif /* OPENSSL_NO_CHACHA */
315     { NULL, NULL, NULL }
316 };
317
318 static const OSSL_ALGORITHM deflt_macs[] = {
319 #ifndef OPENSSL_NO_BLAKE2
320     { "BLAKE2BMAC", "default=yes", blake2bmac_functions },
321     { "BLAKE2SMAC", "default=yes", blake2smac_functions },
322 #endif
323 #ifndef OPENSSL_NO_CMAC
324     { "CMAC", "default=yes", cmac_functions },
325 #endif
326     { "GMAC", "default=yes", gmac_functions },
327     { "HMAC", "default=yes", hmac_functions },
328     { "KMAC-128:KMAC128", "default=yes", kmac128_functions },
329     { "KMAC-256:KMAC256", "default=yes", kmac256_functions },
330 #ifndef OPENSSL_NO_SIPHASH
331     { "SIPHASH", "default=yes", siphash_functions },
332 #endif
333 #ifndef OPENSSL_NO_POLY1305
334     { "POLY1305", "default=yes", poly1305_functions },
335 #endif
336     { NULL, NULL, NULL }
337 };
338
339 static const OSSL_ALGORITHM deflt_kdfs[] = {
340     { "HKDF", "default=yes", kdf_hkdf_functions },
341     { "SSKDF", "default=yes", kdf_sskdf_functions },
342     { "PBKDF2", "default=yes", kdf_pbkdf2_functions },
343     { "SSHKDF", "default=yes", kdf_sshkdf_functions },
344     { "X963KDF", "default=yes", kdf_x963_kdf_functions },
345     { "TLS1-PRF", "default=yes", kdf_tls1_prf_functions },
346     { "KBKDF", "default=yes", kdf_kbkdf_functions },
347 #ifndef OPENSSL_NO_CMS
348     { "X942KDF", "default=yes", kdf_x942_kdf_functions },
349 #endif
350 #ifndef OPENSSL_NO_SCRYPT
351     { "SCRYPT:id-scrypt", "default=yes", kdf_scrypt_functions },
352 #endif
353     { "KRB5KDF", "default=yes", kdf_krb5kdf_functions },
354     { NULL, NULL, NULL }
355 };
356
357 static const OSSL_ALGORITHM deflt_keyexch[] = {
358 #ifndef OPENSSL_NO_DH
359     { "DH:dhKeyAgreement", "default=yes", dh_keyexch_functions },
360 #endif
361     { NULL, NULL, NULL }
362 };
363
364 static const OSSL_ALGORITHM deflt_signature[] = {
365 #ifndef OPENSSL_NO_DSA
366     { "DSA:dsaEncryption", "default=yes", dsa_signature_functions },
367 #endif
368     { NULL, NULL, NULL }
369 };
370
371 static const OSSL_ALGORITHM deflt_asym_cipher[] = {
372     { "RSA:rsaEncryption", "default=yes", rsa_asym_cipher_functions },
373     { NULL, NULL, NULL }
374 };
375
376 static const OSSL_ALGORITHM deflt_keymgmt[] = {
377 #ifndef OPENSSL_NO_DH
378     { "DH", "default=yes", dh_keymgmt_functions },
379 #endif
380 #ifndef OPENSSL_NO_DSA
381     { "DSA", "default=yes", dsa_keymgmt_functions },
382 #endif
383     { "RSA", "default=yes", rsa_keymgmt_functions },
384     { NULL, NULL, NULL }
385 };
386
387 static const OSSL_ALGORITHM *deflt_query(OSSL_PROVIDER *prov,
388                                          int operation_id,
389                                          int *no_cache)
390 {
391     *no_cache = 0;
392     switch (operation_id) {
393     case OSSL_OP_DIGEST:
394         return deflt_digests;
395     case OSSL_OP_CIPHER:
396         return deflt_ciphers;
397     case OSSL_OP_MAC:
398         return deflt_macs;
399     case OSSL_OP_KDF:
400         return deflt_kdfs;
401     case OSSL_OP_KEYMGMT:
402         return deflt_keymgmt;
403     case OSSL_OP_KEYEXCH:
404         return deflt_keyexch;
405     case OSSL_OP_SIGNATURE:
406         return deflt_signature;
407     case OSSL_OP_ASYM_CIPHER:
408         return deflt_asym_cipher;
409     }
410     return NULL;
411 }
412
413 /* Functions we provide to the core */
414 static const OSSL_DISPATCH deflt_dispatch_table[] = {
415     { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params },
416     { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params },
417     { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query },
418     { 0, NULL }
419 };
420
421 OSSL_provider_init_fn ossl_default_provider_init;
422
423 int ossl_default_provider_init(const OSSL_PROVIDER *provider,
424                                const OSSL_DISPATCH *in,
425                                const OSSL_DISPATCH **out,
426                                void **provctx)
427 {
428     OSSL_core_get_library_context_fn *c_get_libctx = NULL;
429
430     for (; in->function_id != 0; in++) {
431         switch (in->function_id) {
432         case OSSL_FUNC_CORE_GETTABLE_PARAMS:
433             c_gettable_params = OSSL_get_core_gettable_params(in);
434             break;
435         case OSSL_FUNC_CORE_GET_PARAMS:
436             c_get_params = OSSL_get_core_get_params(in);
437             break;
438         case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT:
439             c_get_libctx = OSSL_get_core_get_library_context(in);
440             break;
441         default:
442             /* Just ignore anything we don't understand */
443             break;
444         }
445     }
446
447     if (c_get_libctx == NULL)
448         return 0;
449
450     *out = deflt_dispatch_table;
451
452     /*
453      * We want to make sure that all calls from this provider that requires
454      * a library context use the same context as the one used to call our
455      * functions.  We do that by passing it along as the provider context.
456      */
457     *provctx = c_get_libctx(provider);
458     return 1;
459 }