openssl.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. /*
  2. * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (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 <internal/cryptlib.h>
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include <openssl/bio.h>
  14. #include <openssl/crypto.h>
  15. #include <openssl/lhash.h>
  16. #include <openssl/conf.h>
  17. #include <openssl/x509.h>
  18. #include <openssl/pem.h>
  19. #include <openssl/ssl.h>
  20. #ifndef OPENSSL_NO_ENGINE
  21. # include <openssl/engine.h>
  22. #endif
  23. #include <openssl/err.h>
  24. #include "s_apps.h"
  25. /* Needed to get the other O_xxx flags. */
  26. #ifdef OPENSSL_SYS_VMS
  27. # include <unixio.h>
  28. #endif
  29. #include "apps.h"
  30. #define INCLUDE_FUNCTION_TABLE
  31. #include "progs.h"
  32. /* Structure to hold the number of columns to be displayed and the
  33. * field width used to display them.
  34. */
  35. typedef struct {
  36. int columns;
  37. int width;
  38. } DISPLAY_COLUMNS;
  39. /* Special sentinel to exit the program. */
  40. #define EXIT_THE_PROGRAM (-1)
  41. /*
  42. * The LHASH callbacks ("hash" & "cmp") have been replaced by functions with
  43. * the base prototypes (we cast each variable inside the function to the
  44. * required type of "FUNCTION*"). This removes the necessity for
  45. * macro-generated wrapper functions.
  46. */
  47. static LHASH_OF(FUNCTION) *prog_init(void);
  48. static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);
  49. static void list_pkey(void);
  50. static void list_pkey_meth(void);
  51. static void list_type(FUNC_TYPE ft, int one);
  52. static void list_disabled(void);
  53. char *default_config_file = NULL;
  54. BIO *bio_in = NULL;
  55. BIO *bio_out = NULL;
  56. BIO *bio_err = NULL;
  57. static void calculate_columns(DISPLAY_COLUMNS *dc)
  58. {
  59. FUNCTION *f;
  60. int len, maxlen = 0;
  61. for (f = functions; f->name != NULL; ++f)
  62. if (f->type == FT_general || f->type == FT_md || f->type == FT_cipher)
  63. if ((len = strlen(f->name)) > maxlen)
  64. maxlen = len;
  65. dc->width = maxlen + 2;
  66. dc->columns = (80 - 1) / dc->width;
  67. }
  68. static int apps_startup()
  69. {
  70. #ifdef SIGPIPE
  71. signal(SIGPIPE, SIG_IGN);
  72. #endif
  73. /* Set non-default library initialisation settings */
  74. if (!OPENSSL_init_ssl(OPENSSL_INIT_ENGINE_ALL_BUILTIN
  75. | OPENSSL_INIT_LOAD_CONFIG, NULL))
  76. return 0;
  77. setup_ui_method();
  78. return 1;
  79. }
  80. static void apps_shutdown()
  81. {
  82. destroy_ui_method();
  83. destroy_prefix_method();
  84. }
  85. static char *make_config_name()
  86. {
  87. const char *t;
  88. size_t len;
  89. char *p;
  90. if ((t = getenv("OPENSSL_CONF")) != NULL)
  91. return OPENSSL_strdup(t);
  92. t = X509_get_default_cert_area();
  93. len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1;
  94. p = app_malloc(len, "config filename buffer");
  95. strcpy(p, t);
  96. #ifndef OPENSSL_SYS_VMS
  97. strcat(p, "/");
  98. #endif
  99. strcat(p, OPENSSL_CONF);
  100. return p;
  101. }
  102. int main(int argc, char *argv[])
  103. {
  104. FUNCTION f, *fp;
  105. LHASH_OF(FUNCTION) *prog = NULL;
  106. char **copied_argv = NULL;
  107. char *p, *pname;
  108. char buf[1024];
  109. const char *prompt;
  110. ARGS arg;
  111. int first, n, i, ret = 0;
  112. arg.argv = NULL;
  113. arg.size = 0;
  114. /* Set up some of the environment. */
  115. default_config_file = make_config_name();
  116. bio_in = dup_bio_in(FORMAT_TEXT);
  117. bio_out = dup_bio_out(FORMAT_TEXT);
  118. bio_err = dup_bio_err(FORMAT_TEXT);
  119. #if defined(OPENSSL_SYS_VMS) && defined(__DECC)
  120. copied_argv = argv = copy_argv(&argc, argv);
  121. #elif defined(_WIN32)
  122. /*
  123. * Replace argv[] with UTF-8 encoded strings.
  124. */
  125. win32_utf8argv(&argc, &argv);
  126. #endif
  127. p = getenv("OPENSSL_DEBUG_MEMORY");
  128. if (p != NULL && strcmp(p, "on") == 0)
  129. CRYPTO_set_mem_debug(1);
  130. CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
  131. if (getenv("OPENSSL_FIPS")) {
  132. BIO_printf(bio_err, "FIPS mode not supported.\n");
  133. return 1;
  134. }
  135. if (!apps_startup()) {
  136. BIO_printf(bio_err,
  137. "FATAL: Startup failure (dev note: apps_startup() failed)\n");
  138. ERR_print_errors(bio_err);
  139. ret = 1;
  140. goto end;
  141. }
  142. prog = prog_init();
  143. pname = opt_progname(argv[0]);
  144. /* first check the program name */
  145. f.name = pname;
  146. fp = lh_FUNCTION_retrieve(prog, &f);
  147. if (fp != NULL) {
  148. argv[0] = pname;
  149. ret = fp->func(argc, argv);
  150. goto end;
  151. }
  152. /* If there is stuff on the command line, run with that. */
  153. if (argc != 1) {
  154. argc--;
  155. argv++;
  156. ret = do_cmd(prog, argc, argv);
  157. if (ret < 0)
  158. ret = 0;
  159. goto end;
  160. }
  161. /* ok, lets enter interactive mode */
  162. for (;;) {
  163. ret = 0;
  164. /* Read a line, continue reading if line ends with \ */
  165. for (p = buf, n = sizeof(buf), i = 0, first = 1; n > 0; first = 0) {
  166. prompt = first ? "OpenSSL> " : "> ";
  167. p[0] = '\0';
  168. #ifndef READLINE
  169. fputs(prompt, stdout);
  170. fflush(stdout);
  171. if (!fgets(p, n, stdin))
  172. goto end;
  173. if (p[0] == '\0')
  174. goto end;
  175. i = strlen(p);
  176. if (i <= 1)
  177. break;
  178. if (p[i - 2] != '\\')
  179. break;
  180. i -= 2;
  181. p += i;
  182. n -= i;
  183. #else
  184. {
  185. extern char *readline(const char *);
  186. extern void add_history(const char *cp);
  187. char *text;
  188. text = readline(prompt);
  189. if (text == NULL)
  190. goto end;
  191. i = strlen(text);
  192. if (i == 0 || i > n)
  193. break;
  194. if (text[i - 1] != '\\') {
  195. p += strlen(strcpy(p, text));
  196. free(text);
  197. add_history(buf);
  198. break;
  199. }
  200. text[i - 1] = '\0';
  201. p += strlen(strcpy(p, text));
  202. free(text);
  203. n -= i;
  204. }
  205. #endif
  206. }
  207. if (!chopup_args(&arg, buf)) {
  208. BIO_printf(bio_err, "Can't parse (no memory?)\n");
  209. break;
  210. }
  211. ret = do_cmd(prog, arg.argc, arg.argv);
  212. if (ret == EXIT_THE_PROGRAM) {
  213. ret = 0;
  214. goto end;
  215. }
  216. if (ret != 0)
  217. BIO_printf(bio_err, "error in %s\n", arg.argv[0]);
  218. (void)BIO_flush(bio_out);
  219. (void)BIO_flush(bio_err);
  220. }
  221. ret = 1;
  222. end:
  223. OPENSSL_free(copied_argv);
  224. OPENSSL_free(default_config_file);
  225. lh_FUNCTION_free(prog);
  226. OPENSSL_free(arg.argv);
  227. app_RAND_write();
  228. BIO_free(bio_in);
  229. BIO_free_all(bio_out);
  230. apps_shutdown();
  231. #ifndef OPENSSL_NO_CRYPTO_MDEBUG
  232. if (CRYPTO_mem_leaks(bio_err) <= 0)
  233. ret = 1;
  234. #endif
  235. BIO_free(bio_err);
  236. EXIT(ret);
  237. }
  238. static void list_cipher_fn(const EVP_CIPHER *c,
  239. const char *from, const char *to, void *arg)
  240. {
  241. if (c != NULL) {
  242. BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
  243. } else {
  244. if (from == NULL)
  245. from = "<undefined>";
  246. if (to == NULL)
  247. to = "<undefined>";
  248. BIO_printf(arg, "%s => %s\n", from, to);
  249. }
  250. }
  251. static void list_md_fn(const EVP_MD *m,
  252. const char *from, const char *to, void *arg)
  253. {
  254. if (m != NULL) {
  255. BIO_printf(arg, "%s\n", EVP_MD_name(m));
  256. } else {
  257. if (from == NULL)
  258. from = "<undefined>";
  259. if (to == NULL)
  260. to = "<undefined>";
  261. BIO_printf((BIO *)arg, "%s => %s\n", from, to);
  262. }
  263. }
  264. static void list_missing_help(void)
  265. {
  266. const FUNCTION *fp;
  267. const OPTIONS *o;
  268. for (fp = functions; fp->name != NULL; fp++) {
  269. if ((o = fp->help) != NULL) {
  270. /* If there is help, list what flags are not documented. */
  271. for ( ; o->name != NULL; o++) {
  272. if (o->helpstr == NULL)
  273. BIO_printf(bio_out, "%s %s\n", fp->name, o->name);
  274. }
  275. } else if (fp->func != dgst_main) {
  276. /* If not aliased to the dgst command, */
  277. BIO_printf(bio_out, "%s *\n", fp->name);
  278. }
  279. }
  280. }
  281. static void list_options_for_command(const char *command)
  282. {
  283. const FUNCTION *fp;
  284. const OPTIONS *o;
  285. for (fp = functions; fp->name != NULL; fp++)
  286. if (strcmp(fp->name, command) == 0)
  287. break;
  288. if (fp->name == NULL) {
  289. BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
  290. command);
  291. return;
  292. }
  293. if ((o = fp->help) == NULL)
  294. return;
  295. for ( ; o->name != NULL; o++) {
  296. if (o->name == OPT_HELP_STR
  297. || o->name == OPT_MORE_STR
  298. || o->name[0] == '\0')
  299. continue;
  300. BIO_printf(bio_out, "%s %c\n", o->name, o->valtype);
  301. }
  302. }
  303. /* Unified enum for help and list commands. */
  304. typedef enum HELPLIST_CHOICE {
  305. OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE,
  306. OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_OPTIONS,
  307. OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
  308. OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED, OPT_MISSING_HELP
  309. } HELPLIST_CHOICE;
  310. const OPTIONS list_options[] = {
  311. {"help", OPT_HELP, '-', "Display this summary"},
  312. {"1", OPT_ONE, '-', "List in one column"},
  313. {"commands", OPT_COMMANDS, '-', "List of standard commands"},
  314. {"digest-commands", OPT_DIGEST_COMMANDS, '-',
  315. "List of message digest commands"},
  316. {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
  317. "List of message digest algorithms"},
  318. {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
  319. {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
  320. "List of cipher algorithms"},
  321. {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
  322. "List of public key algorithms"},
  323. {"public-key-methods", OPT_PK_METHOD, '-',
  324. "List of public key methods"},
  325. {"disabled", OPT_DISABLED, '-',
  326. "List of disabled features"},
  327. {"missing-help", OPT_MISSING_HELP, '-',
  328. "List missing detailed help strings"},
  329. {"options", OPT_OPTIONS, 's',
  330. "List options for specified command"},
  331. {NULL}
  332. };
  333. int list_main(int argc, char **argv)
  334. {
  335. char *prog;
  336. HELPLIST_CHOICE o;
  337. int one = 0, done = 0;
  338. prog = opt_init(argc, argv, list_options);
  339. while ((o = opt_next()) != OPT_EOF) {
  340. switch (o) {
  341. case OPT_EOF: /* Never hit, but suppresses warning */
  342. case OPT_ERR:
  343. opthelp:
  344. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  345. return 1;
  346. case OPT_HELP:
  347. opt_help(list_options);
  348. break;
  349. case OPT_ONE:
  350. one = 1;
  351. break;
  352. case OPT_COMMANDS:
  353. list_type(FT_general, one);
  354. break;
  355. case OPT_DIGEST_COMMANDS:
  356. list_type(FT_md, one);
  357. break;
  358. case OPT_DIGEST_ALGORITHMS:
  359. EVP_MD_do_all_sorted(list_md_fn, bio_out);
  360. break;
  361. case OPT_CIPHER_COMMANDS:
  362. list_type(FT_cipher, one);
  363. break;
  364. case OPT_CIPHER_ALGORITHMS:
  365. EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
  366. break;
  367. case OPT_PK_ALGORITHMS:
  368. list_pkey();
  369. break;
  370. case OPT_PK_METHOD:
  371. list_pkey_meth();
  372. break;
  373. case OPT_DISABLED:
  374. list_disabled();
  375. break;
  376. case OPT_MISSING_HELP:
  377. list_missing_help();
  378. break;
  379. case OPT_OPTIONS:
  380. list_options_for_command(opt_arg());
  381. break;
  382. }
  383. done = 1;
  384. }
  385. if (opt_num_rest() != 0) {
  386. BIO_printf(bio_err, "Extra arguments given.\n");
  387. goto opthelp;
  388. }
  389. if (!done)
  390. goto opthelp;
  391. return 0;
  392. }
  393. typedef enum HELP_CHOICE {
  394. OPT_hERR = -1, OPT_hEOF = 0, OPT_hHELP
  395. } HELP_CHOICE;
  396. const OPTIONS help_options[] = {
  397. {OPT_HELP_STR, 1, '-', "Usage: help [options]\n"},
  398. {OPT_HELP_STR, 1, '-', " help [command]\n"},
  399. {"help", OPT_hHELP, '-', "Display this summary"},
  400. {NULL}
  401. };
  402. int help_main(int argc, char **argv)
  403. {
  404. FUNCTION *fp;
  405. int i, nl;
  406. FUNC_TYPE tp;
  407. char *prog;
  408. HELP_CHOICE o;
  409. DISPLAY_COLUMNS dc;
  410. prog = opt_init(argc, argv, help_options);
  411. while ((o = opt_next()) != OPT_hEOF) {
  412. switch (o) {
  413. case OPT_hERR:
  414. case OPT_hEOF:
  415. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  416. return 1;
  417. case OPT_hHELP:
  418. opt_help(help_options);
  419. return 0;
  420. }
  421. }
  422. if (opt_num_rest() == 1) {
  423. char *new_argv[3];
  424. new_argv[0] = opt_rest()[0];
  425. new_argv[1] = "--help";
  426. new_argv[2] = NULL;
  427. return do_cmd(prog_init(), 2, new_argv);
  428. }
  429. if (opt_num_rest() != 0) {
  430. BIO_printf(bio_err, "Usage: %s\n", prog);
  431. return 1;
  432. }
  433. calculate_columns(&dc);
  434. BIO_printf(bio_err, "Standard commands");
  435. i = 0;
  436. tp = FT_none;
  437. for (fp = functions; fp->name != NULL; fp++) {
  438. nl = 0;
  439. if (i++ % dc.columns == 0) {
  440. BIO_printf(bio_err, "\n");
  441. nl = 1;
  442. }
  443. if (fp->type != tp) {
  444. tp = fp->type;
  445. if (!nl)
  446. BIO_printf(bio_err, "\n");
  447. if (tp == FT_md) {
  448. i = 1;
  449. BIO_printf(bio_err,
  450. "\nMessage Digest commands (see the `dgst' command for more details)\n");
  451. } else if (tp == FT_cipher) {
  452. i = 1;
  453. BIO_printf(bio_err,
  454. "\nCipher commands (see the `enc' command for more details)\n");
  455. }
  456. }
  457. BIO_printf(bio_err, "%-*s", dc.width, fp->name);
  458. }
  459. BIO_printf(bio_err, "\n\n");
  460. return 0;
  461. }
  462. static void list_type(FUNC_TYPE ft, int one)
  463. {
  464. FUNCTION *fp;
  465. int i = 0;
  466. DISPLAY_COLUMNS dc = {0};
  467. if (!one)
  468. calculate_columns(&dc);
  469. for (fp = functions; fp->name != NULL; fp++) {
  470. if (fp->type != ft)
  471. continue;
  472. if (one) {
  473. BIO_printf(bio_out, "%s\n", fp->name);
  474. } else {
  475. if (i % dc.columns == 0 && i > 0)
  476. BIO_printf(bio_out, "\n");
  477. BIO_printf(bio_out, "%-*s", dc.width, fp->name);
  478. i++;
  479. }
  480. }
  481. if (!one)
  482. BIO_printf(bio_out, "\n\n");
  483. }
  484. static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
  485. {
  486. FUNCTION f, *fp;
  487. if (argc <= 0 || argv[0] == NULL)
  488. return 0;
  489. f.name = argv[0];
  490. fp = lh_FUNCTION_retrieve(prog, &f);
  491. if (fp == NULL) {
  492. if (EVP_get_digestbyname(argv[0])) {
  493. f.type = FT_md;
  494. f.func = dgst_main;
  495. fp = &f;
  496. } else if (EVP_get_cipherbyname(argv[0])) {
  497. f.type = FT_cipher;
  498. f.func = enc_main;
  499. fp = &f;
  500. }
  501. }
  502. if (fp != NULL) {
  503. return fp->func(argc, argv);
  504. }
  505. if ((strncmp(argv[0], "no-", 3)) == 0) {
  506. /*
  507. * User is asking if foo is unsupported, by trying to "run" the
  508. * no-foo command. Strange.
  509. */
  510. f.name = argv[0] + 3;
  511. if (lh_FUNCTION_retrieve(prog, &f) == NULL) {
  512. BIO_printf(bio_out, "%s\n", argv[0]);
  513. return 0;
  514. }
  515. BIO_printf(bio_out, "%s\n", argv[0] + 3);
  516. return 1;
  517. }
  518. if (strcmp(argv[0], "quit") == 0 || strcmp(argv[0], "q") == 0 ||
  519. strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0)
  520. /* Special value to mean "exit the program. */
  521. return EXIT_THE_PROGRAM;
  522. BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
  523. argv[0]);
  524. return 1;
  525. }
  526. static void list_pkey(void)
  527. {
  528. int i;
  529. for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
  530. const EVP_PKEY_ASN1_METHOD *ameth;
  531. int pkey_id, pkey_base_id, pkey_flags;
  532. const char *pinfo, *pem_str;
  533. ameth = EVP_PKEY_asn1_get0(i);
  534. EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
  535. &pinfo, &pem_str, ameth);
  536. if (pkey_flags & ASN1_PKEY_ALIAS) {
  537. BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
  538. BIO_printf(bio_out, "\tAlias for: %s\n",
  539. OBJ_nid2ln(pkey_base_id));
  540. } else {
  541. BIO_printf(bio_out, "Name: %s\n", pinfo);
  542. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  543. pkey_flags & ASN1_PKEY_DYNAMIC ?
  544. "External" : "Builtin");
  545. BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
  546. if (pem_str == NULL)
  547. pem_str = "(none)";
  548. BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
  549. }
  550. }
  551. }
  552. static void list_pkey_meth(void)
  553. {
  554. size_t i;
  555. size_t meth_count = EVP_PKEY_meth_get_count();
  556. for (i = 0; i < meth_count; i++) {
  557. const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
  558. int pkey_id, pkey_flags;
  559. EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
  560. BIO_printf(bio_out, "%s\n", OBJ_nid2ln(pkey_id));
  561. BIO_printf(bio_out, "\tType: %s Algorithm\n",
  562. pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin");
  563. }
  564. }
  565. static int function_cmp(const FUNCTION * a, const FUNCTION * b)
  566. {
  567. return strncmp(a->name, b->name, 8);
  568. }
  569. static unsigned long function_hash(const FUNCTION * a)
  570. {
  571. return OPENSSL_LH_strhash(a->name);
  572. }
  573. static int SortFnByName(const void *_f1, const void *_f2)
  574. {
  575. const FUNCTION *f1 = _f1;
  576. const FUNCTION *f2 = _f2;
  577. if (f1->type != f2->type)
  578. return f1->type - f2->type;
  579. return strcmp(f1->name, f2->name);
  580. }
  581. static void list_disabled(void)
  582. {
  583. BIO_puts(bio_out, "Disabled algorithms:\n");
  584. #ifdef OPENSSL_NO_ARIA
  585. BIO_puts(bio_out, "ARIA\n");
  586. #endif
  587. #ifdef OPENSSL_NO_BF
  588. BIO_puts(bio_out, "BF\n");
  589. #endif
  590. #ifdef OPENSSL_NO_BLAKE2
  591. BIO_puts(bio_out, "BLAKE2\n");
  592. #endif
  593. #ifdef OPENSSL_NO_CAMELLIA
  594. BIO_puts(bio_out, "CAMELLIA\n");
  595. #endif
  596. #ifdef OPENSSL_NO_CAST
  597. BIO_puts(bio_out, "CAST\n");
  598. #endif
  599. #ifdef OPENSSL_NO_CMAC
  600. BIO_puts(bio_out, "CMAC\n");
  601. #endif
  602. #ifdef OPENSSL_NO_CMS
  603. BIO_puts(bio_out, "CMS\n");
  604. #endif
  605. #ifdef OPENSSL_NO_COMP
  606. BIO_puts(bio_out, "COMP\n");
  607. #endif
  608. #ifdef OPENSSL_NO_DES
  609. BIO_puts(bio_out, "DES\n");
  610. #endif
  611. #ifdef OPENSSL_NO_DGRAM
  612. BIO_puts(bio_out, "DGRAM\n");
  613. #endif
  614. #ifdef OPENSSL_NO_DH
  615. BIO_puts(bio_out, "DH\n");
  616. #endif
  617. #ifdef OPENSSL_NO_DSA
  618. BIO_puts(bio_out, "DSA\n");
  619. #endif
  620. #if defined(OPENSSL_NO_DTLS)
  621. BIO_puts(bio_out, "DTLS\n");
  622. #endif
  623. #if defined(OPENSSL_NO_DTLS1)
  624. BIO_puts(bio_out, "DTLS1\n");
  625. #endif
  626. #if defined(OPENSSL_NO_DTLS1_2)
  627. BIO_puts(bio_out, "DTLS1_2\n");
  628. #endif
  629. #ifdef OPENSSL_NO_EC
  630. BIO_puts(bio_out, "EC\n");
  631. #endif
  632. #ifdef OPENSSL_NO_EC2M
  633. BIO_puts(bio_out, "EC2M\n");
  634. #endif
  635. #ifdef OPENSSL_NO_ENGINE
  636. BIO_puts(bio_out, "ENGINE\n");
  637. #endif
  638. #ifdef OPENSSL_NO_GOST
  639. BIO_puts(bio_out, "GOST\n");
  640. #endif
  641. #ifdef OPENSSL_NO_HEARTBEATS
  642. BIO_puts(bio_out, "HEARTBEATS\n");
  643. #endif
  644. #ifdef OPENSSL_NO_IDEA
  645. BIO_puts(bio_out, "IDEA\n");
  646. #endif
  647. #ifdef OPENSSL_NO_MD2
  648. BIO_puts(bio_out, "MD2\n");
  649. #endif
  650. #ifdef OPENSSL_NO_MD4
  651. BIO_puts(bio_out, "MD4\n");
  652. #endif
  653. #ifdef OPENSSL_NO_MD5
  654. BIO_puts(bio_out, "MD5\n");
  655. #endif
  656. #ifdef OPENSSL_NO_MDC2
  657. BIO_puts(bio_out, "MDC2\n");
  658. #endif
  659. #ifdef OPENSSL_NO_OCB
  660. BIO_puts(bio_out, "OCB\n");
  661. #endif
  662. #ifdef OPENSSL_NO_OCSP
  663. BIO_puts(bio_out, "OCSP\n");
  664. #endif
  665. #ifdef OPENSSL_NO_PSK
  666. BIO_puts(bio_out, "PSK\n");
  667. #endif
  668. #ifdef OPENSSL_NO_RC2
  669. BIO_puts(bio_out, "RC2\n");
  670. #endif
  671. #ifdef OPENSSL_NO_RC4
  672. BIO_puts(bio_out, "RC4\n");
  673. #endif
  674. #ifdef OPENSSL_NO_RC5
  675. BIO_puts(bio_out, "RC5\n");
  676. #endif
  677. #ifdef OPENSSL_NO_RMD160
  678. BIO_puts(bio_out, "RMD160\n");
  679. #endif
  680. #ifdef OPENSSL_NO_RSA
  681. BIO_puts(bio_out, "RSA\n");
  682. #endif
  683. #ifdef OPENSSL_NO_SCRYPT
  684. BIO_puts(bio_out, "SCRYPT\n");
  685. #endif
  686. #ifdef OPENSSL_NO_SCTP
  687. BIO_puts(bio_out, "SCTP\n");
  688. #endif
  689. #ifdef OPENSSL_NO_SEED
  690. BIO_puts(bio_out, "SEED\n");
  691. #endif
  692. #ifdef OPENSSL_NO_SM2
  693. BIO_puts(bio_out, "SM2\n");
  694. #endif
  695. #ifdef OPENSSL_NO_SM3
  696. BIO_puts(bio_out, "SM3\n");
  697. #endif
  698. #ifdef OPENSSL_NO_SM4
  699. BIO_puts(bio_out, "SM4\n");
  700. #endif
  701. #ifdef OPENSSL_NO_SOCK
  702. BIO_puts(bio_out, "SOCK\n");
  703. #endif
  704. #ifdef OPENSSL_NO_SRP
  705. BIO_puts(bio_out, "SRP\n");
  706. #endif
  707. #ifdef OPENSSL_NO_SRTP
  708. BIO_puts(bio_out, "SRTP\n");
  709. #endif
  710. #ifdef OPENSSL_NO_SSL3
  711. BIO_puts(bio_out, "SSL3\n");
  712. #endif
  713. #ifdef OPENSSL_NO_TLS1
  714. BIO_puts(bio_out, "TLS1\n");
  715. #endif
  716. #ifdef OPENSSL_NO_TLS1_1
  717. BIO_puts(bio_out, "TLS1_1\n");
  718. #endif
  719. #ifdef OPENSSL_NO_TLS1_2
  720. BIO_puts(bio_out, "TLS1_2\n");
  721. #endif
  722. #ifdef OPENSSL_NO_WHIRLPOOL
  723. BIO_puts(bio_out, "WHIRLPOOL\n");
  724. #endif
  725. #ifndef ZLIB
  726. BIO_puts(bio_out, "ZLIB\n");
  727. #endif
  728. }
  729. static LHASH_OF(FUNCTION) *prog_init(void)
  730. {
  731. static LHASH_OF(FUNCTION) *ret = NULL;
  732. static int prog_inited = 0;
  733. FUNCTION *f;
  734. size_t i;
  735. if (prog_inited)
  736. return ret;
  737. prog_inited = 1;
  738. /* Sort alphabetically within category. For nicer help displays. */
  739. for (i = 0, f = functions; f->name != NULL; ++f, ++i)
  740. ;
  741. qsort(functions, i, sizeof(*functions), SortFnByName);
  742. if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)
  743. return NULL;
  744. for (f = functions; f->name != NULL; f++)
  745. (void)lh_FUNCTION_insert(ret, f);
  746. return ret;
  747. }