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