Revert "Add some casts for %j"
[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, 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 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             /* If there is help, list what flags are not documented. */
297             for ( ; o->name != NULL; o++) {
298                 if (o->helpstr == NULL)
299                     BIO_printf(bio_out, "%s %s\n", fp->name, o->name);
300             }
301         } else if (fp->func != dgst_main) {
302             /* If not aliased to the dgst command, */
303             BIO_printf(bio_out, "%s *\n", fp->name);
304         }
305     }
306 }
307
308 static void list_options_for_command(const char *command)
309 {
310     const FUNCTION *fp;
311     const OPTIONS *o;
312
313     for (fp = functions; fp->name != NULL; fp++)
314         if (strcmp(fp->name, command) == 0)
315             break;
316     if (fp->name == NULL) {
317         BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
318                 command);
319         return;
320     }
321
322     if ((o = fp->help) == NULL)
323         return;
324
325     for ( ; o->name != NULL; o++) {
326         if (o->name == OPT_HELP_STR
327                 || o->name == OPT_MORE_STR
328                 || o->name[0] == '\0')
329             continue;
330         BIO_printf(bio_out, "%s %c\n", o->name, o->valtype);
331     }
332 }
333
334
335 /* Unified enum for help and list commands. */
336 typedef enum HELPLIST_CHOICE {
337     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE,
338     OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_OPTIONS,
339     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
340     OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED, OPT_MISSING_HELP
341 } HELPLIST_CHOICE;
342
343 const OPTIONS list_options[] = {
344     {"help", OPT_HELP, '-', "Display this summary"},
345     {"1", OPT_ONE, '-', "List in one column"},
346     {"commands", OPT_COMMANDS, '-', "List of standard commands"},
347     {"digest-commands", OPT_DIGEST_COMMANDS, '-',
348      "List of message digest commands"},
349     {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
350      "List of message digest algorithms"},
351     {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
352     {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
353      "List of cipher algorithms"},
354     {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
355      "List of public key algorithms"},
356     {"public-key-methods", OPT_PK_METHOD, '-',
357      "List of public key methods"},
358     {"disabled", OPT_DISABLED, '-',
359      "List of disabled features"},
360     {"missing-help", OPT_MISSING_HELP, '-',
361      "List missing detailed help strings"},
362     {"options", OPT_OPTIONS, 's',
363      "List options for specified command"},
364     {NULL}
365 };
366
367 int list_main(int argc, char **argv)
368 {
369     char *prog;
370     HELPLIST_CHOICE o;
371     int one = 0, done = 0;
372
373     prog = opt_init(argc, argv, list_options);
374     while ((o = opt_next()) != OPT_EOF) {
375         switch (o) {
376         case OPT_EOF:  /* Never hit, but suppresses warning */
377         case OPT_ERR:
378             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
379             return 1;
380         case OPT_HELP:
381             opt_help(list_options);
382             break;
383         case OPT_ONE:
384             one = 1;
385             break;
386         case OPT_COMMANDS:
387             list_type(FT_general, one);
388             break;
389         case OPT_DIGEST_COMMANDS:
390             list_type(FT_md, one);
391             break;
392         case OPT_DIGEST_ALGORITHMS:
393             EVP_MD_do_all_sorted(list_md_fn, bio_out);
394             break;
395         case OPT_CIPHER_COMMANDS:
396             list_type(FT_cipher, one);
397             break;
398         case OPT_CIPHER_ALGORITHMS:
399             EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
400             break;
401         case OPT_PK_ALGORITHMS:
402             list_pkey();
403             break;
404         case OPT_PK_METHOD:
405             list_pkey_meth();
406             break;
407         case OPT_DISABLED:
408             list_disabled();
409             break;
410         case OPT_MISSING_HELP:
411             list_missing_help();
412             break;
413         case OPT_OPTIONS:
414             list_options_for_command(opt_arg());
415             break;
416         }
417         done = 1;
418     }
419
420     if (!done) {
421         BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
422         return 1;
423     }
424
425     return 0;
426 }
427
428 typedef enum HELP_CHOICE {
429     OPT_hERR = -1, OPT_hEOF = 0, OPT_hHELP
430 } HELP_CHOICE;
431
432 const OPTIONS help_options[] = {
433     {"help", OPT_hHELP, '-', "Display this summary"},
434     {NULL}
435 };
436
437
438 int help_main(int argc, char **argv)
439 {
440     FUNCTION *fp;
441     int i, nl;
442     FUNC_TYPE tp;
443     char *prog;
444     HELP_CHOICE o;
445
446     prog = opt_init(argc, argv, help_options);
447     while ((o = opt_next()) != OPT_hEOF) {
448         switch (o) {
449         case OPT_hERR:
450         case OPT_hEOF:
451             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
452             return 1;
453         case OPT_hHELP:
454             opt_help(help_options);
455             return 0;
456         }
457     }
458
459     if (opt_num_rest() != 0) {
460         BIO_printf(bio_err, "Usage: %s\n", prog);
461         return 1;
462     }
463
464     BIO_printf(bio_err, "\nStandard commands");
465     i = 0;
466     tp = FT_none;
467     for (fp = functions; fp->name != NULL; fp++) {
468         nl = 0;
469         if (((i++) % COLUMNS) == 0) {
470             BIO_printf(bio_err, "\n");
471             nl = 1;
472         }
473         if (fp->type != tp) {
474             tp = fp->type;
475             if (!nl)
476                 BIO_printf(bio_err, "\n");
477             if (tp == FT_md) {
478                 i = 1;
479                 BIO_printf(bio_err,
480                            "\nMessage Digest commands (see the `dgst' command for more details)\n");
481             } else if (tp == FT_cipher) {
482                 i = 1;
483                 BIO_printf(bio_err,
484                            "\nCipher commands (see the `enc' command for more details)\n");
485             }
486         }
487         BIO_printf(bio_err, FORMAT, fp->name);
488     }
489     BIO_printf(bio_err, "\n\n");
490     return 0;
491 }
492
493 int exit_main(int argc, char **argv)
494 {
495     return EXIT_THE_PROGRAM;
496 }
497
498 static void list_type(FUNC_TYPE ft, int one)
499 {
500     FUNCTION *fp;
501     int i = 0;
502
503     for (fp = functions; fp->name != NULL; fp++) {
504         if (fp->type != ft)
505             continue;
506         if (one) {
507             BIO_printf(bio_out, "%s\n", fp->name);
508         } else {
509             if ((i++ % COLUMNS) == 0 && fp != functions)
510                 BIO_printf(bio_out, "\n");
511             BIO_printf(bio_out, FORMAT, fp->name);
512         }
513     }
514     if (!one)
515         BIO_printf(bio_out, "\n");
516 }
517
518 static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
519 {
520     FUNCTION f, *fp;
521
522     if (argc <= 0 || argv[0] == NULL)
523         return (0);
524     f.name = argv[0];
525     fp = lh_FUNCTION_retrieve(prog, &f);
526     if (fp == NULL) {
527         if (EVP_get_digestbyname(argv[0])) {
528             f.type = FT_md;
529             f.func = dgst_main;
530             fp = &f;
531         } else if (EVP_get_cipherbyname(argv[0])) {
532             f.type = FT_cipher;
533             f.func = enc_main;
534             fp = &f;
535         }
536     }
537     if (fp != NULL) {
538         return (fp->func(argc, argv));
539     }
540     if ((strncmp(argv[0], "no-", 3)) == 0) {
541         /*
542          * User is asking if foo is unsupported, by trying to "run" the
543          * no-foo command.  Strange.
544          */
545         f.name = argv[0] + 3;
546         if (lh_FUNCTION_retrieve(prog, &f) == NULL) {
547             BIO_printf(bio_out, "%s\n", argv[0]);
548             return (0);
549         }
550         BIO_printf(bio_out, "%s\n", argv[0] + 3);
551         return 1;
552     }
553     if (strcmp(argv[0], "quit") == 0 || strcmp(argv[0], "q") == 0 ||
554         strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0)
555         /* Special value to mean "exit the program. */
556         return EXIT_THE_PROGRAM;
557
558     BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
559                argv[0]);
560     return (1);
561 }
562
563 static void list_pkey(void)
564 {
565     int i;
566
567     for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
568         const EVP_PKEY_ASN1_METHOD *ameth;
569         int pkey_id, pkey_base_id, pkey_flags;
570         const char *pinfo, *pem_str;
571         ameth = EVP_PKEY_asn1_get0(i);
572         EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
573                                 &pinfo, &pem_str, ameth);
574         if (pkey_flags & ASN1_PKEY_ALIAS) {
575             BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
576             BIO_printf(bio_out, "\tAlias for: %s\n",
577                        OBJ_nid2ln(pkey_base_id));
578         } else {
579             BIO_printf(bio_out, "Name: %s\n", pinfo);
580             BIO_printf(bio_out, "\tType: %s Algorithm\n",
581                        pkey_flags & ASN1_PKEY_DYNAMIC ?
582                        "External" : "Builtin");
583             BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
584             if (pem_str == NULL)
585                 pem_str = "(none)";
586             BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
587         }
588
589     }
590 }
591
592 static void list_pkey_meth(void)
593 {
594     size_t i;
595     size_t meth_count = EVP_PKEY_meth_get_count();
596
597     for (i = 0; i < meth_count; i++) {
598         const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
599         int pkey_id, pkey_flags;
600
601         EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
602         BIO_printf(bio_out, "%s\n", OBJ_nid2ln(pkey_id));
603         BIO_printf(bio_out, "\tType: %s Algorithm\n",
604                    pkey_flags & ASN1_PKEY_DYNAMIC ?  "External" : "Builtin");
605     }
606 }
607
608 static int function_cmp(const FUNCTION * a, const FUNCTION * b)
609 {
610     return strncmp(a->name, b->name, 8);
611 }
612
613 static unsigned long function_hash(const FUNCTION * a)
614 {
615     return OPENSSL_LH_strhash(a->name);
616 }
617
618 static int SortFnByName(const void *_f1, const void *_f2)
619 {
620     const FUNCTION *f1 = _f1;
621     const FUNCTION *f2 = _f2;
622
623     if (f1->type != f2->type)
624         return f1->type - f2->type;
625     return strcmp(f1->name, f2->name);
626 }
627
628 static void list_disabled(void)
629 {
630     BIO_puts(bio_out, "Disabled algorithms:\n");
631 #ifdef OPENSSL_NO_ARIA
632     BIO_puts(bio_out, "ARIA\n");
633 #endif
634 #ifdef OPENSSL_NO_BF
635     BIO_puts(bio_out, "BF\n");
636 #endif
637 #ifdef OPENSSL_NO_BLAKE2
638     BIO_puts(bio_out, "BLAKE2\n");
639 #endif
640 #ifdef OPENSSL_NO_CAMELLIA
641     BIO_puts(bio_out, "CAMELLIA\n");
642 #endif
643 #ifdef OPENSSL_NO_CAST
644     BIO_puts(bio_out, "CAST\n");
645 #endif
646 #ifdef OPENSSL_NO_CMAC
647     BIO_puts(bio_out, "CMAC\n");
648 #endif
649 #ifdef OPENSSL_NO_CMS
650     BIO_puts(bio_out, "CMS\n");
651 #endif
652 #ifdef OPENSSL_NO_COMP
653     BIO_puts(bio_out, "COMP\n");
654 #endif
655 #ifdef OPENSSL_NO_DES
656     BIO_puts(bio_out, "DES\n");
657 #endif
658 #ifdef OPENSSL_NO_DGRAM
659     BIO_puts(bio_out, "DGRAM\n");
660 #endif
661 #ifdef OPENSSL_NO_DH
662     BIO_puts(bio_out, "DH\n");
663 #endif
664 #ifdef OPENSSL_NO_DSA
665     BIO_puts(bio_out, "DSA\n");
666 #endif
667 #if defined(OPENSSL_NO_DTLS)
668     BIO_puts(bio_out, "DTLS\n");
669 #endif
670 #if defined(OPENSSL_NO_DTLS1)
671     BIO_puts(bio_out, "DTLS1\n");
672 #endif
673 #if defined(OPENSSL_NO_DTLS1_2)
674     BIO_puts(bio_out, "DTLS1_2\n");
675 #endif
676 #ifdef OPENSSL_NO_EC
677     BIO_puts(bio_out, "EC\n");
678 #endif
679 #ifdef OPENSSL_NO_EC2M
680     BIO_puts(bio_out, "EC2M\n");
681 #endif
682 #ifdef OPENSSL_NO_ENGINE
683     BIO_puts(bio_out, "ENGINE\n");
684 #endif
685 #ifdef OPENSSL_NO_GOST
686     BIO_puts(bio_out, "GOST\n");
687 #endif
688 #ifdef OPENSSL_NO_HEARTBEATS
689     BIO_puts(bio_out, "HEARTBEATS\n");
690 #endif
691 #ifdef OPENSSL_NO_IDEA
692     BIO_puts(bio_out, "IDEA\n");
693 #endif
694 #ifdef OPENSSL_NO_MD2
695     BIO_puts(bio_out, "MD2\n");
696 #endif
697 #ifdef OPENSSL_NO_MD4
698     BIO_puts(bio_out, "MD4\n");
699 #endif
700 #ifdef OPENSSL_NO_MD5
701     BIO_puts(bio_out, "MD5\n");
702 #endif
703 #ifdef OPENSSL_NO_MDC2
704     BIO_puts(bio_out, "MDC2\n");
705 #endif
706 #ifdef OPENSSL_NO_OCB
707     BIO_puts(bio_out, "OCB\n");
708 #endif
709 #ifdef OPENSSL_NO_OCSP
710     BIO_puts(bio_out, "OCSP\n");
711 #endif
712 #ifdef OPENSSL_NO_PSK
713     BIO_puts(bio_out, "PSK\n");
714 #endif
715 #ifdef OPENSSL_NO_RC2
716     BIO_puts(bio_out, "RC2\n");
717 #endif
718 #ifdef OPENSSL_NO_RC4
719     BIO_puts(bio_out, "RC4\n");
720 #endif
721 #ifdef OPENSSL_NO_RC5
722     BIO_puts(bio_out, "RC5\n");
723 #endif
724 #ifdef OPENSSL_NO_RMD160
725     BIO_puts(bio_out, "RMD160\n");
726 #endif
727 #ifdef OPENSSL_NO_RSA
728     BIO_puts(bio_out, "RSA\n");
729 #endif
730 #ifdef OPENSSL_NO_SCRYPT
731     BIO_puts(bio_out, "SCRYPT\n");
732 #endif
733 #ifdef OPENSSL_NO_SCTP
734     BIO_puts(bio_out, "SCTP\n");
735 #endif
736 #ifdef OPENSSL_NO_SEED
737     BIO_puts(bio_out, "SEED\n");
738 #endif
739 #ifdef OPENSSL_NO_SOCK
740     BIO_puts(bio_out, "SOCK\n");
741 #endif
742 #ifdef OPENSSL_NO_SRP
743     BIO_puts(bio_out, "SRP\n");
744 #endif
745 #ifdef OPENSSL_NO_SRTP
746     BIO_puts(bio_out, "SRTP\n");
747 #endif
748 #ifdef OPENSSL_NO_SSL3
749     BIO_puts(bio_out, "SSL3\n");
750 #endif
751 #ifdef OPENSSL_NO_TLS1
752     BIO_puts(bio_out, "TLS1\n");
753 #endif
754 #ifdef OPENSSL_NO_TLS1_1
755     BIO_puts(bio_out, "TLS1_1\n");
756 #endif
757 #ifdef OPENSSL_NO_TLS1_2
758     BIO_puts(bio_out, "TLS1_2\n");
759 #endif
760 #ifdef OPENSSL_NO_WHIRLPOOL
761     BIO_puts(bio_out, "WHIRLPOOL\n");
762 #endif
763 #ifndef ZLIB
764     BIO_puts(bio_out, "ZLIB\n");
765 #endif
766 }
767
768 static LHASH_OF(FUNCTION) *prog_init(void)
769 {
770     LHASH_OF(FUNCTION) *ret;
771     FUNCTION *f;
772     size_t i;
773
774     /* Sort alphabetically within category. For nicer help displays. */
775     for (i = 0, f = functions; f->name != NULL; ++f, ++i) ;
776     qsort(functions, i, sizeof(*functions), SortFnByName);
777
778     if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)
779         return (NULL);
780
781     for (f = functions; f->name != NULL; f++)
782         (void)lh_FUNCTION_insert(ret, f);
783     return (ret);
784 }