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