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