openssl.c 21 KB

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