]> git.ipfire.org Git - thirdparty/openssl.git/blame - apps/openssl.c
Clean up the VMS hacks in crypto/rand/randfile.c
[thirdparty/openssl.git] / apps / openssl.c
CommitLineData
846e33c7
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3ac82faa 3 *
846e33c7
RS
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
3ac82faa
BM
8 */
9
d02b48c6
RE
10#include <stdio.h>
11#include <string.h>
12#include <stdlib.h>
ec577822
BM
13#include <openssl/bio.h>
14#include <openssl/crypto.h>
3d1160d5 15#include <openssl/rand.h>
ec577822
BM
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>
0b13e9f0 21#ifndef OPENSSL_NO_ENGINE
0f113f3e 22# include <openssl/engine.h>
0b13e9f0 23#endif
ec577822 24#include <openssl/err.h>
856650de 25#ifdef OPENSSL_FIPS
0f113f3e 26# include <openssl/fips.h>
856650de 27#endif
3b061a00
RS
28#define USE_SOCKETS /* needed for the _O_BINARY defs in the MS world */
29#include "s_apps.h"
30/* Needed to get the other O_xxx flags. */
31#ifdef OPENSSL_SYS_VMS
32# include <unixio.h>
33#endif
1e7e1c8d 34#define INCLUDE_FUNCTION_TABLE
7e1b7485
RS
35#include "apps.h"
36
7e1b7485
RS
37
38#ifdef OPENSSL_NO_CAMELLIA
39# define FORMAT "%-15s"
40# define COLUMNS 5
41#else
42# define FORMAT "%-18s"
43# define COLUMNS 4
44#endif
45
46/* Special sentinel to exit the program. */
47#define EXIT_THE_PROGRAM (-1)
d02b48c6 48
0f113f3e
MC
49/*
50 * The LHASH callbacks ("hash" & "cmp") have been replaced by functions with
51 * the base prototypes (we cast each variable inside the function to the
52 * required type of "FUNCTION*"). This removes the necessity for
53 * macro-generated wrapper functions.
54 */
0f113f3e
MC
55static LHASH_OF(FUNCTION) *prog_init(void);
56static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[]);
2f58faad
RS
57static void list_pkey(void);
58static void list_type(FUNC_TYPE ft);
a760a380 59static void list_disabled(void);
0f113f3e 60char *default_config_file = NULL;
d02b48c6 61
df2ee0e2 62static CONF *config = NULL;
7e1b7485
RS
63BIO *bio_in = NULL;
64BIO *bio_out = NULL;
0f113f3e 65BIO *bio_err = NULL;
7e1b7485 66
a0a82324 67static int apps_startup()
7e1b7485
RS
68{
69#ifdef SIGPIPE
70 signal(SIGPIPE, SIG_IGN);
71#endif
a0a82324 72
b9f75707 73 /* Set non-default library initialisation settings */
0fc32b07
MC
74 if (!OPENSSL_init_crypto(OPENSSL_INIT_ENGINE_ALL_BUILTIN
75 | OPENSSL_INIT_LOAD_CONFIG, NULL))
76 return 0;
a0a82324 77
923b1857 78#ifndef OPENSSL_NO_UI
7e1b7485 79 setup_ui_method();
923b1857 80#endif
b9f75707 81
a0a82324 82 return 1;
7e1b7485
RS
83}
84
85static void apps_shutdown()
86{
923b1857 87#ifndef OPENSSL_NO_UI
7e1b7485 88 destroy_ui_method();
923b1857 89#endif
7e1b7485
RS
90}
91
92static char *make_config_name()
93{
cc01d217 94 const char *t;
7e1b7485
RS
95 size_t len;
96 char *p;
97
b0700d2c 98 if ((t = getenv("OPENSSL_CONF")) != NULL)
7644a9ae 99 return OPENSSL_strdup(t);
cc01d217
RS
100
101 t = X509_get_default_cert_area();
102 len = strlen(t) + 1 + strlen(OPENSSL_CONF) + 1;
68dc6824 103 p = app_malloc(len, "config filename buffer");
cc01d217 104 strcpy(p, t);
7e1b7485 105#ifndef OPENSSL_SYS_VMS
cc01d217 106 strcat(p, "/");
d02b48c6 107#endif
cc01d217 108 strcat(p, OPENSSL_CONF);
7e1b7485
RS
109
110 return p;
111}
112
7e1b7485 113int main(int argc, char *argv[])
0f113f3e 114{
0f113f3e 115 FUNCTION f, *fp;
0f113f3e 116 LHASH_OF(FUNCTION) *prog = NULL;
7e1b7485 117 char **copied_argv = NULL;
cc01d217 118 char *p, *pname;
7e1b7485
RS
119 char buf[1024];
120 const char *prompt;
121 ARGS arg;
122 int first, n, i, ret = 0;
8ecef24a 123
7e1b7485
RS
124 arg.argv = NULL;
125 arg.size = 0;
126
7768e116
RS
127 /* Set up some of the environment. */
128 default_config_file = make_config_name();
a60994df
RL
129 bio_in = dup_bio_in(FORMAT_TEXT);
130 bio_out = dup_bio_out(FORMAT_TEXT);
149bd5d6 131 bio_err = dup_bio_err(FORMAT_TEXT);
7768e116 132
368058d0
RL
133#if defined(OPENSSL_SYS_VMS) && defined(__DECC)
134 copied_argv = argv = copy_argv(&argc, argv);
7e1b7485
RS
135#endif
136
137 p = getenv("OPENSSL_DEBUG_MEMORY");
bbd86bf5
RS
138 if (p != NULL && strcmp(p, "on") == 0)
139 CRYPTO_set_mem_debug(1);
0f113f3e 140 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
3ac82faa 141
0f113f3e 142 if (getenv("OPENSSL_FIPS")) {
856650de 143#ifdef OPENSSL_FIPS
0f113f3e 144 if (!FIPS_mode_set(1)) {
7768e116
RS
145 ERR_print_errors(bio_err);
146 return 1;
0f113f3e 147 }
856650de 148#else
7768e116
RS
149 BIO_printf(bio_err, "FIPS mode not supported.\n");
150 return 1;
856650de 151#endif
0f113f3e
MC
152 }
153
a0a82324
MC
154 if (!apps_startup())
155 goto end;
156
7e1b7485 157 prog = prog_init();
368058d0 158 pname = opt_progname(argv[0]);
0f113f3e 159
0f113f3e 160 /* first check the program name */
0f113f3e
MC
161 f.name = pname;
162 fp = lh_FUNCTION_retrieve(prog, &f);
163 if (fp != NULL) {
368058d0
RL
164 argv[0] = pname;
165 ret = fp->func(argc, argv);
0f113f3e
MC
166 goto end;
167 }
168
7e1b7485
RS
169 /* If there is stuff on the command line, run with that. */
170 if (argc != 1) {
171 argc--;
368058d0
RL
172 argv++;
173 ret = do_cmd(prog, argc, argv);
0f113f3e
MC
174 if (ret < 0)
175 ret = 0;
176 goto end;
177 }
178
7e1b7485 179 /* ok, lets enter interactive mode */
0f113f3e
MC
180 for (;;) {
181 ret = 0;
57d5edad
RS
182 /* Read a line, continue reading if line ends with \ */
183 for (p = buf, n = sizeof buf, i = 0, first = 1; n > 0; first = 0) {
1c9c2435 184 prompt = first ? "OpenSSL> " : "> ";
0f113f3e 185 p[0] = '\0';
57d5edad 186#ifndef READLINE
0f113f3e
MC
187 fputs(prompt, stdout);
188 fflush(stdout);
189 if (!fgets(p, n, stdin))
190 goto end;
191 if (p[0] == '\0')
192 goto end;
193 i = strlen(p);
194 if (i <= 1)
195 break;
196 if (p[i - 2] != '\\')
197 break;
198 i -= 2;
199 p += i;
200 n -= i;
57d5edad
RS
201#else
202 {
203 extern char *readline(const char *);
204 extern void add_history(const char *cp);
205 char *text;
206
72106aaa 207 text = readline(prompt);
57d5edad
RS
208 if (text == NULL)
209 goto end;
210 i = strlen(text);
211 if (i == 0 || i > n)
212 break;
213 if (text[i - 1] != '\\') {
214 p += strlen(strcpy(p, text));
215 free(text);
216 add_history(buf);
217 break;
218 }
219
220 text[i - 1] = '\0';
221 p += strlen(strcpy(p, text));
222 free(text);
223 n -= i;
224 }
225#endif
0f113f3e 226 }
57d5edad 227
7e1b7485
RS
228 if (!chopup_args(&arg, buf)) {
229 BIO_printf(bio_err, "Can't parse (no memory?)\n");
0f113f3e 230 break;
7e1b7485 231 }
0f113f3e 232
7e1b7485
RS
233 ret = do_cmd(prog, arg.argc, arg.argv);
234 if (ret == EXIT_THE_PROGRAM) {
0f113f3e
MC
235 ret = 0;
236 goto end;
237 }
238 if (ret != 0)
7e1b7485
RS
239 BIO_printf(bio_err, "error in %s\n", arg.argv[0]);
240 (void)BIO_flush(bio_out);
0f113f3e
MC
241 (void)BIO_flush(bio_err);
242 }
0f113f3e
MC
243 ret = 1;
244 end:
b548a1f1 245 OPENSSL_free(copied_argv);
cc01d217 246 OPENSSL_free(default_config_file);
25aaa98a
RS
247 NCONF_free(config);
248 config = NULL;
249 lh_FUNCTION_free(prog);
b548a1f1 250 OPENSSL_free(arg.argv);
0f113f3e 251
7e1b7485
RS
252 BIO_free(bio_in);
253 BIO_free_all(bio_out);
0f113f3e 254 apps_shutdown();
c2e27310 255#ifndef OPENSSL_NO_CRYPTO_MDEBUG
541e9565
DSH
256 if (CRYPTO_mem_leaks(bio_err) <= 0)
257 ret = 1;
bbd86bf5 258#endif
ca3a82c3 259 BIO_free(bio_err);
aa147792 260 EXIT(ret);
7e1b7485
RS
261}
262
263OPTIONS exit_options[] = {
264 {NULL}
265};
266
2f58faad
RS
267static void list_cipher_fn(const EVP_CIPHER *c,
268 const char *from, const char *to, void *arg)
269{
270 if (c)
271 BIO_printf(arg, "%s\n", EVP_CIPHER_name(c));
272 else {
273 if (!from)
274 from = "<undefined>";
275 if (!to)
276 to = "<undefined>";
277 BIO_printf(arg, "%s => %s\n", from, to);
278 }
279}
280
281static void list_md_fn(const EVP_MD *m,
282 const char *from, const char *to, void *arg)
283{
284 if (m)
285 BIO_printf(arg, "%s\n", EVP_MD_name(m));
286 else {
287 if (!from)
288 from = "<undefined>";
289 if (!to)
290 to = "<undefined>";
291 BIO_printf((BIO *)arg, "%s => %s\n", from, to);
292 }
293}
294
7e1b7485
RS
295/* Unified enum for help and list commands. */
296typedef enum HELPLIST_CHOICE {
297 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP,
298 OPT_COMMANDS, OPT_DIGEST_COMMANDS,
299 OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
a760a380 300 OPT_PK_ALGORITHMS, OPT_DISABLED
7e1b7485
RS
301} HELPLIST_CHOICE;
302
303OPTIONS list_options[] = {
304 {"help", OPT_HELP, '-', "Display this summary"},
305 {"commands", OPT_COMMANDS, '-', "List of standard commands"},
306 {"digest-commands", OPT_DIGEST_COMMANDS, '-',
307 "List of message digest commands"},
308 {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
309 "List of message digest algorithms"},
310 {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
311 {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
312 "List of cipher algorithms"},
313 {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
314 "List of public key algorithms"},
a760a380
DSH
315 {"disabled", OPT_DISABLED, '-',
316 "List of disabled features"},
7e1b7485
RS
317 {NULL}
318};
319
320int list_main(int argc, char **argv)
321{
322 char *prog;
323 HELPLIST_CHOICE o;
19948cea 324 int done = 0;
7e1b7485
RS
325
326 prog = opt_init(argc, argv, list_options);
327 while ((o = opt_next()) != OPT_EOF) {
328 switch (o) {
19948cea 329 case OPT_EOF: /* Never hit, but suppresses warning */
7e1b7485
RS
330 case OPT_ERR:
331 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
332 return 1;
333 case OPT_HELP:
334 opt_help(list_options);
335 break;
336 case OPT_COMMANDS:
2f58faad
RS
337 list_type(FT_general);
338 break;
7e1b7485 339 case OPT_DIGEST_COMMANDS:
2f58faad
RS
340 list_type(FT_md);
341 break;
7e1b7485 342 case OPT_DIGEST_ALGORITHMS:
2f58faad
RS
343 EVP_MD_do_all_sorted(list_md_fn, bio_out);
344 break;
7e1b7485 345 case OPT_CIPHER_COMMANDS:
2f58faad
RS
346 list_type(FT_cipher);
347 break;
7e1b7485 348 case OPT_CIPHER_ALGORITHMS:
2f58faad
RS
349 EVP_CIPHER_do_all_sorted(list_cipher_fn, bio_out);
350 break;
7e1b7485 351 case OPT_PK_ALGORITHMS:
2f58faad
RS
352 list_pkey();
353 break;
a760a380
DSH
354 case OPT_DISABLED:
355 list_disabled();
356 break;
7e1b7485 357 }
19948cea
BL
358 done = 1;
359 }
360
361 if (!done) {
362 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
363 return 1;
7e1b7485
RS
364 }
365
366 return 0;
367}
368
369OPTIONS help_options[] = {
370 {"help", OPT_HELP, '-', "Display this summary"},
371 {NULL}
372};
373
374int help_main(int argc, char **argv)
375{
376 FUNCTION *fp;
377 int i, nl;
378 FUNC_TYPE tp;
379 char *prog;
380 HELPLIST_CHOICE o;
381
382 prog = opt_init(argc, argv, help_options);
383 while ((o = opt_next()) != OPT_EOF) {
384 switch (o) {
385 default:
386 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
387 return 1;
388 case OPT_HELP:
389 opt_help(help_options);
390 return 0;
391 }
392 }
7e1b7485 393
5d94e5b6 394 if (opt_num_rest() != 0) {
7e1b7485
RS
395 BIO_printf(bio_err, "Usage: %s\n", prog);
396 return 1;
397 }
398
399 BIO_printf(bio_err, "\nStandard commands");
400 i = 0;
401 tp = FT_none;
402 for (fp = functions; fp->name != NULL; fp++) {
403 nl = 0;
404 if (((i++) % COLUMNS) == 0) {
405 BIO_printf(bio_err, "\n");
406 nl = 1;
407 }
408 if (fp->type != tp) {
409 tp = fp->type;
410 if (!nl)
411 BIO_printf(bio_err, "\n");
412 if (tp == FT_md) {
413 i = 1;
414 BIO_printf(bio_err,
415 "\nMessage Digest commands (see the `dgst' command for more details)\n");
416 } else if (tp == FT_cipher) {
417 i = 1;
418 BIO_printf(bio_err,
419 "\nCipher commands (see the `enc' command for more details)\n");
420 }
421 }
422 BIO_printf(bio_err, FORMAT, fp->name);
423 }
424 BIO_printf(bio_err, "\n\n");
425 return 0;
426}
8c00f4cf 427
7e1b7485
RS
428int exit_main(int argc, char **argv)
429{
430 return EXIT_THE_PROGRAM;
0f113f3e 431}
d02b48c6 432
2f58faad 433static void list_type(FUNC_TYPE ft)
7e1b7485
RS
434{
435 FUNCTION *fp;
436 int i = 0;
437
438 for (fp = functions; fp->name != NULL; fp++)
2f58faad 439 if (fp->type == ft) {
7e1b7485
RS
440 if ((i++ % COLUMNS) == 0)
441 BIO_printf(bio_out, "\n");
442 BIO_printf(bio_out, FORMAT, fp->name);
443 }
444 BIO_printf(bio_out, "\n");
7e1b7485 445}
fc8ee06b 446
3c1d6bbc 447static int do_cmd(LHASH_OF(FUNCTION) *prog, int argc, char *argv[])
0f113f3e
MC
448{
449 FUNCTION f, *fp;
0f113f3e 450
7e1b7485
RS
451 if (argc <= 0 || argv[0] == NULL)
452 return (0);
0f113f3e
MC
453 f.name = argv[0];
454 fp = lh_FUNCTION_retrieve(prog, &f);
455 if (fp == NULL) {
456 if (EVP_get_digestbyname(argv[0])) {
7e1b7485 457 f.type = FT_md;
0f113f3e
MC
458 f.func = dgst_main;
459 fp = &f;
460 } else if (EVP_get_cipherbyname(argv[0])) {
7e1b7485 461 f.type = FT_cipher;
0f113f3e
MC
462 f.func = enc_main;
463 fp = &f;
464 }
465 }
466 if (fp != NULL) {
7e1b7485
RS
467 return (fp->func(argc, argv));
468 }
469 if ((strncmp(argv[0], "no-", 3)) == 0) {
470 /*
471 * User is asking if foo is unsupported, by trying to "run" the
472 * no-foo command. Strange.
473 */
0f113f3e 474 f.name = argv[0] + 3;
7e1b7485
RS
475 if (lh_FUNCTION_retrieve(prog, &f) == NULL) {
476 BIO_printf(bio_out, "%s\n", argv[0]);
477 return (0);
0f113f3e 478 }
7e1b7485
RS
479 BIO_printf(bio_out, "%s\n", argv[0] + 3);
480 return 1;
50acf46b 481 }
7e1b7485
RS
482 if (strcmp(argv[0], "quit") == 0 || strcmp(argv[0], "q") == 0 ||
483 strcmp(argv[0], "exit") == 0 || strcmp(argv[0], "bye") == 0)
484 /* Special value to mean "exit the program. */
485 return EXIT_THE_PROGRAM;
0f113f3e 486
7e1b7485
RS
487 BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
488 argv[0]);
489 return (1);
0f113f3e 490}
50acf46b 491
2f58faad 492static void list_pkey(void)
0f113f3e
MC
493{
494 int i;
7e1b7485 495
0f113f3e
MC
496 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
497 const EVP_PKEY_ASN1_METHOD *ameth;
498 int pkey_id, pkey_base_id, pkey_flags;
499 const char *pinfo, *pem_str;
500 ameth = EVP_PKEY_asn1_get0(i);
501 EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
502 &pinfo, &pem_str, ameth);
503 if (pkey_flags & ASN1_PKEY_ALIAS) {
7e1b7485
RS
504 BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
505 BIO_printf(bio_out, "\tAlias for: %s\n",
0f113f3e
MC
506 OBJ_nid2ln(pkey_base_id));
507 } else {
7e1b7485
RS
508 BIO_printf(bio_out, "Name: %s\n", pinfo);
509 BIO_printf(bio_out, "\tType: %s Algorithm\n",
0f113f3e
MC
510 pkey_flags & ASN1_PKEY_DYNAMIC ?
511 "External" : "Builtin");
7e1b7485 512 BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
0f113f3e
MC
513 if (pem_str == NULL)
514 pem_str = "(none)";
7e1b7485 515 BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
0f113f3e
MC
516 }
517
518 }
0f113f3e 519}
3c1d6bbc 520
0f113f3e
MC
521static int function_cmp(const FUNCTION * a, const FUNCTION * b)
522{
523 return strncmp(a->name, b->name, 8);
524}
50acf46b 525
0f113f3e
MC
526static unsigned long function_hash(const FUNCTION * a)
527{
528 return lh_strhash(a->name);
529}
d02b48c6 530
7e1b7485
RS
531static int SortFnByName(const void *_f1, const void *_f2)
532{
533 const FUNCTION *f1 = _f1;
534 const FUNCTION *f2 = _f2;
535
536 if (f1->type != f2->type)
537 return f1->type - f2->type;
538 return strcmp(f1->name, f2->name);
539}
540
a760a380
DSH
541static void list_disabled(void)
542{
d230bd1d 543 BIO_puts(bio_out, "Disabled algorithms:\n");
27dae1b0
RL
544#ifdef OPENSSL_NO_BF
545 BIO_puts(bio_out, "BF\n");
546#endif
2d0b4412
BC
547#ifndef OPENSSL_NO_BLAKE2
548 BIO_puts(bio_out, "BLAKE2\n");
549#endif
27dae1b0
RL
550#ifdef OPENSSL_NO_CAMELLIA
551 BIO_puts(bio_out, "CAMELLIA\n");
552#endif
553#ifdef OPENSSL_NO_CAST
554 BIO_puts(bio_out, "CAST\n");
555#endif
56c1ef05
RL
556#ifdef OPENSSL_NO_CMAC
557 BIO_puts(bio_out, "CMAC\n");
558#endif
27dae1b0
RL
559#ifdef OPENSSL_NO_CMS
560 BIO_puts(bio_out, "CMS\n");
561#endif
66b14bab
RL
562#ifdef OPENSSL_NO_COMP
563 BIO_puts(bio_out, "COMP\n");
564#endif
27dae1b0
RL
565#ifdef OPENSSL_NO_DES
566 BIO_puts(bio_out, "DES\n");
567#endif
2df84dd3
RL
568#ifdef OPENSSL_NO_DGRAM
569 BIO_puts(bio_out, "DGRAM\n");
570#endif
a760a380
DSH
571#ifdef OPENSSL_NO_DH
572 BIO_puts(bio_out, "DH\n");
573#endif
574#ifdef OPENSSL_NO_DSA
575 BIO_puts(bio_out, "DSA\n");
576#endif
a5ecdc6a
KR
577#if defined(OPENSSL_NO_DTLS)
578 BIO_puts(bio_out, "DTLS\n");
66b14bab 579#endif
6b01bed2
VD
580#if defined(OPENSSL_NO_DTLS1)
581 BIO_puts(bio_out, "DTLS1\n");
582#endif
583#if defined(OPENSSL_NO_DTLS1_2)
584 BIO_puts(bio_out, "DTLS1_2\n");
585#endif
a760a380
DSH
586#ifdef OPENSSL_NO_EC
587 BIO_puts(bio_out, "EC\n");
588#endif
589#ifdef OPENSSL_NO_EC2M
590 BIO_puts(bio_out, "EC2M\n");
591#endif
27dae1b0
RL
592#ifdef OPENSSL_NO_ENGINE
593 BIO_puts(bio_out, "ENGINE\n");
594#endif
2df84dd3
RL
595#ifdef OPENSSL_NO_GOST
596 BIO_puts(bio_out, "GOST\n");
597#endif
22e3dcb7
RS
598#ifdef OPENSSL_NO_HEARTBEATS
599 BIO_puts(bio_out, "HEARTBEATS\n");
600#endif
27dae1b0
RL
601#ifdef OPENSSL_NO_IDEA
602 BIO_puts(bio_out, "IDEA\n");
603#endif
604#ifdef OPENSSL_NO_MD2
605 BIO_puts(bio_out, "MD2\n");
606#endif
607#ifdef OPENSSL_NO_MD4
608 BIO_puts(bio_out, "MD4\n");
609#endif
610#ifdef OPENSSL_NO_MD5
611 BIO_puts(bio_out, "MD5\n");
612#endif
613#ifdef OPENSSL_NO_MDC2
614 BIO_puts(bio_out, "MDC2\n");
615#endif
2df84dd3
RL
616#ifdef OPENSSL_NO_OCB
617 BIO_puts(bio_out, "OCB\n");
618#endif
27dae1b0
RL
619#ifdef OPENSSL_NO_OCSP
620 BIO_puts(bio_out, "OCSP\n");
621#endif
a760a380
DSH
622#ifdef OPENSSL_NO_PSK
623 BIO_puts(bio_out, "PSK\n");
624#endif
27dae1b0
RL
625#ifdef OPENSSL_NO_RC2
626 BIO_puts(bio_out, "RC2\n");
627#endif
628#ifdef OPENSSL_NO_RC4
629 BIO_puts(bio_out, "RC4\n");
630#endif
631#ifdef OPENSSL_NO_RC5
632 BIO_puts(bio_out, "RC5\n");
633#endif
634#ifdef OPENSSL_NO_RMD160
635 BIO_puts(bio_out, "RMD160\n");
636#endif
d230bd1d
RL
637#ifdef OPENSSL_NO_RSA
638 BIO_puts(bio_out, "RSA\n");
639#endif
66b14bab
RL
640#ifdef OPENSSL_NO_SCRYPT
641 BIO_puts(bio_out, "SCRYPT\n");
642#endif
2df84dd3
RL
643#ifdef OPENSSL_NO_SCTP
644 BIO_puts(bio_out, "SCTP\n");
645#endif
27dae1b0
RL
646#ifdef OPENSSL_NO_SEED
647 BIO_puts(bio_out, "SEED\n");
648#endif
649#ifdef OPENSSL_NO_SOCK
650 BIO_puts(bio_out, "SOCK\n");
651#endif
a760a380
DSH
652#ifdef OPENSSL_NO_SRP
653 BIO_puts(bio_out, "SRP\n");
654#endif
66b14bab
RL
655#ifdef OPENSSL_NO_SRTP
656 BIO_puts(bio_out, "SRTP\n");
657#endif
658#ifdef OPENSSL_NO_SSL3
659 BIO_puts(bio_out, "SSL3\n");
660#endif
6b01bed2
VD
661#ifdef OPENSSL_NO_TLS1
662 BIO_puts(bio_out, "TLS1\n");
663#endif
664#ifdef OPENSSL_NO_TLS1_1
665 BIO_puts(bio_out, "TLS1_1\n");
666#endif
667#ifdef OPENSSL_NO_TLS1_2
668 BIO_puts(bio_out, "TLS1_2\n");
669#endif
27dae1b0
RL
670#ifdef OPENSSL_NO_WHIRLPOOL
671 BIO_puts(bio_out, "WHIRLPOOL\n");
672#endif
d230bd1d
RL
673#ifndef ZLIB
674 BIO_puts(bio_out, "ZLIB\n");
675#endif
a760a380
DSH
676}
677
0f113f3e
MC
678static LHASH_OF(FUNCTION) *prog_init(void)
679{
680 LHASH_OF(FUNCTION) *ret;
681 FUNCTION *f;
682 size_t i;
683
7e1b7485 684 /* Sort alphabetically within category. For nicer help displays. */
0f113f3e 685 for (i = 0, f = functions; f->name != NULL; ++f, ++i) ;
b4faea50 686 qsort(functions, i, sizeof(*functions), SortFnByName);
0f113f3e 687
62d0577e 688 if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)
0f113f3e
MC
689 return (NULL);
690
691 for (f = functions; f->name != NULL; f++)
692 (void)lh_FUNCTION_insert(ret, f);
693 return (ret);
694}