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