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 <assert.h>
11e1051a39Sopenharmony_ci#include <openssl/core_dispatch.h>
12e1051a39Sopenharmony_ci#include <openssl/core_names.h>
13e1051a39Sopenharmony_ci#include <openssl/params.h>
14e1051a39Sopenharmony_ci#include <openssl/fips_names.h>
15e1051a39Sopenharmony_ci#include <openssl/rand.h> /* RAND_get0_public() */
16e1051a39Sopenharmony_ci#include <openssl/proverr.h>
17e1051a39Sopenharmony_ci#include "internal/cryptlib.h"
18e1051a39Sopenharmony_ci#include "prov/implementations.h"
19e1051a39Sopenharmony_ci#include "prov/names.h"
20e1051a39Sopenharmony_ci#include "prov/provider_ctx.h"
21e1051a39Sopenharmony_ci#include "prov/providercommon.h"
22e1051a39Sopenharmony_ci#include "prov/provider_util.h"
23e1051a39Sopenharmony_ci#include "prov/seeding.h"
24e1051a39Sopenharmony_ci#include "self_test.h"
25e1051a39Sopenharmony_ci#include "internal/core.h"
26e1051a39Sopenharmony_ci
27e1051a39Sopenharmony_cistatic const char FIPS_DEFAULT_PROPERTIES[] = "provider=fips,fips=yes";
28e1051a39Sopenharmony_cistatic const char FIPS_UNAPPROVED_PROPERTIES[] = "provider=fips,fips=no";
29e1051a39Sopenharmony_ci
30e1051a39Sopenharmony_ci/*
31e1051a39Sopenharmony_ci * Forward declarations to ensure that interface functions are correctly
32e1051a39Sopenharmony_ci * defined.
33e1051a39Sopenharmony_ci */
34e1051a39Sopenharmony_cistatic OSSL_FUNC_provider_teardown_fn fips_teardown;
35e1051a39Sopenharmony_cistatic OSSL_FUNC_provider_gettable_params_fn fips_gettable_params;
36e1051a39Sopenharmony_cistatic OSSL_FUNC_provider_get_params_fn fips_get_params;
37e1051a39Sopenharmony_cistatic OSSL_FUNC_provider_query_operation_fn fips_query;
38e1051a39Sopenharmony_ci
39e1051a39Sopenharmony_ci#define ALGC(NAMES, FUNC, CHECK) { { NAMES, FIPS_DEFAULT_PROPERTIES, FUNC }, CHECK }
40e1051a39Sopenharmony_ci#define ALG(NAMES, FUNC) ALGC(NAMES, FUNC, NULL)
41e1051a39Sopenharmony_ci
42e1051a39Sopenharmony_ciextern OSSL_FUNC_core_thread_start_fn *c_thread_start;
43e1051a39Sopenharmony_ciint FIPS_security_check_enabled(OSSL_LIB_CTX *libctx);
44e1051a39Sopenharmony_ci
45e1051a39Sopenharmony_ci/*
46e1051a39Sopenharmony_ci * Should these function pointers be stored in the provider side provctx? Could
47e1051a39Sopenharmony_ci * they ever be different from one init to the next? We assume not for now.
48e1051a39Sopenharmony_ci */
49e1051a39Sopenharmony_ci
50e1051a39Sopenharmony_ci/* Functions provided by the core */
51e1051a39Sopenharmony_cistatic OSSL_FUNC_core_gettable_params_fn *c_gettable_params;
52e1051a39Sopenharmony_cistatic OSSL_FUNC_core_get_params_fn *c_get_params;
53e1051a39Sopenharmony_ciOSSL_FUNC_core_thread_start_fn *c_thread_start;
54e1051a39Sopenharmony_cistatic OSSL_FUNC_core_new_error_fn *c_new_error;
55e1051a39Sopenharmony_cistatic OSSL_FUNC_core_set_error_debug_fn *c_set_error_debug;
56e1051a39Sopenharmony_cistatic OSSL_FUNC_core_vset_error_fn *c_vset_error;
57e1051a39Sopenharmony_cistatic OSSL_FUNC_core_set_error_mark_fn *c_set_error_mark;
58e1051a39Sopenharmony_cistatic OSSL_FUNC_core_clear_last_error_mark_fn *c_clear_last_error_mark;
59e1051a39Sopenharmony_cistatic OSSL_FUNC_core_pop_error_to_mark_fn *c_pop_error_to_mark;
60e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_malloc_fn *c_CRYPTO_malloc;
61e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_zalloc_fn *c_CRYPTO_zalloc;
62e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_free_fn *c_CRYPTO_free;
63e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_clear_free_fn *c_CRYPTO_clear_free;
64e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_realloc_fn *c_CRYPTO_realloc;
65e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_clear_realloc_fn *c_CRYPTO_clear_realloc;
66e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_secure_malloc_fn *c_CRYPTO_secure_malloc;
67e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_secure_zalloc_fn *c_CRYPTO_secure_zalloc;
68e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_secure_free_fn *c_CRYPTO_secure_free;
69e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_secure_clear_free_fn *c_CRYPTO_secure_clear_free;
70e1051a39Sopenharmony_cistatic OSSL_FUNC_CRYPTO_secure_allocated_fn *c_CRYPTO_secure_allocated;
71e1051a39Sopenharmony_cistatic OSSL_FUNC_BIO_vsnprintf_fn *c_BIO_vsnprintf;
72e1051a39Sopenharmony_cistatic OSSL_FUNC_self_test_cb_fn *c_stcbfn = NULL;
73e1051a39Sopenharmony_cistatic OSSL_FUNC_core_get_libctx_fn *c_get_libctx = NULL;
74e1051a39Sopenharmony_ci
75e1051a39Sopenharmony_citypedef struct fips_global_st {
76e1051a39Sopenharmony_ci    const OSSL_CORE_HANDLE *handle;
77e1051a39Sopenharmony_ci    SELF_TEST_POST_PARAMS selftest_params;
78e1051a39Sopenharmony_ci    int fips_security_checks;
79e1051a39Sopenharmony_ci    const char *fips_security_check_option;
80e1051a39Sopenharmony_ci} FIPS_GLOBAL;
81e1051a39Sopenharmony_ci
82e1051a39Sopenharmony_cistatic void *fips_prov_ossl_ctx_new(OSSL_LIB_CTX *libctx)
83e1051a39Sopenharmony_ci{
84e1051a39Sopenharmony_ci    FIPS_GLOBAL *fgbl = OPENSSL_zalloc(sizeof(*fgbl));
85e1051a39Sopenharmony_ci
86e1051a39Sopenharmony_ci    if (fgbl == NULL)
87e1051a39Sopenharmony_ci        return NULL;
88e1051a39Sopenharmony_ci    fgbl->fips_security_checks = 1;
89e1051a39Sopenharmony_ci    fgbl->fips_security_check_option = "1";
90e1051a39Sopenharmony_ci
91e1051a39Sopenharmony_ci    return fgbl;
92e1051a39Sopenharmony_ci}
93e1051a39Sopenharmony_ci
94e1051a39Sopenharmony_cistatic void fips_prov_ossl_ctx_free(void *fgbl)
95e1051a39Sopenharmony_ci{
96e1051a39Sopenharmony_ci    OPENSSL_free(fgbl);
97e1051a39Sopenharmony_ci}
98e1051a39Sopenharmony_ci
99e1051a39Sopenharmony_cistatic const OSSL_LIB_CTX_METHOD fips_prov_ossl_ctx_method = {
100e1051a39Sopenharmony_ci    OSSL_LIB_CTX_METHOD_DEFAULT_PRIORITY,
101e1051a39Sopenharmony_ci    fips_prov_ossl_ctx_new,
102e1051a39Sopenharmony_ci    fips_prov_ossl_ctx_free,
103e1051a39Sopenharmony_ci};
104e1051a39Sopenharmony_ci
105e1051a39Sopenharmony_ci
106e1051a39Sopenharmony_ci/* Parameters we provide to the core */
107e1051a39Sopenharmony_cistatic const OSSL_PARAM fips_param_types[] = {
108e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_NAME, OSSL_PARAM_UTF8_PTR, NULL, 0),
109e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_VERSION, OSSL_PARAM_UTF8_PTR, NULL, 0),
110e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_BUILDINFO, OSSL_PARAM_UTF8_PTR, NULL, 0),
111e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_STATUS, OSSL_PARAM_INTEGER, NULL, 0),
112e1051a39Sopenharmony_ci    OSSL_PARAM_DEFN(OSSL_PROV_PARAM_SECURITY_CHECKS, OSSL_PARAM_INTEGER, NULL, 0),
113e1051a39Sopenharmony_ci    OSSL_PARAM_END
114e1051a39Sopenharmony_ci};
115e1051a39Sopenharmony_ci
116e1051a39Sopenharmony_cistatic int fips_get_params_from_core(FIPS_GLOBAL *fgbl)
117e1051a39Sopenharmony_ci{
118e1051a39Sopenharmony_ci    /*
119e1051a39Sopenharmony_ci    * Parameters to retrieve from the core provider - required for self testing.
120e1051a39Sopenharmony_ci    * NOTE: inside core_get_params() these will be loaded from config items
121e1051a39Sopenharmony_ci    * stored inside prov->parameters (except for
122e1051a39Sopenharmony_ci    * OSSL_PROV_PARAM_CORE_MODULE_FILENAME).
123e1051a39Sopenharmony_ci    * OSSL_PROV_FIPS_PARAM_SECURITY_CHECKS is not a self test parameter.
124e1051a39Sopenharmony_ci    */
125e1051a39Sopenharmony_ci    OSSL_PARAM core_params[8], *p = core_params;
126e1051a39Sopenharmony_ci
127e1051a39Sopenharmony_ci    *p++ = OSSL_PARAM_construct_utf8_ptr(
128e1051a39Sopenharmony_ci            OSSL_PROV_PARAM_CORE_MODULE_FILENAME,
129e1051a39Sopenharmony_ci            (char **)&fgbl->selftest_params.module_filename,
130e1051a39Sopenharmony_ci            sizeof(fgbl->selftest_params.module_filename));
131e1051a39Sopenharmony_ci    *p++ = OSSL_PARAM_construct_utf8_ptr(
132e1051a39Sopenharmony_ci            OSSL_PROV_FIPS_PARAM_MODULE_MAC,
133e1051a39Sopenharmony_ci            (char **)&fgbl->selftest_params.module_checksum_data,
134e1051a39Sopenharmony_ci            sizeof(fgbl->selftest_params.module_checksum_data));
135e1051a39Sopenharmony_ci    *p++ = OSSL_PARAM_construct_utf8_ptr(
136e1051a39Sopenharmony_ci            OSSL_PROV_FIPS_PARAM_INSTALL_MAC,
137e1051a39Sopenharmony_ci            (char **)&fgbl->selftest_params.indicator_checksum_data,
138e1051a39Sopenharmony_ci            sizeof(fgbl->selftest_params.indicator_checksum_data));
139e1051a39Sopenharmony_ci    *p++ = OSSL_PARAM_construct_utf8_ptr(
140e1051a39Sopenharmony_ci            OSSL_PROV_FIPS_PARAM_INSTALL_STATUS,
141e1051a39Sopenharmony_ci            (char **)&fgbl->selftest_params.indicator_data,
142e1051a39Sopenharmony_ci            sizeof(fgbl->selftest_params.indicator_data));
143e1051a39Sopenharmony_ci    *p++ = OSSL_PARAM_construct_utf8_ptr(
144e1051a39Sopenharmony_ci            OSSL_PROV_FIPS_PARAM_INSTALL_VERSION,
145e1051a39Sopenharmony_ci            (char **)&fgbl->selftest_params.indicator_version,
146e1051a39Sopenharmony_ci            sizeof(fgbl->selftest_params.indicator_version));
147e1051a39Sopenharmony_ci    *p++ = OSSL_PARAM_construct_utf8_ptr(
148e1051a39Sopenharmony_ci            OSSL_PROV_FIPS_PARAM_CONDITIONAL_ERRORS,
149e1051a39Sopenharmony_ci            (char **)&fgbl->selftest_params.conditional_error_check,
150e1051a39Sopenharmony_ci            sizeof(fgbl->selftest_params.conditional_error_check));
151e1051a39Sopenharmony_ci    *p++ = OSSL_PARAM_construct_utf8_ptr(
152e1051a39Sopenharmony_ci            OSSL_PROV_FIPS_PARAM_SECURITY_CHECKS,
153e1051a39Sopenharmony_ci            (char **)&fgbl->fips_security_check_option,
154e1051a39Sopenharmony_ci            sizeof(fgbl->fips_security_check_option));
155e1051a39Sopenharmony_ci    *p = OSSL_PARAM_construct_end();
156e1051a39Sopenharmony_ci
157e1051a39Sopenharmony_ci    if (!c_get_params(fgbl->handle, core_params)) {
158e1051a39Sopenharmony_ci        ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
159e1051a39Sopenharmony_ci        return 0;
160e1051a39Sopenharmony_ci    }
161e1051a39Sopenharmony_ci
162e1051a39Sopenharmony_ci    return 1;
163e1051a39Sopenharmony_ci}
164e1051a39Sopenharmony_ci
165e1051a39Sopenharmony_cistatic const OSSL_PARAM *fips_gettable_params(void *provctx)
166e1051a39Sopenharmony_ci{
167e1051a39Sopenharmony_ci    return fips_param_types;
168e1051a39Sopenharmony_ci}
169e1051a39Sopenharmony_ci
170e1051a39Sopenharmony_cistatic int fips_get_params(void *provctx, OSSL_PARAM params[])
171e1051a39Sopenharmony_ci{
172e1051a39Sopenharmony_ci    OSSL_PARAM *p;
173e1051a39Sopenharmony_ci    FIPS_GLOBAL *fgbl = ossl_lib_ctx_get_data(ossl_prov_ctx_get0_libctx(provctx),
174e1051a39Sopenharmony_ci                                              OSSL_LIB_CTX_FIPS_PROV_INDEX,
175e1051a39Sopenharmony_ci                                              &fips_prov_ossl_ctx_method);
176e1051a39Sopenharmony_ci
177e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_NAME);
178e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, "OpenSSL FIPS Provider"))
179e1051a39Sopenharmony_ci        return 0;
180e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_VERSION);
181e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_VERSION_STR))
182e1051a39Sopenharmony_ci        return 0;
183e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_BUILDINFO);
184e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_utf8_ptr(p, OPENSSL_FULL_VERSION_STR))
185e1051a39Sopenharmony_ci        return 0;
186e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_STATUS);
187e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_int(p, ossl_prov_is_running()))
188e1051a39Sopenharmony_ci        return 0;
189e1051a39Sopenharmony_ci    p = OSSL_PARAM_locate(params, OSSL_PROV_PARAM_SECURITY_CHECKS);
190e1051a39Sopenharmony_ci    if (p != NULL && !OSSL_PARAM_set_int(p, fgbl->fips_security_checks))
191e1051a39Sopenharmony_ci        return 0;
192e1051a39Sopenharmony_ci    return 1;
193e1051a39Sopenharmony_ci}
194e1051a39Sopenharmony_ci
195e1051a39Sopenharmony_cistatic void set_self_test_cb(FIPS_GLOBAL *fgbl)
196e1051a39Sopenharmony_ci{
197e1051a39Sopenharmony_ci    const OSSL_CORE_HANDLE *handle =
198e1051a39Sopenharmony_ci        FIPS_get_core_handle(fgbl->selftest_params.libctx);
199e1051a39Sopenharmony_ci
200e1051a39Sopenharmony_ci    if (c_stcbfn != NULL && c_get_libctx != NULL) {
201e1051a39Sopenharmony_ci        c_stcbfn(c_get_libctx(handle), &fgbl->selftest_params.cb,
202e1051a39Sopenharmony_ci                              &fgbl->selftest_params.cb_arg);
203e1051a39Sopenharmony_ci    } else {
204e1051a39Sopenharmony_ci        fgbl->selftest_params.cb = NULL;
205e1051a39Sopenharmony_ci        fgbl->selftest_params.cb_arg = NULL;
206e1051a39Sopenharmony_ci    }
207e1051a39Sopenharmony_ci}
208e1051a39Sopenharmony_ci
209e1051a39Sopenharmony_cistatic int fips_self_test(void *provctx)
210e1051a39Sopenharmony_ci{
211e1051a39Sopenharmony_ci    FIPS_GLOBAL *fgbl = ossl_lib_ctx_get_data(ossl_prov_ctx_get0_libctx(provctx),
212e1051a39Sopenharmony_ci                                              OSSL_LIB_CTX_FIPS_PROV_INDEX,
213e1051a39Sopenharmony_ci                                              &fips_prov_ossl_ctx_method);
214e1051a39Sopenharmony_ci
215e1051a39Sopenharmony_ci    set_self_test_cb(fgbl);
216e1051a39Sopenharmony_ci    return SELF_TEST_post(&fgbl->selftest_params, 1) ? 1 : 0;
217e1051a39Sopenharmony_ci}
218e1051a39Sopenharmony_ci
219e1051a39Sopenharmony_ci/*
220e1051a39Sopenharmony_ci * For the algorithm names, we use the following formula for our primary
221e1051a39Sopenharmony_ci * names:
222e1051a39Sopenharmony_ci *
223e1051a39Sopenharmony_ci *     ALGNAME[VERSION?][-SUBNAME[VERSION?]?][-SIZE?][-MODE?]
224e1051a39Sopenharmony_ci *
225e1051a39Sopenharmony_ci *     VERSION is only present if there are multiple versions of
226e1051a39Sopenharmony_ci *     an alg (MD2, MD4, MD5).  It may be omitted if there is only
227e1051a39Sopenharmony_ci *     one version (if a subsequent version is released in the future,
228e1051a39Sopenharmony_ci *     we can always change the canonical name, and add the old name
229e1051a39Sopenharmony_ci *     as an alias).
230e1051a39Sopenharmony_ci *
231e1051a39Sopenharmony_ci *     SUBNAME may be present where we are combining multiple
232e1051a39Sopenharmony_ci *     algorithms together, e.g. MD5-SHA1.
233e1051a39Sopenharmony_ci *
234e1051a39Sopenharmony_ci *     SIZE is only present if multiple versions of an algorithm exist
235e1051a39Sopenharmony_ci *     with different sizes (e.g. AES-128-CBC, AES-256-CBC)
236e1051a39Sopenharmony_ci *
237e1051a39Sopenharmony_ci *     MODE is only present where applicable.
238e1051a39Sopenharmony_ci *
239e1051a39Sopenharmony_ci * We add diverse other names where applicable, such as the names that
240e1051a39Sopenharmony_ci * NIST uses, or that are used for ASN.1 OBJECT IDENTIFIERs, or names
241e1051a39Sopenharmony_ci * we have used historically.
242e1051a39Sopenharmony_ci */
243e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_digests[] = {
244e1051a39Sopenharmony_ci    /* Our primary name:NiST name[:our older names] */
245e1051a39Sopenharmony_ci    { PROV_NAMES_SHA1, FIPS_DEFAULT_PROPERTIES, ossl_sha1_functions },
246e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_224, FIPS_DEFAULT_PROPERTIES, ossl_sha224_functions },
247e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_256, FIPS_DEFAULT_PROPERTIES, ossl_sha256_functions },
248e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_384, FIPS_DEFAULT_PROPERTIES, ossl_sha384_functions },
249e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_512, FIPS_DEFAULT_PROPERTIES, ossl_sha512_functions },
250e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_512_224, FIPS_DEFAULT_PROPERTIES,
251e1051a39Sopenharmony_ci      ossl_sha512_224_functions },
252e1051a39Sopenharmony_ci    { PROV_NAMES_SHA2_512_256, FIPS_DEFAULT_PROPERTIES,
253e1051a39Sopenharmony_ci      ossl_sha512_256_functions },
254e1051a39Sopenharmony_ci
255e1051a39Sopenharmony_ci    /* We agree with NIST here, so one name only */
256e1051a39Sopenharmony_ci    { PROV_NAMES_SHA3_224, FIPS_DEFAULT_PROPERTIES, ossl_sha3_224_functions },
257e1051a39Sopenharmony_ci    { PROV_NAMES_SHA3_256, FIPS_DEFAULT_PROPERTIES, ossl_sha3_256_functions },
258e1051a39Sopenharmony_ci    { PROV_NAMES_SHA3_384, FIPS_DEFAULT_PROPERTIES, ossl_sha3_384_functions },
259e1051a39Sopenharmony_ci    { PROV_NAMES_SHA3_512, FIPS_DEFAULT_PROPERTIES, ossl_sha3_512_functions },
260e1051a39Sopenharmony_ci
261e1051a39Sopenharmony_ci    { PROV_NAMES_SHAKE_128, FIPS_DEFAULT_PROPERTIES, ossl_shake_128_functions },
262e1051a39Sopenharmony_ci    { PROV_NAMES_SHAKE_256, FIPS_DEFAULT_PROPERTIES, ossl_shake_256_functions },
263e1051a39Sopenharmony_ci
264e1051a39Sopenharmony_ci    /*
265e1051a39Sopenharmony_ci     * KECCAK-KMAC-128 and KECCAK-KMAC-256 as hashes are mostly useful for
266e1051a39Sopenharmony_ci     * KMAC128 and KMAC256.
267e1051a39Sopenharmony_ci     */
268e1051a39Sopenharmony_ci    { PROV_NAMES_KECCAK_KMAC_128, FIPS_DEFAULT_PROPERTIES,
269e1051a39Sopenharmony_ci      ossl_keccak_kmac_128_functions },
270e1051a39Sopenharmony_ci    { PROV_NAMES_KECCAK_KMAC_256, FIPS_DEFAULT_PROPERTIES,
271e1051a39Sopenharmony_ci      ossl_keccak_kmac_256_functions },
272e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
273e1051a39Sopenharmony_ci};
274e1051a39Sopenharmony_ci
275e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM_CAPABLE fips_ciphers[] = {
276e1051a39Sopenharmony_ci    /* Our primary name[:ASN.1 OID name][:our older names] */
277e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_ECB, ossl_aes256ecb_functions),
278e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_ECB, ossl_aes192ecb_functions),
279e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_ECB, ossl_aes128ecb_functions),
280e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CBC, ossl_aes256cbc_functions),
281e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CBC, ossl_aes192cbc_functions),
282e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CBC, ossl_aes128cbc_functions),
283e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CBC_CTS, ossl_aes256cbc_cts_functions),
284e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CBC_CTS, ossl_aes192cbc_cts_functions),
285e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CBC_CTS, ossl_aes128cbc_cts_functions),
286e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_OFB, ossl_aes256ofb_functions),
287e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_OFB, ossl_aes192ofb_functions),
288e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_OFB, ossl_aes128ofb_functions),
289e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CFB, ossl_aes256cfb_functions),
290e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CFB, ossl_aes192cfb_functions),
291e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CFB, ossl_aes128cfb_functions),
292e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CFB1, ossl_aes256cfb1_functions),
293e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CFB1, ossl_aes192cfb1_functions),
294e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CFB1, ossl_aes128cfb1_functions),
295e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CFB8, ossl_aes256cfb8_functions),
296e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CFB8, ossl_aes192cfb8_functions),
297e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CFB8, ossl_aes128cfb8_functions),
298e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CTR, ossl_aes256ctr_functions),
299e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CTR, ossl_aes192ctr_functions),
300e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CTR, ossl_aes128ctr_functions),
301e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_XTS, ossl_aes256xts_functions),
302e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_XTS, ossl_aes128xts_functions),
303e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_GCM, ossl_aes256gcm_functions),
304e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_GCM, ossl_aes192gcm_functions),
305e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_GCM, ossl_aes128gcm_functions),
306e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_CCM, ossl_aes256ccm_functions),
307e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_CCM, ossl_aes192ccm_functions),
308e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_CCM, ossl_aes128ccm_functions),
309e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_WRAP, ossl_aes256wrap_functions),
310e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_WRAP, ossl_aes192wrap_functions),
311e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_WRAP, ossl_aes128wrap_functions),
312e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_WRAP_PAD, ossl_aes256wrappad_functions),
313e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_WRAP_PAD, ossl_aes192wrappad_functions),
314e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_WRAP_PAD, ossl_aes128wrappad_functions),
315e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_WRAP_INV, ossl_aes256wrapinv_functions),
316e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_WRAP_INV, ossl_aes192wrapinv_functions),
317e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_WRAP_INV, ossl_aes128wrapinv_functions),
318e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_256_WRAP_PAD_INV, ossl_aes256wrappadinv_functions),
319e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_192_WRAP_PAD_INV, ossl_aes192wrappadinv_functions),
320e1051a39Sopenharmony_ci    ALG(PROV_NAMES_AES_128_WRAP_PAD_INV, ossl_aes128wrappadinv_functions),
321e1051a39Sopenharmony_ci    ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA1, ossl_aes128cbc_hmac_sha1_functions,
322e1051a39Sopenharmony_ci         ossl_cipher_capable_aes_cbc_hmac_sha1),
323e1051a39Sopenharmony_ci    ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA1, ossl_aes256cbc_hmac_sha1_functions,
324e1051a39Sopenharmony_ci         ossl_cipher_capable_aes_cbc_hmac_sha1),
325e1051a39Sopenharmony_ci    ALGC(PROV_NAMES_AES_128_CBC_HMAC_SHA256, ossl_aes128cbc_hmac_sha256_functions,
326e1051a39Sopenharmony_ci         ossl_cipher_capable_aes_cbc_hmac_sha256),
327e1051a39Sopenharmony_ci    ALGC(PROV_NAMES_AES_256_CBC_HMAC_SHA256, ossl_aes256cbc_hmac_sha256_functions,
328e1051a39Sopenharmony_ci         ossl_cipher_capable_aes_cbc_hmac_sha256),
329e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DES
330e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE3_ECB, ossl_tdes_ede3_ecb_functions),
331e1051a39Sopenharmony_ci    ALG(PROV_NAMES_DES_EDE3_CBC, ossl_tdes_ede3_cbc_functions),
332e1051a39Sopenharmony_ci#endif  /* OPENSSL_NO_DES */
333e1051a39Sopenharmony_ci    { { NULL, NULL, NULL }, NULL }
334e1051a39Sopenharmony_ci};
335e1051a39Sopenharmony_cistatic OSSL_ALGORITHM exported_fips_ciphers[OSSL_NELEM(fips_ciphers)];
336e1051a39Sopenharmony_ci
337e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_macs[] = {
338e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_CMAC
339e1051a39Sopenharmony_ci    { PROV_NAMES_CMAC, FIPS_DEFAULT_PROPERTIES, ossl_cmac_functions },
340e1051a39Sopenharmony_ci#endif
341e1051a39Sopenharmony_ci    { PROV_NAMES_GMAC, FIPS_DEFAULT_PROPERTIES, ossl_gmac_functions },
342e1051a39Sopenharmony_ci    { PROV_NAMES_HMAC, FIPS_DEFAULT_PROPERTIES, ossl_hmac_functions },
343e1051a39Sopenharmony_ci    { PROV_NAMES_KMAC_128, FIPS_DEFAULT_PROPERTIES, ossl_kmac128_functions },
344e1051a39Sopenharmony_ci    { PROV_NAMES_KMAC_256, FIPS_DEFAULT_PROPERTIES, ossl_kmac256_functions },
345e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
346e1051a39Sopenharmony_ci};
347e1051a39Sopenharmony_ci
348e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_kdfs[] = {
349e1051a39Sopenharmony_ci    { PROV_NAMES_HKDF, FIPS_DEFAULT_PROPERTIES, ossl_kdf_hkdf_functions },
350e1051a39Sopenharmony_ci    { PROV_NAMES_TLS1_3_KDF, FIPS_DEFAULT_PROPERTIES,
351e1051a39Sopenharmony_ci      ossl_kdf_tls1_3_kdf_functions },
352e1051a39Sopenharmony_ci    { PROV_NAMES_SSKDF, FIPS_DEFAULT_PROPERTIES, ossl_kdf_sskdf_functions },
353e1051a39Sopenharmony_ci    { PROV_NAMES_PBKDF2, FIPS_DEFAULT_PROPERTIES, ossl_kdf_pbkdf2_functions },
354e1051a39Sopenharmony_ci    { PROV_NAMES_SSHKDF, FIPS_DEFAULT_PROPERTIES, ossl_kdf_sshkdf_functions },
355e1051a39Sopenharmony_ci    { PROV_NAMES_X963KDF, FIPS_DEFAULT_PROPERTIES,
356e1051a39Sopenharmony_ci      ossl_kdf_x963_kdf_functions },
357e1051a39Sopenharmony_ci    { PROV_NAMES_X942KDF_ASN1, FIPS_DEFAULT_PROPERTIES,
358e1051a39Sopenharmony_ci      ossl_kdf_x942_kdf_functions },
359e1051a39Sopenharmony_ci    { PROV_NAMES_TLS1_PRF, FIPS_DEFAULT_PROPERTIES,
360e1051a39Sopenharmony_ci      ossl_kdf_tls1_prf_functions },
361e1051a39Sopenharmony_ci    { PROV_NAMES_KBKDF, FIPS_DEFAULT_PROPERTIES, ossl_kdf_kbkdf_functions },
362e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
363e1051a39Sopenharmony_ci};
364e1051a39Sopenharmony_ci
365e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_rands[] = {
366e1051a39Sopenharmony_ci    { PROV_NAMES_CTR_DRBG, FIPS_DEFAULT_PROPERTIES, ossl_drbg_ctr_functions },
367e1051a39Sopenharmony_ci    { PROV_NAMES_HASH_DRBG, FIPS_DEFAULT_PROPERTIES, ossl_drbg_hash_functions },
368e1051a39Sopenharmony_ci    { PROV_NAMES_HMAC_DRBG, FIPS_DEFAULT_PROPERTIES, ossl_drbg_ossl_hmac_functions },
369e1051a39Sopenharmony_ci    { PROV_NAMES_TEST_RAND, FIPS_UNAPPROVED_PROPERTIES, ossl_test_rng_functions },
370e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
371e1051a39Sopenharmony_ci};
372e1051a39Sopenharmony_ci
373e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_keyexch[] = {
374e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DH
375e1051a39Sopenharmony_ci    { PROV_NAMES_DH, FIPS_DEFAULT_PROPERTIES, ossl_dh_keyexch_functions },
376e1051a39Sopenharmony_ci#endif
377e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_EC
378e1051a39Sopenharmony_ci    { PROV_NAMES_ECDH, FIPS_DEFAULT_PROPERTIES, ossl_ecdh_keyexch_functions },
379e1051a39Sopenharmony_ci    { PROV_NAMES_X25519, FIPS_DEFAULT_PROPERTIES, ossl_x25519_keyexch_functions },
380e1051a39Sopenharmony_ci    { PROV_NAMES_X448, FIPS_DEFAULT_PROPERTIES, ossl_x448_keyexch_functions },
381e1051a39Sopenharmony_ci#endif
382e1051a39Sopenharmony_ci    { PROV_NAMES_TLS1_PRF, FIPS_DEFAULT_PROPERTIES,
383e1051a39Sopenharmony_ci      ossl_kdf_tls1_prf_keyexch_functions },
384e1051a39Sopenharmony_ci    { PROV_NAMES_HKDF, FIPS_DEFAULT_PROPERTIES, ossl_kdf_hkdf_keyexch_functions },
385e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
386e1051a39Sopenharmony_ci};
387e1051a39Sopenharmony_ci
388e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_signature[] = {
389e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DSA
390e1051a39Sopenharmony_ci    { PROV_NAMES_DSA, FIPS_DEFAULT_PROPERTIES, ossl_dsa_signature_functions },
391e1051a39Sopenharmony_ci#endif
392e1051a39Sopenharmony_ci    { PROV_NAMES_RSA, FIPS_DEFAULT_PROPERTIES, ossl_rsa_signature_functions },
393e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_EC
394e1051a39Sopenharmony_ci    { PROV_NAMES_ED25519, FIPS_DEFAULT_PROPERTIES, ossl_ed25519_signature_functions },
395e1051a39Sopenharmony_ci    { PROV_NAMES_ED448, FIPS_DEFAULT_PROPERTIES, ossl_ed448_signature_functions },
396e1051a39Sopenharmony_ci    { PROV_NAMES_ECDSA, FIPS_DEFAULT_PROPERTIES, ossl_ecdsa_signature_functions },
397e1051a39Sopenharmony_ci#endif
398e1051a39Sopenharmony_ci    { PROV_NAMES_HMAC, FIPS_DEFAULT_PROPERTIES,
399e1051a39Sopenharmony_ci      ossl_mac_legacy_hmac_signature_functions },
400e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_CMAC
401e1051a39Sopenharmony_ci    { PROV_NAMES_CMAC, FIPS_DEFAULT_PROPERTIES,
402e1051a39Sopenharmony_ci      ossl_mac_legacy_cmac_signature_functions },
403e1051a39Sopenharmony_ci#endif
404e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
405e1051a39Sopenharmony_ci};
406e1051a39Sopenharmony_ci
407e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_asym_cipher[] = {
408e1051a39Sopenharmony_ci    { PROV_NAMES_RSA, FIPS_DEFAULT_PROPERTIES, ossl_rsa_asym_cipher_functions },
409e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
410e1051a39Sopenharmony_ci};
411e1051a39Sopenharmony_ci
412e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_asym_kem[] = {
413e1051a39Sopenharmony_ci    { PROV_NAMES_RSA, FIPS_DEFAULT_PROPERTIES, ossl_rsa_asym_kem_functions },
414e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
415e1051a39Sopenharmony_ci};
416e1051a39Sopenharmony_ci
417e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM fips_keymgmt[] = {
418e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DH
419e1051a39Sopenharmony_ci    { PROV_NAMES_DH, FIPS_DEFAULT_PROPERTIES, ossl_dh_keymgmt_functions,
420e1051a39Sopenharmony_ci      PROV_DESCS_DH },
421e1051a39Sopenharmony_ci    { PROV_NAMES_DHX, FIPS_DEFAULT_PROPERTIES, ossl_dhx_keymgmt_functions,
422e1051a39Sopenharmony_ci      PROV_DESCS_DHX },
423e1051a39Sopenharmony_ci#endif
424e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_DSA
425e1051a39Sopenharmony_ci    { PROV_NAMES_DSA, FIPS_DEFAULT_PROPERTIES, ossl_dsa_keymgmt_functions,
426e1051a39Sopenharmony_ci      PROV_DESCS_DSA },
427e1051a39Sopenharmony_ci#endif
428e1051a39Sopenharmony_ci    { PROV_NAMES_RSA, FIPS_DEFAULT_PROPERTIES, ossl_rsa_keymgmt_functions,
429e1051a39Sopenharmony_ci      PROV_DESCS_RSA },
430e1051a39Sopenharmony_ci    { PROV_NAMES_RSA_PSS, FIPS_DEFAULT_PROPERTIES,
431e1051a39Sopenharmony_ci      ossl_rsapss_keymgmt_functions, PROV_DESCS_RSA_PSS },
432e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_EC
433e1051a39Sopenharmony_ci    { PROV_NAMES_EC, FIPS_DEFAULT_PROPERTIES, ossl_ec_keymgmt_functions,
434e1051a39Sopenharmony_ci      PROV_DESCS_EC },
435e1051a39Sopenharmony_ci    { PROV_NAMES_X25519, FIPS_DEFAULT_PROPERTIES, ossl_x25519_keymgmt_functions,
436e1051a39Sopenharmony_ci      PROV_DESCS_X25519 },
437e1051a39Sopenharmony_ci    { PROV_NAMES_X448, FIPS_DEFAULT_PROPERTIES, ossl_x448_keymgmt_functions,
438e1051a39Sopenharmony_ci      PROV_DESCS_X448 },
439e1051a39Sopenharmony_ci    { PROV_NAMES_ED25519, FIPS_DEFAULT_PROPERTIES, ossl_ed25519_keymgmt_functions,
440e1051a39Sopenharmony_ci      PROV_DESCS_ED25519 },
441e1051a39Sopenharmony_ci    { PROV_NAMES_ED448, FIPS_DEFAULT_PROPERTIES, ossl_ed448_keymgmt_functions,
442e1051a39Sopenharmony_ci      PROV_DESCS_ED448 },
443e1051a39Sopenharmony_ci#endif
444e1051a39Sopenharmony_ci    { PROV_NAMES_TLS1_PRF, FIPS_DEFAULT_PROPERTIES, ossl_kdf_keymgmt_functions,
445e1051a39Sopenharmony_ci      PROV_DESCS_TLS1_PRF_SIGN },
446e1051a39Sopenharmony_ci    { PROV_NAMES_HKDF, FIPS_DEFAULT_PROPERTIES, ossl_kdf_keymgmt_functions,
447e1051a39Sopenharmony_ci      PROV_DESCS_HKDF_SIGN },
448e1051a39Sopenharmony_ci    { PROV_NAMES_HMAC, FIPS_DEFAULT_PROPERTIES, ossl_mac_legacy_keymgmt_functions,
449e1051a39Sopenharmony_ci      PROV_DESCS_HMAC_SIGN },
450e1051a39Sopenharmony_ci#ifndef OPENSSL_NO_CMAC
451e1051a39Sopenharmony_ci    { PROV_NAMES_CMAC, FIPS_DEFAULT_PROPERTIES,
452e1051a39Sopenharmony_ci      ossl_cmac_legacy_keymgmt_functions, PROV_DESCS_CMAC_SIGN },
453e1051a39Sopenharmony_ci#endif
454e1051a39Sopenharmony_ci    { NULL, NULL, NULL }
455e1051a39Sopenharmony_ci};
456e1051a39Sopenharmony_ci
457e1051a39Sopenharmony_cistatic const OSSL_ALGORITHM *fips_query(void *provctx, int operation_id,
458e1051a39Sopenharmony_ci                                        int *no_cache)
459e1051a39Sopenharmony_ci{
460e1051a39Sopenharmony_ci    *no_cache = 0;
461e1051a39Sopenharmony_ci
462e1051a39Sopenharmony_ci    if (!ossl_prov_is_running())
463e1051a39Sopenharmony_ci        return NULL;
464e1051a39Sopenharmony_ci
465e1051a39Sopenharmony_ci    switch (operation_id) {
466e1051a39Sopenharmony_ci    case OSSL_OP_DIGEST:
467e1051a39Sopenharmony_ci        return fips_digests;
468e1051a39Sopenharmony_ci    case OSSL_OP_CIPHER:
469e1051a39Sopenharmony_ci        return exported_fips_ciphers;
470e1051a39Sopenharmony_ci    case OSSL_OP_MAC:
471e1051a39Sopenharmony_ci        return fips_macs;
472e1051a39Sopenharmony_ci    case OSSL_OP_KDF:
473e1051a39Sopenharmony_ci        return fips_kdfs;
474e1051a39Sopenharmony_ci    case OSSL_OP_RAND:
475e1051a39Sopenharmony_ci        return fips_rands;
476e1051a39Sopenharmony_ci    case OSSL_OP_KEYMGMT:
477e1051a39Sopenharmony_ci        return fips_keymgmt;
478e1051a39Sopenharmony_ci    case OSSL_OP_KEYEXCH:
479e1051a39Sopenharmony_ci        return fips_keyexch;
480e1051a39Sopenharmony_ci    case OSSL_OP_SIGNATURE:
481e1051a39Sopenharmony_ci        return fips_signature;
482e1051a39Sopenharmony_ci    case OSSL_OP_ASYM_CIPHER:
483e1051a39Sopenharmony_ci        return fips_asym_cipher;
484e1051a39Sopenharmony_ci    case OSSL_OP_KEM:
485e1051a39Sopenharmony_ci        return fips_asym_kem;
486e1051a39Sopenharmony_ci    }
487e1051a39Sopenharmony_ci    return NULL;
488e1051a39Sopenharmony_ci}
489e1051a39Sopenharmony_ci
490e1051a39Sopenharmony_cistatic void fips_teardown(void *provctx)
491e1051a39Sopenharmony_ci{
492e1051a39Sopenharmony_ci    OSSL_LIB_CTX_free(PROV_LIBCTX_OF(provctx));
493e1051a39Sopenharmony_ci    ossl_prov_ctx_free(provctx);
494e1051a39Sopenharmony_ci}
495e1051a39Sopenharmony_ci
496e1051a39Sopenharmony_cistatic void fips_intern_teardown(void *provctx)
497e1051a39Sopenharmony_ci{
498e1051a39Sopenharmony_ci    /*
499e1051a39Sopenharmony_ci     * We know that the library context is the same as for the outer provider,
500e1051a39Sopenharmony_ci     * so no need to destroy it here.
501e1051a39Sopenharmony_ci     */
502e1051a39Sopenharmony_ci    ossl_prov_ctx_free(provctx);
503e1051a39Sopenharmony_ci}
504e1051a39Sopenharmony_ci
505e1051a39Sopenharmony_ci/* Functions we provide to the core */
506e1051a39Sopenharmony_cistatic const OSSL_DISPATCH fips_dispatch_table[] = {
507e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))fips_teardown },
508e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_GETTABLE_PARAMS, (void (*)(void))fips_gettable_params },
509e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_GET_PARAMS, (void (*)(void))fips_get_params },
510e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query },
511e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_GET_CAPABILITIES,
512e1051a39Sopenharmony_ci      (void (*)(void))ossl_prov_get_capabilities },
513e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_SELF_TEST, (void (*)(void))fips_self_test },
514e1051a39Sopenharmony_ci    { 0, NULL }
515e1051a39Sopenharmony_ci};
516e1051a39Sopenharmony_ci
517e1051a39Sopenharmony_ci/* Functions we provide to ourself */
518e1051a39Sopenharmony_cistatic const OSSL_DISPATCH intern_dispatch_table[] = {
519e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_TEARDOWN, (void (*)(void))fips_intern_teardown },
520e1051a39Sopenharmony_ci    { OSSL_FUNC_PROVIDER_QUERY_OPERATION, (void (*)(void))fips_query },
521e1051a39Sopenharmony_ci    { 0, NULL }
522e1051a39Sopenharmony_ci};
523e1051a39Sopenharmony_ci
524e1051a39Sopenharmony_ci/*
525e1051a39Sopenharmony_ci * On VMS, the provider init function name is expected to be uppercase,
526e1051a39Sopenharmony_ci * see the pragmas in <openssl/core.h>.  Let's do the same with this
527e1051a39Sopenharmony_ci * internal name.  This is how symbol names are treated by default
528e1051a39Sopenharmony_ci * by the compiler if nothing else is said, but since this is part
529e1051a39Sopenharmony_ci * of libfips, and we build our libraries with mixed case symbol names,
530e1051a39Sopenharmony_ci * we must switch back to this default explicitly here.
531e1051a39Sopenharmony_ci */
532e1051a39Sopenharmony_ci#ifdef __VMS
533e1051a39Sopenharmony_ci# pragma names save
534e1051a39Sopenharmony_ci# pragma names uppercase,truncated
535e1051a39Sopenharmony_ci#endif
536e1051a39Sopenharmony_ciOSSL_provider_init_fn OSSL_provider_init_int;
537e1051a39Sopenharmony_ci#ifdef __VMS
538e1051a39Sopenharmony_ci# pragma names restore
539e1051a39Sopenharmony_ci#endif
540e1051a39Sopenharmony_ciint OSSL_provider_init_int(const OSSL_CORE_HANDLE *handle,
541e1051a39Sopenharmony_ci                           const OSSL_DISPATCH *in,
542e1051a39Sopenharmony_ci                           const OSSL_DISPATCH **out,
543e1051a39Sopenharmony_ci                           void **provctx)
544e1051a39Sopenharmony_ci{
545e1051a39Sopenharmony_ci    FIPS_GLOBAL *fgbl;
546e1051a39Sopenharmony_ci    OSSL_LIB_CTX *libctx = NULL;
547e1051a39Sopenharmony_ci    SELF_TEST_POST_PARAMS selftest_params;
548e1051a39Sopenharmony_ci
549e1051a39Sopenharmony_ci    memset(&selftest_params, 0, sizeof(selftest_params));
550e1051a39Sopenharmony_ci
551e1051a39Sopenharmony_ci    if (!ossl_prov_seeding_from_dispatch(in))
552e1051a39Sopenharmony_ci        goto err;
553e1051a39Sopenharmony_ci    for (; in->function_id != 0; in++) {
554e1051a39Sopenharmony_ci        /*
555e1051a39Sopenharmony_ci         * We do not support the scenario of an application linked against
556e1051a39Sopenharmony_ci         * multiple versions of libcrypto (e.g. one static and one dynamic), but
557e1051a39Sopenharmony_ci         * sharing a single fips.so. We do a simple sanity check here.
558e1051a39Sopenharmony_ci         */
559e1051a39Sopenharmony_ci#define set_func(c, f) if (c == NULL) c = f; else if (c != f) return 0;
560e1051a39Sopenharmony_ci        switch (in->function_id) {
561e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_GET_LIBCTX:
562e1051a39Sopenharmony_ci            set_func(c_get_libctx, OSSL_FUNC_core_get_libctx(in));
563e1051a39Sopenharmony_ci            break;
564e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_GETTABLE_PARAMS:
565e1051a39Sopenharmony_ci            set_func(c_gettable_params, OSSL_FUNC_core_gettable_params(in));
566e1051a39Sopenharmony_ci            break;
567e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_GET_PARAMS:
568e1051a39Sopenharmony_ci            set_func(c_get_params, OSSL_FUNC_core_get_params(in));
569e1051a39Sopenharmony_ci            break;
570e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_THREAD_START:
571e1051a39Sopenharmony_ci            set_func(c_thread_start, OSSL_FUNC_core_thread_start(in));
572e1051a39Sopenharmony_ci            break;
573e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_NEW_ERROR:
574e1051a39Sopenharmony_ci            set_func(c_new_error, OSSL_FUNC_core_new_error(in));
575e1051a39Sopenharmony_ci            break;
576e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_SET_ERROR_DEBUG:
577e1051a39Sopenharmony_ci            set_func(c_set_error_debug, OSSL_FUNC_core_set_error_debug(in));
578e1051a39Sopenharmony_ci            break;
579e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_VSET_ERROR:
580e1051a39Sopenharmony_ci            set_func(c_vset_error, OSSL_FUNC_core_vset_error(in));
581e1051a39Sopenharmony_ci            break;
582e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_SET_ERROR_MARK:
583e1051a39Sopenharmony_ci            set_func(c_set_error_mark, OSSL_FUNC_core_set_error_mark(in));
584e1051a39Sopenharmony_ci            break;
585e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_CLEAR_LAST_ERROR_MARK:
586e1051a39Sopenharmony_ci            set_func(c_clear_last_error_mark,
587e1051a39Sopenharmony_ci                     OSSL_FUNC_core_clear_last_error_mark(in));
588e1051a39Sopenharmony_ci            break;
589e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_POP_ERROR_TO_MARK:
590e1051a39Sopenharmony_ci            set_func(c_pop_error_to_mark, OSSL_FUNC_core_pop_error_to_mark(in));
591e1051a39Sopenharmony_ci            break;
592e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_MALLOC:
593e1051a39Sopenharmony_ci            set_func(c_CRYPTO_malloc, OSSL_FUNC_CRYPTO_malloc(in));
594e1051a39Sopenharmony_ci            break;
595e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_ZALLOC:
596e1051a39Sopenharmony_ci            set_func(c_CRYPTO_zalloc, OSSL_FUNC_CRYPTO_zalloc(in));
597e1051a39Sopenharmony_ci            break;
598e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_FREE:
599e1051a39Sopenharmony_ci            set_func(c_CRYPTO_free, OSSL_FUNC_CRYPTO_free(in));
600e1051a39Sopenharmony_ci            break;
601e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_CLEAR_FREE:
602e1051a39Sopenharmony_ci            set_func(c_CRYPTO_clear_free, OSSL_FUNC_CRYPTO_clear_free(in));
603e1051a39Sopenharmony_ci            break;
604e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_REALLOC:
605e1051a39Sopenharmony_ci            set_func(c_CRYPTO_realloc, OSSL_FUNC_CRYPTO_realloc(in));
606e1051a39Sopenharmony_ci            break;
607e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_CLEAR_REALLOC:
608e1051a39Sopenharmony_ci            set_func(c_CRYPTO_clear_realloc,
609e1051a39Sopenharmony_ci                     OSSL_FUNC_CRYPTO_clear_realloc(in));
610e1051a39Sopenharmony_ci            break;
611e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_SECURE_MALLOC:
612e1051a39Sopenharmony_ci            set_func(c_CRYPTO_secure_malloc,
613e1051a39Sopenharmony_ci                     OSSL_FUNC_CRYPTO_secure_malloc(in));
614e1051a39Sopenharmony_ci            break;
615e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_SECURE_ZALLOC:
616e1051a39Sopenharmony_ci            set_func(c_CRYPTO_secure_zalloc,
617e1051a39Sopenharmony_ci                     OSSL_FUNC_CRYPTO_secure_zalloc(in));
618e1051a39Sopenharmony_ci            break;
619e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_SECURE_FREE:
620e1051a39Sopenharmony_ci            set_func(c_CRYPTO_secure_free,
621e1051a39Sopenharmony_ci                     OSSL_FUNC_CRYPTO_secure_free(in));
622e1051a39Sopenharmony_ci            break;
623e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_SECURE_CLEAR_FREE:
624e1051a39Sopenharmony_ci            set_func(c_CRYPTO_secure_clear_free,
625e1051a39Sopenharmony_ci                     OSSL_FUNC_CRYPTO_secure_clear_free(in));
626e1051a39Sopenharmony_ci            break;
627e1051a39Sopenharmony_ci        case OSSL_FUNC_CRYPTO_SECURE_ALLOCATED:
628e1051a39Sopenharmony_ci            set_func(c_CRYPTO_secure_allocated,
629e1051a39Sopenharmony_ci                     OSSL_FUNC_CRYPTO_secure_allocated(in));
630e1051a39Sopenharmony_ci            break;
631e1051a39Sopenharmony_ci        case OSSL_FUNC_BIO_NEW_FILE:
632e1051a39Sopenharmony_ci            set_func(selftest_params.bio_new_file_cb,
633e1051a39Sopenharmony_ci                     OSSL_FUNC_BIO_new_file(in));
634e1051a39Sopenharmony_ci            break;
635e1051a39Sopenharmony_ci        case OSSL_FUNC_BIO_NEW_MEMBUF:
636e1051a39Sopenharmony_ci            set_func(selftest_params.bio_new_buffer_cb,
637e1051a39Sopenharmony_ci                     OSSL_FUNC_BIO_new_membuf(in));
638e1051a39Sopenharmony_ci            break;
639e1051a39Sopenharmony_ci        case OSSL_FUNC_BIO_READ_EX:
640e1051a39Sopenharmony_ci            set_func(selftest_params.bio_read_ex_cb,
641e1051a39Sopenharmony_ci                     OSSL_FUNC_BIO_read_ex(in));
642e1051a39Sopenharmony_ci            break;
643e1051a39Sopenharmony_ci        case OSSL_FUNC_BIO_FREE:
644e1051a39Sopenharmony_ci            set_func(selftest_params.bio_free_cb, OSSL_FUNC_BIO_free(in));
645e1051a39Sopenharmony_ci            break;
646e1051a39Sopenharmony_ci        case OSSL_FUNC_BIO_VSNPRINTF:
647e1051a39Sopenharmony_ci            set_func(c_BIO_vsnprintf, OSSL_FUNC_BIO_vsnprintf(in));
648e1051a39Sopenharmony_ci            break;
649e1051a39Sopenharmony_ci        case OSSL_FUNC_SELF_TEST_CB:
650e1051a39Sopenharmony_ci            set_func(c_stcbfn, OSSL_FUNC_self_test_cb(in));
651e1051a39Sopenharmony_ci            break;
652e1051a39Sopenharmony_ci        default:
653e1051a39Sopenharmony_ci            /* Just ignore anything we don't understand */
654e1051a39Sopenharmony_ci            break;
655e1051a39Sopenharmony_ci        }
656e1051a39Sopenharmony_ci    }
657e1051a39Sopenharmony_ci
658e1051a39Sopenharmony_ci    /*  Create a context. */
659e1051a39Sopenharmony_ci    if ((*provctx = ossl_prov_ctx_new()) == NULL
660e1051a39Sopenharmony_ci        || (libctx = OSSL_LIB_CTX_new()) == NULL) {
661e1051a39Sopenharmony_ci        /*
662e1051a39Sopenharmony_ci         * We free libctx separately here and only here because it hasn't
663e1051a39Sopenharmony_ci         * been attached to *provctx.  All other error paths below rely
664e1051a39Sopenharmony_ci         * solely on fips_teardown.
665e1051a39Sopenharmony_ci         */
666e1051a39Sopenharmony_ci        OSSL_LIB_CTX_free(libctx);
667e1051a39Sopenharmony_ci        goto err;
668e1051a39Sopenharmony_ci    }
669e1051a39Sopenharmony_ci
670e1051a39Sopenharmony_ci    if ((fgbl = ossl_lib_ctx_get_data(libctx, OSSL_LIB_CTX_FIPS_PROV_INDEX,
671e1051a39Sopenharmony_ci                                      &fips_prov_ossl_ctx_method)) == NULL)
672e1051a39Sopenharmony_ci        goto err;
673e1051a39Sopenharmony_ci
674e1051a39Sopenharmony_ci    fgbl->handle = handle;
675e1051a39Sopenharmony_ci
676e1051a39Sopenharmony_ci    /*
677e1051a39Sopenharmony_ci     * We did initial set up of selftest_params in a local copy, because we
678e1051a39Sopenharmony_ci     * could not create fgbl until c_CRYPTO_zalloc was defined in the loop
679e1051a39Sopenharmony_ci     * above.
680e1051a39Sopenharmony_ci     */
681e1051a39Sopenharmony_ci    fgbl->selftest_params = selftest_params;
682e1051a39Sopenharmony_ci
683e1051a39Sopenharmony_ci    fgbl->selftest_params.libctx = libctx;
684e1051a39Sopenharmony_ci
685e1051a39Sopenharmony_ci    set_self_test_cb(fgbl);
686e1051a39Sopenharmony_ci
687e1051a39Sopenharmony_ci    if (!fips_get_params_from_core(fgbl)) {
688e1051a39Sopenharmony_ci        /* Error already raised */
689e1051a39Sopenharmony_ci        goto err;
690e1051a39Sopenharmony_ci    }
691e1051a39Sopenharmony_ci    /*
692e1051a39Sopenharmony_ci     * Disable the conditional error check if it's disabled in the fips config
693e1051a39Sopenharmony_ci     * file.
694e1051a39Sopenharmony_ci     */
695e1051a39Sopenharmony_ci    if (fgbl->selftest_params.conditional_error_check != NULL
696e1051a39Sopenharmony_ci        && strcmp(fgbl->selftest_params.conditional_error_check, "0") == 0)
697e1051a39Sopenharmony_ci        SELF_TEST_disable_conditional_error_state();
698e1051a39Sopenharmony_ci
699e1051a39Sopenharmony_ci    /* Disable the security check if it's disabled in the fips config file. */
700e1051a39Sopenharmony_ci    if (fgbl->fips_security_check_option != NULL
701e1051a39Sopenharmony_ci        && strcmp(fgbl->fips_security_check_option, "0") == 0)
702e1051a39Sopenharmony_ci        fgbl->fips_security_checks = 0;
703e1051a39Sopenharmony_ci
704e1051a39Sopenharmony_ci    ossl_prov_cache_exported_algorithms(fips_ciphers, exported_fips_ciphers);
705e1051a39Sopenharmony_ci
706e1051a39Sopenharmony_ci    if (!SELF_TEST_post(&fgbl->selftest_params, 0)) {
707e1051a39Sopenharmony_ci        ERR_raise(ERR_LIB_PROV, PROV_R_SELF_TEST_POST_FAILURE);
708e1051a39Sopenharmony_ci        goto err;
709e1051a39Sopenharmony_ci    }
710e1051a39Sopenharmony_ci
711e1051a39Sopenharmony_ci    ossl_prov_ctx_set0_libctx(*provctx, libctx);
712e1051a39Sopenharmony_ci    ossl_prov_ctx_set0_handle(*provctx, handle);
713e1051a39Sopenharmony_ci
714e1051a39Sopenharmony_ci    *out = fips_dispatch_table;
715e1051a39Sopenharmony_ci    return 1;
716e1051a39Sopenharmony_ci err:
717e1051a39Sopenharmony_ci    fips_teardown(*provctx);
718e1051a39Sopenharmony_ci    OSSL_LIB_CTX_free(libctx);
719e1051a39Sopenharmony_ci    *provctx = NULL;
720e1051a39Sopenharmony_ci    return 0;
721e1051a39Sopenharmony_ci}
722e1051a39Sopenharmony_ci
723e1051a39Sopenharmony_ci/*
724e1051a39Sopenharmony_ci * The internal init function used when the FIPS module uses EVP to call
725e1051a39Sopenharmony_ci * another algorithm also in the FIPS module. This is a recursive call that has
726e1051a39Sopenharmony_ci * been made from within the FIPS module itself. To make this work, we populate
727e1051a39Sopenharmony_ci * the provider context of this inner instance with the same library context
728e1051a39Sopenharmony_ci * that was used in the EVP call that initiated this recursive call.
729e1051a39Sopenharmony_ci */
730e1051a39Sopenharmony_ciOSSL_provider_init_fn ossl_fips_intern_provider_init;
731e1051a39Sopenharmony_ciint ossl_fips_intern_provider_init(const OSSL_CORE_HANDLE *handle,
732e1051a39Sopenharmony_ci                                   const OSSL_DISPATCH *in,
733e1051a39Sopenharmony_ci                                   const OSSL_DISPATCH **out,
734e1051a39Sopenharmony_ci                                   void **provctx)
735e1051a39Sopenharmony_ci{
736e1051a39Sopenharmony_ci    OSSL_FUNC_core_get_libctx_fn *c_internal_get_libctx = NULL;
737e1051a39Sopenharmony_ci
738e1051a39Sopenharmony_ci    for (; in->function_id != 0; in++) {
739e1051a39Sopenharmony_ci        switch (in->function_id) {
740e1051a39Sopenharmony_ci        case OSSL_FUNC_CORE_GET_LIBCTX:
741e1051a39Sopenharmony_ci            c_internal_get_libctx = OSSL_FUNC_core_get_libctx(in);
742e1051a39Sopenharmony_ci            break;
743e1051a39Sopenharmony_ci        default:
744e1051a39Sopenharmony_ci            break;
745e1051a39Sopenharmony_ci        }
746e1051a39Sopenharmony_ci    }
747e1051a39Sopenharmony_ci
748e1051a39Sopenharmony_ci    if (c_internal_get_libctx == NULL)
749e1051a39Sopenharmony_ci        return 0;
750e1051a39Sopenharmony_ci
751e1051a39Sopenharmony_ci    if ((*provctx = ossl_prov_ctx_new()) == NULL)
752e1051a39Sopenharmony_ci        return 0;
753e1051a39Sopenharmony_ci
754e1051a39Sopenharmony_ci    /*
755e1051a39Sopenharmony_ci     * Using the parent library context only works because we are a built-in
756e1051a39Sopenharmony_ci     * internal provider. This is not something that most providers would be
757e1051a39Sopenharmony_ci     * able to do.
758e1051a39Sopenharmony_ci     */
759e1051a39Sopenharmony_ci    ossl_prov_ctx_set0_libctx(*provctx,
760e1051a39Sopenharmony_ci                              (OSSL_LIB_CTX *)c_internal_get_libctx(handle));
761e1051a39Sopenharmony_ci    ossl_prov_ctx_set0_handle(*provctx, handle);
762e1051a39Sopenharmony_ci
763e1051a39Sopenharmony_ci    *out = intern_dispatch_table;
764e1051a39Sopenharmony_ci    return 1;
765e1051a39Sopenharmony_ci}
766e1051a39Sopenharmony_ci
767e1051a39Sopenharmony_civoid ERR_new(void)
768e1051a39Sopenharmony_ci{
769e1051a39Sopenharmony_ci    c_new_error(NULL);
770e1051a39Sopenharmony_ci}
771e1051a39Sopenharmony_ci
772e1051a39Sopenharmony_civoid ERR_set_debug(const char *file, int line, const char *func)
773e1051a39Sopenharmony_ci{
774e1051a39Sopenharmony_ci    c_set_error_debug(NULL, file, line, func);
775e1051a39Sopenharmony_ci}
776e1051a39Sopenharmony_ci
777e1051a39Sopenharmony_civoid ERR_set_error(int lib, int reason, const char *fmt, ...)
778e1051a39Sopenharmony_ci{
779e1051a39Sopenharmony_ci    va_list args;
780e1051a39Sopenharmony_ci
781e1051a39Sopenharmony_ci    va_start(args, fmt);
782e1051a39Sopenharmony_ci    c_vset_error(NULL, ERR_PACK(lib, 0, reason), fmt, args);
783e1051a39Sopenharmony_ci    va_end(args);
784e1051a39Sopenharmony_ci}
785e1051a39Sopenharmony_ci
786e1051a39Sopenharmony_civoid ERR_vset_error(int lib, int reason, const char *fmt, va_list args)
787e1051a39Sopenharmony_ci{
788e1051a39Sopenharmony_ci    c_vset_error(NULL, ERR_PACK(lib, 0, reason), fmt, args);
789e1051a39Sopenharmony_ci}
790e1051a39Sopenharmony_ci
791e1051a39Sopenharmony_ciint ERR_set_mark(void)
792e1051a39Sopenharmony_ci{
793e1051a39Sopenharmony_ci    return c_set_error_mark(NULL);
794e1051a39Sopenharmony_ci}
795e1051a39Sopenharmony_ci
796e1051a39Sopenharmony_ciint ERR_clear_last_mark(void)
797e1051a39Sopenharmony_ci{
798e1051a39Sopenharmony_ci    return c_clear_last_error_mark(NULL);
799e1051a39Sopenharmony_ci}
800e1051a39Sopenharmony_ci
801e1051a39Sopenharmony_ciint ERR_pop_to_mark(void)
802e1051a39Sopenharmony_ci{
803e1051a39Sopenharmony_ci    return c_pop_error_to_mark(NULL);
804e1051a39Sopenharmony_ci}
805e1051a39Sopenharmony_ci
806e1051a39Sopenharmony_ci/*
807e1051a39Sopenharmony_ci * This must take a library context, since it's called from the depths
808e1051a39Sopenharmony_ci * of crypto/initthread.c code, where it's (correctly) assumed that the
809e1051a39Sopenharmony_ci * passed caller argument is an OSSL_LIB_CTX pointer (since the same routine
810e1051a39Sopenharmony_ci * is also called from other parts of libcrypto, which all pass around a
811e1051a39Sopenharmony_ci * OSSL_LIB_CTX pointer)
812e1051a39Sopenharmony_ci */
813e1051a39Sopenharmony_ciconst OSSL_CORE_HANDLE *FIPS_get_core_handle(OSSL_LIB_CTX *libctx)
814e1051a39Sopenharmony_ci{
815e1051a39Sopenharmony_ci    FIPS_GLOBAL *fgbl = ossl_lib_ctx_get_data(libctx,
816e1051a39Sopenharmony_ci                                              OSSL_LIB_CTX_FIPS_PROV_INDEX,
817e1051a39Sopenharmony_ci                                              &fips_prov_ossl_ctx_method);
818e1051a39Sopenharmony_ci
819e1051a39Sopenharmony_ci    if (fgbl == NULL)
820e1051a39Sopenharmony_ci        return NULL;
821e1051a39Sopenharmony_ci
822e1051a39Sopenharmony_ci    return fgbl->handle;
823e1051a39Sopenharmony_ci}
824e1051a39Sopenharmony_ci
825e1051a39Sopenharmony_civoid *CRYPTO_malloc(size_t num, const char *file, int line)
826e1051a39Sopenharmony_ci{
827e1051a39Sopenharmony_ci    return c_CRYPTO_malloc(num, file, line);
828e1051a39Sopenharmony_ci}
829e1051a39Sopenharmony_ci
830e1051a39Sopenharmony_civoid *CRYPTO_zalloc(size_t num, const char *file, int line)
831e1051a39Sopenharmony_ci{
832e1051a39Sopenharmony_ci    return c_CRYPTO_zalloc(num, file, line);
833e1051a39Sopenharmony_ci}
834e1051a39Sopenharmony_ci
835e1051a39Sopenharmony_civoid CRYPTO_free(void *ptr, const char *file, int line)
836e1051a39Sopenharmony_ci{
837e1051a39Sopenharmony_ci    c_CRYPTO_free(ptr, file, line);
838e1051a39Sopenharmony_ci}
839e1051a39Sopenharmony_ci
840e1051a39Sopenharmony_civoid CRYPTO_clear_free(void *ptr, size_t num, const char *file, int line)
841e1051a39Sopenharmony_ci{
842e1051a39Sopenharmony_ci    c_CRYPTO_clear_free(ptr, num, file, line);
843e1051a39Sopenharmony_ci}
844e1051a39Sopenharmony_ci
845e1051a39Sopenharmony_civoid *CRYPTO_realloc(void *addr, size_t num, const char *file, int line)
846e1051a39Sopenharmony_ci{
847e1051a39Sopenharmony_ci    return c_CRYPTO_realloc(addr, num, file, line);
848e1051a39Sopenharmony_ci}
849e1051a39Sopenharmony_ci
850e1051a39Sopenharmony_civoid *CRYPTO_clear_realloc(void *addr, size_t old_num, size_t num,
851e1051a39Sopenharmony_ci                           const char *file, int line)
852e1051a39Sopenharmony_ci{
853e1051a39Sopenharmony_ci    return c_CRYPTO_clear_realloc(addr, old_num, num, file, line);
854e1051a39Sopenharmony_ci}
855e1051a39Sopenharmony_ci
856e1051a39Sopenharmony_civoid *CRYPTO_secure_malloc(size_t num, const char *file, int line)
857e1051a39Sopenharmony_ci{
858e1051a39Sopenharmony_ci    return c_CRYPTO_secure_malloc(num, file, line);
859e1051a39Sopenharmony_ci}
860e1051a39Sopenharmony_ci
861e1051a39Sopenharmony_civoid *CRYPTO_secure_zalloc(size_t num, const char *file, int line)
862e1051a39Sopenharmony_ci{
863e1051a39Sopenharmony_ci    return c_CRYPTO_secure_zalloc(num, file, line);
864e1051a39Sopenharmony_ci}
865e1051a39Sopenharmony_ci
866e1051a39Sopenharmony_civoid CRYPTO_secure_free(void *ptr, const char *file, int line)
867e1051a39Sopenharmony_ci{
868e1051a39Sopenharmony_ci    c_CRYPTO_secure_free(ptr, file, line);
869e1051a39Sopenharmony_ci}
870e1051a39Sopenharmony_ci
871e1051a39Sopenharmony_civoid CRYPTO_secure_clear_free(void *ptr, size_t num, const char *file, int line)
872e1051a39Sopenharmony_ci{
873e1051a39Sopenharmony_ci    c_CRYPTO_secure_clear_free(ptr, num, file, line);
874e1051a39Sopenharmony_ci}
875e1051a39Sopenharmony_ci
876e1051a39Sopenharmony_ciint CRYPTO_secure_allocated(const void *ptr)
877e1051a39Sopenharmony_ci{
878e1051a39Sopenharmony_ci    return c_CRYPTO_secure_allocated(ptr);
879e1051a39Sopenharmony_ci}
880e1051a39Sopenharmony_ci
881e1051a39Sopenharmony_ciint BIO_snprintf(char *buf, size_t n, const char *format, ...)
882e1051a39Sopenharmony_ci{
883e1051a39Sopenharmony_ci    va_list args;
884e1051a39Sopenharmony_ci    int ret;
885e1051a39Sopenharmony_ci
886e1051a39Sopenharmony_ci    va_start(args, format);
887e1051a39Sopenharmony_ci    ret = c_BIO_vsnprintf(buf, n, format, args);
888e1051a39Sopenharmony_ci    va_end(args);
889e1051a39Sopenharmony_ci    return ret;
890e1051a39Sopenharmony_ci}
891e1051a39Sopenharmony_ci
892e1051a39Sopenharmony_ciint FIPS_security_check_enabled(OSSL_LIB_CTX *libctx)
893e1051a39Sopenharmony_ci{
894e1051a39Sopenharmony_ci    FIPS_GLOBAL *fgbl = ossl_lib_ctx_get_data(libctx,
895e1051a39Sopenharmony_ci                                              OSSL_LIB_CTX_FIPS_PROV_INDEX,
896e1051a39Sopenharmony_ci                                              &fips_prov_ossl_ctx_method);
897e1051a39Sopenharmony_ci
898e1051a39Sopenharmony_ci    return fgbl->fips_security_checks;
899e1051a39Sopenharmony_ci}
900e1051a39Sopenharmony_ci
901e1051a39Sopenharmony_civoid OSSL_SELF_TEST_get_callback(OSSL_LIB_CTX *libctx, OSSL_CALLBACK **cb,
902e1051a39Sopenharmony_ci                                 void **cbarg)
903e1051a39Sopenharmony_ci{
904e1051a39Sopenharmony_ci    assert(libctx != NULL);
905e1051a39Sopenharmony_ci
906e1051a39Sopenharmony_ci    if (c_stcbfn != NULL && c_get_libctx != NULL) {
907e1051a39Sopenharmony_ci        /* Get the parent libctx */
908e1051a39Sopenharmony_ci        c_stcbfn(c_get_libctx(FIPS_get_core_handle(libctx)), cb, cbarg);
909e1051a39Sopenharmony_ci    } else {
910e1051a39Sopenharmony_ci        if (cb != NULL)
911e1051a39Sopenharmony_ci            *cb = NULL;
912e1051a39Sopenharmony_ci        if (cbarg != NULL)
913e1051a39Sopenharmony_ci            *cbarg = NULL;
914e1051a39Sopenharmony_ci    }
915e1051a39Sopenharmony_ci}
916