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