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