2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
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
10 /* We need to use some deprecated APIs */
11 #define OPENSSL_SUPPRESS_DEPRECATED
14 #include <openssl/evp.h>
15 #include <openssl/err.h>
16 #include <openssl/provider.h>
17 #include <openssl/safestack.h>
18 #include <openssl/kdf.h>
19 #include <openssl/encoder.h>
20 #include <openssl/decoder.h>
21 #include <openssl/core_names.h>
22 #include <openssl/rand.h>
24 #include "app_params.h"
29 static int verbose = 0;
31 static void legacy_cipher_fn(const EVP_CIPHER *c,
32 const char *from, const char *to, void *arg)
35 BIO_printf(arg, " %s\n", EVP_CIPHER_name(c));
41 BIO_printf(arg, " %s => %s\n", from, to);
45 DEFINE_STACK_OF(EVP_CIPHER)
46 static int cipher_cmp(const EVP_CIPHER * const *a,
47 const EVP_CIPHER * const *b)
49 int ret = EVP_CIPHER_number(*a) - EVP_CIPHER_number(*b);
52 ret = strcmp(OSSL_PROVIDER_name(EVP_CIPHER_provider(*a)),
53 OSSL_PROVIDER_name(EVP_CIPHER_provider(*b)));
58 static void collect_ciphers(EVP_CIPHER *cipher, void *stack)
60 STACK_OF(EVP_CIPHER) *cipher_stack = stack;
62 if (sk_EVP_CIPHER_push(cipher_stack, cipher) > 0)
63 EVP_CIPHER_up_ref(cipher);
66 static void list_ciphers(void)
68 STACK_OF(EVP_CIPHER) *ciphers = sk_EVP_CIPHER_new(cipher_cmp);
71 if (ciphers == NULL) {
72 BIO_printf(bio_err, "ERROR: Memory allocation\n");
75 BIO_printf(bio_out, "Legacy:\n");
76 EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
78 BIO_printf(bio_out, "Provided:\n");
79 EVP_CIPHER_do_all_provided(NULL, collect_ciphers, ciphers);
80 sk_EVP_CIPHER_sort(ciphers);
81 for (i = 0; i < sk_EVP_CIPHER_num(ciphers); i++) {
82 const EVP_CIPHER *c = sk_EVP_CIPHER_value(ciphers, i);
83 STACK_OF(OPENSSL_CSTRING) *names =
84 sk_OPENSSL_CSTRING_new(name_cmp);
86 EVP_CIPHER_names_do_all(c, collect_names, names);
88 BIO_printf(bio_out, " ");
89 print_names(bio_out, names);
90 BIO_printf(bio_out, " @ %s\n",
91 OSSL_PROVIDER_name(EVP_CIPHER_provider(c)));
93 sk_OPENSSL_CSTRING_free(names);
96 print_param_types("retrievable algorithm parameters",
97 EVP_CIPHER_gettable_params(c), 4);
98 print_param_types("retrievable operation parameters",
99 EVP_CIPHER_gettable_ctx_params(c), 4);
100 print_param_types("settable operation parameters",
101 EVP_CIPHER_settable_ctx_params(c), 4);
104 sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free);
107 static void list_md_fn(const EVP_MD *m,
108 const char *from, const char *to, void *arg)
111 BIO_printf(arg, " %s\n", EVP_MD_name(m));
114 from = "<undefined>";
117 BIO_printf((BIO *)arg, " %s => %s\n", from, to);
121 DEFINE_STACK_OF(EVP_MD)
122 static int md_cmp(const EVP_MD * const *a, const EVP_MD * const *b)
124 int ret = EVP_MD_number(*a) - EVP_MD_number(*b);
127 ret = strcmp(OSSL_PROVIDER_name(EVP_MD_provider(*a)),
128 OSSL_PROVIDER_name(EVP_MD_provider(*b)));
133 static void collect_digests(EVP_MD *md, void *stack)
135 STACK_OF(EVP_MD) *digest_stack = stack;
137 if (sk_EVP_MD_push(digest_stack, md) > 0)
141 static void list_digests(void)
143 STACK_OF(EVP_MD) *digests = sk_EVP_MD_new(md_cmp);
146 if (digests == NULL) {
147 BIO_printf(bio_err, "ERROR: Memory allocation\n");
150 BIO_printf(bio_out, "Legacy:\n");
151 EVP_MD_do_all_sorted(list_md_fn, bio_out);
153 BIO_printf(bio_out, "Provided:\n");
154 EVP_MD_do_all_provided(NULL, collect_digests, digests);
155 sk_EVP_MD_sort(digests);
156 for (i = 0; i < sk_EVP_MD_num(digests); i++) {
157 const EVP_MD *m = sk_EVP_MD_value(digests, i);
158 STACK_OF(OPENSSL_CSTRING) *names =
159 sk_OPENSSL_CSTRING_new(name_cmp);
161 EVP_MD_names_do_all(m, collect_names, names);
163 BIO_printf(bio_out, " ");
164 print_names(bio_out, names);
165 BIO_printf(bio_out, " @ %s\n",
166 OSSL_PROVIDER_name(EVP_MD_provider(m)));
168 sk_OPENSSL_CSTRING_free(names);
171 print_param_types("retrievable algorithm parameters",
172 EVP_MD_gettable_params(m), 4);
173 print_param_types("retrievable operation parameters",
174 EVP_MD_gettable_ctx_params(m), 4);
175 print_param_types("settable operation parameters",
176 EVP_MD_settable_ctx_params(m), 4);
179 sk_EVP_MD_pop_free(digests, EVP_MD_free);
182 DEFINE_STACK_OF(EVP_MAC)
183 static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b)
185 int ret = EVP_MAC_number(*a) - EVP_MAC_number(*b);
188 ret = strcmp(OSSL_PROVIDER_name(EVP_MAC_provider(*a)),
189 OSSL_PROVIDER_name(EVP_MAC_provider(*b)));
194 static void collect_macs(EVP_MAC *mac, void *stack)
196 STACK_OF(EVP_MAC) *mac_stack = stack;
198 if (sk_EVP_MAC_push(mac_stack, mac) > 0)
202 static void list_macs(void)
204 STACK_OF(EVP_MAC) *macs = sk_EVP_MAC_new(mac_cmp);
208 BIO_printf(bio_err, "ERROR: Memory allocation\n");
211 BIO_printf(bio_out, "Provided MACs:\n");
212 EVP_MAC_do_all_provided(NULL, collect_macs, macs);
213 sk_EVP_MAC_sort(macs);
214 for (i = 0; i < sk_EVP_MAC_num(macs); i++) {
215 const EVP_MAC *m = sk_EVP_MAC_value(macs, i);
216 STACK_OF(OPENSSL_CSTRING) *names =
217 sk_OPENSSL_CSTRING_new(name_cmp);
219 EVP_MAC_names_do_all(m, collect_names, names);
221 BIO_printf(bio_out, " ");
222 print_names(bio_out, names);
223 BIO_printf(bio_out, " @ %s\n",
224 OSSL_PROVIDER_name(EVP_MAC_provider(m)));
226 sk_OPENSSL_CSTRING_free(names);
229 print_param_types("retrievable algorithm parameters",
230 EVP_MAC_gettable_params(m), 4);
231 print_param_types("retrievable operation parameters",
232 EVP_MAC_gettable_ctx_params(m), 4);
233 print_param_types("settable operation parameters",
234 EVP_MAC_settable_ctx_params(m), 4);
237 sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
243 DEFINE_STACK_OF(EVP_KDF)
244 static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b)
246 int ret = EVP_KDF_number(*a) - EVP_KDF_number(*b);
249 ret = strcmp(OSSL_PROVIDER_name(EVP_KDF_provider(*a)),
250 OSSL_PROVIDER_name(EVP_KDF_provider(*b)));
255 static void collect_kdfs(EVP_KDF *kdf, void *stack)
257 STACK_OF(EVP_KDF) *kdf_stack = stack;
259 sk_EVP_KDF_push(kdf_stack, kdf);
263 static void list_kdfs(void)
265 STACK_OF(EVP_KDF) *kdfs = sk_EVP_KDF_new(kdf_cmp);
269 BIO_printf(bio_err, "ERROR: Memory allocation\n");
272 BIO_printf(bio_out, "Provided KDFs and PDFs:\n");
273 EVP_KDF_do_all_provided(NULL, collect_kdfs, kdfs);
274 sk_EVP_KDF_sort(kdfs);
275 for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) {
276 const EVP_KDF *k = sk_EVP_KDF_value(kdfs, i);
277 STACK_OF(OPENSSL_CSTRING) *names =
278 sk_OPENSSL_CSTRING_new(name_cmp);
280 EVP_KDF_names_do_all(k, collect_names, names);
282 BIO_printf(bio_out, " ");
283 print_names(bio_out, names);
284 BIO_printf(bio_out, " @ %s\n",
285 OSSL_PROVIDER_name(EVP_KDF_provider(k)));
287 sk_OPENSSL_CSTRING_free(names);
290 print_param_types("retrievable algorithm parameters",
291 EVP_KDF_gettable_params(k), 4);
292 print_param_types("retrievable operation parameters",
293 EVP_KDF_gettable_ctx_params(k), 4);
294 print_param_types("settable operation parameters",
295 EVP_KDF_settable_ctx_params(k), 4);
298 sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free);
304 DEFINE_STACK_OF(EVP_RAND)
306 static int rand_cmp(const EVP_RAND * const *a, const EVP_RAND * const *b)
308 int ret = strcasecmp(EVP_RAND_name(*a), EVP_RAND_name(*b));
311 ret = strcmp(OSSL_PROVIDER_name(EVP_RAND_provider(*a)),
312 OSSL_PROVIDER_name(EVP_RAND_provider(*b)));
317 static void collect_rands(EVP_RAND *rand, void *stack)
319 STACK_OF(EVP_RAND) *rand_stack = stack;
321 sk_EVP_RAND_push(rand_stack, rand);
322 EVP_RAND_up_ref(rand);
325 static void list_random_generators(void)
327 STACK_OF(EVP_RAND) *rands = sk_EVP_RAND_new(rand_cmp);
331 BIO_printf(bio_err, "ERROR: Memory allocation\n");
334 BIO_printf(bio_out, "Provided RNGs and seed sources:\n");
335 EVP_RAND_do_all_provided(NULL, collect_rands, rands);
336 sk_EVP_RAND_sort(rands);
337 for (i = 0; i < sk_EVP_RAND_num(rands); i++) {
338 const EVP_RAND *m = sk_EVP_RAND_value(rands, i);
340 BIO_printf(bio_out, " %s", EVP_RAND_name(m));
341 BIO_printf(bio_out, " @ %s\n",
342 OSSL_PROVIDER_name(EVP_RAND_provider(m)));
345 print_param_types("retrievable algorithm parameters",
346 EVP_RAND_gettable_params(m), 4);
347 print_param_types("retrievable operation parameters",
348 EVP_RAND_gettable_ctx_params(m), 4);
349 print_param_types("settable operation parameters",
350 EVP_RAND_settable_ctx_params(m), 4);
353 sk_EVP_RAND_pop_free(rands, EVP_RAND_free);
356 static void display_random(const char *name, EVP_RAND_CTX *drbg)
361 const OSSL_PARAM *gettables;
362 OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
363 unsigned char buf[1000];
365 BIO_printf(bio_out, "%s:\n", name);
367 rand = EVP_RAND_CTX_rand(drbg);
369 BIO_printf(bio_out, " %s", EVP_RAND_name(rand));
370 BIO_printf(bio_out, " @ %s\n",
371 OSSL_PROVIDER_name(EVP_RAND_provider(rand)));
373 switch (EVP_RAND_state(drbg)) {
374 case EVP_RAND_STATE_UNINITIALISED:
377 case EVP_RAND_STATE_READY:
380 case EVP_RAND_STATE_ERROR:
387 BIO_printf(bio_out, " state = %s\n", p);
389 gettables = EVP_RAND_gettable_ctx_params(rand);
390 if (gettables != NULL)
391 for (; gettables->key != NULL; gettables++) {
392 /* State has been dealt with already, so ignore */
393 if (strcasecmp(gettables->key, OSSL_RAND_PARAM_STATE) == 0)
395 /* Outside of verbose mode, we skip non-string values */
396 if (gettables->data_type != OSSL_PARAM_UTF8_STRING
397 && gettables->data_type != OSSL_PARAM_UTF8_PTR
400 params->key = gettables->key;
401 params->data_type = gettables->data_type;
402 if (gettables->data_type == OSSL_PARAM_UNSIGNED_INTEGER
403 || gettables->data_type == OSSL_PARAM_INTEGER) {
405 params->data_size = sizeof(u);
408 params->data_size = sizeof(buf);
410 params->return_size = 0;
411 if (EVP_RAND_get_ctx_params(drbg, params))
412 print_param_value(params, 2);
417 static void list_random_instances(void)
419 display_random("primary", RAND_get0_primary(NULL));
420 display_random("public", RAND_get0_public(NULL));
421 display_random("private", RAND_get0_private(NULL));
427 DEFINE_STACK_OF(OSSL_ENCODER)
428 static int encoder_cmp(const OSSL_ENCODER * const *a,
429 const OSSL_ENCODER * const *b)
431 int ret = OSSL_ENCODER_number(*a) - OSSL_ENCODER_number(*b);
434 ret = strcmp(OSSL_PROVIDER_name(OSSL_ENCODER_provider(*a)),
435 OSSL_PROVIDER_name(OSSL_ENCODER_provider(*b)));
439 static void collect_encoders(OSSL_ENCODER *encoder, void *stack)
441 STACK_OF(OSSL_ENCODER) *encoder_stack = stack;
443 sk_OSSL_ENCODER_push(encoder_stack, encoder);
444 OSSL_ENCODER_up_ref(encoder);
447 static void list_encoders(void)
449 STACK_OF(OSSL_ENCODER) *encoders;
452 encoders = sk_OSSL_ENCODER_new(encoder_cmp);
453 if (encoders == NULL) {
454 BIO_printf(bio_err, "ERROR: Memory allocation\n");
457 BIO_printf(bio_out, "Provided ENCODERs:\n");
458 OSSL_ENCODER_do_all_provided(NULL, collect_encoders, encoders);
459 sk_OSSL_ENCODER_sort(encoders);
461 for (i = 0; i < sk_OSSL_ENCODER_num(encoders); i++) {
462 OSSL_ENCODER *k = sk_OSSL_ENCODER_value(encoders, i);
463 STACK_OF(OPENSSL_CSTRING) *names =
464 sk_OPENSSL_CSTRING_new(name_cmp);
466 OSSL_ENCODER_names_do_all(k, collect_names, names);
468 BIO_printf(bio_out, " ");
469 print_names(bio_out, names);
470 BIO_printf(bio_out, " @ %s (%s)\n",
471 OSSL_PROVIDER_name(OSSL_ENCODER_provider(k)),
472 OSSL_ENCODER_properties(k));
474 sk_OPENSSL_CSTRING_free(names);
477 print_param_types("settable operation parameters",
478 OSSL_ENCODER_settable_ctx_params(k), 4);
481 sk_OSSL_ENCODER_pop_free(encoders, OSSL_ENCODER_free);
487 DEFINE_STACK_OF(OSSL_DECODER)
488 static int decoder_cmp(const OSSL_DECODER * const *a,
489 const OSSL_DECODER * const *b)
491 int ret = OSSL_DECODER_number(*a) - OSSL_DECODER_number(*b);
494 ret = strcmp(OSSL_PROVIDER_name(OSSL_DECODER_provider(*a)),
495 OSSL_PROVIDER_name(OSSL_DECODER_provider(*b)));
499 static void collect_decoders(OSSL_DECODER *decoder, void *stack)
501 STACK_OF(OSSL_DECODER) *decoder_stack = stack;
503 sk_OSSL_DECODER_push(decoder_stack, decoder);
504 OSSL_DECODER_up_ref(decoder);
507 static void list_decoders(void)
509 STACK_OF(OSSL_DECODER) *decoders;
512 decoders = sk_OSSL_DECODER_new(decoder_cmp);
513 if (decoders == NULL) {
514 BIO_printf(bio_err, "ERROR: Memory allocation\n");
517 BIO_printf(bio_out, "Provided DECODERs:\n");
518 OSSL_DECODER_do_all_provided(NULL, collect_decoders,
520 sk_OSSL_DECODER_sort(decoders);
522 for (i = 0; i < sk_OSSL_DECODER_num(decoders); i++) {
523 OSSL_DECODER *k = sk_OSSL_DECODER_value(decoders, i);
524 STACK_OF(OPENSSL_CSTRING) *names =
525 sk_OPENSSL_CSTRING_new(name_cmp);
527 OSSL_DECODER_names_do_all(k, collect_names, names);
529 BIO_printf(bio_out, " ");
530 print_names(bio_out, names);
531 BIO_printf(bio_out, " @ %s (%s)\n",
532 OSSL_PROVIDER_name(OSSL_DECODER_provider(k)),
533 OSSL_DECODER_properties(k));
535 sk_OPENSSL_CSTRING_free(names);
538 print_param_types("settable operation parameters",
539 OSSL_DECODER_settable_ctx_params(k), 4);
542 sk_OSSL_DECODER_pop_free(decoders, OSSL_DECODER_free);
545 static void list_missing_help(void)
550 for (fp = functions; fp->name != NULL; fp++) {
551 if ((o = fp->help) != NULL) {
552 /* If there is help, list what flags are not documented. */
553 for ( ; o->name != NULL; o++) {
554 if (o->helpstr == NULL)
555 BIO_printf(bio_out, "%s %s\n", fp->name, o->name);
557 } else if (fp->func != dgst_main) {
558 /* If not aliased to the dgst command, */
559 BIO_printf(bio_out, "%s *\n", fp->name);
564 static void list_objects(void)
566 int max_nid = OBJ_new_nid(0);
568 char *oid_buf = NULL;
571 /* Skip 0, since that's NID_undef */
572 for (i = 1; i < max_nid; i++) {
573 const ASN1_OBJECT *obj = OBJ_nid2obj(i);
574 const char *sn = OBJ_nid2sn(i);
575 const char *ln = OBJ_nid2ln(i);
579 * If one of the retrieved objects somehow generated an error,
580 * we ignore it. The check for NID_undef below will detect the
581 * error and simply skip to the next NID.
585 if (OBJ_obj2nid(obj) == NID_undef)
588 if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) {
589 BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln);
596 oid_buf = OPENSSL_realloc(oid_buf, n + 1);
597 if (oid_buf == NULL) {
598 BIO_printf(bio_err, "ERROR: Memory allocation\n");
603 if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0)
605 if (ln == NULL || strcmp(sn, ln) == 0)
606 BIO_printf(bio_out, "%s = %s\n", sn, oid_buf);
608 BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf);
611 OPENSSL_free(oid_buf);
614 static void list_options_for_command(const char *command)
619 for (fp = functions; fp->name != NULL; fp++)
620 if (strcmp(fp->name, command) == 0)
622 if (fp->name == NULL) {
623 BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
628 if ((o = fp->help) == NULL)
631 for ( ; o->name != NULL; o++) {
634 if (o->name == OPT_PARAM_STR)
637 if (o->name == OPT_HELP_STR
638 || o->name == OPT_MORE_STR
639 || o->name == OPT_SECTION_STR
640 || o->name[0] == '\0')
642 BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c);
644 /* Always output the -- marker since it is sometimes documented. */
645 BIO_printf(bio_out, "- -\n");
648 static void list_type(FUNC_TYPE ft, int one)
654 memset(&dc, 0, sizeof(dc));
656 calculate_columns(functions, &dc);
658 for (fp = functions; fp->name != NULL; fp++) {
662 BIO_printf(bio_out, "%s\n", fp->name);
664 if (i % dc.columns == 0 && i > 0)
665 BIO_printf(bio_out, "\n");
666 BIO_printf(bio_out, "%-*s", dc.width, fp->name);
671 BIO_printf(bio_out, "\n\n");
674 static void list_pkey(void)
678 for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
679 const EVP_PKEY_ASN1_METHOD *ameth;
680 int pkey_id, pkey_base_id, pkey_flags;
681 const char *pinfo, *pem_str;
682 ameth = EVP_PKEY_asn1_get0(i);
683 EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
684 &pinfo, &pem_str, ameth);
685 if (pkey_flags & ASN1_PKEY_ALIAS) {
686 BIO_printf(bio_out, "Name: %s\n", OBJ_nid2ln(pkey_id));
687 BIO_printf(bio_out, "\tAlias for: %s\n",
688 OBJ_nid2ln(pkey_base_id));
690 BIO_printf(bio_out, "Name: %s\n", pinfo);
691 BIO_printf(bio_out, "\tType: %s Algorithm\n",
692 pkey_flags & ASN1_PKEY_DYNAMIC ?
693 "External" : "Builtin");
694 BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
697 BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
703 #ifndef OPENSSL_NO_DEPRECATED_3_0
704 static void list_pkey_meth(void)
707 size_t meth_count = EVP_PKEY_meth_get_count();
709 for (i = 0; i < meth_count; i++) {
710 const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
711 int pkey_id, pkey_flags;
713 EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
714 BIO_printf(bio_out, "%s\n", OBJ_nid2ln(pkey_id));
715 BIO_printf(bio_out, "\tType: %s Algorithm\n",
716 pkey_flags & ASN1_PKEY_DYNAMIC ? "External" : "Builtin");
721 #ifndef OPENSSL_NO_DEPRECATED_3_0
722 static void list_engines(void)
724 # ifndef OPENSSL_NO_ENGINE
727 BIO_puts(bio_out, "Engines:\n");
728 e = ENGINE_get_first();
730 BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
731 e = ENGINE_get_next(e);
734 BIO_puts(bio_out, "Engine support is disabled.\n");
739 static void list_disabled(void)
741 BIO_puts(bio_out, "Disabled algorithms:\n");
742 #ifdef OPENSSL_NO_ARIA
743 BIO_puts(bio_out, "ARIA\n");
746 BIO_puts(bio_out, "BF\n");
748 #ifdef OPENSSL_NO_BLAKE2
749 BIO_puts(bio_out, "BLAKE2\n");
751 #ifdef OPENSSL_NO_CAMELLIA
752 BIO_puts(bio_out, "CAMELLIA\n");
754 #ifdef OPENSSL_NO_CAST
755 BIO_puts(bio_out, "CAST\n");
757 #ifdef OPENSSL_NO_CMAC
758 BIO_puts(bio_out, "CMAC\n");
760 #ifdef OPENSSL_NO_CMS
761 BIO_puts(bio_out, "CMS\n");
763 #ifdef OPENSSL_NO_COMP
764 BIO_puts(bio_out, "COMP\n");
766 #ifdef OPENSSL_NO_DES
767 BIO_puts(bio_out, "DES\n");
769 #ifdef OPENSSL_NO_DGRAM
770 BIO_puts(bio_out, "DGRAM\n");
773 BIO_puts(bio_out, "DH\n");
775 #ifdef OPENSSL_NO_DSA
776 BIO_puts(bio_out, "DSA\n");
778 #if defined(OPENSSL_NO_DTLS)
779 BIO_puts(bio_out, "DTLS\n");
781 #if defined(OPENSSL_NO_DTLS1)
782 BIO_puts(bio_out, "DTLS1\n");
784 #if defined(OPENSSL_NO_DTLS1_2)
785 BIO_puts(bio_out, "DTLS1_2\n");
788 BIO_puts(bio_out, "EC\n");
790 #ifdef OPENSSL_NO_EC2M
791 BIO_puts(bio_out, "EC2M\n");
793 #if defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
794 BIO_puts(bio_out, "ENGINE\n");
796 #ifdef OPENSSL_NO_GOST
797 BIO_puts(bio_out, "GOST\n");
799 #ifdef OPENSSL_NO_IDEA
800 BIO_puts(bio_out, "IDEA\n");
802 #ifdef OPENSSL_NO_MD2
803 BIO_puts(bio_out, "MD2\n");
805 #ifdef OPENSSL_NO_MD4
806 BIO_puts(bio_out, "MD4\n");
808 #ifdef OPENSSL_NO_MD5
809 BIO_puts(bio_out, "MD5\n");
811 #ifdef OPENSSL_NO_MDC2
812 BIO_puts(bio_out, "MDC2\n");
814 #ifdef OPENSSL_NO_OCB
815 BIO_puts(bio_out, "OCB\n");
817 #ifdef OPENSSL_NO_OCSP
818 BIO_puts(bio_out, "OCSP\n");
820 #ifdef OPENSSL_NO_PSK
821 BIO_puts(bio_out, "PSK\n");
823 #ifdef OPENSSL_NO_RC2
824 BIO_puts(bio_out, "RC2\n");
826 #ifdef OPENSSL_NO_RC4
827 BIO_puts(bio_out, "RC4\n");
829 #ifdef OPENSSL_NO_RC5
830 BIO_puts(bio_out, "RC5\n");
832 #ifdef OPENSSL_NO_RMD160
833 BIO_puts(bio_out, "RMD160\n");
835 #ifdef OPENSSL_NO_RSA
836 BIO_puts(bio_out, "RSA\n");
838 #ifdef OPENSSL_NO_SCRYPT
839 BIO_puts(bio_out, "SCRYPT\n");
841 #ifdef OPENSSL_NO_SCTP
842 BIO_puts(bio_out, "SCTP\n");
844 #ifdef OPENSSL_NO_SEED
845 BIO_puts(bio_out, "SEED\n");
847 #ifdef OPENSSL_NO_SM2
848 BIO_puts(bio_out, "SM2\n");
850 #ifdef OPENSSL_NO_SM3
851 BIO_puts(bio_out, "SM3\n");
853 #ifdef OPENSSL_NO_SM4
854 BIO_puts(bio_out, "SM4\n");
856 #ifdef OPENSSL_NO_SOCK
857 BIO_puts(bio_out, "SOCK\n");
859 #ifdef OPENSSL_NO_SRP
860 BIO_puts(bio_out, "SRP\n");
862 #ifdef OPENSSL_NO_SRTP
863 BIO_puts(bio_out, "SRTP\n");
865 #ifdef OPENSSL_NO_SSL3
866 BIO_puts(bio_out, "SSL3\n");
868 #ifdef OPENSSL_NO_TLS1
869 BIO_puts(bio_out, "TLS1\n");
871 #ifdef OPENSSL_NO_TLS1_1
872 BIO_puts(bio_out, "TLS1_1\n");
874 #ifdef OPENSSL_NO_TLS1_2
875 BIO_puts(bio_out, "TLS1_2\n");
877 #ifdef OPENSSL_NO_WHIRLPOOL
878 BIO_puts(bio_out, "WHIRLPOOL\n");
881 BIO_puts(bio_out, "ZLIB\n");
885 /* Unified enum for help and list commands. */
886 typedef enum HELPLIST_CHOICE {
887 OPT_ERR = -1, OPT_EOF = 0, OPT_HELP, OPT_ONE, OPT_VERBOSE,
888 OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
889 OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
890 OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
891 OPT_KDF_ALGORITHMS, OPT_RANDOM_INSTANCES, OPT_RANDOM_GENERATORS,
892 OPT_ENCODERS, OPT_DECODERS,
893 OPT_MISSING_HELP, OPT_OBJECTS,
894 #ifndef OPENSSL_NO_DEPRECATED_3_0
900 const OPTIONS list_options[] = {
902 OPT_SECTION("General"),
903 {"help", OPT_HELP, '-', "Display this summary"},
905 OPT_SECTION("Output"),
906 {"1", OPT_ONE, '-', "List in one column"},
907 {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
908 {"commands", OPT_COMMANDS, '-', "List of standard commands"},
909 {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
910 {"digest-commands", OPT_DIGEST_COMMANDS, '-',
911 "List of message digest commands"},
912 {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
913 "List of message digest algorithms"},
914 {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
915 "List of key derivation and pseudo random function algorithms"},
916 {"random-instances", OPT_RANDOM_INSTANCES, '-',
917 "List the primary, pubic and private random number generator details"},
918 {"random-generators", OPT_RANDOM_GENERATORS, '-',
919 "List of random number generators"},
920 {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
921 "List of message authentication code algorithms"},
922 {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
923 {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
924 "List of cipher algorithms"},
925 {"encoders", OPT_ENCODERS, '-', "List of encoding methods" },
926 {"decoders", OPT_DECODERS, '-', "List of decoding methods" },
927 {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
928 "List of public key algorithms"},
929 #ifndef OPENSSL_NO_DEPRECATED_3_0
930 {"public-key-methods", OPT_PK_METHOD, '-',
931 "List of public key methods"},
932 {"engines", OPT_ENGINES, '-',
933 "List of loaded engines"},
935 {"disabled", OPT_DISABLED, '-', "List of disabled features"},
936 {"missing-help", OPT_MISSING_HELP, '-',
937 "List missing detailed help strings"},
938 {"options", OPT_OPTIONS, 's',
939 "List options for specified command"},
940 {"objects", OPT_OBJECTS, '-',
941 "List built in objects (OID<->name mappings)"},
947 int list_main(int argc, char **argv)
951 int one = 0, done = 0;
953 unsigned int commands:1;
954 unsigned int random_instances:1;
955 unsigned int random_generators:1;
956 unsigned int digest_commands:1;
957 unsigned int digest_algorithms:1;
958 unsigned int kdf_algorithms:1;
959 unsigned int mac_algorithms:1;
960 unsigned int cipher_commands:1;
961 unsigned int cipher_algorithms:1;
962 unsigned int encoder_algorithms:1;
963 unsigned int decoder_algorithms:1;
964 unsigned int pk_algorithms:1;
965 unsigned int pk_method:1;
966 #ifndef OPENSSL_NO_DEPRECATED_3_0
967 unsigned int engines:1;
969 unsigned int disabled:1;
970 unsigned int missing_help:1;
971 unsigned int objects:1;
972 unsigned int options:1;
975 verbose = 0; /* Clear a possible previous call */
977 prog = opt_init(argc, argv, list_options);
978 while ((o = opt_next()) != OPT_EOF) {
980 case OPT_EOF: /* Never hit, but suppresses warning */
983 BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
986 opt_help(list_options);
994 case OPT_DIGEST_COMMANDS:
995 todo.digest_commands = 1;
997 case OPT_DIGEST_ALGORITHMS:
998 todo.digest_algorithms = 1;
1000 case OPT_KDF_ALGORITHMS:
1001 todo.kdf_algorithms = 1;
1003 case OPT_RANDOM_INSTANCES:
1004 todo.random_instances = 1;
1006 case OPT_RANDOM_GENERATORS:
1007 todo.random_generators = 1;
1009 case OPT_MAC_ALGORITHMS:
1010 todo.mac_algorithms = 1;
1012 case OPT_CIPHER_COMMANDS:
1013 todo.cipher_commands = 1;
1015 case OPT_CIPHER_ALGORITHMS:
1016 todo.cipher_algorithms = 1;
1019 todo.encoder_algorithms = 1;
1022 todo.decoder_algorithms = 1;
1024 case OPT_PK_ALGORITHMS:
1025 todo.pk_algorithms = 1;
1030 #ifndef OPENSSL_NO_DEPRECATED_3_0
1038 case OPT_MISSING_HELP:
1039 todo.missing_help = 1;
1045 list_options_for_command(opt_arg());
1050 case OPT_PROV_CASES:
1051 if (!opt_provider(o))
1057 if (opt_num_rest() != 0) {
1058 BIO_printf(bio_err, "Extra arguments given.\n");
1063 list_type(FT_general, one);
1064 if (todo.random_instances)
1065 list_random_instances();
1066 if (todo.random_generators)
1067 list_random_generators();
1068 if (todo.digest_commands)
1069 list_type(FT_md, one);
1070 if (todo.digest_algorithms)
1072 if (todo.kdf_algorithms)
1074 if (todo.mac_algorithms)
1076 if (todo.cipher_commands)
1077 list_type(FT_cipher, one);
1078 if (todo.cipher_algorithms)
1080 if (todo.encoder_algorithms)
1082 if (todo.decoder_algorithms)
1084 if (todo.pk_algorithms)
1086 #ifndef OPENSSL_NO_DEPRECATED_3_0
1094 if (todo.missing_help)
1095 list_missing_help();