]>
Commit | Line | Data |
---|---|---|
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 | 13 | #include <openssl/core.h> |
23c48d94 | 14 | #include <openssl/core_dispatch.h> |
8a73348b MC |
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 | */ | |
363b1e5d DMSP |
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; | |
fdaad3f1 | 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 */ | |
363b1e5d DMSP |
36 | static OSSL_FUNC_core_gettable_params_fn *c_gettable_params = NULL; |
37 | static OSSL_FUNC_core_get_params_fn *c_get_params = NULL; | |
8a73348b MC |
38 | |
39 | /* Parameters we provide to the core */ | |
26175013 RL |
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), | |
eab7b424 | 44 | OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0), |
26175013 | 45 | OSSL_PARAM_END |
8a73348b MC |
46 | }; |
47 | ||
fdaad3f1 | 48 | static const OSSL_PARAM *deflt_gettable_params(void *provctx) |
8a73348b MC |
49 | { |
50 | return deflt_param_types; | |
51 | } | |
52 | ||
fdaad3f1 | 53 | static int deflt_get_params(void *provctx, OSSL_PARAM params[]) |
8a73348b | 54 | { |
4e7991b4 | 55 | OSSL_PARAM *p; |
8a73348b MC |
56 | |
57 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME); | |
58 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider")) | |
59 | return 0; | |
60 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION); | |
61 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR)) | |
62 | return 0; | |
63 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO); | |
64 | if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR)) | |
65 | return 0; | |
04cb5ec0 | 66 | p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS); |
eab7b424 | 67 | if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running())) |
04cb5ec0 | 68 | return 0; |
8a73348b MC |
69 | return 1; |
70 | } | |
71 | ||
df553b79 RL |
72 | /* |
73 | * For the algorithm names, we use the following formula for our primary | |
74 | * names: | |
75 | * | |
76 | * ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?] | |
77 | * | |
78 | * VERSION is only present if there are multiple versions of | |
79 | * an alg (MD2, MD4, MD5). It may be omitted if there is only | |
80 | * one version (if a subsequent version is released in the future, | |
81 | * we can always change the canonical name, and add the old name | |
82 | * as an alias). | |
83 | * | |
84 | * SUBNAME may be present where we are combining multiple | |
85 | * algorithms together, e.g. MD5-SHA1. | |
86 | * | |
87 | * SIZE is only present if multiple versions of an algorithm exist | |
88 | * with different sizes (e.g. AES-128-CBC, AES-256-CBC) | |
89 | * | |
90 | * MODE is only present where applicable. | |
91 | * | |
92 | * We add diverse other names where applicable, such as the names that | |
93 | * NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names | |
94 | * we have used historically. | |
cc35c3ed MC |
95 | * |
96 | * Algorithm names are case insensitive, but we use all caps in our "canonical" | |
97 | * names for consistency. | |
df553b79 | 98 | */ |
de29ff17 | 99 | static const OSSL_ALGORITHM deflt_digests[] = { |
df553b79 | 100 | /* Our primary name:NIST name[:our older names] */ |
1be63951 P |
101 | { "SHA1:SHA-1:SSL3-SHA1", "provider=default", ossl_sha1_functions }, |
102 | { "SHA2-224:SHA-224:SHA224", "provider=default", ossl_sha224_functions }, | |
103 | { "SHA2-256:SHA-256:SHA256", "provider=default", ossl_sha256_functions }, | |
104 | { "SHA2-384:SHA-384:SHA384", "provider=default", ossl_sha384_functions }, | |
105 | { "SHA2-512:SHA-512:SHA512", "provider=default", ossl_sha512_functions }, | |
745fc918 | 106 | { "SHA2-512/224:SHA-512/224:SHA512-224", "provider=default", |
1be63951 | 107 | ossl_sha512_224_functions }, |
745fc918 | 108 | { "SHA2-512/256:SHA-512/256:SHA512-256", "provider=default", |
1be63951 | 109 | ossl_sha512_256_functions }, |
d5e5e2ff | 110 | |
df553b79 | 111 | /* We agree with NIST here, so one name only */ |
1be63951 P |
112 | { "SHA3-224", "provider=default", ossl_sha3_224_functions }, |
113 | { "SHA3-256", "provider=default", ossl_sha3_256_functions }, | |
114 | { "SHA3-384", "provider=default", ossl_sha3_384_functions }, | |
115 | { "SHA3-512", "provider=default", ossl_sha3_512_functions }, | |
d5e5e2ff | 116 | |
e23cda00 | 117 | /* |
cc35c3ed MC |
118 | * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for |
119 | * the KMAC-128 and KMAC-256. | |
e23cda00 | 120 | */ |
1be63951 P |
121 | { "KECCAK-KMAC-128:KECCAK-KMAC128", "provider=default", |
122 | ossl_keccak_kmac_128_functions }, | |
123 | { "KECCAK-KMAC-256:KECCAK-KMAC256", "provider=default", | |
124 | ossl_keccak_kmac_256_functions }, | |
d5e5e2ff | 125 | |
df553b79 | 126 | /* Our primary name:NIST name */ |
1be63951 P |
127 | { "SHAKE-128:SHAKE128", "provider=default", ossl_shake_128_functions }, |
128 | { "SHAKE-256:SHAKE256", "provider=default", ossl_shake_256_functions }, | |
d5e5e2ff SL |
129 | |
130 | #ifndef OPENSSL_NO_BLAKE2 | |
df553b79 RL |
131 | /* |
132 | * https://blake2.net/ doesn't specify size variants, | |
133 | * but mentions that Bouncy Castle uses the names | |
134 | * BLAKE2b-160, BLAKE2b-256, BLAKE2b-384, and BLAKE2b-512 | |
135 | * If we assume that "2b" and "2s" are versions, that pattern | |
136 | * fits with ours. We also add our historical names. | |
137 | */ | |
1be63951 P |
138 | { "BLAKE2S-256:BLAKE2s256", "provider=default", ossl_blake2s256_functions }, |
139 | { "BLAKE2B-512:BLAKE2b512", "provider=default", ossl_blake2b512_functions }, | |
d5e5e2ff SL |
140 | #endif /* OPENSSL_NO_BLAKE2 */ |
141 | ||
142 | #ifndef OPENSSL_NO_SM3 | |
1be63951 | 143 | { "SM3", "provider=default", ossl_sm3_functions }, |
d5e5e2ff SL |
144 | #endif /* OPENSSL_NO_SM3 */ |
145 | ||
146 | #ifndef OPENSSL_NO_MD5 | |
1be63951 P |
147 | { "MD5:SSL3-MD5", "provider=default", ossl_md5_functions }, |
148 | { "MD5-SHA1", "provider=default", ossl_md5_sha1_functions }, | |
d5e5e2ff SL |
149 | #endif /* OPENSSL_NO_MD5 */ |
150 | ||
de29ff17 MC |
151 | { NULL, NULL, NULL } |
152 | }; | |
153 | ||
0d2bfe52 | 154 | static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = { |
1be63951 P |
155 | ALG("NULL", ossl_null_functions), |
156 | ALG("AES-256-ECB", ossl_aes256ecb_functions), | |
157 | ALG("AES-192-ECB", ossl_aes192ecb_functions), | |
158 | ALG("AES-128-ECB", ossl_aes128ecb_functions), | |
159 | ALG("AES-256-CBC:AES256", ossl_aes256cbc_functions), | |
160 | ALG("AES-192-CBC:AES192", ossl_aes192cbc_functions), | |
161 | ALG("AES-128-CBC:AES128", ossl_aes128cbc_functions), | |
162 | ALG("AES-128-CBC-CTS", ossl_aes128cbc_cts_functions), | |
163 | ALG("AES-192-CBC-CTS", ossl_aes192cbc_cts_functions), | |
164 | ALG("AES-256-CBC-CTS", ossl_aes256cbc_cts_functions), | |
165 | ALG("AES-256-OFB", ossl_aes256ofb_functions), | |
166 | ALG("AES-192-OFB", ossl_aes192ofb_functions), | |
167 | ALG("AES-128-OFB", ossl_aes128ofb_functions), | |
168 | ALG("AES-256-CFB", ossl_aes256cfb_functions), | |
169 | ALG("AES-192-CFB", ossl_aes192cfb_functions), | |
170 | ALG("AES-128-CFB", ossl_aes128cfb_functions), | |
171 | ALG("AES-256-CFB1", ossl_aes256cfb1_functions), | |
172 | ALG("AES-192-CFB1", ossl_aes192cfb1_functions), | |
173 | ALG("AES-128-CFB1", ossl_aes128cfb1_functions), | |
174 | ALG("AES-256-CFB8", ossl_aes256cfb8_functions), | |
175 | ALG("AES-192-CFB8", ossl_aes192cfb8_functions), | |
176 | ALG("AES-128-CFB8", ossl_aes128cfb8_functions), | |
177 | ALG("AES-256-CTR", ossl_aes256ctr_functions), | |
178 | ALG("AES-192-CTR", ossl_aes192ctr_functions), | |
179 | ALG("AES-128-CTR", ossl_aes128ctr_functions), | |
180 | ALG("AES-256-XTS", ossl_aes256xts_functions), | |
181 | ALG("AES-128-XTS", ossl_aes128xts_functions), | |
3837c202 | 182 | #ifndef OPENSSL_NO_OCB |
1be63951 P |
183 | ALG("AES-256-OCB", ossl_aes256ocb_functions), |
184 | ALG("AES-192-OCB", ossl_aes192ocb_functions), | |
185 | ALG("AES-128-OCB", ossl_aes128ocb_functions), | |
3837c202 | 186 | #endif /* OPENSSL_NO_OCB */ |
eb173822 | 187 | #ifndef OPENSSL_NO_SIV |
1be63951 P |
188 | ALG("AES-128-SIV", ossl_aes128siv_functions), |
189 | ALG("AES-192-SIV", ossl_aes192siv_functions), | |
190 | ALG("AES-256-SIV", ossl_aes256siv_functions), | |
eb173822 | 191 | #endif /* OPENSSL_NO_SIV */ |
1be63951 P |
192 | ALG("AES-256-GCM:id-aes256-GCM", ossl_aes256gcm_functions), |
193 | ALG("AES-192-GCM:id-aes192-GCM", ossl_aes192gcm_functions), | |
194 | ALG("AES-128-GCM:id-aes128-GCM", ossl_aes128gcm_functions), | |
195 | ALG("AES-256-CCM:id-aes256-CCM", ossl_aes256ccm_functions), | |
196 | ALG("AES-192-CCM:id-aes192-CCM", ossl_aes192ccm_functions), | |
197 | ALG("AES-128-CCM:id-aes128-CCM", ossl_aes128ccm_functions), | |
198 | ALG("AES-256-WRAP:id-aes256-wrap:AES256-WRAP", ossl_aes256wrap_functions), | |
199 | ALG("AES-192-WRAP:id-aes192-wrap:AES192-WRAP", ossl_aes192wrap_functions), | |
200 | ALG("AES-128-WRAP:id-aes128-wrap:AES128-WRAP", ossl_aes128wrap_functions), | |
0d2bfe52 | 201 | ALG("AES-256-WRAP-PAD:id-aes256-wrap-pad:AES256-WRAP-PAD", |
1be63951 | 202 | ossl_aes256wrappad_functions), |
0d2bfe52 | 203 | ALG("AES-192-WRAP-PAD:id-aes192-wrap-pad:AES192-WRAP-PAD", |
1be63951 | 204 | ossl_aes192wrappad_functions), |
0d2bfe52 | 205 | ALG("AES-128-WRAP-PAD:id-aes128-wrap-pad:AES128-WRAP-PAD", |
1be63951 P |
206 | ossl_aes128wrappad_functions), |
207 | ALGC("AES-128-CBC-HMAC-SHA1", ossl_aes128cbc_hmac_sha1_functions, | |
0d2bfe52 | 208 | cipher_capable_aes_cbc_hmac_sha1), |
1be63951 | 209 | ALGC("AES-256-CBC-HMAC-SHA1", ossl_aes256cbc_hmac_sha1_functions, |
0d2bfe52 | 210 | cipher_capable_aes_cbc_hmac_sha1), |
1be63951 | 211 | ALGC("AES-128-CBC-HMAC-SHA256", ossl_aes128cbc_hmac_sha256_functions, |
0d2bfe52 | 212 | cipher_capable_aes_cbc_hmac_sha256), |
1be63951 | 213 | ALGC("AES-256-CBC-HMAC-SHA256", ossl_aes256cbc_hmac_sha256_functions, |
0d2bfe52 | 214 | cipher_capable_aes_cbc_hmac_sha256), |
a672a02a | 215 | #ifndef OPENSSL_NO_ARIA |
1be63951 P |
216 | ALG("ARIA-256-GCM", ossl_aria256gcm_functions), |
217 | ALG("ARIA-192-GCM", ossl_aria192gcm_functions), | |
218 | ALG("ARIA-128-GCM", ossl_aria128gcm_functions), | |
219 | ALG("ARIA-256-CCM", ossl_aria256ccm_functions), | |
220 | ALG("ARIA-192-CCM", ossl_aria192ccm_functions), | |
221 | ALG("ARIA-128-CCM", ossl_aria128ccm_functions), | |
222 | ALG("ARIA-256-ECB", ossl_aria256ecb_functions), | |
223 | ALG("ARIA-192-ECB", ossl_aria192ecb_functions), | |
224 | ALG("ARIA-128-ECB", ossl_aria128ecb_functions), | |
225 | ALG("ARIA-256-CBC:ARIA256", ossl_aria256cbc_functions), | |
226 | ALG("ARIA-192-CBC:ARIA192", ossl_aria192cbc_functions), | |
227 | ALG("ARIA-128-CBC:ARIA128", ossl_aria128cbc_functions), | |
228 | ALG("ARIA-256-OFB", ossl_aria256ofb_functions), | |
229 | ALG("ARIA-192-OFB", ossl_aria192ofb_functions), | |
230 | ALG("ARIA-128-OFB", ossl_aria128ofb_functions), | |
231 | ALG("ARIA-256-CFB", ossl_aria256cfb_functions), | |
232 | ALG("ARIA-192-CFB", ossl_aria192cfb_functions), | |
233 | ALG("ARIA-128-CFB", ossl_aria128cfb_functions), | |
234 | ALG("ARIA-256-CFB1", ossl_aria256cfb1_functions), | |
235 | ALG("ARIA-192-CFB1", ossl_aria192cfb1_functions), | |
236 | ALG("ARIA-128-CFB1", ossl_aria128cfb1_functions), | |
237 | ALG("ARIA-256-CFB8", ossl_aria256cfb8_functions), | |
238 | ALG("ARIA-192-CFB8", ossl_aria192cfb8_functions), | |
239 | ALG("ARIA-128-CFB8", ossl_aria128cfb8_functions), | |
240 | ALG("ARIA-256-CTR", ossl_aria256ctr_functions), | |
241 | ALG("ARIA-192-CTR", ossl_aria192ctr_functions), | |
242 | ALG("ARIA-128-CTR", ossl_aria128ctr_functions), | |
a672a02a | 243 | #endif /* OPENSSL_NO_ARIA */ |
e1178600 | 244 | #ifndef OPENSSL_NO_CAMELLIA |
1be63951 P |
245 | ALG("CAMELLIA-256-ECB", ossl_camellia256ecb_functions), |
246 | ALG("CAMELLIA-192-ECB", ossl_camellia192ecb_functions), | |
247 | ALG("CAMELLIA-128-ECB", ossl_camellia128ecb_functions), | |
248 | ALG("CAMELLIA-256-CBC:CAMELLIA256", ossl_camellia256cbc_functions), | |
249 | ALG("CAMELLIA-192-CBC:CAMELLIA192", ossl_camellia192cbc_functions), | |
250 | ALG("CAMELLIA-128-CBC:CAMELLIA128", ossl_camellia128cbc_functions), | |
251 | ALG("CAMELLIA-256-OFB", ossl_camellia256ofb_functions), | |
252 | ALG("CAMELLIA-192-OFB", ossl_camellia192ofb_functions), | |
253 | ALG("CAMELLIA-128-OFB", ossl_camellia128ofb_functions), | |
254 | ALG("CAMELLIA-256-CFB", ossl_camellia256cfb_functions), | |
255 | ALG("CAMELLIA-192-CFB", ossl_camellia192cfb_functions), | |
256 | ALG("CAMELLIA-128-CFB", ossl_camellia128cfb_functions), | |
257 | ALG("CAMELLIA-256-CFB1", ossl_camellia256cfb1_functions), | |
258 | ALG("CAMELLIA-192-CFB1", ossl_camellia192cfb1_functions), | |
259 | ALG("CAMELLIA-128-CFB1", ossl_camellia128cfb1_functions), | |
260 | ALG("CAMELLIA-256-CFB8", ossl_camellia256cfb8_functions), | |
261 | ALG("CAMELLIA-192-CFB8", ossl_camellia192cfb8_functions), | |
262 | ALG("CAMELLIA-128-CFB8", ossl_camellia128cfb8_functions), | |
263 | ALG("CAMELLIA-256-CTR", ossl_camellia256ctr_functions), | |
264 | ALG("CAMELLIA-192-CTR", ossl_camellia192ctr_functions), | |
265 | ALG("CAMELLIA-128-CTR", ossl_camellia128ctr_functions), | |
e1178600 | 266 | #endif /* OPENSSL_NO_CAMELLIA */ |
cb1548bc | 267 | #ifndef OPENSSL_NO_DES |
1be63951 P |
268 | ALG("DES-EDE3-ECB:DES-EDE3", ossl_tdes_ede3_ecb_functions), |
269 | ALG("DES-EDE3-CBC:DES3", ossl_tdes_ede3_cbc_functions), | |
270 | ALG("DES-EDE3-OFB", ossl_tdes_ede3_ofb_functions), | |
271 | ALG("DES-EDE3-CFB", ossl_tdes_ede3_cfb_functions), | |
272 | ALG("DES-EDE3-CFB8", ossl_tdes_ede3_cfb8_functions), | |
273 | ALG("DES-EDE3-CFB1", ossl_tdes_ede3_cfb1_functions), | |
274 | ALG("DES3-WRAP:id-smime-alg-CMS3DESwrap", ossl_tdes_wrap_cbc_functions), | |
275 | ALG("DES-EDE-ECB:DES-EDE", ossl_tdes_ede2_ecb_functions), | |
276 | ALG("DES-EDE-CBC", ossl_tdes_ede2_cbc_functions), | |
277 | ALG("DES-EDE-OFB", ossl_tdes_ede2_ofb_functions), | |
278 | ALG("DES-EDE-CFB", ossl_tdes_ede2_cfb_functions), | |
cb1548bc | 279 | #endif /* OPENSSL_NO_DES */ |
105dde25 | 280 | #ifndef OPENSSL_NO_SM4 |
1be63951 P |
281 | ALG("SM4-ECB", ossl_sm4128ecb_functions), |
282 | ALG("SM4-CBC:SM4", ossl_sm4128cbc_functions), | |
283 | ALG("SM4-CTR", ossl_sm4128ctr_functions), | |
284 | ALG("SM4-OFB:SM4-OFB128", ossl_sm4128ofb128_functions), | |
285 | ALG("SM4-CFB:SM4-CFB128", ossl_sm4128cfb128_functions), | |
105dde25 | 286 | #endif /* OPENSSL_NO_SM4 */ |
3d5a7578 | 287 | #ifndef OPENSSL_NO_CHACHA |
1be63951 | 288 | ALG("ChaCha20", ossl_chacha20_functions), |
3d5a7578 | 289 | # ifndef OPENSSL_NO_POLY1305 |
1be63951 | 290 | ALG("ChaCha20-Poly1305", ossl_chacha20_ossl_poly1305_functions), |
3d5a7578 SL |
291 | # endif /* OPENSSL_NO_POLY1305 */ |
292 | #endif /* OPENSSL_NO_CHACHA */ | |
0d2bfe52 | 293 | { { NULL, NULL, NULL }, NULL } |
aab26e6f | 294 | }; |
0d2bfe52 | 295 | static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)]; |
aab26e6f | 296 | |
55a0a117 RL |
297 | static const OSSL_ALGORITHM deflt_macs[] = { |
298 | #ifndef OPENSSL_NO_BLAKE2 | |
1be63951 P |
299 | { "BLAKE2BMAC", "provider=default", ossl_blake2bmac_functions }, |
300 | { "BLAKE2SMAC", "provider=default", ossl_blake2smac_functions }, | |
2e5db6ad RL |
301 | #endif |
302 | #ifndef OPENSSL_NO_CMAC | |
1be63951 | 303 | { "CMAC", "provider=default", ossl_cmac_functions }, |
55a0a117 | 304 | #endif |
1be63951 P |
305 | { "GMAC", "provider=default", ossl_gmac_functions }, |
306 | { "HMAC", "provider=default", ossl_hmac_functions }, | |
307 | { "KMAC-128:KMAC128", "provider=default", ossl_kmac128_functions }, | |
308 | { "KMAC-256:KMAC256", "provider=default", ossl_kmac256_functions }, | |
4657693d | 309 | #ifndef OPENSSL_NO_SIPHASH |
1be63951 | 310 | { "SIPHASH", "provider=default", ossl_siphash_functions }, |
ae0b6b92 RL |
311 | #endif |
312 | #ifndef OPENSSL_NO_POLY1305 | |
1be63951 | 313 | { "POLY1305", "provider=default", ossl_poly1305_functions }, |
4657693d | 314 | #endif |
55a0a117 RL |
315 | { NULL, NULL, NULL } |
316 | }; | |
317 | ||
e3405a4a | 318 | static const OSSL_ALGORITHM deflt_kdfs[] = { |
1be63951 P |
319 | { "HKDF", "provider=default", ossl_kdf_hkdf_functions }, |
320 | { "SSKDF", "provider=default", ossl_kdf_sskdf_functions }, | |
321 | { "PBKDF2", "provider=default", ossl_kdf_pbkdf2_functions }, | |
322 | { "PKCS12KDF", "provider=default", ossl_kdf_pkcs12_functions }, | |
323 | { "SSHKDF", "provider=default", ossl_kdf_sshkdf_functions }, | |
324 | { "X963KDF", "provider=default", ossl_kdf_x963_kdf_functions }, | |
325 | { "TLS1-PRF", "provider=default", ossl_kdf_tls1_prf_functions }, | |
326 | { "KBKDF", "provider=default", ossl_kdf_kbkdf_functions }, | |
e3405a4a | 327 | #ifndef OPENSSL_NO_CMS |
1be63951 | 328 | { "X942KDF", "provider=default", ossl_kdf_x942_kdf_functions }, |
e3405a4a P |
329 | #endif |
330 | #ifndef OPENSSL_NO_SCRYPT | |
1be63951 | 331 | { "SCRYPT:id-scrypt", "provider=default", ossl_kdf_scrypt_functions }, |
e3405a4a | 332 | #endif |
1be63951 | 333 | { "KRB5KDF", "provider=default", ossl_kdf_krb5kdf_functions }, |
0fee1dff | 334 | { NULL, NULL, NULL } |
e3405a4a P |
335 | }; |
336 | ||
89e29174 | 337 | static const OSSL_ALGORITHM deflt_keyexch[] = { |
76ca35e7 | 338 | #ifndef OPENSSL_NO_DH |
1be63951 | 339 | { "DH:dhKeyAgreement", "provider=default", ossl_dh_keyexch_functions }, |
6f7d2135 MC |
340 | #endif |
341 | #ifndef OPENSSL_NO_EC | |
1be63951 P |
342 | { "ECDH", "provider=default", ecossl_dh_keyexch_functions }, |
343 | { "X25519", "provider=default", ossl_x25519_keyexch_functions }, | |
344 | { "X448", "provider=default", ossl_x448_keyexch_functions }, | |
8b84b075 | 345 | #endif |
1be63951 P |
346 | { "TLS1-PRF", "provider=default", ossl_kdf_tls1_prf_keyexch_functions }, |
347 | { "HKDF", "provider=default", ossl_kdf_hkdf_keyexch_functions }, | |
348 | { "SCRYPT:id-scrypt", "provider=default", | |
349 | ossl_kdf_scrypt_keyexch_functions }, | |
8b84b075 RL |
350 | { NULL, NULL, NULL } |
351 | }; | |
352 | ||
bcc4ae67 | 353 | static const OSSL_ALGORITHM deflt_rands[] = { |
1be63951 P |
354 | { "CTR-DRBG", "provider=default", ossl_drbg_ctr_functions }, |
355 | { "HASH-DRBG", "provider=default", ossl_drbg_hash_functions }, | |
356 | { "HMAC-DRBG", "provider=default", ossl_drbg_ossl_hmac_functions }, | |
357 | { "TEST-RAND", "provider=default", ossl_test_rng_functions }, | |
bcc4ae67 P |
358 | { NULL, NULL, NULL } |
359 | }; | |
360 | ||
4889dadc MC |
361 | static const OSSL_ALGORITHM deflt_signature[] = { |
362 | #ifndef OPENSSL_NO_DSA | |
1be63951 | 363 | { "DSA:dsaEncryption", "provider=default", ossl_dsa_signature_functions }, |
4889dadc | 364 | #endif |
1be63951 | 365 | { "RSA:rsaEncryption", "provider=default", ossl_rsa_signature_functions }, |
3965480c | 366 | #ifndef OPENSSL_NO_EC |
1be63951 P |
367 | { "ED25519:Ed25519", "provider=default", ossl_ed25519_signature_functions }, |
368 | { "ED448:Ed448", "provider=default", ossl_ed448_signature_functions }, | |
369 | { "ECDSA", "provider=default", ecossl_dsa_signature_functions }, | |
d0b79f86 PY |
370 | # ifndef OPENSSL_NO_SM2 |
371 | { "SM2", "provider=default", sm2_signature_functions }, | |
372 | # endif | |
3965480c | 373 | #endif |
1be63951 P |
374 | { "HMAC", "provider=default", ossl_mac_legacy_hmac_signature_functions }, |
375 | { "SIPHASH", "provider=default", | |
376 | ossl_mac_legacy_siphash_signature_functions }, | |
4db71d01 | 377 | #ifndef OPENSSL_NO_POLY1305 |
1be63951 P |
378 | { "POLY1305", "provider=default", |
379 | ossl_mac_legacy_poly1305_signature_functions }, | |
a540ef90 MC |
380 | #endif |
381 | #ifndef OPENSSL_NO_CMAC | |
1be63951 | 382 | { "CMAC", "provider=default", ossl_mac_legacy_cmac_signature_functions }, |
4db71d01 | 383 | #endif |
4889dadc MC |
384 | { NULL, NULL, NULL } |
385 | }; | |
386 | ||
89abd1b6 | 387 | static const OSSL_ALGORITHM deflt_asym_cipher[] = { |
1be63951 | 388 | { "RSA:rsaEncryption", "provider=default", ossl_rsa_asym_cipher_functions }, |
ce64d3ee MC |
389 | #ifndef OPENSSL_NO_SM2 |
390 | { "SM2", "provider=default", sm2_asym_cipher_functions }, | |
391 | #endif | |
89abd1b6 MC |
392 | { NULL, NULL, NULL } |
393 | }; | |
4889dadc | 394 | |
80f4fd18 | 395 | static const OSSL_ALGORITHM deflt_asym_kem[] = { |
1be63951 | 396 | { "RSA", "provider=default", ossl_rsa_asym_kem_functions }, |
80f4fd18 SL |
397 | { NULL, NULL, NULL } |
398 | }; | |
399 | ||
8b84b075 RL |
400 | static const OSSL_ALGORITHM deflt_keymgmt[] = { |
401 | #ifndef OPENSSL_NO_DH | |
1be63951 P |
402 | { "DH:dhKeyAgreement", "provider=default", ossl_dh_keymgmt_functions }, |
403 | { "DHX:X9.42 DH:dhpublicnumber", "provider=default", | |
404 | ossl_dhx_keymgmt_functions }, | |
4889dadc MC |
405 | #endif |
406 | #ifndef OPENSSL_NO_DSA | |
1be63951 | 407 | { "DSA:dsaEncryption", "provider=default", ossl_dsa_keymgmt_functions }, |
76ca35e7 | 408 | #endif |
1be63951 P |
409 | { "RSA:rsaEncryption", "provider=default", ossl_rsa_keymgmt_functions }, |
410 | { "RSA-PSS:RSASSA-PSS", "provider=default", ossl_rsapss_keymgmt_functions }, | |
90d3cb57 | 411 | #ifndef OPENSSL_NO_EC |
1be63951 P |
412 | { "EC:id-ecPublicKey", "provider=default", ossl_ec_keymgmt_functions }, |
413 | { "X25519", "provider=default", ossl_x25519_keymgmt_functions }, | |
414 | { "X448", "provider=default", ossl_x448_keymgmt_functions }, | |
415 | { "ED25519", "provider=default", ossl_ed25519_keymgmt_functions }, | |
416 | { "ED448", "provider=default", ossl_ed448_keymgmt_functions }, | |
90d3cb57 | 417 | #endif |
1be63951 P |
418 | { "TLS1-PRF", "provider=default", ossl_kdf_keymgmt_functions }, |
419 | { "HKDF", "provider=default", ossl_kdf_keymgmt_functions }, | |
420 | { "SCRYPT:id-scrypt", "provider=default", ossl_kdf_keymgmt_functions }, | |
421 | { "HMAC", "provider=default", ossl_mac_legacy_keymgmt_functions }, | |
422 | { "SIPHASH", "provider=default", ossl_mac_legacy_keymgmt_functions }, | |
4db71d01 | 423 | #ifndef OPENSSL_NO_POLY1305 |
1be63951 | 424 | { "POLY1305", "provider=default", ossl_mac_legacy_keymgmt_functions }, |
a540ef90 MC |
425 | #endif |
426 | #ifndef OPENSSL_NO_CMAC | |
1be63951 | 427 | { "CMAC", "provider=default", ossl_cossl_mac_legacy_keymgmt_functions }, |
d0b79f86 | 428 | #endif |
7ee511d0 PY |
429 | #ifndef OPENSSL_NO_SM2 |
430 | { "SM2", "provider=default", sm2_keymgmt_functions }, | |
4db71d01 | 431 | #endif |
89e29174 MC |
432 | { NULL, NULL, NULL } |
433 | }; | |
434 | ||
ece9304c | 435 | static const OSSL_ALGORITHM deflt_encoder[] = { |
111dc4b0 | 436 | #define ENCODER(name, _fips, _output, func_table) \ |
dfc0857d | 437 | { name, \ |
111dc4b0 | 438 | "provider=default,fips=" _fips ",output=" _output, \ |
dfc0857d | 439 | (func_table) } |
1017b8e4 | 440 | |
ece9304c | 441 | #include "encoders.inc" |
1017b8e4 RL |
442 | { NULL, NULL, NULL } |
443 | }; | |
ece9304c | 444 | #undef ENCODER |
1017b8e4 | 445 | |
ece9304c | 446 | static const OSSL_ALGORITHM deflt_decoder[] = { |
b48ca22a | 447 | #define DECODER(name, _fips, _input, func_table) \ |
a3f15e23 | 448 | { name, \ |
b48ca22a | 449 | "provider=default,fips=" _fips ",input=" _input, \ |
a3f15e23 | 450 | (func_table) } |
dcfacbbf | 451 | |
ece9304c | 452 | #include "decoders.inc" |
677add38 RL |
453 | { NULL, NULL, NULL } |
454 | }; | |
ece9304c | 455 | #undef DECODER |
677add38 | 456 | |
63f187cf | 457 | static const OSSL_ALGORITHM deflt_store[] = { |
ce43db7a JS |
458 | #define STORE(name, _fips, func_table) \ |
459 | { name, "provider=default,fips=" _fips, (func_table) }, | |
63f187cf RL |
460 | |
461 | #include "stores.inc" | |
462 | { NULL, NULL, NULL } | |
463 | #undef STORE | |
464 | }; | |
465 | ||
fdaad3f1 | 466 | static const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id, |
de29ff17 MC |
467 | int *no_cache) |
468 | { | |
469 | *no_cache = 0; | |
470 | switch (operation_id) { | |
471 | case OSSL_OP_DIGEST: | |
472 | return deflt_digests; | |
aab26e6f | 473 | case OSSL_OP_CIPHER: |
0d2bfe52 SL |
474 | ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers); |
475 | return exported_ciphers; | |
55a0a117 RL |
476 | case OSSL_OP_MAC: |
477 | return deflt_macs; | |
e3405a4a P |
478 | case OSSL_OP_KDF: |
479 | return deflt_kdfs; | |
bcc4ae67 P |
480 | case OSSL_OP_RAND: |
481 | return deflt_rands; | |
8b84b075 RL |
482 | case OSSL_OP_KEYMGMT: |
483 | return deflt_keymgmt; | |
89e29174 MC |
484 | case OSSL_OP_KEYEXCH: |
485 | return deflt_keyexch; | |
4889dadc MC |
486 | case OSSL_OP_SIGNATURE: |
487 | return deflt_signature; | |
89abd1b6 MC |
488 | case OSSL_OP_ASYM_CIPHER: |
489 | return deflt_asym_cipher; | |
80f4fd18 SL |
490 | case OSSL_OP_KEM: |
491 | return deflt_asym_kem; | |
ece9304c RL |
492 | case OSSL_OP_ENCODER: |
493 | return deflt_encoder; | |
494 | case OSSL_OP_DECODER: | |
495 | return deflt_decoder; | |
63f187cf RL |
496 | case OSSL_OP_STORE: |
497 | return deflt_store; | |
de29ff17 MC |
498 | } |
499 | return NULL; | |
500 | } | |
501 | ||
72bfc958 | 502 | |
78906fff RL |
503 | static void deflt_teardown(void *provctx) |
504 | { | |
d40b42ab | 505 | BIO_meth_free(PROV_CTX_get0_core_bio_method(provctx)); |
78906fff RL |
506 | PROV_CTX_free(provctx); |
507 | } | |
508 | ||
8a73348b MC |
509 | /* Functions we provide to the core */ |
510 | static const OSSL_DISPATCH deflt_dispatch_table[] = { | |
78906fff | 511 | { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown }, |
dca97d00 | 512 | { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params }, |
8a73348b | 513 | { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params }, |
de29ff17 | 514 | { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query }, |
72bfc958 | 515 | { OSSL_FUNC_PROVIDER_GET_CAPABILITIES, (void (*)(void))provider_get_capabilities }, |
8a73348b MC |
516 | { 0, NULL } |
517 | }; | |
518 | ||
519 | OSSL_provider_init_fn ossl_default_provider_init; | |
520 | ||
d40b42ab | 521 | int ossl_default_provider_init(const OSSL_CORE_HANDLE *handle, |
8a73348b | 522 | const OSSL_DISPATCH *in, |
a39eb840 RL |
523 | const OSSL_DISPATCH **out, |
524 | void **provctx) | |
8a73348b | 525 | { |
363b1e5d | 526 | OSSL_FUNC_core_get_library_context_fn *c_get_libctx = NULL; |
d40b42ab | 527 | BIO_METHOD *corebiometh; |
8013a933 | 528 | |
63665fff RL |
529 | if (!ossl_prov_bio_from_dispatch(in)) |
530 | return 0; | |
8a73348b MC |
531 | for (; in->function_id != 0; in++) { |
532 | switch (in->function_id) { | |
dca97d00 | 533 | case OSSL_FUNC_CORE_GETTABLE_PARAMS: |
363b1e5d | 534 | c_gettable_params = OSSL_FUNC_core_gettable_params(in); |
8a73348b MC |
535 | break; |
536 | case OSSL_FUNC_CORE_GET_PARAMS: | |
363b1e5d | 537 | c_get_params = OSSL_FUNC_core_get_params(in); |
8a73348b | 538 | break; |
8013a933 | 539 | case OSSL_FUNC_CORE_GET_LIBRARY_CONTEXT: |
363b1e5d | 540 | c_get_libctx = OSSL_FUNC_core_get_library_context(in); |
8013a933 | 541 | break; |
8a73348b MC |
542 | default: |
543 | /* Just ignore anything we don't understand */ | |
544 | break; | |
545 | } | |
546 | } | |
547 | ||
8013a933 RL |
548 | if (c_get_libctx == NULL) |
549 | return 0; | |
550 | ||
8013a933 RL |
551 | /* |
552 | * We want to make sure that all calls from this provider that requires | |
553 | * a library context use the same context as the one used to call our | |
d40b42ab | 554 | * functions. We do that by passing it along in the provider context. |
78906fff | 555 | * |
d40b42ab | 556 | * This only works for built-in providers. Most providers should |
78906fff | 557 | * create their own library context. |
8013a933 | 558 | */ |
d40b42ab MC |
559 | if ((*provctx = PROV_CTX_new()) == NULL |
560 | || (corebiometh = bio_prov_init_bio_method()) == NULL) { | |
561 | PROV_CTX_free(*provctx); | |
562 | *provctx = NULL; | |
78906fff | 563 | return 0; |
d40b42ab MC |
564 | } |
565 | PROV_CTX_set0_library_context(*provctx, (OPENSSL_CTX *)c_get_libctx(handle)); | |
566 | PROV_CTX_set0_handle(*provctx, handle); | |
567 | PROV_CTX_set0_core_bio_method(*provctx, corebiometh); | |
78906fff RL |
568 | |
569 | *out = deflt_dispatch_table; | |
570 | ||
8a73348b MC |
571 | return 1; |
572 | } |