include source root directory via -I for libnonfips.a
[oweals/openssl.git] / apps / list.c
1 /*
2  * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (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 <string.h>
11 #include <openssl/evp.h>
12 #include <openssl/err.h>
13 #include <openssl/provider.h>
14 #include <openssl/safestack.h>
15 #include <openssl/kdf.h>
16 #include "apps.h"
17 #include "app_params.h"
18 #include "progs.h"
19 #include "opt.h"
20 #include "names.h"
21
22 DEFINE_STACK_OF_CSTRING()
23
24 static int verbose = 0;
25
26 static void legacy_cipher_fn(const EVP_CIPHER *c,
27                              const char *from, const char *to, void *arg)
28 {
29     if (c != NULL) {
30         BIO_printf(arg, "  %s\n", EVP_CIPHER_name(c));
31     } else {
32         if (from == NULL)
33             from = "<undefined>";
34         if (to == NULL)
35             to = "<undefined>";
36         BIO_printf(arg, "  %s => %s\n", from, to);
37     }
38 }
39
40 DEFINE_STACK_OF(EVP_CIPHER)
41 static int cipher_cmp(const EVP_CIPHER * const *a,
42                       const EVP_CIPHER * const *b)
43 {
44     int ret = EVP_CIPHER_number(*a) - EVP_CIPHER_number(*b);
45
46     if (ret == 0)
47         ret = strcmp(OSSL_PROVIDER_name(EVP_CIPHER_provider(*a)),
48                      OSSL_PROVIDER_name(EVP_CIPHER_provider(*b)));
49
50     return ret;
51 }
52
53 static void collect_ciphers(EVP_CIPHER *cipher, void *stack)
54 {
55     STACK_OF(EVP_CIPHER) *cipher_stack = stack;
56
57     if (sk_EVP_CIPHER_push(cipher_stack, cipher) > 0)
58         EVP_CIPHER_up_ref(cipher);
59 }
60
61 static void list_ciphers(void)
62 {
63     STACK_OF(EVP_CIPHER) *ciphers = sk_EVP_CIPHER_new(cipher_cmp);
64     int i;
65
66     if (ciphers == NULL) {
67         BIO_printf(bio_err, "ERROR: Memory allocation\n");
68         return;
69     }
70     BIO_printf(bio_out, "Legacy:\n");
71     EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
72
73     BIO_printf(bio_out, "Provided:\n");
74     EVP_CIPHER_do_all_provided(NULL, collect_ciphers, ciphers);
75     sk_EVP_CIPHER_sort(ciphers);
76     for (i = 0; i < sk_EVP_CIPHER_num(ciphers); i++) {
77         const EVP_CIPHER *c = sk_EVP_CIPHER_value(ciphers, i);
78         STACK_OF(OPENSSL_CSTRING) *names =
79             sk_OPENSSL_CSTRING_new(name_cmp);
80
81         EVP_CIPHER_names_do_all(c, collect_names, names);
82
83         BIO_printf(bio_out, "  ");
84         print_names(bio_out, names);
85         BIO_printf(bio_out, " @ %s\n",
86                    OSSL_PROVIDER_name(EVP_CIPHER_provider(c)));
87
88         sk_OPENSSL_CSTRING_free(names);
89
90         if (verbose) {
91             print_param_types("retrievable algorithm parameters",
92                               EVP_CIPHER_gettable_params(c), 4);
93             print_param_types("retrievable operation parameters",
94                               EVP_CIPHER_gettable_ctx_params(c), 4);
95             print_param_types("settable operation parameters",
96                               EVP_CIPHER_settable_ctx_params(c), 4);
97         }
98     }
99     sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free);
100 }
101
102 static void list_md_fn(const EVP_MD *m,
103                        const char *from, const char *to, void *arg)
104 {
105     if (m != NULL) {
106         BIO_printf(arg, "  %s\n", EVP_MD_name(m));
107     } else {
108         if (from == NULL)
109             from = "<undefined>";
110         if (to == NULL)
111             to = "<undefined>";
112         BIO_printf((BIO *)arg, "  %s => %s\n", from, to);
113     }
114 }
115
116 DEFINE_STACK_OF(EVP_MD)
117 static int md_cmp(const EVP_MD * const *a, const EVP_MD * const *b)
118 {
119     int ret = EVP_MD_number(*a) - EVP_MD_number(*b);
120
121     if (ret == 0)
122         ret = strcmp(OSSL_PROVIDER_name(EVP_MD_provider(*a)),
123                      OSSL_PROVIDER_name(EVP_MD_provider(*b)));
124
125     return ret;
126 }
127
128 static void collect_digests(EVP_MD *md, void *stack)
129 {
130     STACK_OF(EVP_MD) *digest_stack = stack;
131
132     if (sk_EVP_MD_push(digest_stack, md) > 0)
133         EVP_MD_up_ref(md);
134 }
135
136 static void list_digests(void)
137 {
138     STACK_OF(EVP_MD) *digests = sk_EVP_MD_new(md_cmp);
139     int i;
140
141     if (digests == NULL) {
142         BIO_printf(bio_err, "ERROR: Memory allocation\n");
143         return;
144     }
145     BIO_printf(bio_out, "Legacy:\n");
146     EVP_MD_do_all_sorted(list_md_fn, bio_out);
147
148     BIO_printf(bio_out, "Provided:\n");
149     EVP_MD_do_all_provided(NULL, collect_digests, digests);
150     sk_EVP_MD_sort(digests);
151     for (i = 0; i < sk_EVP_MD_num(digests); i++) {
152         const EVP_MD *m = sk_EVP_MD_value(digests, i);
153         STACK_OF(OPENSSL_CSTRING) *names =
154             sk_OPENSSL_CSTRING_new(name_cmp);
155
156         EVP_MD_names_do_all(m, collect_names, names);
157
158         BIO_printf(bio_out, "  ");
159         print_names(bio_out, names);
160         BIO_printf(bio_out, " @ %s\n",
161                    OSSL_PROVIDER_name(EVP_MD_provider(m)));
162
163         sk_OPENSSL_CSTRING_free(names);
164
165         if (verbose) {
166             print_param_types("retrievable algorithm parameters",
167                               EVP_MD_gettable_params(m), 4);
168             print_param_types("retrievable operation parameters",
169                               EVP_MD_gettable_ctx_params(m), 4);
170             print_param_types("settable operation parameters",
171                               EVP_MD_settable_ctx_params(m), 4);
172         }
173     }
174     sk_EVP_MD_pop_free(digests, EVP_MD_free);
175 }
176
177 DEFINE_STACK_OF(EVP_MAC)
178 static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b)
179 {
180     int ret = EVP_MAC_number(*a) - EVP_MAC_number(*b);
181
182     if (ret == 0)
183         ret = strcmp(OSSL_PROVIDER_name(EVP_MAC_provider(*a)),
184                      OSSL_PROVIDER_name(EVP_MAC_provider(*b)));
185
186     return ret;
187 }
188
189 static void collect_macs(EVP_MAC *mac, void *stack)
190 {
191     STACK_OF(EVP_MAC) *mac_stack = stack;
192
193     if (sk_EVP_MAC_push(mac_stack, mac) > 0)
194         EVP_MAC_up_ref(mac);
195 }
196
197 static void list_macs(void)
198 {
199     STACK_OF(EVP_MAC) *macs = sk_EVP_MAC_new(mac_cmp);
200     int i;
201
202     if (macs == NULL) {
203         BIO_printf(bio_err, "ERROR: Memory allocation\n");
204         return;
205     }
206     BIO_printf(bio_out, "Provided MACs:\n");
207     EVP_MAC_do_all_provided(NULL, collect_macs, macs);
208     sk_EVP_MAC_sort(macs);
209     for (i = 0; i < sk_EVP_MAC_num(macs); i++) {
210         const EVP_MAC *m = sk_EVP_MAC_value(macs, i);
211         STACK_OF(OPENSSL_CSTRING) *names =
212             sk_OPENSSL_CSTRING_new(name_cmp);
213
214         EVP_MAC_names_do_all(m, collect_names, names);
215
216         BIO_printf(bio_out, "  ");
217         print_names(bio_out, names);
218         BIO_printf(bio_out, " @ %s\n",
219                    OSSL_PROVIDER_name(EVP_MAC_provider(m)));
220
221         sk_OPENSSL_CSTRING_free(names);
222
223         if (verbose) {
224             print_param_types("retrievable algorithm parameters",
225                               EVP_MAC_gettable_params(m), 4);
226             print_param_types("retrievable operation parameters",
227                               EVP_MAC_gettable_ctx_params(m), 4);
228             print_param_types("settable operation parameters",
229                               EVP_MAC_settable_ctx_params(m), 4);
230         }
231     }
232     sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
233 }
234
235 /*
236  * KDFs and PRFs
237  */
238 DEFINE_STACK_OF(EVP_KDF)
239 static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b)
240 {
241     int ret = EVP_KDF_number(*a) - EVP_KDF_number(*b);
242
243     if (ret == 0)
244         ret = strcmp(OSSL_PROVIDER_name(EVP_KDF_provider(*a)),
245                      OSSL_PROVIDER_name(EVP_KDF_provider(*b)));
246
247     return ret;
248 }
249
250 static void collect_kdfs(EVP_KDF *kdf, void *stack)
251 {
252     STACK_OF(EVP_KDF) *kdf_stack = stack;
253
254     sk_EVP_KDF_push(kdf_stack, kdf);
255     EVP_KDF_up_ref(kdf);
256 }
257
258 static void list_kdfs(void)
259 {
260     STACK_OF(EVP_KDF) *kdfs = sk_EVP_KDF_new(kdf_cmp);
261     int i;
262
263     if (kdfs == NULL) {
264         BIO_printf(bio_err, "ERROR: Memory allocation\n");
265         return;
266     }
267     BIO_printf(bio_out, "Provided KDFs and PDFs:\n");
268     EVP_KDF_do_all_provided(NULL, collect_kdfs, kdfs);
269     sk_EVP_KDF_sort(kdfs);
270     for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) {
271         const EVP_KDF *k = sk_EVP_KDF_value(kdfs, i);
272         STACK_OF(OPENSSL_CSTRING) *names =
273             sk_OPENSSL_CSTRING_new(name_cmp);
274
275         EVP_KDF_names_do_all(k, collect_names, names);
276
277         BIO_printf(bio_out, "  ");
278         print_names(bio_out, names);
279         BIO_printf(bio_out, " @ %s\n",
280                    OSSL_PROVIDER_name(EVP_KDF_provider(k)));
281
282         sk_OPENSSL_CSTRING_free(names);
283
284         if (verbose) {
285             print_param_types("retrievable algorithm parameters",
286                               EVP_KDF_gettable_params(k), 4);
287             print_param_types("retrievable operation parameters",
288                               EVP_KDF_gettable_ctx_params(k), 4);
289             print_param_types("settable operation parameters",
290                               EVP_KDF_settable_ctx_params(k), 4);
291         }
292     }
293     sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free);
294 }
295
296 /*
297  * RANDs
298  */
299 DEFINE_STACK_OF(EVP_RAND)
300
301 static int rand_cmp(const EVP_RAND * const *a, const EVP_RAND * const *b)
302 {
303     int ret = strcasecmp(EVP_RAND_name(*a), EVP_RAND_name(*b));
304
305     if (ret == 0)
306         ret = strcmp(OSSL_PROVIDER_name(EVP_RAND_provider(*a)),
307                      OSSL_PROVIDER_name(EVP_RAND_provider(*b)));
308
309     return ret;
310 }
311
312 static void collect_rands(EVP_RAND *rand, void *stack)
313 {
314     STACK_OF(EVP_RAND) *rand_stack = stack;
315
316     sk_EVP_RAND_push(rand_stack, rand);
317     EVP_RAND_up_ref(rand);
318 }
319
320 static void list_random_generators(void)
321 {
322     STACK_OF(EVP_RAND) *rands = sk_EVP_RAND_new(rand_cmp);
323     int i;
324
325     if (rands == NULL) {
326         BIO_printf(bio_err, "ERROR: Memory allocation\n");
327         return;
328     }
329     BIO_printf(bio_out, "Provided RNGs and seed sources:\n");
330     EVP_RAND_do_all_provided(NULL, collect_rands, rands);
331     sk_EVP_RAND_sort(rands);
332     for (i = 0; i < sk_EVP_RAND_num(rands); i++) {
333         const EVP_RAND *m = sk_EVP_RAND_value(rands, i);
334
335         BIO_printf(bio_out, "  %s", EVP_RAND_name(m));
336         BIO_printf(bio_out, " @ %s\n",
337                    OSSL_PROVIDER_name(EVP_RAND_provider(m)));
338
339         if (verbose) {
340             print_param_types("retrievable algorithm parameters",
341                               EVP_RAND_gettable_params(m), 4);
342             print_param_types("retrievable operation parameters",
343                               EVP_RAND_gettable_ctx_params(m), 4);
344             print_param_types("settable operation parameters",
345                               EVP_RAND_settable_ctx_params(m), 4);
346         }
347     }
348     sk_EVP_RAND_pop_free(rands, EVP_RAND_free);
349 }
350
351 static void list_missing_help(void)
352 {
353     const FUNCTION *fp;
354     const OPTIONS *o;
355
356     for (fp = functions; fp->name != NULL; fp++) {
357         if ((o = fp->help) != NULL) {
358             /* If there is help, list what flags are not documented. */
359             for ( ; o->name != NULL; o++) {
360                 if (o->helpstr == NULL)
361                     BIO_printf(bio_out, "%s %s\n", fp->name, o->name);
362             }
363         } else if (fp->func != dgst_main) {
364             /* If not aliased to the dgst command, */
365             BIO_printf(bio_out, "%s *\n", fp->name);
366         }
367     }
368 }
369
370 static void list_objects(void)
371 {
372     int max_nid = OBJ_new_nid(0);
373     int i;
374     char *oid_buf = NULL;
375     int oid_size = 0;
376
377     /* Skip 0, since that's NID_undef */
378     for (i = 1; i < max_nid; i++) {
379         const ASN1_OBJECT *obj = OBJ_nid2obj(i);
380         const char *sn = OBJ_nid2sn(i);
381         const char *ln = OBJ_nid2ln(i);
382         int n = 0;
383
384         /*
385          * If one of the retrieved objects somehow generated an error,
386          * we ignore it.  The check for NID_undef below will detect the
387          * error and simply skip to the next NID.
388          */
389         ERR_clear_error();
390
391         if (OBJ_obj2nid(obj) == NID_undef)
392             continue;
393
394         if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) {
395             BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln);
396             continue;
397         }
398         if (n < 0)
399             break;               /* Error */
400
401         if (n > oid_size) {
402             oid_buf = OPENSSL_realloc(oid_buf, n + 1);
403             if (oid_buf == NULL) {
404                 BIO_printf(bio_err, "ERROR: Memory allocation\n");
405                 break;           /* Error */
406             }
407             oid_size = n + 1;
408         }
409         if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0)
410             break;               /* Error */
411         if (ln == NULL || strcmp(sn, ln) == 0)
412             BIO_printf(bio_out, "%s = %s\n", sn, oid_buf);
413         else
414             BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf);
415     }
416
417     OPENSSL_free(oid_buf);
418 }
419
420 static void list_options_for_command(const char *command)
421 {
422     const FUNCTION *fp;
423     const OPTIONS *o;
424
425     for (fp = functions; fp->name != NULL; fp++)
426         if (strcmp(fp->name, command) == 0)
427             break;
428     if (fp->name == NULL) {
429         BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
430                 command);
431         return;
432     }
433
434     if ((o = fp->help) == NULL)
435         return;
436
437     for ( ; o->name != NULL; o++) {
438         char c = o->valtype;
439
440         if (o->name == OPT_PARAM_STR)
441             break;
442
443         if (o->name == OPT_HELP_STR
444                 || o->name == OPT_MORE_STR
445                 || o->name == OPT_SECTION_STR
446                 || o->name[0] == '\0')
447             continue;
448         BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c);
449     }
450     /* Always output the -- marker since it is sometimes documented. */
451     BIO_printf(bio_out, "- -\n");
452 }
453
454 static void list_type(FUNC_TYPE ft, int one)
455 {
456     FUNCTION *fp;
457     int i = 0;
458     DISPLAY_COLUMNS dc;
459
460     memset(&dc, 0, sizeof(dc));
461     if (!one)
462         calculate_columns(functions, &dc);
463
464     for (fp = functions; fp->name != NULL; fp++) {
465         if (fp->type != ft)
466             continue;
467         if (one) {
468             BIO_printf(bio_out, "%s\n", fp->name);
469         } else {
470             if (i % dc.columns == 0 && i > 0)
471                 BIO_printf(bio_out, "\n");
472             BIO_printf(bio_out, "%-*s", dc.width, fp->name);
473             i++;
474         }
475     }
476     if (!one)
477         BIO_printf(bio_out, "\n\n");
478 }
479
480 static void list_pkey(void)
481 {
482     int i;
483
484     for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
485         const EVP_PKEY_ASN1_METHOD *ameth;
486         int pkey_id, pkey_base_id, pkey_flags;
487         const char *pinfo, *pem_str;
488         ameth = EVP_PKEY_asn1_get0(i);
489         EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
490                                 &pinfo, &pem_str, ameth);
491         if (pkey_flags & ASN1_PKEY_ALIAS) {
492             BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
493             BIO_printf(bio_out, "\tAlias for: %s\n",
494                        OBJ_nid2ln(pkey_base_id));
495         } else {
496             BIO_printf(bio_out, "Name: %s\n", pinfo);
497             BIO_printf(bio_out, "\tType: %s Algorithm\n",
498                        pkey_flags & ASN1_PKEY_DYNAMIC ?
499                        "External" : "Builtin");
500             BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
501             if (pem_str == NULL)
502                 pem_str = "(none)";
503             BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
504         }
505
506     }
507 }
508
509 static void list_pkey_meth(void)
510 {
511     size_t i;
512     size_t meth_count = EVP_PKEY_meth_get_count();
513
514     for (i = 0; i < meth_count; i++) {
515         const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
516         int pkey_id, pkey_flags;
517
518         EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
519         BIO_printf(bio_out, "%s\n", OBJ_nid2ln(pkey_id));
520         BIO_printf(bio_out, "\tType: %s Algorithm\n",
521                    pkey_flags & ASN1_PKEY_DYNAMIC ?  "External" : "Builtin");
522     }
523 }
524
525 static void list_engines(void)
526 {
527 #ifndef OPENSSL_NO_ENGINE
528     ENGINE *e;
529
530     BIO_puts(bio_out, "Engines:\n");
531     e = ENGINE_get_first();
532     while (e) {
533         BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
534         e = ENGINE_get_next(e);
535     }
536 #else
537     BIO_puts(bio_out, "Engine support is disabled.\n");
538 #endif
539 }
540
541 static void list_disabled(void)
542 {
543     BIO_puts(bio_out, "Disabled algorithms:\n");
544 #ifdef OPENSSL_NO_ARIA
545     BIO_puts(bio_out, "ARIA\n");
546 #endif
547 #ifdef OPENSSL_NO_BF
548     BIO_puts(bio_out, "BF\n");
549 #endif
550 #ifdef OPENSSL_NO_BLAKE2
551     BIO_puts(bio_out, "BLAKE2\n");
552 #endif
553 #ifdef OPENSSL_NO_CAMELLIA
554     BIO_puts(bio_out, "CAMELLIA\n");
555 #endif
556 #ifdef OPENSSL_NO_CAST
557     BIO_puts(bio_out, "CAST\n");
558 #endif
559 #ifdef OPENSSL_NO_CMAC
560     BIO_puts(bio_out, "CMAC\n");
561 #endif
562 #ifdef OPENSSL_NO_CMS
563     BIO_puts(bio_out, "CMS\n");
564 #endif
565 #ifdef OPENSSL_NO_COMP
566     BIO_puts(bio_out, "COMP\n");
567 #endif
568 #ifdef OPENSSL_NO_DES
569     BIO_puts(bio_out, "DES\n");
570 #endif
571 #ifdef OPENSSL_NO_DGRAM
572     BIO_puts(bio_out, "DGRAM\n");
573 #endif
574 #ifdef OPENSSL_NO_DH
575     BIO_puts(bio_out, "DH\n");
576 #endif
577 #ifdef OPENSSL_NO_DSA
578     BIO_puts(bio_out, "DSA\n");
579 #endif
580 #if defined(OPENSSL_NO_DTLS)
581     BIO_puts(bio_out, "DTLS\n");
582 #endif
583 #if defined(OPENSSL_NO_DTLS1)
584     BIO_puts(bio_out, "DTLS1\n");
585 #endif
586 #if defined(OPENSSL_NO_DTLS1_2)
587     BIO_puts(bio_out, "DTLS1_2\n");
588 #endif
589 #ifdef OPENSSL_NO_EC
590     BIO_puts(bio_out, "EC\n");
591 #endif
592 #ifdef OPENSSL_NO_EC2M
593     BIO_puts(bio_out, "EC2M\n");
594 #endif
595 #ifdef OPENSSL_NO_ENGINE
596     BIO_puts(bio_out, "ENGINE\n");
597 #endif
598 #ifdef OPENSSL_NO_GOST
599     BIO_puts(bio_out, "GOST\n");
600 #endif
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
616 #ifdef OPENSSL_NO_OCB
617     BIO_puts(bio_out, "OCB\n");
618 #endif
619 #ifdef OPENSSL_NO_OCSP
620     BIO_puts(bio_out, "OCSP\n");
621 #endif
622 #ifdef OPENSSL_NO_PSK
623     BIO_puts(bio_out, "PSK\n");
624 #endif
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
637 #ifdef OPENSSL_NO_RSA
638     BIO_puts(bio_out, "RSA\n");
639 #endif
640 #ifdef OPENSSL_NO_SCRYPT
641     BIO_puts(bio_out, "SCRYPT\n");
642 #endif
643 #ifdef OPENSSL_NO_SCTP
644     BIO_puts(bio_out, "SCTP\n");
645 #endif
646 #ifdef OPENSSL_NO_SEED
647     BIO_puts(bio_out, "SEED\n");
648 #endif
649 #ifdef OPENSSL_NO_SM2
650     BIO_puts(bio_out, "SM2\n");
651 #endif
652 #ifdef OPENSSL_NO_SM3
653     BIO_puts(bio_out, "SM3\n");
654 #endif
655 #ifdef OPENSSL_NO_SM4
656     BIO_puts(bio_out, "SM4\n");
657 #endif
658 #ifdef OPENSSL_NO_SOCK
659     BIO_puts(bio_out, "SOCK\n");
660 #endif
661 #ifdef OPENSSL_NO_SRP
662     BIO_puts(bio_out, "SRP\n");
663 #endif
664 #ifdef OPENSSL_NO_SRTP
665     BIO_puts(bio_out, "SRTP\n");
666 #endif
667 #ifdef OPENSSL_NO_SSL3
668     BIO_puts(bio_out, "SSL3\n");
669 #endif
670 #ifdef OPENSSL_NO_TLS1
671     BIO_puts(bio_out, "TLS1\n");
672 #endif
673 #ifdef OPENSSL_NO_TLS1_1
674     BIO_puts(bio_out, "TLS1_1\n");
675 #endif
676 #ifdef OPENSSL_NO_TLS1_2
677     BIO_puts(bio_out, "TLS1_2\n");
678 #endif
679 #ifdef OPENSSL_NO_WHIRLPOOL
680     BIO_puts(bio_out, "WHIRLPOOL\n");
681 #endif
682 #ifndef ZLIB
683     BIO_puts(bio_out, "ZLIB\n");
684 #endif
685 }
686
687 /* Unified enum for help and list commands. */
688 typedef enum HELPLIST_CHOICE {
689     OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE, OPT_VERBOSE,
690     OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
691     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
692     OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_ENGINES, OPT_DISABLED,
693     OPT_KDF_ALGORITHMS, OPT_RANDOM_GENERATORS, OPT_MISSING_HELP, OPT_OBJECTS,
694     OPT_PROV_ENUM
695 } HELPLIST_CHOICE;
696
697 const OPTIONS list_options[] = {
698
699     OPT_SECTION("General"),
700     {"help", OPT_HELP, '-', "Display this summary"},
701
702     OPT_SECTION("Output"),
703     {"1", OPT_ONE, '-', "List in one column"},
704     {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
705     {"commands", OPT_COMMANDS, '-', "List of standard commands"},
706     {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
707     {"digest-commands", OPT_DIGEST_COMMANDS, '-',
708      "List of message digest commands"},
709     {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
710      "List of message digest algorithms"},
711     {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
712      "List of key derivation and pseudo random function algorithms"},
713     {"random-generators", OPT_RANDOM_GENERATORS, '-',
714       "List of random number generators"},
715     {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
716      "List of message authentication code algorithms"},
717     {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
718     {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
719      "List of cipher algorithms"},
720     {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
721      "List of public key algorithms"},
722     {"public-key-methods", OPT_PK_METHOD, '-',
723      "List of public key methods"},
724     {"engines", OPT_ENGINES, '-',
725      "List of loaded engines"},
726     {"disabled", OPT_DISABLED, '-',
727      "List of disabled features"},
728     {"missing-help", OPT_MISSING_HELP, '-',
729      "List missing detailed help strings"},
730     {"options", OPT_OPTIONS, 's',
731      "List options for specified command"},
732     {"objects", OPT_OBJECTS, '-',
733      "List built in objects (OID<->name mappings)"},
734
735     OPT_PROV_OPTIONS,
736     {NULL}
737 };
738
739 int list_main(int argc, char **argv)
740 {
741     char *prog;
742     HELPLIST_CHOICE o;
743     int one = 0, done = 0;
744     struct {
745         unsigned int commands:1;
746         unsigned int random_generators:1;
747         unsigned int digest_commands:1;
748         unsigned int digest_algorithms:1;
749         unsigned int kdf_algorithms:1;
750         unsigned int mac_algorithms:1;
751         unsigned int cipher_commands:1;
752         unsigned int cipher_algorithms:1;
753         unsigned int pk_algorithms:1;
754         unsigned int pk_method:1;
755         unsigned int engines:1;
756         unsigned int disabled:1;
757         unsigned int missing_help:1;
758         unsigned int objects:1;
759         unsigned int options:1;
760     } todo = { 0, };
761
762     verbose = 0;                 /* Clear a possible previous call */
763
764     prog = opt_init(argc, argv, list_options);
765     while ((o = opt_next()) != OPT_EOF) {
766         switch (o) {
767         case OPT_EOF:  /* Never hit, but suppresses warning */
768         case OPT_ERR:
769 opthelp:
770             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
771             return 1;
772         case OPT_HELP:
773             opt_help(list_options);
774             break;
775         case OPT_ONE:
776             one = 1;
777             break;
778         case OPT_COMMANDS:
779             todo.commands = 1;
780             break;
781         case OPT_DIGEST_COMMANDS:
782             todo.digest_commands = 1;
783             break;
784         case OPT_DIGEST_ALGORITHMS:
785             todo.digest_algorithms = 1;
786             break;
787         case OPT_KDF_ALGORITHMS:
788             todo.kdf_algorithms = 1;
789             break;
790         case OPT_RANDOM_GENERATORS:
791             todo.random_generators = 1;
792             break;
793         case OPT_MAC_ALGORITHMS:
794             todo.mac_algorithms = 1;
795             break;
796         case OPT_CIPHER_COMMANDS:
797             todo.cipher_commands = 1;
798             break;
799         case OPT_CIPHER_ALGORITHMS:
800             todo.cipher_algorithms = 1;
801             break;
802         case OPT_PK_ALGORITHMS:
803             todo.pk_algorithms = 1;
804             break;
805         case OPT_PK_METHOD:
806             todo.pk_method = 1;
807             break;
808         case OPT_ENGINES:
809             todo.engines = 1;
810             break;
811         case OPT_DISABLED:
812             todo.disabled = 1;
813             break;
814         case OPT_MISSING_HELP:
815             todo.missing_help = 1;
816             break;
817         case OPT_OBJECTS:
818             todo.objects = 1;
819             break;
820         case OPT_OPTIONS:
821             list_options_for_command(opt_arg());
822             break;
823         case OPT_VERBOSE:
824             verbose = 1;
825             break;
826         case OPT_PROV_CASES:
827             if (!opt_provider(o))
828                 return 1;
829             break;
830         }
831         done = 1;
832     }
833     if (opt_num_rest() != 0) {
834         BIO_printf(bio_err, "Extra arguments given.\n");
835         goto opthelp;
836     }
837
838     if (todo.commands)
839         list_type(FT_general, one);
840     if (todo.random_generators)
841         list_random_generators();
842     if (todo.digest_commands)
843         list_type(FT_md, one);
844     if (todo.digest_algorithms)
845         list_digests();
846     if (todo.kdf_algorithms)
847         list_kdfs();
848     if (todo.mac_algorithms)
849         list_macs();
850     if (todo.cipher_commands)
851         list_type(FT_cipher, one);
852     if (todo.cipher_algorithms)
853         list_ciphers();
854     if (todo.pk_algorithms)
855         list_pkey();
856     if (todo.pk_method)
857         list_pkey_meth();
858     if (todo.engines)
859         list_engines();
860     if (todo.disabled)
861         list_disabled();
862     if (todo.missing_help)
863         list_missing_help();
864     if (todo.objects)
865         list_objects();
866
867     if (!done)
868         goto opthelp;
869
870     return 0;
871 }