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