1e1051a39Sopenharmony_ci/*
2e1051a39Sopenharmony_ci * Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
3e1051a39Sopenharmony_ci *
4e1051a39Sopenharmony_ci * Licensed under the Apache License 2.0 (the "License").  You may not use
5e1051a39Sopenharmony_ci * this file except in compliance with the License.  You can obtain a copy
6e1051a39Sopenharmony_ci * in the file LICENSE in the source distribution or at
7e1051a39Sopenharmony_ci * https://www.openssl.org/source/license.html
8e1051a39Sopenharmony_ci */
9e1051a39Sopenharmony_ci
10e1051a39Sopenharmony_ci#include <string.h>
11e1051a39Sopenharmony_ci#include <stdio.h>
12e1051a39Sopenharmony_ci#include <openssl/opensslconf.h>
13e1051a39Sopenharmony_ci#include <openssl/core.h>
14e1051a39Sopenharmony_ci#include <openssl/core_dispatch.h>
15e1051a39Sopenharmony_ci#include <openssl/core_names.h>
16e1051a39Sopenharmony_ci#include <openssl/params.h>
17e1051a39Sopenharmony_ci#include "prov/bio.h"
18e1051a39Sopenharmony_ci#include "prov/provider_ctx.h"
19e1051a39Sopenharmony_ci#include "prov/providercommon.h"
20e1051a39Sopenharmony_ci#include "prov/implementations.h"
21e1051a39Sopenharmony_ci#include "prov/names.h"
22e1051a39Sopenharmony_ci#include "prov/provider_util.h"
23e1051a39Sopenharmony_ci#include "prov/seeding.h"
24e1051a39Sopenharmony_ci#include "internal/nelem.h"
25e1051a39Sopenharmony_ci
26e1051a39Sopenharmony_ci/*
27e1051a39Sopenharmony_ci * Forward declarations to ensure that interface functions are correctly
28e1051a39Sopenharmony_ci * defined.
29e1051a39Sopenharmony_ci */
30e1051a39Sopenharmony_cistatic OSSL_FUNC_provider_gettable_params_fn deflt_gettable_params;
31e1051a39Sopenharmony_cistatic OSSL_FUNC_provider_get_params_fn deflt_get_params;
32e1051a39Sopenharmony_cistatic OSSL_FUNC_provider_query_operation_fn deflt_query;
33e1051a39Sopenharmony_ci
34e1051a39Sopenharmony_ci#define ALGC(NAMES, FUNC, CHECK) { { NAMES, "provider=default", FUNC }, CHECK }
35e1051a39Sopenharmony_ci#define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
36e1051a39Sopenharmony_ci
37e1051a39Sopenharmony_ci/* Functions provided by the core */
38e1051a39Sopenharmony_cistatic OSSL_FUNC_core_gettable_params_fn *c_gettable_params = NULL;
39e1051a39Sopenharmony_cistatic OSSL_FUNC_core_get_params_fn *c_get_params = NULL;
40e1051a39Sopenharmony_ci
41e1051a39Sopenharmony_ci/* Parameters we provide to the core */
42e1051a39Sopenharmony_cistatic const OSSL_PARAM deflt_param_types[] = {
43e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
44e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
45e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
46e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
47e1051a39Sopenharmony_ci    OSSL_PARAM_END
48e1051a39Sopenharmony_ci};
49e1051a39Sopenharmony_ci
50e1051a39Sopenharmony_cistatic const OSSL_PARAM *deflt_gettable_params(void *provctx)
51e1051a39Sopenharmony_ci{
52e1051a39Sopenharmony_ci    return deflt_param_types;
53e1051a39Sopenharmony_ci}
54e1051a39Sopenharmony_ci
55e1051a39Sopenharmony_cistatic int deflt_get_params(void *provctx, OSSL_PARAM params[])
56e1051a39Sopenharmony_ci{
57e1051a39Sopenharmony_ci    OSSL_PARAM *p;
58e1051a39Sopenharmony_ci
59e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
60e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL Default Provider"))
61e1051a39Sopenharmony_ci        return 0;
62e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
63e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
64e1051a39Sopenharmony_ci        return 0;
65e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
66e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
67e1051a39Sopenharmony_ci        return 0;
68e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
69e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
70e1051a39Sopenharmony_ci        return 0;
71e1051a39Sopenharmony_ci    return 1;
72e1051a39Sopenharmony_ci}
73e1051a39Sopenharmony_ci
74e1051a39Sopenharmony_ci/*
75e1051a39Sopenharmony_ci * For the algorithm names, we use the following formula for our primary
76e1051a39Sopenharmony_ci * names:
77e1051a39Sopenharmony_ci *
78e1051a39Sopenharmony_ci *     ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
79e1051a39Sopenharmony_ci *
80e1051a39Sopenharmony_ci *     VERSION is only present if there are multiple versions of
81e1051a39Sopenharmony_ci *     an alg (MD2, MD4, MD5).  It may be omitted if there is only
82e1051a39Sopenharmony_ci *     one version (if a subsequent version is released in the future,
83e1051a39Sopenharmony_ci *     we can always change the canonical name, and add the old name
84e1051a39Sopenharmony_ci *     as an alias).
85e1051a39Sopenharmony_ci *
86e1051a39Sopenharmony_ci *     SUBNAME may be present where we are combining multiple
87e1051a39Sopenharmony_ci *     algorithms together, e.g. MD5-SHA1.
88e1051a39Sopenharmony_ci *
89e1051a39Sopenharmony_ci *     SIZE is only present if multiple versions of an algorithm exist
90e1051a39Sopenharmony_ci *     with different sizes (e.g. AES-128-CBC, AES-256-CBC)
91e1051a39Sopenharmony_ci *
92e1051a39Sopenharmony_ci *     MODE is only present where applicable.
93e1051a39Sopenharmony_ci *
94e1051a39Sopenharmony_ci * We add diverse other names where applicable, such as the names that
95e1051a39Sopenharmony_ci * NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names
96e1051a39Sopenharmony_ci * we have used historically.
97e1051a39Sopenharmony_ci *
98e1051a39Sopenharmony_ci * Algorithm names are case insensitive, but we use all caps in our "canonical"
99e1051a39Sopenharmony_ci * names for consistency.
100e1051a39Sopenharmony_ci */
101e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_digests[] = {
102e1051a39Sopenharmony_ci    /* Our primary name:NIST name[:our older names] */
103e1051a39Sopenharmony_ci    { PROV_NAMES_SHA1, "provider=default", ossl_sha1_functions },
104e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_224, "provider=default", ossl_sha224_functions },
105e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_256, "provider=default", ossl_sha256_functions },
106e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_384, "provider=default", ossl_sha384_functions },
107e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_512, "provider=default", ossl_sha512_functions },
108e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_512_224, "provider=default", ossl_sha512_224_functions },
109e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_512_256, "provider=default", ossl_sha512_256_functions },
110e1051a39Sopenharmony_ci
111e1051a39Sopenharmony_ci    /* We agree with NIST here, so one name only */
112e1051a39Sopenharmony_ci    { PROV_NAMES_SHA3_224, "provider=default", ossl_sha3_224_functions },
113e1051a39Sopenharmony_ci    { PROV_NAMES_SHA3_256, "provider=default", ossl_sha3_256_functions },
114e1051a39Sopenharmony_ci    { PROV_NAMES_SHA3_384, "provider=default", ossl_sha3_384_functions },
115e1051a39Sopenharmony_ci    { PROV_NAMES_SHA3_512, "provider=default", ossl_sha3_512_functions },
116e1051a39Sopenharmony_ci
117e1051a39Sopenharmony_ci    /*
118e1051a39Sopenharmony_ci     * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for
119e1051a39Sopenharmony_ci     * the KMAC-128 and KMAC-256.
120e1051a39Sopenharmony_ci     */
121e1051a39Sopenharmony_ci    { PROV_NAMES_KECCAK_KMAC_128, "provider=default",
122e1051a39Sopenharmony_ci      ossl_keccak_kmac_128_functions },
123e1051a39Sopenharmony_ci    { PROV_NAMES_KECCAK_KMAC_256, "provider=default",
124e1051a39Sopenharmony_ci      ossl_keccak_kmac_256_functions },
125e1051a39Sopenharmony_ci
126e1051a39Sopenharmony_ci    /* Our primary name:NIST name */
127e1051a39Sopenharmony_ci    { PROV_NAMES_SHAKE_128, "provider=default", ossl_shake_128_functions },
128e1051a39Sopenharmony_ci    { PROV_NAMES_SHAKE_256, "provider=default", ossl_shake_256_functions },
129e1051a39Sopenharmony_ci
130e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_BLAKE2
131e1051a39Sopenharmony_ci    /*
132e1051a39Sopenharmony_ci     * https://blake2.net/ doesn't specify size variants,
133e1051a39Sopenharmony_ci     * but mentions that Bouncy Castle uses the names
134e1051a39Sopenharmony_ci     * BLAKE2b-160, BLAKE2b-256, BLAKE2b-384, and BLAKE2b-512
135e1051a39Sopenharmony_ci     * If we assume that "2b" and "2s" are versions, that pattern
136e1051a39Sopenharmony_ci     * fits with ours.  We also add our historical names.
137e1051a39Sopenharmony_ci     */
138e1051a39Sopenharmony_ci    { PROV_NAMES_BLAKE2S_256, "provider=default", ossl_blake2s256_functions },
139e1051a39Sopenharmony_ci    { PROV_NAMES_BLAKE2B_512, "provider=default", ossl_blake2b512_functions },
140e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_BLAKE2 */
141e1051a39Sopenharmony_ci
142e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_SM3
143e1051a39Sopenharmony_ci    { PROV_NAMES_SM3, "provider=default", ossl_sm3_functions },
144e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_SM3 */
145e1051a39Sopenharmony_ci
146e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_MD5
147e1051a39Sopenharmony_ci    { PROV_NAMES_MD5, "provider=default", ossl_md5_functions },
148e1051a39Sopenharmony_ci    { PROV_NAMES_MD5_SHA1, "provider=default", ossl_md5_sha1_functions },
149e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_MD5 */
150e1051a39Sopenharmony_ci
151e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_RMD160
152e1051a39Sopenharmony_ci    { PROV_NAMES_RIPEMD_160, "provider=default", ossl_ripemd160_functions },
153e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_RMD160 */
154e1051a39Sopenharmony_ci
155e1051a39Sopenharmony_ci    { PROV_NAMES_NULL, "provider=default", ossl_nullmd_functions },
156e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
157e1051a39Sopenharmony_ci};
158e1051a39Sopenharmony_ci
159e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM_CAPABLE deflt_ciphers[] = {
160e1051a39Sopenharmony_ci    ALG(PROV_NAMES_NULL, ossl_null_functions),
161e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_ECB, ossl_aes256ecb_functions),
162e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_ECB, ossl_aes192ecb_functions),
163e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_ECB, ossl_aes128ecb_functions),
164e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CBC, ossl_aes256cbc_functions),
165e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CBC, ossl_aes192cbc_functions),
166e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CBC, ossl_aes128cbc_functions),
167e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CBC_CTS, ossl_aes128cbc_cts_functions),
168e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CBC_CTS, ossl_aes192cbc_cts_functions),
169e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CBC_CTS, ossl_aes256cbc_cts_functions),
170e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_OFB, ossl_aes256ofb_functions),
171e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_OFB, ossl_aes192ofb_functions),
172e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_OFB, ossl_aes128ofb_functions),
173e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CFB, ossl_aes256cfb_functions),
174e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CFB, ossl_aes192cfb_functions),
175e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CFB, ossl_aes128cfb_functions),
176e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CFB1, ossl_aes256cfb1_functions),
177e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CFB1, ossl_aes192cfb1_functions),
178e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CFB1, ossl_aes128cfb1_functions),
179e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CFB8, ossl_aes256cfb8_functions),
180e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CFB8, ossl_aes192cfb8_functions),
181e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CFB8, ossl_aes128cfb8_functions),
182e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CTR, ossl_aes256ctr_functions),
183e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CTR, ossl_aes192ctr_functions),
184e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CTR, ossl_aes128ctr_functions),
185e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_XTS, ossl_aes256xts_functions),
186e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_XTS, ossl_aes128xts_functions),
187e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_OCB
188e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_OCB, ossl_aes256ocb_functions),
189e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_OCB, ossl_aes192ocb_functions),
190e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_OCB, ossl_aes128ocb_functions),
191e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_OCB */
192e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_SIV
193e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_SIV, ossl_aes128siv_functions),
194e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_SIV, ossl_aes192siv_functions),
195e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_SIV, ossl_aes256siv_functions),
196e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_SIV */
197e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_GCM, ossl_aes256gcm_functions),
198e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_GCM, ossl_aes192gcm_functions),
199e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_GCM, ossl_aes128gcm_functions),
200e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CCM, ossl_aes256ccm_functions),
201e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CCM, ossl_aes192ccm_functions),
202e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CCM, ossl_aes128ccm_functions),
203e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_WRAP, ossl_aes256wrap_functions),
204e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_WRAP, ossl_aes192wrap_functions),
205e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_WRAP, ossl_aes128wrap_functions),
206e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_WRAP_PAD, ossl_aes256wrappad_functions),
207e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_WRAP_PAD, ossl_aes192wrappad_functions),
208e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_WRAP_PAD, ossl_aes128wrappad_functions),
209e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_WRAP_INV, ossl_aes256wrapinv_functions),
210e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_WRAP_INV, ossl_aes192wrapinv_functions),
211e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_WRAP_INV, ossl_aes128wrapinv_functions),
212e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_WRAP_PAD_INV, ossl_aes256wrappadinv_functions),
213e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_WRAP_PAD_INV, ossl_aes192wrappadinv_functions),
214e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_WRAP_PAD_INV, ossl_aes128wrappadinv_functions),
215e1051a39Sopenharmony_ci    ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA1, ossl_aes128cbc_hmac_sha1_functions,
216e1051a39Sopenharmony_ci         ossl_cipher_capable_aes_cbc_hmac_sha1),
217e1051a39Sopenharmony_ci    ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA1, ossl_aes256cbc_hmac_sha1_functions,
218e1051a39Sopenharmony_ci         ossl_cipher_capable_aes_cbc_hmac_sha1),
219e1051a39Sopenharmony_ci    ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA256, ossl_aes128cbc_hmac_sha256_functions,
220e1051a39Sopenharmony_ci        ossl_cipher_capable_aes_cbc_hmac_sha256),
221e1051a39Sopenharmony_ci    ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA256, ossl_aes256cbc_hmac_sha256_functions,
222e1051a39Sopenharmony_ci         ossl_cipher_capable_aes_cbc_hmac_sha256),
223e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_ARIA
224e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_GCM, ossl_aria256gcm_functions),
225e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_GCM, ossl_aria192gcm_functions),
226e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_GCM, ossl_aria128gcm_functions),
227e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_CCM, ossl_aria256ccm_functions),
228e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_CCM, ossl_aria192ccm_functions),
229e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_CCM, ossl_aria128ccm_functions),
230e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_ECB, ossl_aria256ecb_functions),
231e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_ECB, ossl_aria192ecb_functions),
232e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_ECB, ossl_aria128ecb_functions),
233e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_CBC, ossl_aria256cbc_functions),
234e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_CBC, ossl_aria192cbc_functions),
235e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_CBC, ossl_aria128cbc_functions),
236e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_OFB, ossl_aria256ofb_functions),
237e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_OFB, ossl_aria192ofb_functions),
238e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_OFB, ossl_aria128ofb_functions),
239e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_CFB, ossl_aria256cfb_functions),
240e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_CFB, ossl_aria192cfb_functions),
241e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_CFB, ossl_aria128cfb_functions),
242e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_CFB1, ossl_aria256cfb1_functions),
243e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_CFB1, ossl_aria192cfb1_functions),
244e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_CFB1, ossl_aria128cfb1_functions),
245e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_CFB8, ossl_aria256cfb8_functions),
246e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_CFB8, ossl_aria192cfb8_functions),
247e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_CFB8, ossl_aria128cfb8_functions),
248e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_256_CTR, ossl_aria256ctr_functions),
249e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_192_CTR, ossl_aria192ctr_functions),
250e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ARIA_128_CTR, ossl_aria128ctr_functions),
251e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_ARIA */
252e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_CAMELLIA
253e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_256_ECB, ossl_camellia256ecb_functions),
254e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_192_ECB, ossl_camellia192ecb_functions),
255e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_128_ECB, ossl_camellia128ecb_functions),
256e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_256_CBC, ossl_camellia256cbc_functions),
257e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_192_CBC, ossl_camellia192cbc_functions),
258e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_128_CBC, ossl_camellia128cbc_functions),
259e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_128_CBC_CTS, ossl_camellia128cbc_cts_functions),
260e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_192_CBC_CTS, ossl_camellia192cbc_cts_functions),
261e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_256_CBC_CTS, ossl_camellia256cbc_cts_functions),
262e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_256_OFB, ossl_camellia256ofb_functions),
263e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_192_OFB, ossl_camellia192ofb_functions),
264e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_128_OFB, ossl_camellia128ofb_functions),
265e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_256_CFB, ossl_camellia256cfb_functions),
266e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_192_CFB, ossl_camellia192cfb_functions),
267e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_128_CFB, ossl_camellia128cfb_functions),
268e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_256_CFB1, ossl_camellia256cfb1_functions),
269e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_192_CFB1, ossl_camellia192cfb1_functions),
270e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_128_CFB1, ossl_camellia128cfb1_functions),
271e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_256_CFB8, ossl_camellia256cfb8_functions),
272e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_192_CFB8, ossl_camellia192cfb8_functions),
273e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_128_CFB8, ossl_camellia128cfb8_functions),
274e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_256_CTR, ossl_camellia256ctr_functions),
275e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_192_CTR, ossl_camellia192ctr_functions),
276e1051a39Sopenharmony_ci    ALG(PROV_NAMES_CAMELLIA_128_CTR, ossl_camellia128ctr_functions),
277e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_CAMELLIA */
278e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DES
279e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE3_ECB, ossl_tdes_ede3_ecb_functions),
280e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE3_CBC, ossl_tdes_ede3_cbc_functions),
281e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE3_OFB, ossl_tdes_ede3_ofb_functions),
282e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE3_CFB, ossl_tdes_ede3_cfb_functions),
283e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE3_CFB8, ossl_tdes_ede3_cfb8_functions),
284e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE3_CFB1, ossl_tdes_ede3_cfb1_functions),
285e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES3_WRAP, ossl_tdes_wrap_cbc_functions),
286e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE_ECB, ossl_tdes_ede2_ecb_functions),
287e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE_CBC, ossl_tdes_ede2_cbc_functions),
288e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE_OFB, ossl_tdes_ede2_ofb_functions),
289e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE_CFB, ossl_tdes_ede2_cfb_functions),
290e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_DES */
291e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_SM4
292e1051a39Sopenharmony_ci    ALG(PROV_NAMES_SM4_GCM, ossl_sm4128gcm_functions),
293e1051a39Sopenharmony_ci    ALG(PROV_NAMES_SM4_CCM, ossl_sm4128ccm_functions),
294e1051a39Sopenharmony_ci    ALG(PROV_NAMES_SM4_ECB, ossl_sm4128ecb_functions),
295e1051a39Sopenharmony_ci    ALG(PROV_NAMES_SM4_CBC, ossl_sm4128cbc_functions),
296e1051a39Sopenharmony_ci    ALG(PROV_NAMES_SM4_CTR, ossl_sm4128ctr_functions),
297e1051a39Sopenharmony_ci    ALG(PROV_NAMES_SM4_OFB, ossl_sm4128ofb128_functions),
298e1051a39Sopenharmony_ci    ALG(PROV_NAMES_SM4_CFB, ossl_sm4128cfb128_functions),
299e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_SM4 */
300e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_CHACHA
301e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ChaCha20, ossl_chacha20_functions),
302e1051a39Sopenharmony_ci# ifndef OPENSSL_NO_POLY1305
303e1051a39Sopenharmony_ci    ALG(PROV_NAMES_ChaCha20_Poly1305, ossl_chacha20_ossl_poly1305_functions),
304e1051a39Sopenharmony_ci# endif /* OPENSSL_NO_POLY1305 */
305e1051a39Sopenharmony_ci#endif /* OPENSSL_NO_CHACHA */
306e1051a39Sopenharmony_ci    { { NULL, NULL, NULL }, NULL }
307e1051a39Sopenharmony_ci};
308e1051a39Sopenharmony_cistatic OSSL_ALGORITHM exported_ciphers[OSSL_NELEM(deflt_ciphers)];
309e1051a39Sopenharmony_ci
310e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_macs[] = {
311e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_BLAKE2
312e1051a39Sopenharmony_ci    { PROV_NAMES_BLAKE2BMAC, "provider=default", ossl_blake2bmac_functions },
313e1051a39Sopenharmony_ci    { PROV_NAMES_BLAKE2SMAC, "provider=default", ossl_blake2smac_functions },
314e1051a39Sopenharmony_ci#endif
315e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_CMAC
316e1051a39Sopenharmony_ci    { PROV_NAMES_CMAC, "provider=default", ossl_cmac_functions },
317e1051a39Sopenharmony_ci#endif
318e1051a39Sopenharmony_ci    { PROV_NAMES_GMAC, "provider=default", ossl_gmac_functions },
319e1051a39Sopenharmony_ci    { PROV_NAMES_HMAC, "provider=default", ossl_hmac_functions },
320e1051a39Sopenharmony_ci    { PROV_NAMES_KMAC_128, "provider=default", ossl_kmac128_functions },
321e1051a39Sopenharmony_ci    { PROV_NAMES_KMAC_256, "provider=default", ossl_kmac256_functions },
322e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_SIPHASH
323e1051a39Sopenharmony_ci    { PROV_NAMES_SIPHASH, "provider=default", ossl_siphash_functions },
324e1051a39Sopenharmony_ci#endif
325e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_POLY1305
326e1051a39Sopenharmony_ci    { PROV_NAMES_POLY1305, "provider=default", ossl_poly1305_functions },
327e1051a39Sopenharmony_ci#endif
328e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
329e1051a39Sopenharmony_ci};
330e1051a39Sopenharmony_ci
331e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_kdfs[] = {
332e1051a39Sopenharmony_ci    { PROV_NAMES_HKDF, "provider=default", ossl_kdf_hkdf_functions },
333e1051a39Sopenharmony_ci    { PROV_NAMES_TLS1_3_KDF, "provider=default",
334e1051a39Sopenharmony_ci      ossl_kdf_tls1_3_kdf_functions },
335e1051a39Sopenharmony_ci    { PROV_NAMES_SSKDF, "provider=default", ossl_kdf_sskdf_functions },
336e1051a39Sopenharmony_ci    { PROV_NAMES_PBKDF2, "provider=default", ossl_kdf_pbkdf2_functions },
337e1051a39Sopenharmony_ci    { PROV_NAMES_PKCS12KDF, "provider=default", ossl_kdf_pkcs12_functions },
338e1051a39Sopenharmony_ci    { PROV_NAMES_SSHKDF, "provider=default", ossl_kdf_sshkdf_functions },
339e1051a39Sopenharmony_ci    { PROV_NAMES_X963KDF, "provider=default", ossl_kdf_x963_kdf_functions },
340e1051a39Sopenharmony_ci    { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_tls1_prf_functions },
341e1051a39Sopenharmony_ci    { PROV_NAMES_KBKDF, "provider=default", ossl_kdf_kbkdf_functions },
342e1051a39Sopenharmony_ci    { PROV_NAMES_X942KDF_ASN1, "provider=default", ossl_kdf_x942_kdf_functions },
343e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_SCRYPT
344e1051a39Sopenharmony_ci    { PROV_NAMES_SCRYPT, "provider=default", ossl_kdf_scrypt_functions },
345e1051a39Sopenharmony_ci#endif
346e1051a39Sopenharmony_ci    { PROV_NAMES_KRB5KDF, "provider=default", ossl_kdf_krb5kdf_functions },
347e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
348e1051a39Sopenharmony_ci};
349e1051a39Sopenharmony_ci
350e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_keyexch[] = {
351e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DH
352e1051a39Sopenharmony_ci    { PROV_NAMES_DH, "provider=default", ossl_dh_keyexch_functions },
353e1051a39Sopenharmony_ci#endif
354e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_EC
355e1051a39Sopenharmony_ci    { PROV_NAMES_ECDH, "provider=default", ossl_ecdh_keyexch_functions },
356e1051a39Sopenharmony_ci    { PROV_NAMES_X25519, "provider=default", ossl_x25519_keyexch_functions },
357e1051a39Sopenharmony_ci    { PROV_NAMES_X448, "provider=default", ossl_x448_keyexch_functions },
358e1051a39Sopenharmony_ci#endif
359e1051a39Sopenharmony_ci    { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_tls1_prf_keyexch_functions },
360e1051a39Sopenharmony_ci    { PROV_NAMES_HKDF, "provider=default", ossl_kdf_hkdf_keyexch_functions },
361e1051a39Sopenharmony_ci    { PROV_NAMES_SCRYPT, "provider=default",
362e1051a39Sopenharmony_ci      ossl_kdf_scrypt_keyexch_functions },
363e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
364e1051a39Sopenharmony_ci};
365e1051a39Sopenharmony_ci
366e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_rands[] = {
367e1051a39Sopenharmony_ci    { PROV_NAMES_CTR_DRBG, "provider=default", ossl_drbg_ctr_functions },
368e1051a39Sopenharmony_ci    { PROV_NAMES_HASH_DRBG, "provider=default", ossl_drbg_hash_functions },
369e1051a39Sopenharmony_ci    { PROV_NAMES_HMAC_DRBG, "provider=default", ossl_drbg_ossl_hmac_functions },
370e1051a39Sopenharmony_ci    { PROV_NAMES_SEED_SRC, "provider=default", ossl_seed_src_functions },
371e1051a39Sopenharmony_ci    { PROV_NAMES_TEST_RAND, "provider=default", ossl_test_rng_functions },
372e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
373e1051a39Sopenharmony_ci};
374e1051a39Sopenharmony_ci
375e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_signature[] = {
376e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DSA
377e1051a39Sopenharmony_ci    { PROV_NAMES_DSA, "provider=default", ossl_dsa_signature_functions },
378e1051a39Sopenharmony_ci#endif
379e1051a39Sopenharmony_ci    { PROV_NAMES_RSA, "provider=default", ossl_rsa_signature_functions },
380e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_EC
381e1051a39Sopenharmony_ci    { PROV_NAMES_ED25519, "provider=default", ossl_ed25519_signature_functions },
382e1051a39Sopenharmony_ci    { PROV_NAMES_ED448, "provider=default", ossl_ed448_signature_functions },
383e1051a39Sopenharmony_ci    { PROV_NAMES_ECDSA, "provider=default", ossl_ecdsa_signature_functions },
384e1051a39Sopenharmony_ci# ifndef OPENSSL_NO_SM2
385e1051a39Sopenharmony_ci    { PROV_NAMES_SM2, "provider=default", ossl_sm2_signature_functions },
386e1051a39Sopenharmony_ci# endif
387e1051a39Sopenharmony_ci#endif
388e1051a39Sopenharmony_ci    { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_hmac_signature_functions },
389e1051a39Sopenharmony_ci    { PROV_NAMES_SIPHASH, "provider=default",
390e1051a39Sopenharmony_ci      ossl_mac_legacy_siphash_signature_functions },
391e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_POLY1305
392e1051a39Sopenharmony_ci    { PROV_NAMES_POLY1305, "provider=default",
393e1051a39Sopenharmony_ci      ossl_mac_legacy_poly1305_signature_functions },
394e1051a39Sopenharmony_ci#endif
395e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_CMAC
396e1051a39Sopenharmony_ci    { PROV_NAMES_CMAC, "provider=default", ossl_mac_legacy_cmac_signature_functions },
397e1051a39Sopenharmony_ci#endif
398e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
399e1051a39Sopenharmony_ci};
400e1051a39Sopenharmony_ci
401e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_asym_cipher[] = {
402e1051a39Sopenharmony_ci    { PROV_NAMES_RSA, "provider=default", ossl_rsa_asym_cipher_functions },
403e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_SM2
404e1051a39Sopenharmony_ci    { PROV_NAMES_SM2, "provider=default", ossl_sm2_asym_cipher_functions },
405e1051a39Sopenharmony_ci#endif
406e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
407e1051a39Sopenharmony_ci};
408e1051a39Sopenharmony_ci
409e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_asym_kem[] = {
410e1051a39Sopenharmony_ci    { PROV_NAMES_RSA, "provider=default", ossl_rsa_asym_kem_functions },
411e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
412e1051a39Sopenharmony_ci};
413e1051a39Sopenharmony_ci
414e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_keymgmt[] = {
415e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DH
416e1051a39Sopenharmony_ci    { PROV_NAMES_DH, "provider=default", ossl_dh_keymgmt_functions,
417e1051a39Sopenharmony_ci      PROV_DESCS_DH },
418e1051a39Sopenharmony_ci    { PROV_NAMES_DHX, "provider=default", ossl_dhx_keymgmt_functions,
419e1051a39Sopenharmony_ci      PROV_DESCS_DHX },
420e1051a39Sopenharmony_ci#endif
421e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DSA
422e1051a39Sopenharmony_ci    { PROV_NAMES_DSA, "provider=default", ossl_dsa_keymgmt_functions,
423e1051a39Sopenharmony_ci      PROV_DESCS_DSA},
424e1051a39Sopenharmony_ci#endif
425e1051a39Sopenharmony_ci    { PROV_NAMES_RSA, "provider=default", ossl_rsa_keymgmt_functions,
426e1051a39Sopenharmony_ci      PROV_DESCS_RSA },
427e1051a39Sopenharmony_ci    { PROV_NAMES_RSA_PSS, "provider=default", ossl_rsapss_keymgmt_functions,
428e1051a39Sopenharmony_ci      PROV_DESCS_RSA_PSS },
429e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_EC
430e1051a39Sopenharmony_ci    { PROV_NAMES_EC, "provider=default", ossl_ec_keymgmt_functions,
431e1051a39Sopenharmony_ci      PROV_DESCS_EC },
432e1051a39Sopenharmony_ci    { PROV_NAMES_X25519, "provider=default", ossl_x25519_keymgmt_functions,
433e1051a39Sopenharmony_ci      PROV_DESCS_X25519 },
434e1051a39Sopenharmony_ci    { PROV_NAMES_X448, "provider=default", ossl_x448_keymgmt_functions,
435e1051a39Sopenharmony_ci      PROV_DESCS_X448 },
436e1051a39Sopenharmony_ci    { PROV_NAMES_ED25519, "provider=default", ossl_ed25519_keymgmt_functions,
437e1051a39Sopenharmony_ci      PROV_DESCS_ED25519 },
438e1051a39Sopenharmony_ci    { PROV_NAMES_ED448, "provider=default", ossl_ed448_keymgmt_functions,
439e1051a39Sopenharmony_ci      PROV_DESCS_ED448 },
440e1051a39Sopenharmony_ci#endif
441e1051a39Sopenharmony_ci    { PROV_NAMES_TLS1_PRF, "provider=default", ossl_kdf_keymgmt_functions,
442e1051a39Sopenharmony_ci      PROV_DESCS_TLS1_PRF_SIGN },
443e1051a39Sopenharmony_ci    { PROV_NAMES_HKDF, "provider=default", ossl_kdf_keymgmt_functions,
444e1051a39Sopenharmony_ci      PROV_DESCS_HKDF_SIGN },
445e1051a39Sopenharmony_ci    { PROV_NAMES_SCRYPT, "provider=default", ossl_kdf_keymgmt_functions,
446e1051a39Sopenharmony_ci      PROV_DESCS_SCRYPT_SIGN },
447e1051a39Sopenharmony_ci    { PROV_NAMES_HMAC, "provider=default", ossl_mac_legacy_keymgmt_functions,
448e1051a39Sopenharmony_ci      PROV_DESCS_HMAC_SIGN },
449e1051a39Sopenharmony_ci    { PROV_NAMES_SIPHASH, "provider=default", ossl_mac_legacy_keymgmt_functions,
450e1051a39Sopenharmony_ci      PROV_DESCS_SIPHASH_SIGN },
451e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_POLY1305
452e1051a39Sopenharmony_ci    { PROV_NAMES_POLY1305, "provider=default", ossl_mac_legacy_keymgmt_functions,
453e1051a39Sopenharmony_ci      PROV_DESCS_POLY1305_SIGN },
454e1051a39Sopenharmony_ci#endif
455e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_CMAC
456e1051a39Sopenharmony_ci    { PROV_NAMES_CMAC, "provider=default", ossl_cmac_legacy_keymgmt_functions,
457e1051a39Sopenharmony_ci      PROV_DESCS_CMAC_SIGN },
458e1051a39Sopenharmony_ci#endif
459e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_SM2
460e1051a39Sopenharmony_ci    { PROV_NAMES_SM2, "provider=default", ossl_sm2_keymgmt_functions,
461e1051a39Sopenharmony_ci      PROV_DESCS_SM2 },
462e1051a39Sopenharmony_ci#endif
463e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
464e1051a39Sopenharmony_ci};
465e1051a39Sopenharmony_ci
466e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_encoder[] = {
467e1051a39Sopenharmony_ci#define ENCODER_PROVIDER "default"
468e1051a39Sopenharmony_ci#include "encoders.inc"
469e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
470e1051a39Sopenharmony_ci#undef ENCODER_PROVIDER
471e1051a39Sopenharmony_ci};
472e1051a39Sopenharmony_ci
473e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_decoder[] = {
474e1051a39Sopenharmony_ci#define DECODER_PROVIDER "default"
475e1051a39Sopenharmony_ci#include "decoders.inc"
476e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
477e1051a39Sopenharmony_ci#undef DECODER_PROVIDER
478e1051a39Sopenharmony_ci};
479e1051a39Sopenharmony_ci
480e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM deflt_store[] = {
481e1051a39Sopenharmony_ci#define STORE(name, _fips, func_table)                           \
482e1051a39Sopenharmony_ci    { name, "provider=default,fips=" _fips, (func_table) },
483e1051a39Sopenharmony_ci
484e1051a39Sopenharmony_ci#include "stores.inc"
485e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
486e1051a39Sopenharmony_ci#undef STORE
487e1051a39Sopenharmony_ci};
488e1051a39Sopenharmony_ci
489e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM *deflt_query(void *provctx, int operation_id,
490e1051a39Sopenharmony_ci                                         int *no_cache)
491e1051a39Sopenharmony_ci{
492e1051a39Sopenharmony_ci    *no_cache = 0;
493e1051a39Sopenharmony_ci    switch (operation_id) {
494e1051a39Sopenharmony_ci    case OSSL_OP_DIGEST:
495e1051a39Sopenharmony_ci        return deflt_digests;
496e1051a39Sopenharmony_ci    case OSSL_OP_CIPHER:
497e1051a39Sopenharmony_ci        return exported_ciphers;
498e1051a39Sopenharmony_ci    case OSSL_OP_MAC:
499e1051a39Sopenharmony_ci        return deflt_macs;
500e1051a39Sopenharmony_ci    case OSSL_OP_KDF:
501e1051a39Sopenharmony_ci        return deflt_kdfs;
502e1051a39Sopenharmony_ci    case OSSL_OP_RAND:
503e1051a39Sopenharmony_ci        return deflt_rands;
504e1051a39Sopenharmony_ci    case OSSL_OP_KEYMGMT:
505e1051a39Sopenharmony_ci        return deflt_keymgmt;
506e1051a39Sopenharmony_ci    case OSSL_OP_KEYEXCH:
507e1051a39Sopenharmony_ci        return deflt_keyexch;
508e1051a39Sopenharmony_ci    case OSSL_OP_SIGNATURE:
509e1051a39Sopenharmony_ci        return deflt_signature;
510e1051a39Sopenharmony_ci    case OSSL_OP_ASYM_CIPHER:
511e1051a39Sopenharmony_ci        return deflt_asym_cipher;
512e1051a39Sopenharmony_ci    case OSSL_OP_KEM:
513e1051a39Sopenharmony_ci        return deflt_asym_kem;
514e1051a39Sopenharmony_ci    case OSSL_OP_ENCODER:
515e1051a39Sopenharmony_ci        return deflt_encoder;
516e1051a39Sopenharmony_ci    case OSSL_OP_DECODER:
517e1051a39Sopenharmony_ci        return deflt_decoder;
518e1051a39Sopenharmony_ci    case OSSL_OP_STORE:
519e1051a39Sopenharmony_ci        return deflt_store;
520e1051a39Sopenharmony_ci    }
521e1051a39Sopenharmony_ci    return NULL;
522e1051a39Sopenharmony_ci}
523e1051a39Sopenharmony_ci
524e1051a39Sopenharmony_ci
525e1051a39Sopenharmony_cistatic void deflt_teardown(void *provctx)
526e1051a39Sopenharmony_ci{
527e1051a39Sopenharmony_ci    BIO_meth_free(ossl_prov_ctx_get0_core_bio_method(provctx));
528e1051a39Sopenharmony_ci    ossl_prov_ctx_free(provctx);
529e1051a39Sopenharmony_ci}
530e1051a39Sopenharmony_ci
531e1051a39Sopenharmony_ci/* Functions we provide to the core */
532e1051a39Sopenharmony_cistatic const OSSL_DISPATCH deflt_dispatch_table[] = {
533e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))deflt_teardown },
534e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))deflt_gettable_params },
535e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))deflt_get_params },
536e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))deflt_query },
537e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_GET_CAPABILITIES,
538e1051a39Sopenharmony_ci      (void (*)(void))ossl_prov_get_capabilities },
539e1051a39Sopenharmony_ci    { 0, NULL }
540e1051a39Sopenharmony_ci};
541e1051a39Sopenharmony_ci
542e1051a39Sopenharmony_ciOSSL_provider_init_fn ossl_default_provider_init;
543e1051a39Sopenharmony_ci
544e1051a39Sopenharmony_ciint ossl_default_provider_init(const OSSL_CORE_HANDLE *handle,
545e1051a39Sopenharmony_ci                               const OSSL_DISPATCH *in,
546e1051a39Sopenharmony_ci                               const OSSL_DISPATCH **out,
547e1051a39Sopenharmony_ci                               void **provctx)
548e1051a39Sopenharmony_ci{
549e1051a39Sopenharmony_ci    OSSL_FUNC_core_get_libctx_fn *c_get_libctx = NULL;
550e1051a39Sopenharmony_ci    BIO_METHOD *corebiometh;
551e1051a39Sopenharmony_ci
552e1051a39Sopenharmony_ci    if (!ossl_prov_bio_from_dispatch(in)
553e1051a39Sopenharmony_ci            || !ossl_prov_seeding_from_dispatch(in))
554e1051a39Sopenharmony_ci        return 0;
555e1051a39Sopenharmony_ci    for (; in->function_id != 0; in++) {
556e1051a39Sopenharmony_ci        switch (in->function_id) {
557e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_GETTABLE_PARAMS:
558e1051a39Sopenharmony_ci            c_gettable_params = OSSL_FUNC_core_gettable_params(in);
559e1051a39Sopenharmony_ci            break;
560e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_GET_PARAMS:
561e1051a39Sopenharmony_ci            c_get_params = OSSL_FUNC_core_get_params(in);
562e1051a39Sopenharmony_ci            break;
563e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_GET_LIBCTX:
564e1051a39Sopenharmony_ci            c_get_libctx = OSSL_FUNC_core_get_libctx(in);
565e1051a39Sopenharmony_ci            break;
566e1051a39Sopenharmony_ci        default:
567e1051a39Sopenharmony_ci            /* Just ignore anything we don't understand */
568e1051a39Sopenharmony_ci            break;
569e1051a39Sopenharmony_ci        }
570e1051a39Sopenharmony_ci    }
571e1051a39Sopenharmony_ci
572e1051a39Sopenharmony_ci    if (c_get_libctx == NULL)
573e1051a39Sopenharmony_ci        return 0;
574e1051a39Sopenharmony_ci
575e1051a39Sopenharmony_ci    /*
576e1051a39Sopenharmony_ci     * We want to make sure that all calls from this provider that requires
577e1051a39Sopenharmony_ci     * a library context use the same context as the one used to call our
578e1051a39Sopenharmony_ci     * functions.  We do that by passing it along in the provider context.
579e1051a39Sopenharmony_ci     *
580e1051a39Sopenharmony_ci     * This only works for built-in providers.  Most providers should
581e1051a39Sopenharmony_ci     * create their own library context.
582e1051a39Sopenharmony_ci     */
583e1051a39Sopenharmony_ci    if ((*provctx = ossl_prov_ctx_new()) == NULL
584e1051a39Sopenharmony_ci            || (corebiometh = ossl_bio_prov_init_bio_method()) == NULL) {
585e1051a39Sopenharmony_ci        ossl_prov_ctx_free(*provctx);
586e1051a39Sopenharmony_ci        *provctx = NULL;
587e1051a39Sopenharmony_ci        return 0;
588e1051a39Sopenharmony_ci    }
589e1051a39Sopenharmony_ci    ossl_prov_ctx_set0_libctx(*provctx,
590e1051a39Sopenharmony_ci                                       (OSSL_LIB_CTX *)c_get_libctx(handle));
591e1051a39Sopenharmony_ci    ossl_prov_ctx_set0_handle(*provctx, handle);
592e1051a39Sopenharmony_ci    ossl_prov_ctx_set0_core_bio_method(*provctx, corebiometh);
593e1051a39Sopenharmony_ci
594e1051a39Sopenharmony_ci    *out = deflt_dispatch_table;
595e1051a39Sopenharmony_ci    ossl_prov_cache_exported_algorithms(deflt_ciphers, exported_ciphers);
596e1051a39Sopenharmony_ci
597e1051a39Sopenharmony_ci    return 1;
598e1051a39Sopenharmony_ci}
599