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