]> git.ipfire.org Git - thirdparty/openssl.git/blob - providers/defltprov.c
PROV: Implement PEM to DER deserializer
[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
66 return 1;
67 }
68
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.
92 *
93 * Algorithm names are case insensitive, but we use all caps in our "canonical"
94 * names for consistency.
95 */
96 static const OSSL_ALGORITHM deflt_digests[] = {
97 /* Our primary name:NIST name[:our older names] */
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",
104 sha512_224_functions },
105 { "SHA2-512/256:SHA-512/256:SHA512-256", "provider=default",
106 sha512_256_functions },
107
108 /* We agree with NIST here, so one name only */
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 },
113
114 /*
115 * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for
116 * the KMAC-128 and KMAC-256.
117 */
118 { "KECCAK-KMAC-128:KECCAK-KMAC128", "provider=default", keccak_kmac_128_functions },
119 { "KECCAK-KMAC-256:KECCAK-KMAC256", "provider=default", keccak_kmac_256_functions },
120
121 /* Our primary name:NIST name */
122 { "SHAKE-128:SHAKE128", "provider=default", shake_128_functions },
123 { "SHAKE-256:SHAKE256", "provider=default", shake_256_functions },
124
125 #ifndef OPENSSL_NO_BLAKE2
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 */
133 { "BLAKE2S-256:BLAKE2s256", "provider=default", blake2s256_functions },
134 { "BLAKE2B-512:BLAKE2b512", "provider=default", blake2b512_functions },
135 #endif /* OPENSSL_NO_BLAKE2 */
136
137 #ifndef OPENSSL_NO_SM3
138 { "SM3", "provider=default", sm3_functions },
139 #endif /* OPENSSL_NO_SM3 */
140
141 #ifndef OPENSSL_NO_MD5
142 { "MD5", "provider=default", md5_functions },
143 { "MD5-SHA1", "provider=default", md5_sha1_functions },
144 #endif /* OPENSSL_NO_MD5 */
145
146 { NULL, NULL, NULL }
147 };
148
149 static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
150 ALG("NULL", null_functions),
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-128-CBC-CTS", aes128cbc_cts_functions),
158 ALG("AES-192-CBC-CTS", aes192cbc_cts_functions),
159 ALG("AES-256-CBC-CTS", aes256cbc_cts_functions),
160 ALG("AES-256-OFB", aes256ofb_functions),
161 ALG("AES-192-OFB", aes192ofb_functions),
162 ALG("AES-128-OFB", aes128ofb_functions),
163 ALG("AES-256-CFB", aes256cfb_functions),
164 ALG("AES-192-CFB", aes192cfb_functions),
165 ALG("AES-128-CFB", aes128cfb_functions),
166 ALG("AES-256-CFB1", aes256cfb1_functions),
167 ALG("AES-192-CFB1", aes192cfb1_functions),
168 ALG("AES-128-CFB1", aes128cfb1_functions),
169 ALG("AES-256-CFB8", aes256cfb8_functions),
170 ALG("AES-192-CFB8", aes192cfb8_functions),
171 ALG("AES-128-CFB8", aes128cfb8_functions),
172 ALG("AES-256-CTR", aes256ctr_functions),
173 ALG("AES-192-CTR", aes192ctr_functions),
174 ALG("AES-128-CTR", aes128ctr_functions),
175 ALG("AES-256-XTS", aes256xts_functions),
176 ALG("AES-128-XTS", aes128xts_functions),
177 #ifndef OPENSSL_NO_OCB
178 ALG("AES-256-OCB", aes256ocb_functions),
179 ALG("AES-192-OCB", aes192ocb_functions),
180 ALG("AES-128-OCB", aes128ocb_functions),
181 #endif /* OPENSSL_NO_OCB */
182 #ifndef OPENSSL_NO_SIV
183 ALG("AES-128-SIV", aes128siv_functions),
184 ALG("AES-192-SIV", aes192siv_functions),
185 ALG("AES-256-SIV", aes256siv_functions),
186 #endif /* OPENSSL_NO_SIV */
187 ALG("AES-256-GCM:id-aes256-GCM", aes256gcm_functions),
188 ALG("AES-192-GCM:id-aes192-GCM", aes192gcm_functions),
189 ALG("AES-128-GCM:id-aes128-GCM", aes128gcm_functions),
190 ALG("AES-256-CCM:id-aes256-CCM", aes256ccm_functions),
191 ALG("AES-192-CCM:id-aes192-CCM", aes192ccm_functions),
192 ALG("AES-128-CCM:id-aes128-CCM", aes128ccm_functions),
193 ALG("AES-256-WRAP:id-aes256-wrap:AES256-WRAP", aes256wrap_functions),
194 ALG("AES-192-WRAP:id-aes192-wrap:AES192-WRAP", aes192wrap_functions),
195 ALG("AES-128-WRAP:id-aes128-wrap:AES128-WRAP", aes128wrap_functions),
196 ALG("AES-256-WRAP-PAD:id-aes256-wrap-pad:AES256-WRAP-PAD",
197 aes256wrappad_functions),
198 ALG("AES-192-WRAP-PAD:id-aes192-wrap-pad:AES192-WRAP-PAD",
199 aes192wrappad_functions),
200 ALG("AES-128-WRAP-PAD:id-aes128-wrap-pad:AES128-WRAP-PAD",
201 aes128wrappad_functions),
202 ALGC("AES-128-CBC-HMAC-SHA1", aes128cbc_hmac_sha1_functions,
203 cipher_capable_aes_cbc_hmac_sha1),
204 ALGC("AES-256-CBC-HMAC-SHA1", aes256cbc_hmac_sha1_functions,
205 cipher_capable_aes_cbc_hmac_sha1),
206 ALGC("AES-128-CBC-HMAC-SHA256", aes128cbc_hmac_sha256_functions,
207 cipher_capable_aes_cbc_hmac_sha256),
208 ALGC("AES-256-CBC-HMAC-SHA256", aes256cbc_hmac_sha256_functions,
209 cipher_capable_aes_cbc_hmac_sha256),
210 #ifndef OPENSSL_NO_ARIA
211 ALG("ARIA-256-GCM", aria256gcm_functions),
212 ALG("ARIA-192-GCM", aria192gcm_functions),
213 ALG("ARIA-128-GCM", aria128gcm_functions),
214 ALG("ARIA-256-CCM", aria256ccm_functions),
215 ALG("ARIA-192-CCM", aria192ccm_functions),
216 ALG("ARIA-128-CCM", aria128ccm_functions),
217 ALG("ARIA-256-ECB", aria256ecb_functions),
218 ALG("ARIA-192-ECB", aria192ecb_functions),
219 ALG("ARIA-128-ECB", aria128ecb_functions),
220 ALG("ARIA-256-CBC:ARIA256", aria256cbc_functions),
221 ALG("ARIA-192-CBC:ARIA192", aria192cbc_functions),
222 ALG("ARIA-128-CBC:ARIA128", aria128cbc_functions),
223 ALG("ARIA-256-OFB", aria256ofb_functions),
224 ALG("ARIA-192-OFB", aria192ofb_functions),
225 ALG("ARIA-128-OFB", aria128ofb_functions),
226 ALG("ARIA-256-CFB", aria256cfb_functions),
227 ALG("ARIA-192-CFB", aria192cfb_functions),
228 ALG("ARIA-128-CFB", aria128cfb_functions),
229 ALG("ARIA-256-CFB1", aria256cfb1_functions),
230 ALG("ARIA-192-CFB1", aria192cfb1_functions),
231 ALG("ARIA-128-CFB1", aria128cfb1_functions),
232 ALG("ARIA-256-CFB8", aria256cfb8_functions),
233 ALG("ARIA-192-CFB8", aria192cfb8_functions),
234 ALG("ARIA-128-CFB8", aria128cfb8_functions),
235 ALG("ARIA-256-CTR", aria256ctr_functions),
236 ALG("ARIA-192-CTR", aria192ctr_functions),
237 ALG("ARIA-128-CTR", aria128ctr_functions),
238 #endif /* OPENSSL_NO_ARIA */
239 #ifndef OPENSSL_NO_CAMELLIA
240 ALG("CAMELLIA-256-ECB", camellia256ecb_functions),
241 ALG("CAMELLIA-192-ECB", camellia192ecb_functions),
242 ALG("CAMELLIA-128-ECB", camellia128ecb_functions),
243 ALG("CAMELLIA-256-CBC:CAMELLIA256", camellia256cbc_functions),
244 ALG("CAMELLIA-192-CBC:CAMELLIA192", camellia192cbc_functions),
245 ALG("CAMELLIA-128-CBC:CAMELLIA128", camellia128cbc_functions),
246 ALG("CAMELLIA-256-OFB", camellia256ofb_functions),
247 ALG("CAMELLIA-192-OFB", camellia192ofb_functions),
248 ALG("CAMELLIA-128-OFB", camellia128ofb_functions),
249 ALG("CAMELLIA-256-CFB", camellia256cfb_functions),
250 ALG("CAMELLIA-192-CFB", camellia192cfb_functions),
251 ALG("CAMELLIA-128-CFB", camellia128cfb_functions),
252 ALG("CAMELLIA-256-CFB1", camellia256cfb1_functions),
253 ALG("CAMELLIA-192-CFB1", camellia192cfb1_functions),
254 ALG("CAMELLIA-128-CFB1", camellia128cfb1_functions),
255 ALG("CAMELLIA-256-CFB8", camellia256cfb8_functions),
256 ALG("CAMELLIA-192-CFB8", camellia192cfb8_functions),
257 ALG("CAMELLIA-128-CFB8", camellia128cfb8_functions),
258 ALG("CAMELLIA-256-CTR", camellia256ctr_functions),
259 ALG("CAMELLIA-192-CTR", camellia192ctr_functions),
260 ALG("CAMELLIA-128-CTR", camellia128ctr_functions),
261 #endif /* OPENSSL_NO_CAMELLIA */
262 #ifndef OPENSSL_NO_DES
263 ALG("DES-EDE3-ECB:DES-EDE3", tdes_ede3_ecb_functions),
264 ALG("DES-EDE3-CBC:DES3", tdes_ede3_cbc_functions),
265 ALG("DES-EDE3-OFB", tdes_ede3_ofb_functions),
266 ALG("DES-EDE3-CFB", tdes_ede3_cfb_functions),
267 ALG("DES-EDE3-CFB8", tdes_ede3_cfb8_functions),
268 ALG("DES-EDE3-CFB1", tdes_ede3_cfb1_functions),
269 ALG("DES3-WRAP:id-smime-alg-CMS3DESwrap", tdes_wrap_cbc_functions),
270 ALG("DES-EDE-ECB:DES-EDE", tdes_ede2_ecb_functions),
271 ALG("DES-EDE-CBC", tdes_ede2_cbc_functions),
272 ALG("DES-EDE-OFB", tdes_ede2_ofb_functions),
273 ALG("DES-EDE-CFB", tdes_ede2_cfb_functions),
274 #endif /* OPENSSL_NO_DES */
275 #ifndef OPENSSL_NO_SM4
276 ALG("SM4-ECB", sm4128ecb_functions),
277 ALG("SM4-CBC:SM4", sm4128cbc_functions),
278 ALG("SM4-CTR", sm4128ctr_functions),
279 ALG("SM4-OFB:SM4-OFB128", sm4128ofb128_functions),
280 ALG("SM4-CFB:SM4-CFB128", sm4128cfb128_functions),
281 #endif /* OPENSSL_NO_SM4 */
282 #ifndef OPENSSL_NO_CHACHA
283 ALG("ChaCha20", chacha20_functions),
284 # ifndef OPENSSL_NO_POLY1305
285 ALG("ChaCha20-Poly1305", chacha20_poly1305_functions),
286 # endif /* OPENSSL_NO_POLY1305 */
287 #endif /* OPENSSL_NO_CHACHA */
288 { { NULL, NULL, NULL }, NULL }
289 };
290 static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)];
291
292 static const OSSL_ALGORITHM deflt_macs[] = {
293 #ifndef OPENSSL_NO_BLAKE2
294 { "BLAKE2BMAC", "provider=default", blake2bmac_functions },
295 { "BLAKE2SMAC", "provider=default", blake2smac_functions },
296 #endif
297 #ifndef OPENSSL_NO_CMAC
298 { "CMAC", "provider=default", cmac_functions },
299 #endif
300 { "GMAC", "provider=default", gmac_functions },
301 { "HMAC", "provider=default", hmac_functions },
302 { "KMAC-128:KMAC128", "provider=default", kmac128_functions },
303 { "KMAC-256:KMAC256", "provider=default", kmac256_functions },
304 #ifndef OPENSSL_NO_SIPHASH
305 { "SIPHASH", "provider=default", siphash_functions },
306 #endif
307 #ifndef OPENSSL_NO_POLY1305
308 { "POLY1305", "provider=default", poly1305_functions },
309 #endif
310 { NULL, NULL, NULL }
311 };
312
313 static const OSSL_ALGORITHM deflt_kdfs[] = {
314 { "HKDF", "provider=default", kdf_hkdf_functions },
315 { "SSKDF", "provider=default", kdf_sskdf_functions },
316 { "PBKDF2", "provider=default", kdf_pbkdf2_functions },
317 { "SSHKDF", "provider=default", kdf_sshkdf_functions },
318 { "X963KDF", "provider=default", kdf_x963_kdf_functions },
319 { "TLS1-PRF", "provider=default", kdf_tls1_prf_functions },
320 { "KBKDF", "provider=default", kdf_kbkdf_functions },
321 #ifndef OPENSSL_NO_CMS
322 { "X942KDF", "provider=default", kdf_x942_kdf_functions },
323 #endif
324 #ifndef OPENSSL_NO_SCRYPT
325 { "SCRYPT:id-scrypt", "provider=default", kdf_scrypt_functions },
326 #endif
327 { "KRB5KDF", "provider=default", kdf_krb5kdf_functions },
328 { NULL, NULL, NULL }
329 };
330
331 static const OSSL_ALGORITHM deflt_keyexch[] = {
332 #ifndef OPENSSL_NO_DH
333 { "DH:dhKeyAgreement", "provider=default", dh_keyexch_functions },
334 #endif
335 #ifndef OPENSSL_NO_EC
336 { "ECDH", "provider=default", ecdh_keyexch_functions },
337 { "X25519", "provider=default", x25519_keyexch_functions },
338 { "X448", "provider=default", x448_keyexch_functions },
339 #endif
340 { NULL, NULL, NULL }
341 };
342
343 static const OSSL_ALGORITHM deflt_rands[] = {
344 { "CTR-DRBG", "provider=default", drbg_ctr_functions },
345 { "HASH-DRBG", "provider=default", drbg_hash_functions },
346 { "HMAC-DRBG", "provider=default", drbg_hmac_functions },
347 { "TEST-RAND", "provider=default", test_rng_functions },
348 { NULL, NULL, NULL }
349 };
350
351 static const OSSL_ALGORITHM deflt_signature[] = {
352 #ifndef OPENSSL_NO_DSA
353 { "DSA:dsaEncryption", "provider=default", dsa_signature_functions },
354 #endif
355 { "RSA:rsaEncryption", "provider=default", rsa_signature_functions },
356 #ifndef OPENSSL_NO_EC
357 { "ED25519:Ed25519", "provider=default", ed25519_signature_functions },
358 { "ED448:Ed448", "provider=default", ed448_signature_functions },
359 { "ECDSA", "provider=default", ecdsa_signature_functions },
360 #endif
361 { NULL, NULL, NULL }
362 };
363
364 static const OSSL_ALGORITHM deflt_asym_cipher[] = {
365 { "RSA:rsaEncryption", "provider=default", rsa_asym_cipher_functions },
366 { NULL, NULL, NULL }
367 };
368
369 static const OSSL_ALGORITHM deflt_keymgmt[] = {
370 #ifndef OPENSSL_NO_DH
371 { "DH:dhKeyAgreement", "provider=default", dh_keymgmt_functions },
372 #endif
373 #ifndef OPENSSL_NO_DSA
374 { "DSA:dsaEncryption", "provider=default", dsa_keymgmt_functions },
375 #endif
376 { "RSA:rsaEncryption", "provider=default", rsa_keymgmt_functions },
377 { "RSA-PSS:RSASSA-PSS", "provider=default", rsapss_keymgmt_functions },
378 #ifndef OPENSSL_NO_EC
379 { "EC:id-ecPublicKey", "provider=default", ec_keymgmt_functions },
380 { "X25519", "provider=default", x25519_keymgmt_functions },
381 { "X448", "provider=default", x448_keymgmt_functions },
382 { "ED25519", "provider=default", ed25519_keymgmt_functions },
383 { "ED448", "provider=default", ed448_keymgmt_functions },
384 #endif
385 { NULL, NULL, NULL }
386 };
387
388 /*
389 * Unlike most algorithms in the default provider, the serializers are allowed
390 * for use in FIPS mode because they are not FIPS relevant, and therefore have
391 * the "fips=yes" property.
392 */
393 static const OSSL_ALGORITHM deflt_serializer[] = {
394 { "RSA", "provider=default,fips=yes,format=text,type=private",
395 rsa_priv_text_serializer_functions },
396 { "RSA", "provider=default,fips=yes,format=text,type=public",
397 rsa_pub_text_serializer_functions },
398 { "RSA", "provider=default,fips=yes,format=der,type=private",
399 rsa_priv_der_serializer_functions },
400 { "RSA", "provider=default,fips=yes,format=der,type=public",
401 rsa_pub_der_serializer_functions },
402 { "RSA", "provider=default,fips=yes,format=pem,type=private",
403 rsa_priv_pem_serializer_functions },
404 { "RSA", "provider=default,fips=yes,format=pem,type=public",
405 rsa_pub_pem_serializer_functions },
406 { "RSA-PSS", "provider=default,fips=yes,format=text,type=private",
407 rsa_priv_text_serializer_functions },
408 { "RSA-PSS", "provider=default,fips=yes,format=text,type=public",
409 rsa_pub_text_serializer_functions },
410 { "RSA-PSS", "provider=default,fips=yes,format=der,type=private",
411 rsa_priv_der_serializer_functions },
412 { "RSA-PSS", "provider=default,fips=yes,format=der,type=public",
413 rsa_pub_der_serializer_functions },
414 { "RSA-PSS", "provider=default,fips=yes,format=pem,type=private",
415 rsa_priv_pem_serializer_functions },
416 { "RSA-PSS", "provider=default,fips=yes,format=pem,type=public",
417 rsa_pub_pem_serializer_functions },
418
419 #ifndef OPENSSL_NO_DH
420 { "DH", "provider=default,fips=yes,format=text,type=private",
421 dh_priv_text_serializer_functions },
422 { "DH", "provider=default,fips=yes,format=text,type=public",
423 dh_pub_text_serializer_functions },
424 { "DH", "provider=default,fips=yes,format=text,type=parameters",
425 dh_param_text_serializer_functions },
426 { "DH", "provider=default,fips=yes,format=der,type=private",
427 dh_priv_der_serializer_functions },
428 { "DH", "provider=default,fips=yes,format=der,type=public",
429 dh_pub_der_serializer_functions },
430 { "DH", "provider=default,fips=yes,format=der,type=parameters",
431 dh_param_der_serializer_functions },
432 { "DH", "provider=default,fips=yes,format=pem,type=private",
433 dh_priv_pem_serializer_functions },
434 { "DH", "provider=default,fips=yes,format=pem,type=public",
435 dh_pub_pem_serializer_functions },
436 { "DH", "provider=default,fips=yes,format=pem,type=parameters",
437 dh_param_pem_serializer_functions },
438 #endif
439
440 #ifndef OPENSSL_NO_DSA
441 { "DSA", "provider=default,fips=yes,format=text,type=private",
442 dsa_priv_text_serializer_functions },
443 { "DSA", "provider=default,fips=yes,format=text,type=public",
444 dsa_pub_text_serializer_functions },
445 { "DSA", "provider=default,fips=yes,format=text,type=parameters",
446 dsa_param_text_serializer_functions },
447 { "DSA", "provider=default,fips=yes,format=der,type=private",
448 dsa_priv_der_serializer_functions },
449 { "DSA", "provider=default,fips=yes,format=der,type=public",
450 dsa_pub_der_serializer_functions },
451 { "DSA", "provider=default,fips=yes,format=der,type=parameters",
452 dsa_param_der_serializer_functions },
453 { "DSA", "provider=default,fips=yes,format=pem,type=private",
454 dsa_priv_pem_serializer_functions },
455 { "DSA", "provider=default,fips=yes,format=pem,type=public",
456 dsa_pub_pem_serializer_functions },
457 { "DSA", "provider=default,fips=yes,format=pem,type=parameters",
458 dsa_param_pem_serializer_functions },
459 #endif
460
461 #ifndef OPENSSL_NO_EC
462 { "X25519", "provider=default,fips=yes,format=text,type=private",
463 x25519_priv_print_serializer_functions },
464 { "X25519", "provider=default,fips=yes,format=text,type=public",
465 x25519_pub_print_serializer_functions },
466 { "X25519", "provider=default,fips=yes,format=der,type=private",
467 x25519_priv_der_serializer_functions },
468 { "X25519", "provider=default,fips=yes,format=der,type=public",
469 x25519_pub_der_serializer_functions },
470 { "X25519", "provider=default,fips=yes,format=pem,type=private",
471 x25519_priv_pem_serializer_functions },
472 { "X25519", "provider=default,fips=yes,format=pem,type=public",
473 x25519_pub_pem_serializer_functions },
474
475 { "X448", "provider=default,format=text,type=private",
476 x448_priv_print_serializer_functions },
477 { "X448", "provider=default,format=text,type=public",
478 x448_pub_print_serializer_functions },
479 { "X448", "provider=default,format=der,type=private",
480 x448_priv_der_serializer_functions },
481 { "X448", "provider=default,format=der,type=public",
482 x448_pub_der_serializer_functions },
483 { "X448", "provider=default,format=pem,type=private",
484 x448_priv_pem_serializer_functions },
485 { "X448", "provider=default,format=pem,type=public",
486 x448_pub_pem_serializer_functions },
487
488 { "ED25519", "provider=default,fips=yes,format=text,type=private",
489 ed25519_priv_print_serializer_functions },
490 { "ED25519", "provider=default,fips=yes,format=text,type=public",
491 ed25519_pub_print_serializer_functions },
492 { "ED25519", "provider=default,fips=yes,format=der,type=private",
493 ed25519_priv_der_serializer_functions },
494 { "ED25519", "provider=default,fips=yes,format=der,type=public",
495 ed25519_pub_der_serializer_functions },
496 { "ED25519", "provider=default,fips=yes,format=pem,type=private",
497 ed25519_priv_pem_serializer_functions },
498 { "ED25519", "provider=default,fips=yes,format=pem,type=public",
499 ed25519_pub_pem_serializer_functions },
500
501 { "ED448", "provider=default,format=text,type=private",
502 ed448_priv_print_serializer_functions },
503 { "ED448", "provider=default,format=text,type=public",
504 ed448_pub_print_serializer_functions },
505 { "ED448", "provider=default,format=der,type=private",
506 ed448_priv_der_serializer_functions },
507 { "ED448", "provider=default,format=der,type=public",
508 ed448_pub_der_serializer_functions },
509 { "ED448", "provider=default,format=pem,type=private",
510 ed448_priv_pem_serializer_functions },
511 { "ED448", "provider=default,format=pem,type=public",
512 ed448_pub_pem_serializer_functions },
513
514 { "EC", "provider=default,fips=yes,format=text,type=private",
515 ec_priv_text_serializer_functions },
516 { "EC", "provider=default,fips=yes,format=text,type=public",
517 ec_pub_text_serializer_functions },
518 { "EC", "provider=default,fips=yes,format=text,type=parameters",
519 ec_param_text_serializer_functions },
520 { "EC", "provider=default,fips=yes,format=der,type=private",
521 ec_priv_der_serializer_functions },
522 { "EC", "provider=default,fips=yes,format=der,type=public",
523 ec_pub_der_serializer_functions },
524 { "EC", "provider=default,fips=yes,format=der,type=parameters",
525 ec_param_der_serializer_functions },
526 { "EC", "provider=default,fips=yes,format=pem,type=private",
527 ec_priv_pem_serializer_functions },
528 { "EC", "provider=default,fips=yes,format=pem,type=public",
529 ec_pub_pem_serializer_functions },
530 { "EC", "provider=default,fips=yes,format=pem,type=parameters",
531 ec_param_pem_serializer_functions },
532 #endif
533
534 { NULL, NULL, NULL }
535 };
536
537 static const OSSL_ALGORITHM deflt_deserializer[] = {
538 { "RSA", "provider=default,fips=yes,input=der",
539 der_to_rsa_deserializer_functions },
540
541 { "DER", "provider=default,fips=yes,input=pem",
542 pem_to_der_deserializer_functions },
543
544 { NULL, NULL, NULL }
545 };
546
547 static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id,
548 int *no_cache)
549 {
550 *no_cache = 0;
551 switch (operation_id) {
552 case OSSL_OP_DIGEST:
553 return deflt_digests;
554 case OSSL_OP_CIPHER:
555 ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers);
556 return exported_ciphers;
557 case OSSL_OP_MAC:
558 return deflt_macs;
559 case OSSL_OP_KDF:
560 return deflt_kdfs;
561 case OSSL_OP_RAND:
562 return deflt_rands;
563 case OSSL_OP_KEYMGMT:
564 return deflt_keymgmt;
565 case OSSL_OP_KEYEXCH:
566 return deflt_keyexch;
567 case OSSL_OP_SIGNATURE:
568 return deflt_signature;
569 case OSSL_OP_ASYM_CIPHER:
570 return deflt_asym_cipher;
571 case OSSL_OP_SERIALIZER:
572 return deflt_serializer;
573 case OSSL_OP_DESERIALIZER:
574 return deflt_deserializer;
575 }
576 return NULL;
577 }
578
579
580 static void deflt_teardown(void *provctx)
581 {
582 BIO_meth_free(PROV_CTX_get0_core_bio_method(provctx));
583 PROV_CTX_free(provctx);
584 }
585
586 /* Functions we provide to the core */
587 static const OSSL_DISPATCH deflt_dispatch_table[] = {
588 { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown },
589 { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params },
590 { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params },
591 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query },
592 { OSSL_FUNC_PROVIDER_GET_CAPABILITIES, (void (*)(void))provider_get_capabilities },
593 { 0, NULL }
594 };
595
596 OSSL_provider_init_fn ossl_default_provider_init;
597
598 int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle,
599 const OSSL_DISPATCH *in,
600 const OSSL_DISPATCH **out,
601 void **provctx)
602 {
603 OSSL_FUNC_core_get_library_context_fn *c_get_libctx = NULL;
604 BIO_METHOD *corebiometh;
605
606 if (!ossl_prov_bio_from_dispatch(in))
607 return 0;
608 for (; in->function_id != 0; in++) {
609 switch (in->function_id) {
610 case OSSL_FUNC_CORE_GETTABLE_PARAMS:
611 c_gettable_params = OSSL_FUNC_core_gettable_params(in);
612 break;
613 case OSSL_FUNC_CORE_GET_PARAMS:
614 c_get_params = OSSL_FUNC_core_get_params(in);
615 break;
616 case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT:
617 c_get_libctx = OSSL_FUNC_core_get_library_context(in);
618 break;
619 default:
620 /* Just ignore anything we don't understand */
621 break;
622 }
623 }
624
625 if (c_get_libctx == NULL)
626 return 0;
627
628 /*
629 * We want to make sure that all calls from this provider that requires
630 * a library context use the same context as the one used to call our
631 * functions. We do that by passing it along in the provider context.
632 *
633 * This only works for built-in providers. Most providers should
634 * create their own library context.
635 */
636 if ((*provctx = PROV_CTX_new()) == NULL
637 || (corebiometh = bio_prov_init_bio_method()) == NULL) {
638 PROV_CTX_free(*provctx);
639 *provctx = NULL;
640 return 0;
641 }
642 PROV_CTX_set0_library_context(*provctx, (OPENSSL_CTX *)c_get_libctx(handle));
643 PROV_CTX_set0_handle(*provctx, handle);
644 PROV_CTX_set0_core_bio_method(*provctx, corebiometh);
645
646 *out = deflt_dispatch_table;
647
648 return 1;
649 }