b810ecf8b8944d9feedaa5c33e1f798f58352ef4
[openssl.git] / apps / openssl.c
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to.  The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code.  The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  *    notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  *    notice, this list of conditions and the following disclaimer in the
29  *    documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  *    must display the following acknowledgement:
32  *    "This product includes cryptographic software written by
33  *     Eric Young (eay@cryptsoft.com)"
34  *    The word 'cryptographic' can be left out if the rouines from the library
35  *    being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  *    the apps directory (application code) you must include an acknowledgement:
38  *    "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed.  i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.]
56  */
57 /* ====================================================================
58  * Copyright (c) 1998-2006 The OpenSSL Project.  All rights reserved.
59  *
60  * Redistribution and use in source and binary forms, with or without
61  * modification, are permitted provided that the following conditions
62  * are met:
63  *
64  * 1. Redistributions of source code must retain the above copyright
65  *    notice, this list of conditions and the following disclaimer.
66  *
67  * 2. Redistributions in binary form must reproduce the above copyright
68  *    notice, this list of conditions and the following disclaimer in
69  *    the documentation and/or other materials provided with the
70  *    distribution.
71  *
72  * 3. All advertising materials mentioning features or use of this
73  *    software must display the following acknowledgment:
74  *    "This product includes software developed by the OpenSSL Project
75  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
76  *
77  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
78  *    endorse or promote products derived from this software without
79  *    prior written permission. For written permission, please contact
80  *    openssl-core@openssl.org.
81  *
82  * 5. Products derived from this software may not be called "OpenSSL"
83  *    nor may "OpenSSL" appear in their names without prior written
84  *    permission of the OpenSSL Project.
85  *
86  * 6. Redistributions of any form whatsoever must retain the following
87  *    acknowledgment:
88  *    "This product includes software developed by the OpenSSL Project
89  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
90  *
91  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
92  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
94  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
95  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
96  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
97  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
98  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
99  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
100  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
101  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
102  * OF THE POSSIBILITY OF SUCH DAMAGE.
103  * ====================================================================
104  *
105  * This product includes cryptographic software written by Eric Young
106  * (eay@cryptsoft.com).  This product includes software written by Tim
107  * Hudson (tjh@cryptsoft.com).
108  *
109  */
110
111 #include <stdio.h>
112 #include <string.h>
113 #include <stdlib.h>
114 #include <openssl/bio.h>
115 #include <openssl/crypto.h>
116 #include <openssl/rand.h>
117 #include <openssl/lhash.h>
118 #include <openssl/conf.h>
119 #include <openssl/x509.h>
120 #include <openssl/pem.h>
121 #include <openssl/ssl.h>
122 #ifndef OPENSSL_NO_ENGINE
123 # include <openssl/engine.h>
124 #endif
125 #include <openssl/err.h>
126 #ifdef OPENSSL_FIPS
127 # include <openssl/fips.h>
128 #endif
129 #define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */
130 #include "s_apps.h"
131 /* Needed to get the other O_xxx flags. */
132 #ifdef OPENSSL_SYS_VMS
133 # include <unixio.h>
134 #endif
135 #define INCLUDE_FUNCTION_TABLE
136 #include "apps.h"
137
138
139 #ifdef OPENSSL_NO_CAMELLIA
140 # define FORMAT "%-15s"
141 # define COLUMNS 5
142 #else
143 # define FORMAT "%-18s"
144 # define COLUMNS 4
145 #endif
146
147 /* Special sentinel to exit the program. */
148 #define EXIT_THE_PROGRAM (-1)
149
150 /*
151  * The LHASH callbacks ("hash" & "cmp") have been replaced by functions with
152  * the base prototypes (we cast each variable inside the function to the
153  * required type of "FUNCTION*"). This removes the necessity for
154  * macro-generated wrapper functions.
155  */
156 static LHASH_OF(FUNCTION) *prog_init(void);
157 static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);
158 static void list_pkey(void);
159 static void list_type(FUNC_TYPE ft);
160 static void list_disabled(void);
161 char *default_config_file = NULL;
162
163 static CONF *config = NULL;
164 BIO *bio_in = NULL;
165 BIO *bio_out = NULL;
166 BIO *bio_err = NULL;
167
168 static int apps_startup()
169 {
170 #ifdef SIGPIPE
171     signal(SIGPIPE, SIG_IGN);
172 #endif
173
174     /* Set non-default library initialisation settings */
175     if (!OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN
176                              | OPENSSL_INIT_LOAD_CONFIG, NULL))
177         return 0;
178
179 #ifndef OPENSSL_NO_UI
180     setup_ui_method();
181 #endif
182
183     return 1;
184 }
185
186 static void apps_shutdown()
187 {
188 #ifndef OPENSSL_NO_UI
189     destroy_ui_method();
190 #endif
191 }
192
193 static char *make_config_name()
194 {
195     const char *t;
196     size_t len;
197     char *p;
198
199     if ((t = getenv("OPENSSL_CONF")) != NULL)
200         return OPENSSL_strdup(t);
201
202     t = X509_get_default_cert_area();
203     len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1;
204     p = app_malloc(len, "config filename buffer");
205     strcpy(p, t);
206 #ifndef OPENSSL_SYS_VMS
207     strcat(p, "/");
208 #endif
209     strcat(p, OPENSSL_CONF);
210
211     return p;
212 }
213
214 int main(int argc, char *argv[])
215 {
216     FUNCTION f, *fp;
217     LHASH_OF(FUNCTION) *prog = NULL;
218     char **copied_argv = NULL;
219     char **argv_alias  = NULL;
220     char *p, *pname;
221     char buf[1024];
222     const char *prompt;
223     ARGS arg;
224     int first, n, i, ret = 0;
225
226     arg.argv = NULL;
227     arg.size = 0;
228
229     /* Set up some of the environment. */
230     default_config_file = make_config_name();
231     bio_in = dup_bio_in(FORMAT_TEXT);
232     bio_out = dup_bio_out(FORMAT_TEXT);
233     bio_err = dup_bio_err(FORMAT_TEXT);
234
235 #if defined( OPENSSL_SYS_VMS) && defined(__DECC)
236     copied_argv = argv_alias = copy_argv(&argc, argv);
237 #else
238     argv_alias = argv;
239 #endif
240
241     p = getenv("OPENSSL_DEBUG_MEMORY");
242     if (p != NULL && strcmp(p, "on") == 0)
243         CRYPTO_set_mem_debug(1);
244     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
245
246     if (getenv("OPENSSL_FIPS")) {
247 #ifdef OPENSSL_FIPS
248         if (!FIPS_mode_set(1)) {
249             ERR_print_errors(bio_err);
250             return 1;
251         }
252 #else
253         BIO_printf(bio_err, "FIPS mode not supported.\n");
254         return 1;
255 #endif
256     }
257
258     if (!apps_startup())
259         goto end;
260
261     prog = prog_init();
262     pname = opt_progname(argv_alias[0]);
263
264     /* first check the program name */
265     f.name = pname;
266     fp = lh_FUNCTION_retrieve(prog, &f);
267     if (fp != NULL) {
268         argv_alias[0] = pname;
269         ret = fp->func(argc, argv_alias);
270         goto end;
271     }
272
273     /* If there is stuff on the command line, run with that. */
274     if (argc != 1) {
275         argc--;
276         argv_alias++;
277         ret = do_cmd(prog, argc, argv_alias);
278         if (ret < 0)
279             ret = 0;
280         goto end;
281     }
282
283     /* ok, lets enter interactive mode */
284     for (;;) {
285         ret = 0;
286         /* Read a line, continue reading if line ends with \ */
287         for (p = buf, n = sizeof buf, i = 0, first = 1; n > 0; first = 0) {
288             prompt = first ? "OpenSSL> " : "> ";
289             p[0] = '\0';
290 #ifndef READLINE
291             fputs(prompt, stdout);
292             fflush(stdout);
293             if (!fgets(p, n, stdin))
294                 goto end;
295             if (p[0] == '\0')
296                 goto end;
297             i = strlen(p);
298             if (i <= 1)
299                 break;
300             if (p[i - 2] != '\\')
301                 break;
302             i -= 2;
303             p += i;
304             n -= i;
305 #else
306             {
307                 extern char *readline(const char *);
308                 extern void add_history(const char *cp);
309                 char *text;
310
311                 char *text = readline(prompt);
312                 if (text == NULL)
313                     goto end;
314                 i = strlen(text);
315                 if (i == 0 || i > n)
316                     break;
317                 if (text[i - 1] != '\\') {
318                     p += strlen(strcpy(p, text));
319                     free(text);
320                     add_history(buf);
321                     break;
322                 }
323
324                 text[i - 1] = '\0';
325                 p += strlen(strcpy(p, text));
326                 free(text);
327                 n -= i;
328             }
329 #endif
330         }
331
332         if (!chopup_args(&arg, buf)) {
333             BIO_printf(bio_err, "Can't parse (no memory?)\n");
334             break;
335         }
336
337         ret = do_cmd(prog, arg.argc, arg.argv);
338         if (ret == EXIT_THE_PROGRAM) {
339             ret = 0;
340             goto end;
341         }
342         if (ret != 0)
343             BIO_printf(bio_err, "error in %s\n", arg.argv[0]);
344         (void)BIO_flush(bio_out);
345         (void)BIO_flush(bio_err);
346     }
347     ret = 1;
348  end:
349     OPENSSL_free(copied_argv);
350     OPENSSL_free(default_config_file);
351     NCONF_free(config);
352     config = NULL;
353     lh_FUNCTION_free(prog);
354     OPENSSL_free(arg.argv);
355
356     BIO_free(bio_in);
357     BIO_free_all(bio_out);
358     apps_shutdown();
359 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
360     if (CRYPTO_mem_leaks(bio_err) <= 0)
361         ret = 1;
362 #endif
363     BIO_free(bio_err);
364     EXIT(ret);
365 }
366
367 OPTIONS exit_options[] = {
368     {NULL}
369 };
370
371 static void list_cipher_fn(const EVP_CIPHER *c,
372                            const char *from, const char *to, void *arg)
373 {
374     if (c)
375         BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
376     else {
377         if (!from)
378             from = "<undefined>";
379         if (!to)
380             to = "<undefined>";
381         BIO_printf(arg, "%s => %s\n", from, to);
382     }
383 }
384
385 static void list_md_fn(const EVP_MD *m,
386                        const char *from, const char *to, void *arg)
387 {
388     if (m)
389         BIO_printf(arg, "%s\n", EVP_MD_name(m));
390     else {
391         if (!from)
392             from = "<undefined>";
393         if (!to)
394             to = "<undefined>";
395         BIO_printf((BIO *)arg, "%s => %s\n", from, to);
396     }
397 }
398
399 /* Unified enum for help and list commands. */
400 typedef enum HELPLIST_CHOICE {
401     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
402     OPT_COMMANDS, OPT_DIGEST_COMMANDS,
403     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
404     OPT_PK_ALGORITHMS, OPT_DISABLED
405 } HELPLIST_CHOICE;
406
407 OPTIONS list_options[] = {
408     {"help", OPT_HELP, '-', "Display this summary"},
409     {"commands", OPT_COMMANDS, '-', "List of standard commands"},
410     {"digest-commands", OPT_DIGEST_COMMANDS, '-',
411      "List of message digest commands"},
412     {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
413      "List of message digest algorithms"},
414     {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
415     {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
416      "List of cipher algorithms"},
417     {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
418      "List of public key algorithms"},
419     {"disabled", OPT_DISABLED, '-',
420      "List of disabled features"},
421     {NULL}
422 };
423
424 int list_main(int argc, char **argv)
425 {
426     char *prog;
427     HELPLIST_CHOICE o;
428     int done = 0;
429
430     prog = opt_init(argc, argv, list_options);
431     while ((o = opt_next()) != OPT_EOF) {
432         switch (o) {
433         case OPT_EOF:  /* Never hit, but suppresses warning */
434         case OPT_ERR:
435             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
436             return 1;
437         case OPT_HELP:
438             opt_help(list_options);
439             break;
440         case OPT_COMMANDS:
441             list_type(FT_general);
442             break;
443         case OPT_DIGEST_COMMANDS:
444             list_type(FT_md);
445             break;
446         case OPT_DIGEST_ALGORITHMS:
447             EVP_MD_do_all_sorted(list_md_fn, bio_out);
448             break;
449         case OPT_CIPHER_COMMANDS:
450             list_type(FT_cipher);
451             break;
452         case OPT_CIPHER_ALGORITHMS:
453             EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
454             break;
455         case OPT_PK_ALGORITHMS:
456             list_pkey();
457             break;
458         case OPT_DISABLED:
459             list_disabled();
460             break;
461         }
462         done = 1;
463     }
464
465     if (!done) {
466         BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
467         return 1;
468     }
469
470     return 0;
471 }
472
473 OPTIONS help_options[] = {
474     {"help", OPT_HELP, '-', "Display this summary"},
475     {NULL}
476 };
477
478 int help_main(int argc, char **argv)
479 {
480     FUNCTION *fp;
481     int i, nl;
482     FUNC_TYPE tp;
483     char *prog;
484     HELPLIST_CHOICE o;
485
486     prog = opt_init(argc, argv, help_options);
487     while ((o = opt_next()) != OPT_EOF) {
488         switch (o) {
489         default:
490             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
491             return 1;
492         case OPT_HELP:
493             opt_help(help_options);
494             return 0;
495         }
496     }
497     argc = opt_num_rest();
498     argv = opt_rest();
499
500     if (argc != 0) {
501         BIO_printf(bio_err, "Usage: %s\n", prog);
502         return 1;
503     }
504
505     BIO_printf(bio_err, "\nStandard commands");
506     i = 0;
507     tp = FT_none;
508     for (fp = functions; fp->name != NULL; fp++) {
509         nl = 0;
510         if (((i++) % COLUMNS) == 0) {
511             BIO_printf(bio_err, "\n");
512             nl = 1;
513         }
514         if (fp->type != tp) {
515             tp = fp->type;
516             if (!nl)
517                 BIO_printf(bio_err, "\n");
518             if (tp == FT_md) {
519                 i = 1;
520                 BIO_printf(bio_err,
521                            "\nMessage Digest commands (see the `dgst' command for more details)\n");
522             } else if (tp == FT_cipher) {
523                 i = 1;
524                 BIO_printf(bio_err,
525                            "\nCipher commands (see the `enc' command for more details)\n");
526             }
527         }
528         BIO_printf(bio_err, FORMAT, fp->name);
529     }
530     BIO_printf(bio_err, "\n\n");
531     return 0;
532 }
533
534 int exit_main(int argc, char **argv)
535 {
536     return EXIT_THE_PROGRAM;
537 }
538
539 static void list_type(FUNC_TYPE ft)
540 {
541     FUNCTION *fp;
542     int i = 0;
543
544     for (fp = functions; fp->name != NULL; fp++)
545         if (fp->type == ft) {
546             if ((i++ % COLUMNS) == 0)
547                 BIO_printf(bio_out, "\n");
548             BIO_printf(bio_out, FORMAT, fp->name);
549         }
550     BIO_printf(bio_out, "\n");
551 }
552
553 static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
554 {
555     FUNCTION f, *fp;
556
557     if (argc <= 0 || argv[0] == NULL)
558         return (0);
559     f.name = argv[0];
560     fp = lh_FUNCTION_retrieve(prog, &f);
561     if (fp == NULL) {
562         if (EVP_get_digestbyname(argv[0])) {
563             f.type = FT_md;
564             f.func = dgst_main;
565             fp = &f;
566         } else if (EVP_get_cipherbyname(argv[0])) {
567             f.type = FT_cipher;
568             f.func = enc_main;
569             fp = &f;
570         }
571     }
572     if (fp != NULL) {
573         return (fp->func(argc, argv));
574     }
575     if ((strncmp(argv[0], "no-", 3)) == 0) {
576         /*
577          * User is asking if foo is unsupported, by trying to "run" the
578          * no-foo command.  Strange.
579          */
580         f.name = argv[0] + 3;
581         if (lh_FUNCTION_retrieve(prog, &f) == NULL) {
582             BIO_printf(bio_out, "%s\n", argv[0]);
583             return (0);
584         }
585         BIO_printf(bio_out, "%s\n", argv[0] + 3);
586         return 1;
587     }
588     if (strcmp(argv[0], "quit") == 0 || strcmp(argv[0], "q") == 0 ||
589         strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0)
590         /* Special value to mean "exit the program. */
591         return EXIT_THE_PROGRAM;
592
593     BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
594                argv[0]);
595     return (1);
596 }
597
598 static void list_pkey(void)
599 {
600     int i;
601
602     for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
603         const EVP_PKEY_ASN1_METHOD *ameth;
604         int pkey_id, pkey_base_id, pkey_flags;
605         const char *pinfo, *pem_str;
606         ameth = EVP_PKEY_asn1_get0(i);
607         EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
608                                 &pinfo, &pem_str, ameth);
609         if (pkey_flags & ASN1_PKEY_ALIAS) {
610             BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
611             BIO_printf(bio_out, "\tAlias for: %s\n",
612                        OBJ_nid2ln(pkey_base_id));
613         } else {
614             BIO_printf(bio_out, "Name: %s\n", pinfo);
615             BIO_printf(bio_out, "\tType: %s Algorithm\n",
616                        pkey_flags & ASN1_PKEY_DYNAMIC ?
617                        "External" : "Builtin");
618             BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
619             if (pem_str == NULL)
620                 pem_str = "(none)";
621             BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
622         }
623
624     }
625 }
626
627 static int function_cmp(const FUNCTION * a, const FUNCTION * b)
628 {
629     return strncmp(a->name, b->name, 8);
630 }
631
632 static unsigned long function_hash(const FUNCTION * a)
633 {
634     return lh_strhash(a->name);
635 }
636
637 static int SortFnByName(const void *_f1, const void *_f2)
638 {
639     const FUNCTION *f1 = _f1;
640     const FUNCTION *f2 = _f2;
641
642     if (f1->type != f2->type)
643         return f1->type - f2->type;
644     return strcmp(f1->name, f2->name);
645 }
646
647 static void list_disabled(void)
648 {
649     BIO_puts(bio_out, "Disabled algorithms:\n");
650 #ifdef OPENSSL_NO_AES
651     BIO_puts(bio_out, "AES\n");
652 #endif
653 #ifdef OPENSSL_NO_BF
654     BIO_puts(bio_out, "BF\n");
655 #endif
656 #ifndef OPENSSL_NO_BLAKE2
657     BIO_puts(bio_out, "BLAKE2\n");
658 #endif
659 #ifdef OPENSSL_NO_CAMELLIA
660     BIO_puts(bio_out, "CAMELLIA\n");
661 #endif
662 #ifdef OPENSSL_NO_CAST
663     BIO_puts(bio_out, "CAST\n");
664 #endif
665 #ifdef OPENSSL_NO_CMAC
666     BIO_puts(bio_out, "CMAC\n");
667 #endif
668 #ifdef OPENSSL_NO_CMS
669     BIO_puts(bio_out, "CMS\n");
670 #endif
671 #ifdef OPENSSL_NO_COMP
672     BIO_puts(bio_out, "COMP\n");
673 #endif
674 #ifdef OPENSSL_NO_DES
675     BIO_puts(bio_out, "DES\n");
676 #endif
677 #ifdef OPENSSL_NO_DGRAM
678     BIO_puts(bio_out, "DGRAM\n");
679 #endif
680 #ifdef OPENSSL_NO_DH
681     BIO_puts(bio_out, "DH\n");
682 #endif
683 #ifdef OPENSSL_NO_DSA
684     BIO_puts(bio_out, "DSA\n");
685 #endif
686 #if defined(OPENSSL_NO_DTLS)
687     BIO_puts(bio_out, "DTLS\n");
688 #endif
689 #if defined(OPENSSL_NO_DTLS1)
690     BIO_puts(bio_out, "DTLS1\n");
691 #endif
692 #if defined(OPENSSL_NO_DTLS1_2)
693     BIO_puts(bio_out, "DTLS1_2\n");
694 #endif
695 #ifdef OPENSSL_NO_EC
696     BIO_puts(bio_out, "EC\n");
697 #endif
698 #ifdef OPENSSL_NO_EC2M
699     BIO_puts(bio_out, "EC2M\n");
700 #endif
701 #ifdef OPENSSL_NO_ENGINE
702     BIO_puts(bio_out, "ENGINE\n");
703 #endif
704 #ifdef OPENSSL_NO_GOST
705     BIO_puts(bio_out, "GOST\n");
706 #endif
707 #ifdef OPENSSL_NO_HEARTBEATS
708     BIO_puts(bio_out, "HEARTBEATS\n");
709 #endif
710 #ifdef OPENSSL_NO_HMAC
711     BIO_puts(bio_out, "HMAC\n");
712 #endif
713 #ifdef OPENSSL_NO_IDEA
714     BIO_puts(bio_out, "IDEA\n");
715 #endif
716 #ifdef OPENSSL_NO_MD2
717     BIO_puts(bio_out, "MD2\n");
718 #endif
719 #ifdef OPENSSL_NO_MD4
720     BIO_puts(bio_out, "MD4\n");
721 #endif
722 #ifdef OPENSSL_NO_MD5
723     BIO_puts(bio_out, "MD5\n");
724 #endif
725 #ifdef OPENSSL_NO_MDC2
726     BIO_puts(bio_out, "MDC2\n");
727 #endif
728 #ifdef OPENSSL_NO_OCB
729     BIO_puts(bio_out, "OCB\n");
730 #endif
731 #ifdef OPENSSL_NO_OCSP
732     BIO_puts(bio_out, "OCSP\n");
733 #endif
734 #ifdef OPENSSL_NO_PSK
735     BIO_puts(bio_out, "PSK\n");
736 #endif
737 #ifdef OPENSSL_NO_RC2
738     BIO_puts(bio_out, "RC2\n");
739 #endif
740 #ifdef OPENSSL_NO_RC4
741     BIO_puts(bio_out, "RC4\n");
742 #endif
743 #ifdef OPENSSL_NO_RC5
744     BIO_puts(bio_out, "RC5\n");
745 #endif
746 #ifdef OPENSSL_NO_RMD160
747     BIO_puts(bio_out, "RMD160\n");
748 #endif
749 #ifdef OPENSSL_NO_RSA
750     BIO_puts(bio_out, "RSA\n");
751 #endif
752 #ifdef OPENSSL_NO_SCRYPT
753     BIO_puts(bio_out, "SCRYPT\n");
754 #endif
755 #ifdef OPENSSL_NO_SCT
756     BIO_puts(bio_out, "SCT\n");
757 #endif
758 #ifdef OPENSSL_NO_SCTP
759     BIO_puts(bio_out, "SCTP\n");
760 #endif
761 #ifdef OPENSSL_NO_SEED
762     BIO_puts(bio_out, "SEED\n");
763 #endif
764 #ifdef OPENSSL_NO_SHA
765     BIO_puts(bio_out, "SHA\n");
766 #endif
767 #ifdef OPENSSL_NO_SOCK
768     BIO_puts(bio_out, "SOCK\n");
769 #endif
770 #ifdef OPENSSL_NO_SRP
771     BIO_puts(bio_out, "SRP\n");
772 #endif
773 #ifdef OPENSSL_NO_SRTP
774     BIO_puts(bio_out, "SRTP\n");
775 #endif
776 #ifdef OPENSSL_NO_SSL
777     BIO_puts(bio_out, "SSL\n");
778 #endif
779 #ifdef OPENSSL_NO_SSL3
780     BIO_puts(bio_out, "SSL3\n");
781 #endif
782 #if defined(OPENSSL_NO_TLS)
783     BIO_puts(bio_out, "TLS\n");
784 #endif
785 #ifdef OPENSSL_NO_TLS1
786     BIO_puts(bio_out, "TLS1\n");
787 #endif
788 #ifdef OPENSSL_NO_TLS1_1
789     BIO_puts(bio_out, "TLS1_1\n");
790 #endif
791 #ifdef OPENSSL_NO_TLS1_2
792     BIO_puts(bio_out, "TLS1_2\n");
793 #endif
794 #ifdef OPENSSL_NO_WHIRLPOOL
795     BIO_puts(bio_out, "WHIRLPOOL\n");
796 #endif
797 #ifndef ZLIB
798     BIO_puts(bio_out, "ZLIB\n");
799 #endif
800 }
801
802 static LHASH_OF(FUNCTION) *prog_init(void)
803 {
804     LHASH_OF(FUNCTION) *ret;
805     FUNCTION *f;
806     size_t i;
807
808     /* Sort alphabetically within category. For nicer help displays. */
809     for (i = 0, f = functions; f->name != NULL; ++f, ++i) ;
810     qsort(functions, i, sizeof(*functions), SortFnByName);
811
812     if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)
813         return (NULL);
814
815     for (f = functions; f->name != NULL; f++)
816         (void)lh_FUNCTION_insert(ret, f);
817     return (ret);
818 }