11#include <openssl/opensslconf.h>
12#include <openssl/core.h>
13#include <openssl/core_dispatch.h>
14#include <openssl/core_names.h>
15#include <openssl/params.h>
17#include "prov/provider_ctx.h"
18#include "prov/providercommon.h"
19#include "prov/implementations.h"
20#include "prov/names.h"
21#include "prov/provider_util.h"
22#include "prov/seeding.h"
23#include "internal/nelem.h"
24#include "provider_local.h"
26OSSL_provider_init_fn ossl_uefi_provider_init;
27const OSSL_PROVIDER_INFO ossl_predefined_providers[] = {
28 {
"default",
NULL, ossl_uefi_provider_init,
NULL, 1 },
36static OSSL_FUNC_provider_gettable_params_fn deflt_gettable_params;
37static OSSL_FUNC_provider_get_params_fn deflt_get_params;
38static OSSL_FUNC_provider_query_operation_fn deflt_query;
40#define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK }
41#define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
44static OSSL_FUNC_core_gettable_params_fn *c_gettable_params =
NULL;
45static OSSL_FUNC_core_get_params_fn *c_get_params =
NULL;
48static const OSSL_PARAM deflt_param_types[] = {
49 OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR,
NULL, 0),
50 OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR,
NULL, 0),
51 OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR,
NULL, 0),
52 OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER,
NULL, 0),
56static const OSSL_PARAM *deflt_gettable_params(
void *provctx)
58 return deflt_param_types;
61static int deflt_get_params(
void *provctx, OSSL_PARAM params[])
65 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
66 if (p !=
NULL && !OSSL_PARAM_set_utf8_ptr(p,
"OpenSSL Default Provider"))
68 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
69 if (p !=
NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
71 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
72 if (p !=
NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
74 p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
75 if (p !=
NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
107static const OSSL_ALGORITHM deflt_digests[] = {
109 { PROV_NAMES_SHA1,
"provider=default", ossl_sha1_functions },
110 { PROV_NAMES_SHA2_224,
"provider=default", ossl_sha224_functions },
111 { PROV_NAMES_SHA2_256,
"provider=default", ossl_sha256_functions },
112 { PROV_NAMES_SHA2_384,
"provider=default", ossl_sha384_functions },
113 { PROV_NAMES_SHA2_512,
"provider=default", ossl_sha512_functions },
115#ifndef OPENSSL_NO_SM3
116 { PROV_NAMES_SM3,
"provider=default", ossl_sm3_functions },
119#ifndef OPENSSL_NO_MD5
120 { PROV_NAMES_MD5,
"provider=default", ossl_md5_functions },
123 { PROV_NAMES_NULL,
"provider=default", ossl_nullmd_functions },
127static const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
128 ALG(PROV_NAMES_NULL, ossl_null_functions),
129 ALG(PROV_NAMES_AES_256_ECB, ossl_aes256ecb_functions),
130 ALG(PROV_NAMES_AES_192_ECB, ossl_aes192ecb_functions),
131 ALG(PROV_NAMES_AES_128_ECB, ossl_aes128ecb_functions),
132 ALG(PROV_NAMES_AES_256_CBC, ossl_aes256cbc_functions),
133 ALG(PROV_NAMES_AES_192_CBC, ossl_aes192cbc_functions),
134 ALG(PROV_NAMES_AES_128_CBC, ossl_aes128cbc_functions),
136 ALG(PROV_NAMES_AES_256_CTR, ossl_aes256ctr_functions),
137 ALG(PROV_NAMES_AES_192_CTR, ossl_aes192ctr_functions),
138 ALG(PROV_NAMES_AES_128_CTR, ossl_aes128ctr_functions),
140 ALG(PROV_NAMES_AES_256_GCM, ossl_aes256gcm_functions),
141 ALG(PROV_NAMES_AES_192_GCM, ossl_aes192gcm_functions),
142 ALG(PROV_NAMES_AES_128_GCM, ossl_aes128gcm_functions),
145 PROV_NAMES_AES_128_CBC_HMAC_SHA256,
146 ossl_aes128cbc_hmac_sha256_functions,
147 ossl_cipher_capable_aes_cbc_hmac_sha256
150 PROV_NAMES_AES_256_CBC_HMAC_SHA256,
151 ossl_aes256cbc_hmac_sha256_functions,
152 ossl_cipher_capable_aes_cbc_hmac_sha256
157static OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)];
159static const OSSL_ALGORITHM deflt_macs[] = {
160 { PROV_NAMES_HMAC,
"provider=default", ossl_hmac_functions },
164static const OSSL_ALGORITHM deflt_kdfs[] = {
165 { PROV_NAMES_HKDF,
"provider=default", ossl_kdf_hkdf_functions },
166 { PROV_NAMES_SSKDF,
"provider=default", ossl_kdf_sskdf_functions },
167 { PROV_NAMES_PBKDF2,
"provider=default", ossl_kdf_pbkdf2_functions },
168 { PROV_NAMES_SSHKDF,
"provider=default", ossl_kdf_sshkdf_functions },
169 { PROV_NAMES_TLS1_PRF,
"provider=default", ossl_kdf_tls1_prf_functions },
173static const OSSL_ALGORITHM deflt_keyexch[] = {
175 { PROV_NAMES_DH,
"provider=default", ossl_dh_keyexch_functions },
178 { PROV_NAMES_ECDH,
"provider=default", ossl_ecdh_keyexch_functions },
180 { PROV_NAMES_TLS1_PRF,
"provider=default", ossl_kdf_tls1_prf_keyexch_functions },
181 { PROV_NAMES_HKDF,
"provider=default", ossl_kdf_hkdf_keyexch_functions },
185static const OSSL_ALGORITHM deflt_rands[] = {
186 { PROV_NAMES_CTR_DRBG,
"provider=default", ossl_drbg_ctr_functions },
187 { PROV_NAMES_HASH_DRBG,
"provider=default", ossl_drbg_hash_functions },
191static const OSSL_ALGORITHM deflt_signature[] = {
192 { PROV_NAMES_RSA,
"provider=default", ossl_rsa_signature_functions },
194 { PROV_NAMES_ECDSA,
"provider=default", ossl_ecdsa_signature_functions },
200static const OSSL_ALGORITHM deflt_asym_cipher[] = {
201 { PROV_NAMES_RSA,
"provider=default", ossl_rsa_asym_cipher_functions },
205static const OSSL_ALGORITHM deflt_keymgmt[] = {
207 { PROV_NAMES_DH,
"provider=default", ossl_dh_keymgmt_functions,
209 { PROV_NAMES_DHX,
"provider=default", ossl_dhx_keymgmt_functions,
213 { PROV_NAMES_RSA,
"provider=default", ossl_rsa_keymgmt_functions,
215 { PROV_NAMES_RSA_PSS,
"provider=default", ossl_rsapss_keymgmt_functions,
216 PROV_DESCS_RSA_PSS },
218 { PROV_NAMES_EC,
"provider=default", ossl_ec_keymgmt_functions,
221 { PROV_NAMES_TLS1_PRF,
"provider=default", ossl_kdf_keymgmt_functions,
222 PROV_DESCS_TLS1_PRF_SIGN },
223 { PROV_NAMES_HKDF,
"provider=default", ossl_kdf_keymgmt_functions,
224 PROV_DESCS_HKDF_SIGN },
229static const OSSL_ALGORITHM deflt_decoder[] = {
230#define DECODER_PROVIDER "default"
231#include "decoders.inc"
233#undef DECODER_PROVIDER
236static const OSSL_ALGORITHM *deflt_query(
void *provctx,
int operation_id,
240 switch (operation_id) {
242 return deflt_digests;
244 return exported_ciphers;
251 case OSSL_OP_KEYMGMT:
252 return deflt_keymgmt;
253 case OSSL_OP_KEYEXCH:
254 return deflt_keyexch;
255 case OSSL_OP_SIGNATURE:
256 return deflt_signature;
257 case OSSL_OP_ASYM_CIPHER:
258 return deflt_asym_cipher;
259 case OSSL_OP_DECODER:
260 return deflt_decoder;
266static void deflt_teardown(
void *provctx)
268 BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(provctx));
269 ossl_prov_ctx_free(provctx);
273static const OSSL_DISPATCH deflt_dispatch_table[] = {
274 { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown },
275 { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params },
276 { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params },
277 { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query },
278 { OSSL_FUNC_PROVIDER_GET_CAPABILITIES,
279 (void (*)(void))ossl_prov_get_capabilities },
283OSSL_provider_init_fn ossl_uefi_provider_init;
285int ossl_uefi_provider_init(
const OSSL_CORE_HANDLE *handle,
286 const OSSL_DISPATCH *in,
287 const OSSL_DISPATCH **out,
290 OSSL_FUNC_core_get_libctx_fn *c_get_libctx =
NULL;
291 BIO_METHOD *corebiometh;
293 if (!ossl_prov_bio_from_dispatch(in)
294 || !ossl_prov_seeding_from_dispatch(in))
296 for (; in->function_id != 0; in++) {
297 switch (in->function_id) {
298 case OSSL_FUNC_CORE_GETTABLE_PARAMS:
299 c_gettable_params = OSSL_FUNC_core_gettable_params(in);
301 case OSSL_FUNC_CORE_GET_PARAMS:
302 c_get_params = OSSL_FUNC_core_get_params(in);
304 case OSSL_FUNC_CORE_GET_LIBCTX:
305 c_get_libctx = OSSL_FUNC_core_get_libctx(in);
313 if (c_get_libctx ==
NULL)
324 if ((*provctx = ossl_prov_ctx_new()) ==
NULL
325 || (corebiometh = ossl_bio_prov_init_bio_method()) ==
NULL) {
326 ossl_prov_ctx_free(*provctx);
330 ossl_prov_ctx_set0_libctx(*provctx,
331 (OSSL_LIB_CTX *)c_get_libctx(handle));
332 ossl_prov_ctx_set0_handle(*provctx, handle);
333 ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh);
335 *out = deflt_dispatch_table;
336 ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers);