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