2
0

fipsprov.c 33 KB

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