fipsprov.c 33 KB

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