fipsinstall.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*
  2. * Copyright 2019-2021 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 <string.h>
  10. #include <openssl/evp.h>
  11. #include <openssl/err.h>
  12. #include <openssl/provider.h>
  13. #include <openssl/params.h>
  14. #include <openssl/fips_names.h>
  15. #include <openssl/core_names.h>
  16. #include <openssl/self_test.h>
  17. #include <openssl/fipskey.h>
  18. #include "apps.h"
  19. #include "progs.h"
  20. #define BUFSIZE 4096
  21. /* Configuration file values */
  22. #define VERSION_KEY "version"
  23. #define VERSION_VAL "1"
  24. #define INSTALL_STATUS_VAL "INSTALL_SELF_TEST_KATS_RUN"
  25. static OSSL_CALLBACK self_test_events;
  26. static char *self_test_corrupt_desc = NULL;
  27. static char *self_test_corrupt_type = NULL;
  28. static int self_test_log = 1;
  29. static int quiet = 0;
  30. typedef enum OPTION_choice {
  31. OPT_COMMON,
  32. OPT_IN, OPT_OUT, OPT_MODULE,
  33. OPT_PROV_NAME, OPT_SECTION_NAME, OPT_MAC_NAME, OPT_MACOPT, OPT_VERIFY,
  34. OPT_NO_LOG, OPT_CORRUPT_DESC, OPT_CORRUPT_TYPE, OPT_QUIET, OPT_CONFIG,
  35. OPT_NO_CONDITIONAL_ERRORS,
  36. OPT_NO_SECURITY_CHECKS,
  37. OPT_SELF_TEST_ONLOAD
  38. } OPTION_CHOICE;
  39. const OPTIONS fipsinstall_options[] = {
  40. OPT_SECTION("General"),
  41. {"help", OPT_HELP, '-', "Display this summary"},
  42. {"verify", OPT_VERIFY, '-',
  43. "Verify a config file instead of generating one"},
  44. {"module", OPT_MODULE, '<', "File name of the provider module"},
  45. {"provider_name", OPT_PROV_NAME, 's', "FIPS provider name"},
  46. {"section_name", OPT_SECTION_NAME, 's',
  47. "FIPS Provider config section name (optional)"},
  48. {"no_conditional_errors", OPT_NO_CONDITIONAL_ERRORS, '-',
  49. "Disable the ability of the fips module to enter an error state if"
  50. " any conditional self tests fail"},
  51. {"no_security_checks", OPT_NO_SECURITY_CHECKS, '-',
  52. "Disable the run-time FIPS security checks in the module"},
  53. {"self_test_onload", OPT_SELF_TEST_ONLOAD, '-',
  54. "Forces self tests to always run on module load"},
  55. OPT_SECTION("Input"),
  56. {"in", OPT_IN, '<', "Input config file, used when verifying"},
  57. OPT_SECTION("Output"),
  58. {"out", OPT_OUT, '>', "Output config file, used when generating"},
  59. {"mac_name", OPT_MAC_NAME, 's', "MAC name"},
  60. {"macopt", OPT_MACOPT, 's', "MAC algorithm parameters in n:v form. "
  61. "See 'PARAMETER NAMES' in the EVP_MAC_ docs"},
  62. {"noout", OPT_NO_LOG, '-', "Disable logging of self test events"},
  63. {"corrupt_desc", OPT_CORRUPT_DESC, 's', "Corrupt a self test by description"},
  64. {"corrupt_type", OPT_CORRUPT_TYPE, 's', "Corrupt a self test by type"},
  65. {"config", OPT_CONFIG, '<', "The parent config to verify"},
  66. {"quiet", OPT_QUIET, '-', "No messages, just exit status"},
  67. {NULL}
  68. };
  69. static int do_mac(EVP_MAC_CTX *ctx, unsigned char *tmp, BIO *in,
  70. unsigned char *out, size_t *out_len)
  71. {
  72. int ret = 0;
  73. int i;
  74. size_t outsz = *out_len;
  75. if (!EVP_MAC_init(ctx, NULL, 0, NULL))
  76. goto err;
  77. if (EVP_MAC_CTX_get_mac_size(ctx) > outsz)
  78. goto end;
  79. while ((i = BIO_read(in, (char *)tmp, BUFSIZE)) != 0) {
  80. if (i < 0 || !EVP_MAC_update(ctx, tmp, i))
  81. goto err;
  82. }
  83. end:
  84. if (!EVP_MAC_final(ctx, out, out_len, outsz))
  85. goto err;
  86. ret = 1;
  87. err:
  88. return ret;
  89. }
  90. static int load_fips_prov_and_run_self_test(const char *prov_name)
  91. {
  92. int ret = 0;
  93. OSSL_PROVIDER *prov = NULL;
  94. prov = OSSL_PROVIDER_load(NULL, prov_name);
  95. if (prov == NULL) {
  96. BIO_printf(bio_err, "Failed to load FIPS module\n");
  97. goto end;
  98. }
  99. ret = 1;
  100. end:
  101. OSSL_PROVIDER_unload(prov);
  102. return ret;
  103. }
  104. static int print_mac(BIO *bio, const char *label, const unsigned char *mac,
  105. size_t len)
  106. {
  107. int ret;
  108. char *hexstr = NULL;
  109. hexstr = OPENSSL_buf2hexstr(mac, (long)len);
  110. if (hexstr == NULL)
  111. return 0;
  112. ret = BIO_printf(bio, "%s = %s\n", label, hexstr);
  113. OPENSSL_free(hexstr);
  114. return ret;
  115. }
  116. static int write_config_header(BIO *out, const char *prov_name,
  117. const char *section)
  118. {
  119. return BIO_printf(out, "openssl_conf = openssl_init\n\n")
  120. && BIO_printf(out, "[openssl_init]\n")
  121. && BIO_printf(out, "providers = provider_section\n\n")
  122. && BIO_printf(out, "[provider_section]\n")
  123. && BIO_printf(out, "%s = %s\n\n", prov_name, section);
  124. }
  125. /*
  126. * Outputs a fips related config file that contains entries for the fips
  127. * module checksum, installation indicator checksum and the options
  128. * conditional_errors and security_checks.
  129. *
  130. * Returns 1 if the config file is written otherwise it returns 0 on error.
  131. */
  132. static int write_config_fips_section(BIO *out, const char *section,
  133. unsigned char *module_mac,
  134. size_t module_mac_len,
  135. int conditional_errors,
  136. int security_checks,
  137. unsigned char *install_mac,
  138. size_t install_mac_len)
  139. {
  140. int ret = 0;
  141. if (BIO_printf(out, "[%s]\n", section) <= 0
  142. || BIO_printf(out, "activate = 1\n") <= 0
  143. || BIO_printf(out, "%s = %s\n", OSSL_PROV_FIPS_PARAM_INSTALL_VERSION,
  144. VERSION_VAL) <= 0
  145. || BIO_printf(out, "%s = %s\n", OSSL_PROV_FIPS_PARAM_CONDITIONAL_ERRORS,
  146. conditional_errors ? "1" : "0") <= 0
  147. || BIO_printf(out, "%s = %s\n", OSSL_PROV_FIPS_PARAM_SECURITY_CHECKS,
  148. security_checks ? "1" : "0") <= 0
  149. || !print_mac(out, OSSL_PROV_FIPS_PARAM_MODULE_MAC, module_mac,
  150. module_mac_len))
  151. goto end;
  152. if (install_mac != NULL && install_mac_len > 0) {
  153. if (!print_mac(out, OSSL_PROV_FIPS_PARAM_INSTALL_MAC, install_mac,
  154. install_mac_len)
  155. || BIO_printf(out, "%s = %s\n", OSSL_PROV_FIPS_PARAM_INSTALL_STATUS,
  156. INSTALL_STATUS_VAL) <= 0)
  157. goto end;
  158. }
  159. ret = 1;
  160. end:
  161. return ret;
  162. }
  163. static CONF *generate_config_and_load(const char *prov_name,
  164. const char *section,
  165. unsigned char *module_mac,
  166. size_t module_mac_len,
  167. int conditional_errors,
  168. int security_checks)
  169. {
  170. BIO *mem_bio = NULL;
  171. CONF *conf = NULL;
  172. mem_bio = BIO_new(BIO_s_mem());
  173. if (mem_bio == NULL)
  174. return 0;
  175. if (!write_config_header(mem_bio, prov_name, section)
  176. || !write_config_fips_section(mem_bio, section,
  177. module_mac, module_mac_len,
  178. conditional_errors,
  179. security_checks,
  180. NULL, 0))
  181. goto end;
  182. conf = app_load_config_bio(mem_bio, NULL);
  183. if (conf == NULL)
  184. goto end;
  185. if (CONF_modules_load(conf, NULL, 0) <= 0)
  186. goto end;
  187. BIO_free(mem_bio);
  188. return conf;
  189. end:
  190. NCONF_free(conf);
  191. BIO_free(mem_bio);
  192. return NULL;
  193. }
  194. static void free_config_and_unload(CONF *conf)
  195. {
  196. if (conf != NULL) {
  197. NCONF_free(conf);
  198. CONF_modules_unload(1);
  199. }
  200. }
  201. static int verify_module_load(const char *parent_config_file)
  202. {
  203. return OSSL_LIB_CTX_load_config(NULL, parent_config_file);
  204. }
  205. /*
  206. * Returns 1 if the config file entries match the passed in module_mac and
  207. * install_mac values, otherwise it returns 0.
  208. */
  209. static int verify_config(const char *infile, const char *section,
  210. unsigned char *module_mac, size_t module_mac_len,
  211. unsigned char *install_mac, size_t install_mac_len)
  212. {
  213. int ret = 0;
  214. char *s = NULL;
  215. unsigned char *buf1 = NULL, *buf2 = NULL;
  216. long len;
  217. CONF *conf = NULL;
  218. /* read in the existing values and check they match the saved values */
  219. conf = app_load_config(infile);
  220. if (conf == NULL)
  221. goto end;
  222. s = NCONF_get_string(conf, section, OSSL_PROV_FIPS_PARAM_INSTALL_VERSION);
  223. if (s == NULL || strcmp(s, VERSION_VAL) != 0) {
  224. BIO_printf(bio_err, "version not found\n");
  225. goto end;
  226. }
  227. s = NCONF_get_string(conf, section, OSSL_PROV_FIPS_PARAM_MODULE_MAC);
  228. if (s == NULL) {
  229. BIO_printf(bio_err, "Module integrity MAC not found\n");
  230. goto end;
  231. }
  232. buf1 = OPENSSL_hexstr2buf(s, &len);
  233. if (buf1 == NULL
  234. || (size_t)len != module_mac_len
  235. || memcmp(module_mac, buf1, module_mac_len) != 0) {
  236. BIO_printf(bio_err, "Module integrity mismatch\n");
  237. goto end;
  238. }
  239. if (install_mac != NULL && install_mac_len > 0) {
  240. s = NCONF_get_string(conf, section, OSSL_PROV_FIPS_PARAM_INSTALL_STATUS);
  241. if (s == NULL || strcmp(s, INSTALL_STATUS_VAL) != 0) {
  242. BIO_printf(bio_err, "install status not found\n");
  243. goto end;
  244. }
  245. s = NCONF_get_string(conf, section, OSSL_PROV_FIPS_PARAM_INSTALL_MAC);
  246. if (s == NULL) {
  247. BIO_printf(bio_err, "Install indicator MAC not found\n");
  248. goto end;
  249. }
  250. buf2 = OPENSSL_hexstr2buf(s, &len);
  251. if (buf2 == NULL
  252. || (size_t)len != install_mac_len
  253. || memcmp(install_mac, buf2, install_mac_len) != 0) {
  254. BIO_printf(bio_err, "Install indicator status mismatch\n");
  255. goto end;
  256. }
  257. }
  258. ret = 1;
  259. end:
  260. OPENSSL_free(buf1);
  261. OPENSSL_free(buf2);
  262. NCONF_free(conf);
  263. return ret;
  264. }
  265. int fipsinstall_main(int argc, char **argv)
  266. {
  267. int ret = 1, verify = 0, gotkey = 0, gotdigest = 0, self_test_onload = 0;
  268. int enable_conditional_errors = 1, enable_security_checks = 1;
  269. const char *section_name = "fips_sect";
  270. const char *mac_name = "HMAC";
  271. const char *prov_name = "fips";
  272. BIO *module_bio = NULL, *mem_bio = NULL, *fout = NULL;
  273. char *in_fname = NULL, *out_fname = NULL, *prog;
  274. char *module_fname = NULL, *parent_config = NULL, *module_path = NULL;
  275. const char *tail;
  276. EVP_MAC_CTX *ctx = NULL, *ctx2 = NULL;
  277. STACK_OF(OPENSSL_STRING) *opts = NULL;
  278. OPTION_CHOICE o;
  279. unsigned char *read_buffer = NULL;
  280. unsigned char module_mac[EVP_MAX_MD_SIZE];
  281. size_t module_mac_len = EVP_MAX_MD_SIZE;
  282. unsigned char install_mac[EVP_MAX_MD_SIZE];
  283. size_t install_mac_len = EVP_MAX_MD_SIZE;
  284. EVP_MAC *mac = NULL;
  285. CONF *conf = NULL;
  286. if ((opts = sk_OPENSSL_STRING_new_null()) == NULL)
  287. goto end;
  288. prog = opt_init(argc, argv, fipsinstall_options);
  289. while ((o = opt_next()) != OPT_EOF) {
  290. switch (o) {
  291. case OPT_EOF:
  292. case OPT_ERR:
  293. opthelp:
  294. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  295. goto cleanup;
  296. case OPT_HELP:
  297. opt_help(fipsinstall_options);
  298. ret = 0;
  299. goto end;
  300. case OPT_IN:
  301. in_fname = opt_arg();
  302. break;
  303. case OPT_OUT:
  304. out_fname = opt_arg();
  305. break;
  306. case OPT_NO_CONDITIONAL_ERRORS:
  307. enable_conditional_errors = 0;
  308. break;
  309. case OPT_NO_SECURITY_CHECKS:
  310. enable_security_checks = 0;
  311. break;
  312. case OPT_QUIET:
  313. quiet = 1;
  314. /* FALLTHROUGH */
  315. case OPT_NO_LOG:
  316. self_test_log = 0;
  317. break;
  318. case OPT_CORRUPT_DESC:
  319. self_test_corrupt_desc = opt_arg();
  320. break;
  321. case OPT_CORRUPT_TYPE:
  322. self_test_corrupt_type = opt_arg();
  323. break;
  324. case OPT_PROV_NAME:
  325. prov_name = opt_arg();
  326. break;
  327. case OPT_MODULE:
  328. module_fname = opt_arg();
  329. break;
  330. case OPT_SECTION_NAME:
  331. section_name = opt_arg();
  332. break;
  333. case OPT_MAC_NAME:
  334. mac_name = opt_arg();
  335. break;
  336. case OPT_CONFIG:
  337. parent_config = opt_arg();
  338. break;
  339. case OPT_MACOPT:
  340. if (!sk_OPENSSL_STRING_push(opts, opt_arg()))
  341. goto opthelp;
  342. if (strncmp(opt_arg(), "hexkey:", 7) == 0)
  343. gotkey = 1;
  344. else if (strncmp(opt_arg(), "digest:", 7) == 0)
  345. gotdigest = 1;
  346. break;
  347. case OPT_VERIFY:
  348. verify = 1;
  349. break;
  350. case OPT_SELF_TEST_ONLOAD:
  351. self_test_onload = 1;
  352. break;
  353. }
  354. }
  355. /* No extra arguments. */
  356. argc = opt_num_rest();
  357. if (argc != 0 || (verify && in_fname == NULL))
  358. goto opthelp;
  359. if (parent_config != NULL) {
  360. /* Test that a parent config can load the module */
  361. if (verify_module_load(parent_config)) {
  362. ret = OSSL_PROVIDER_available(NULL, prov_name) ? 0 : 1;
  363. if (!quiet)
  364. BIO_printf(bio_err, "FIPS provider is %s\n",
  365. ret == 0 ? "available" : " not available");
  366. }
  367. goto end;
  368. }
  369. if (module_fname == NULL)
  370. goto opthelp;
  371. tail = opt_path_end(module_fname);
  372. if (tail != NULL) {
  373. module_path = OPENSSL_strdup(module_fname);
  374. if (module_path == NULL)
  375. goto end;
  376. module_path[tail - module_fname] = '\0';
  377. if (!OSSL_PROVIDER_set_default_search_path(NULL, module_path))
  378. goto end;
  379. }
  380. if (self_test_log
  381. || self_test_corrupt_desc != NULL
  382. || self_test_corrupt_type != NULL)
  383. OSSL_SELF_TEST_set_callback(NULL, self_test_events, NULL);
  384. /* Use the default FIPS HMAC digest and key if not specified. */
  385. if (!gotdigest && !sk_OPENSSL_STRING_push(opts, "digest:SHA256"))
  386. goto end;
  387. if (!gotkey && !sk_OPENSSL_STRING_push(opts, "hexkey:" FIPS_KEY_STRING))
  388. goto end;
  389. module_bio = bio_open_default(module_fname, 'r', FORMAT_BINARY);
  390. if (module_bio == NULL) {
  391. BIO_printf(bio_err, "Failed to open module file\n");
  392. goto end;
  393. }
  394. read_buffer = app_malloc(BUFSIZE, "I/O buffer");
  395. if (read_buffer == NULL)
  396. goto end;
  397. mac = EVP_MAC_fetch(app_get0_libctx(), mac_name, app_get0_propq());
  398. if (mac == NULL) {
  399. BIO_printf(bio_err, "Unable to get MAC of type %s\n", mac_name);
  400. goto end;
  401. }
  402. ctx = EVP_MAC_CTX_new(mac);
  403. if (ctx == NULL) {
  404. BIO_printf(bio_err, "Unable to create MAC CTX for module check\n");
  405. goto end;
  406. }
  407. if (opts != NULL) {
  408. int ok = 1;
  409. OSSL_PARAM *params =
  410. app_params_new_from_opts(opts, EVP_MAC_settable_ctx_params(mac));
  411. if (params == NULL)
  412. goto end;
  413. if (!EVP_MAC_CTX_set_params(ctx, params)) {
  414. BIO_printf(bio_err, "MAC parameter error\n");
  415. ERR_print_errors(bio_err);
  416. ok = 0;
  417. }
  418. app_params_free(params);
  419. if (!ok)
  420. goto end;
  421. }
  422. ctx2 = EVP_MAC_CTX_dup(ctx);
  423. if (ctx2 == NULL) {
  424. BIO_printf(bio_err, "Unable to create MAC CTX for install indicator\n");
  425. goto end;
  426. }
  427. if (!do_mac(ctx, read_buffer, module_bio, module_mac, &module_mac_len))
  428. goto end;
  429. if (self_test_onload == 0) {
  430. mem_bio = BIO_new_mem_buf((const void *)INSTALL_STATUS_VAL,
  431. strlen(INSTALL_STATUS_VAL));
  432. if (mem_bio == NULL) {
  433. BIO_printf(bio_err, "Unable to create memory BIO\n");
  434. goto end;
  435. }
  436. if (!do_mac(ctx2, read_buffer, mem_bio, install_mac, &install_mac_len))
  437. goto end;
  438. } else {
  439. install_mac_len = 0;
  440. }
  441. if (verify) {
  442. if (!verify_config(in_fname, section_name, module_mac, module_mac_len,
  443. install_mac, install_mac_len))
  444. goto end;
  445. if (!quiet)
  446. BIO_printf(bio_err, "VERIFY PASSED\n");
  447. } else {
  448. conf = generate_config_and_load(prov_name, section_name, module_mac,
  449. module_mac_len,
  450. enable_conditional_errors,
  451. enable_security_checks);
  452. if (conf == NULL)
  453. goto end;
  454. if (!load_fips_prov_and_run_self_test(prov_name))
  455. goto end;
  456. fout =
  457. out_fname == NULL ? dup_bio_out(FORMAT_TEXT)
  458. : bio_open_default(out_fname, 'w', FORMAT_TEXT);
  459. if (fout == NULL) {
  460. BIO_printf(bio_err, "Failed to open file\n");
  461. goto end;
  462. }
  463. if (!write_config_fips_section(fout, section_name,
  464. module_mac, module_mac_len,
  465. enable_conditional_errors,
  466. enable_security_checks,
  467. install_mac, install_mac_len))
  468. goto end;
  469. if (!quiet)
  470. BIO_printf(bio_err, "INSTALL PASSED\n");
  471. }
  472. ret = 0;
  473. end:
  474. if (ret == 1) {
  475. if (!quiet)
  476. BIO_printf(bio_err, "%s FAILED\n", verify ? "VERIFY" : "INSTALL");
  477. ERR_print_errors(bio_err);
  478. }
  479. cleanup:
  480. OPENSSL_free(module_path);
  481. BIO_free(fout);
  482. BIO_free(mem_bio);
  483. BIO_free(module_bio);
  484. sk_OPENSSL_STRING_free(opts);
  485. EVP_MAC_free(mac);
  486. EVP_MAC_CTX_free(ctx2);
  487. EVP_MAC_CTX_free(ctx);
  488. OPENSSL_free(read_buffer);
  489. free_config_and_unload(conf);
  490. return ret;
  491. }
  492. static int self_test_events(const OSSL_PARAM params[], void *arg)
  493. {
  494. const OSSL_PARAM *p = NULL;
  495. const char *phase = NULL, *type = NULL, *desc = NULL;
  496. int ret = 0;
  497. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_PHASE);
  498. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  499. goto err;
  500. phase = (const char *)p->data;
  501. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_DESC);
  502. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  503. goto err;
  504. desc = (const char *)p->data;
  505. p = OSSL_PARAM_locate_const(params, OSSL_PROV_PARAM_SELF_TEST_TYPE);
  506. if (p == NULL || p->data_type != OSSL_PARAM_UTF8_STRING)
  507. goto err;
  508. type = (const char *)p->data;
  509. if (self_test_log) {
  510. if (strcmp(phase, OSSL_SELF_TEST_PHASE_START) == 0)
  511. BIO_printf(bio_err, "%s : (%s) : ", desc, type);
  512. else if (strcmp(phase, OSSL_SELF_TEST_PHASE_PASS) == 0
  513. || strcmp(phase, OSSL_SELF_TEST_PHASE_FAIL) == 0)
  514. BIO_printf(bio_err, "%s\n", phase);
  515. }
  516. /*
  517. * The self test code will internally corrupt the KAT test result if an
  518. * error is returned during the corrupt phase.
  519. */
  520. if (strcmp(phase, OSSL_SELF_TEST_PHASE_CORRUPT) == 0
  521. && (self_test_corrupt_desc != NULL
  522. || self_test_corrupt_type != NULL)) {
  523. if (self_test_corrupt_desc != NULL
  524. && strcmp(self_test_corrupt_desc, desc) != 0)
  525. goto end;
  526. if (self_test_corrupt_type != NULL
  527. && strcmp(self_test_corrupt_type, type) != 0)
  528. goto end;
  529. BIO_printf(bio_err, "%s ", phase);
  530. goto err;
  531. }
  532. end:
  533. ret = 1;
  534. err:
  535. return ret;
  536. }