xref: /openssl/apps/list.c (revision 23b795d3)
1 /*
2  * Copyright 1995-2024 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 /* We need to use some deprecated APIs */
11 #define OPENSSL_SUPPRESS_DEPRECATED
12 
13 #include "internal/e_os.h"
14 
15 #include <string.h>
16 #include <openssl/evp.h>
17 #include <openssl/err.h>
18 #include <openssl/provider.h>
19 #include <openssl/safestack.h>
20 #include <openssl/kdf.h>
21 #include <openssl/encoder.h>
22 #include <openssl/decoder.h>
23 #include <openssl/store.h>
24 #include <openssl/core_names.h>
25 #include <openssl/rand.h>
26 #include <openssl/tls1.h>
27 #include "apps.h"
28 #include "app_params.h"
29 #include "progs.h"
30 #include "opt.h"
31 #include "names.h"
32 
33 static int verbose = 0;
34 static const char *select_name = NULL;
35 
36 /* Checks to see if algorithms are fetchable */
37 #define IS_FETCHABLE(type, TYPE)                                \
38     static int is_ ## type ## _fetchable(const TYPE *alg)       \
39     {                                                           \
40         TYPE *impl;                                             \
41         const char *propq = app_get0_propq();                   \
42         OSSL_LIB_CTX *libctx = app_get0_libctx();               \
43         const char *name = TYPE ## _get0_name(alg);             \
44                                                                 \
45         ERR_set_mark();                                         \
46         impl = TYPE ## _fetch(libctx, name, propq);             \
47         ERR_pop_to_mark();                                      \
48         if (impl == NULL)                                       \
49             return 0;                                           \
50         TYPE ## _free(impl);                                    \
51         return 1;                                               \
52     }
IS_FETCHABLE(cipher,EVP_CIPHER)53 IS_FETCHABLE(cipher, EVP_CIPHER)
54 IS_FETCHABLE(digest, EVP_MD)
55 IS_FETCHABLE(mac, EVP_MAC)
56 IS_FETCHABLE(kdf, EVP_KDF)
57 IS_FETCHABLE(rand, EVP_RAND)
58 IS_FETCHABLE(keymgmt, EVP_KEYMGMT)
59 IS_FETCHABLE(signature, EVP_SIGNATURE)
60 IS_FETCHABLE(kem, EVP_KEM)
61 IS_FETCHABLE(asym_cipher, EVP_ASYM_CIPHER)
62 IS_FETCHABLE(keyexch, EVP_KEYEXCH)
63 IS_FETCHABLE(decoder, OSSL_DECODER)
64 IS_FETCHABLE(encoder, OSSL_ENCODER)
65 
66 #ifndef OPENSSL_NO_DEPRECATED_3_0
67 static int include_legacy(void)
68 {
69     return app_get0_propq() == NULL;
70 }
71 
legacy_cipher_fn(const EVP_CIPHER * c,const char * from,const char * to,void * arg)72 static void legacy_cipher_fn(const EVP_CIPHER *c,
73                              const char *from, const char *to, void *arg)
74 {
75     if (select_name != NULL
76         && (c == NULL
77             || OPENSSL_strcasecmp(select_name, EVP_CIPHER_get0_name(c)) != 0))
78         return;
79     if (c != NULL) {
80         BIO_printf(arg, "  %s\n", EVP_CIPHER_get0_name(c));
81     } else {
82         if (from == NULL)
83             from = "<undefined>";
84         if (to == NULL)
85             to = "<undefined>";
86         BIO_printf(arg, "  %s => %s\n", from, to);
87     }
88 }
89 #endif
90 
DEFINE_STACK_OF(EVP_CIPHER)91 DEFINE_STACK_OF(EVP_CIPHER)
92 static int cipher_cmp(const EVP_CIPHER * const *a,
93                       const EVP_CIPHER * const *b)
94 {
95     return strcmp(OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(*a)),
96                   OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(*b)));
97 }
98 
collect_ciphers(EVP_CIPHER * cipher,void * stack)99 static void collect_ciphers(EVP_CIPHER *cipher, void *stack)
100 {
101     STACK_OF(EVP_CIPHER) *cipher_stack = stack;
102 
103     if (is_cipher_fetchable(cipher)
104             && sk_EVP_CIPHER_push(cipher_stack, cipher) > 0)
105         EVP_CIPHER_up_ref(cipher);
106 }
107 
list_ciphers(const char * prefix)108 static void list_ciphers(const char *prefix)
109 {
110     STACK_OF(EVP_CIPHER) *ciphers = sk_EVP_CIPHER_new(cipher_cmp);
111     int i;
112 
113     if (ciphers == NULL) {
114         BIO_printf(bio_err, "ERROR: Memory allocation\n");
115         return;
116     }
117 #ifndef OPENSSL_NO_DEPRECATED_3_0
118     if (include_legacy()) {
119         BIO_printf(bio_out, "%sLegacy:\n", prefix);
120         EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
121     }
122 #endif
123 
124     BIO_printf(bio_out, "%sProvided:\n", prefix);
125     EVP_CIPHER_do_all_provided(app_get0_libctx(), collect_ciphers, ciphers);
126     sk_EVP_CIPHER_sort(ciphers);
127     for (i = 0; i < sk_EVP_CIPHER_num(ciphers); i++) {
128         const EVP_CIPHER *c = sk_EVP_CIPHER_value(ciphers, i);
129         STACK_OF(OPENSSL_CSTRING) *names = NULL;
130 
131         if (select_name != NULL && !EVP_CIPHER_is_a(c, select_name))
132             continue;
133 
134         names = sk_OPENSSL_CSTRING_new(name_cmp);
135         if (names != NULL && EVP_CIPHER_names_do_all(c, collect_names, names)) {
136             BIO_printf(bio_out, "  ");
137             print_names(bio_out, names);
138 
139             BIO_printf(bio_out, " @ %s\n",
140                        OSSL_PROVIDER_get0_name(EVP_CIPHER_get0_provider(c)));
141 
142             if (verbose) {
143                 const char *desc = EVP_CIPHER_get0_description(c);
144 
145                 if (desc != NULL)
146                     BIO_printf(bio_out, "    description: %s\n", desc);
147                 print_param_types("retrievable algorithm parameters",
148                                   EVP_CIPHER_gettable_params(c), 4);
149                 print_param_types("retrievable operation parameters",
150                                   EVP_CIPHER_gettable_ctx_params(c), 4);
151                 print_param_types("settable operation parameters",
152                                   EVP_CIPHER_settable_ctx_params(c), 4);
153             }
154         }
155         sk_OPENSSL_CSTRING_free(names);
156     }
157     sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free);
158 }
159 
160 #ifndef OPENSSL_NO_DEPRECATED_3_0
legacy_md_fn(const EVP_MD * m,const char * from,const char * to,void * arg)161 static void legacy_md_fn(const EVP_MD *m,
162                        const char *from, const char *to, void *arg)
163 {
164     if (m != NULL) {
165         BIO_printf(arg, "  %s\n", EVP_MD_get0_name(m));
166     } else {
167         if (from == NULL)
168             from = "<undefined>";
169         if (to == NULL)
170             to = "<undefined>";
171         BIO_printf((BIO *)arg, "  %s => %s\n", from, to);
172     }
173 }
174 #endif
175 
DEFINE_STACK_OF(EVP_MD)176 DEFINE_STACK_OF(EVP_MD)
177 static int md_cmp(const EVP_MD * const *a, const EVP_MD * const *b)
178 {
179     return strcmp(OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(*a)),
180                   OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(*b)));
181 }
182 
collect_digests(EVP_MD * digest,void * stack)183 static void collect_digests(EVP_MD *digest, void *stack)
184 {
185     STACK_OF(EVP_MD) *digest_stack = stack;
186 
187     if (is_digest_fetchable(digest)
188             && sk_EVP_MD_push(digest_stack, digest) > 0)
189         EVP_MD_up_ref(digest);
190 }
191 
list_digests(const char * prefix)192 static void list_digests(const char *prefix)
193 {
194     STACK_OF(EVP_MD) *digests = sk_EVP_MD_new(md_cmp);
195     int i;
196 
197     if (digests == NULL) {
198         BIO_printf(bio_err, "ERROR: Memory allocation\n");
199         return;
200     }
201 #ifndef OPENSSL_NO_DEPRECATED_3_0
202     if (include_legacy()) {
203         BIO_printf(bio_out, "%sLegacy:\n", prefix);
204         EVP_MD_do_all_sorted(legacy_md_fn, bio_out);
205     }
206 #endif
207 
208     BIO_printf(bio_out, "%sProvided:\n", prefix);
209     EVP_MD_do_all_provided(app_get0_libctx(), collect_digests, digests);
210     sk_EVP_MD_sort(digests);
211     for (i = 0; i < sk_EVP_MD_num(digests); i++) {
212         const EVP_MD *m = sk_EVP_MD_value(digests, i);
213         STACK_OF(OPENSSL_CSTRING) *names = NULL;
214 
215         if (select_name != NULL && !EVP_MD_is_a(m, select_name))
216             continue;
217 
218         names = sk_OPENSSL_CSTRING_new(name_cmp);
219         if (names != NULL && EVP_MD_names_do_all(m, collect_names, names)) {
220             BIO_printf(bio_out, "  ");
221             print_names(bio_out, names);
222 
223             BIO_printf(bio_out, " @ %s\n",
224                        OSSL_PROVIDER_get0_name(EVP_MD_get0_provider(m)));
225 
226             if (verbose) {
227                 const char *desc = EVP_MD_get0_description(m);
228 
229                 if (desc != NULL)
230                     BIO_printf(bio_out, "    description: %s\n", desc);
231                 print_param_types("retrievable algorithm parameters",
232                                 EVP_MD_gettable_params(m), 4);
233                 print_param_types("retrievable operation parameters",
234                                 EVP_MD_gettable_ctx_params(m), 4);
235                 print_param_types("settable operation parameters",
236                                 EVP_MD_settable_ctx_params(m), 4);
237             }
238         }
239         sk_OPENSSL_CSTRING_free(names);
240     }
241     sk_EVP_MD_pop_free(digests, EVP_MD_free);
242 }
243 
DEFINE_STACK_OF(EVP_MAC)244 DEFINE_STACK_OF(EVP_MAC)
245 static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b)
246 {
247     return strcmp(OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(*a)),
248                   OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(*b)));
249 }
250 
collect_macs(EVP_MAC * mac,void * stack)251 static void collect_macs(EVP_MAC *mac, void *stack)
252 {
253     STACK_OF(EVP_MAC) *mac_stack = stack;
254 
255     if (is_mac_fetchable(mac)
256             && sk_EVP_MAC_push(mac_stack, mac) > 0)
257         EVP_MAC_up_ref(mac);
258 }
259 
list_macs(void)260 static void list_macs(void)
261 {
262     STACK_OF(EVP_MAC) *macs = sk_EVP_MAC_new(mac_cmp);
263     int i;
264 
265     if (macs == NULL) {
266         BIO_printf(bio_err, "ERROR: Memory allocation\n");
267         return;
268     }
269     BIO_printf(bio_out, "Provided MACs:\n");
270     EVP_MAC_do_all_provided(app_get0_libctx(), collect_macs, macs);
271     sk_EVP_MAC_sort(macs);
272     for (i = 0; i < sk_EVP_MAC_num(macs); i++) {
273         const EVP_MAC *m = sk_EVP_MAC_value(macs, i);
274         STACK_OF(OPENSSL_CSTRING) *names = NULL;
275 
276         if (select_name != NULL && !EVP_MAC_is_a(m, select_name))
277             continue;
278 
279         names = sk_OPENSSL_CSTRING_new(name_cmp);
280         if (names != NULL && EVP_MAC_names_do_all(m, collect_names, names)) {
281             BIO_printf(bio_out, "  ");
282             print_names(bio_out, names);
283 
284             BIO_printf(bio_out, " @ %s\n",
285                        OSSL_PROVIDER_get0_name(EVP_MAC_get0_provider(m)));
286 
287             if (verbose) {
288                 const char *desc = EVP_MAC_get0_description(m);
289 
290                 if (desc != NULL)
291                     BIO_printf(bio_out, "    description: %s\n", desc);
292                 print_param_types("retrievable algorithm parameters",
293                                 EVP_MAC_gettable_params(m), 4);
294                 print_param_types("retrievable operation parameters",
295                                 EVP_MAC_gettable_ctx_params(m), 4);
296                 print_param_types("settable operation parameters",
297                                 EVP_MAC_settable_ctx_params(m), 4);
298             }
299         }
300         sk_OPENSSL_CSTRING_free(names);
301     }
302     sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
303 }
304 
305 /*
306  * KDFs and PRFs
307  */
DEFINE_STACK_OF(EVP_KDF)308 DEFINE_STACK_OF(EVP_KDF)
309 static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b)
310 {
311     return strcmp(OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(*a)),
312                   OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(*b)));
313 }
314 
collect_kdfs(EVP_KDF * kdf,void * stack)315 static void collect_kdfs(EVP_KDF *kdf, void *stack)
316 {
317     STACK_OF(EVP_KDF) *kdf_stack = stack;
318 
319     if (is_kdf_fetchable(kdf)
320             && sk_EVP_KDF_push(kdf_stack, kdf) > 0)
321         EVP_KDF_up_ref(kdf);
322 }
323 
list_kdfs(void)324 static void list_kdfs(void)
325 {
326     STACK_OF(EVP_KDF) *kdfs = sk_EVP_KDF_new(kdf_cmp);
327     int i;
328 
329     if (kdfs == NULL) {
330         BIO_printf(bio_err, "ERROR: Memory allocation\n");
331         return;
332     }
333     BIO_printf(bio_out, "Provided KDFs and PDFs:\n");
334     EVP_KDF_do_all_provided(app_get0_libctx(), collect_kdfs, kdfs);
335     sk_EVP_KDF_sort(kdfs);
336     for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) {
337         const EVP_KDF *k = sk_EVP_KDF_value(kdfs, i);
338         STACK_OF(OPENSSL_CSTRING) *names = NULL;
339 
340         if (select_name != NULL && !EVP_KDF_is_a(k, select_name))
341             continue;
342 
343         names = sk_OPENSSL_CSTRING_new(name_cmp);
344         if (names != NULL && EVP_KDF_names_do_all(k, collect_names, names)) {
345             BIO_printf(bio_out, "  ");
346             print_names(bio_out, names);
347 
348             BIO_printf(bio_out, " @ %s\n",
349                        OSSL_PROVIDER_get0_name(EVP_KDF_get0_provider(k)));
350 
351             if (verbose) {
352                 const char *desc = EVP_KDF_get0_description(k);
353 
354                 if (desc != NULL)
355                     BIO_printf(bio_out, "    description: %s\n", desc);
356                 print_param_types("retrievable algorithm parameters",
357                                 EVP_KDF_gettable_params(k), 4);
358                 print_param_types("retrievable operation parameters",
359                                 EVP_KDF_gettable_ctx_params(k), 4);
360                 print_param_types("settable operation parameters",
361                                 EVP_KDF_settable_ctx_params(k), 4);
362             }
363         }
364         sk_OPENSSL_CSTRING_free(names);
365     }
366     sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free);
367 }
368 
369 /*
370  * RANDs
371  */
DEFINE_STACK_OF(EVP_RAND)372 DEFINE_STACK_OF(EVP_RAND)
373 
374 static int rand_cmp(const EVP_RAND * const *a, const EVP_RAND * const *b)
375 {
376     int ret = OPENSSL_strcasecmp(EVP_RAND_get0_name(*a), EVP_RAND_get0_name(*b));
377 
378     if (ret == 0)
379         ret = strcmp(OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(*a)),
380                      OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(*b)));
381 
382     return ret;
383 }
384 
collect_rands(EVP_RAND * rand,void * stack)385 static void collect_rands(EVP_RAND *rand, void *stack)
386 {
387     STACK_OF(EVP_RAND) *rand_stack = stack;
388 
389     if (is_rand_fetchable(rand)
390             && sk_EVP_RAND_push(rand_stack, rand) > 0)
391         EVP_RAND_up_ref(rand);
392 }
393 
list_random_generators(void)394 static void list_random_generators(void)
395 {
396     STACK_OF(EVP_RAND) *rands = sk_EVP_RAND_new(rand_cmp);
397     int i;
398 
399     if (rands == NULL) {
400         BIO_printf(bio_err, "ERROR: Memory allocation\n");
401         return;
402     }
403     BIO_printf(bio_out, "Provided RNGs and seed sources:\n");
404     EVP_RAND_do_all_provided(app_get0_libctx(), collect_rands, rands);
405     sk_EVP_RAND_sort(rands);
406     for (i = 0; i < sk_EVP_RAND_num(rands); i++) {
407         const EVP_RAND *m = sk_EVP_RAND_value(rands, i);
408 
409         if (select_name != NULL
410             && OPENSSL_strcasecmp(EVP_RAND_get0_name(m), select_name) != 0)
411             continue;
412         BIO_printf(bio_out, "  %s", EVP_RAND_get0_name(m));
413         BIO_printf(bio_out, " @ %s\n",
414                    OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(m)));
415 
416         if (verbose) {
417             const char *desc = EVP_RAND_get0_description(m);
418 
419             if (desc != NULL)
420                 BIO_printf(bio_out, "    description: %s\n", desc);
421             print_param_types("retrievable algorithm parameters",
422                               EVP_RAND_gettable_params(m), 4);
423             print_param_types("retrievable operation parameters",
424                               EVP_RAND_gettable_ctx_params(m), 4);
425             print_param_types("settable operation parameters",
426                               EVP_RAND_settable_ctx_params(m), 4);
427         }
428     }
429     sk_EVP_RAND_pop_free(rands, EVP_RAND_free);
430 }
431 
display_random(const char * name,EVP_RAND_CTX * drbg)432 static void display_random(const char *name, EVP_RAND_CTX *drbg)
433 {
434     EVP_RAND *rand;
435     uint64_t u;
436     const char *p;
437     const OSSL_PARAM *gettables;
438     OSSL_PARAM params[2] = { OSSL_PARAM_END, OSSL_PARAM_END };
439     unsigned char buf[1000];
440 
441     BIO_printf(bio_out, "%s:\n", name);
442     if (drbg != NULL) {
443         rand = EVP_RAND_CTX_get0_rand(drbg);
444 
445         BIO_printf(bio_out, "  %s", EVP_RAND_get0_name(rand));
446         BIO_printf(bio_out, " @ %s\n",
447                    OSSL_PROVIDER_get0_name(EVP_RAND_get0_provider(rand)));
448 
449         switch (EVP_RAND_get_state(drbg)) {
450         case EVP_RAND_STATE_UNINITIALISED:
451             p = "uninitialised";
452             break;
453         case EVP_RAND_STATE_READY:
454             p = "ready";
455             break;
456         case EVP_RAND_STATE_ERROR:
457             p = "error";
458             break;
459         default:
460             p = "unknown";
461             break;
462         }
463         BIO_printf(bio_out, "  state = %s\n", p);
464 
465         gettables = EVP_RAND_gettable_ctx_params(rand);
466         if (gettables != NULL)
467             for (; gettables->key != NULL; gettables++) {
468                 /* State has been dealt with already, so ignore */
469                 if (OPENSSL_strcasecmp(gettables->key, OSSL_RAND_PARAM_STATE) == 0)
470                     continue;
471                 /* Outside of verbose mode, we skip non-string values */
472                 if (gettables->data_type != OSSL_PARAM_UTF8_STRING
473                         && gettables->data_type != OSSL_PARAM_UTF8_PTR
474                         && !verbose)
475                     continue;
476                 params->key = gettables->key;
477                 params->data_type = gettables->data_type;
478                 if (gettables->data_type == OSSL_PARAM_UNSIGNED_INTEGER
479                         || gettables->data_type == OSSL_PARAM_INTEGER) {
480                     params->data = &u;
481                     params->data_size = sizeof(u);
482                 } else {
483                     params->data = buf;
484                     params->data_size = sizeof(buf);
485                 }
486                 params->return_size = 0;
487                 if (EVP_RAND_CTX_get_params(drbg, params))
488                     print_param_value(params, 2);
489             }
490     }
491 }
492 
list_random_instances(void)493 static void list_random_instances(void)
494 {
495     display_random("primary", RAND_get0_primary(NULL));
496     display_random("public", RAND_get0_public(NULL));
497     display_random("private", RAND_get0_private(NULL));
498 }
499 
500 /*
501  * Encoders
502  */
DEFINE_STACK_OF(OSSL_ENCODER)503 DEFINE_STACK_OF(OSSL_ENCODER)
504 static int encoder_cmp(const OSSL_ENCODER * const *a,
505                        const OSSL_ENCODER * const *b)
506 {
507     return strcmp(OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(*a)),
508                   OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(*b)));
509 }
510 
collect_encoders(OSSL_ENCODER * encoder,void * stack)511 static void collect_encoders(OSSL_ENCODER *encoder, void *stack)
512 {
513     STACK_OF(OSSL_ENCODER) *encoder_stack = stack;
514 
515     if (is_encoder_fetchable(encoder)
516             && sk_OSSL_ENCODER_push(encoder_stack, encoder) > 0)
517         OSSL_ENCODER_up_ref(encoder);
518 }
519 
list_encoders(void)520 static void list_encoders(void)
521 {
522     STACK_OF(OSSL_ENCODER) *encoders;
523     int i;
524 
525     encoders = sk_OSSL_ENCODER_new(encoder_cmp);
526     if (encoders == NULL) {
527         BIO_printf(bio_err, "ERROR: Memory allocation\n");
528         return;
529     }
530     BIO_printf(bio_out, "Provided ENCODERs:\n");
531     OSSL_ENCODER_do_all_provided(app_get0_libctx(), collect_encoders,
532                                  encoders);
533     sk_OSSL_ENCODER_sort(encoders);
534 
535     for (i = 0; i < sk_OSSL_ENCODER_num(encoders); i++) {
536         OSSL_ENCODER *k = sk_OSSL_ENCODER_value(encoders, i);
537         STACK_OF(OPENSSL_CSTRING) *names = NULL;
538 
539         if (select_name != NULL && !OSSL_ENCODER_is_a(k, select_name))
540             continue;
541 
542         names = sk_OPENSSL_CSTRING_new(name_cmp);
543         if (names != NULL && OSSL_ENCODER_names_do_all(k, collect_names, names)) {
544             BIO_printf(bio_out, "  ");
545             print_names(bio_out, names);
546 
547             BIO_printf(bio_out, " @ %s (%s)\n",
548                     OSSL_PROVIDER_get0_name(OSSL_ENCODER_get0_provider(k)),
549                     OSSL_ENCODER_get0_properties(k));
550 
551             if (verbose) {
552                 const char *desc = OSSL_ENCODER_get0_description(k);
553 
554                 if (desc != NULL)
555                     BIO_printf(bio_out, "    description: %s\n", desc);
556                 print_param_types("settable operation parameters",
557                                 OSSL_ENCODER_settable_ctx_params(k), 4);
558             }
559         }
560         sk_OPENSSL_CSTRING_free(names);
561     }
562     sk_OSSL_ENCODER_pop_free(encoders, OSSL_ENCODER_free);
563 }
564 
565 /*
566  * Decoders
567  */
DEFINE_STACK_OF(OSSL_DECODER)568 DEFINE_STACK_OF(OSSL_DECODER)
569 static int decoder_cmp(const OSSL_DECODER * const *a,
570                        const OSSL_DECODER * const *b)
571 {
572     return strcmp(OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(*a)),
573                   OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(*b)));
574 }
575 
collect_decoders(OSSL_DECODER * decoder,void * stack)576 static void collect_decoders(OSSL_DECODER *decoder, void *stack)
577 {
578     STACK_OF(OSSL_DECODER) *decoder_stack = stack;
579 
580     if (is_decoder_fetchable(decoder)
581             && sk_OSSL_DECODER_push(decoder_stack, decoder) > 0)
582         OSSL_DECODER_up_ref(decoder);
583 }
584 
list_decoders(void)585 static void list_decoders(void)
586 {
587     STACK_OF(OSSL_DECODER) *decoders;
588     int i;
589 
590     decoders = sk_OSSL_DECODER_new(decoder_cmp);
591     if (decoders == NULL) {
592         BIO_printf(bio_err, "ERROR: Memory allocation\n");
593         return;
594     }
595     BIO_printf(bio_out, "Provided DECODERs:\n");
596     OSSL_DECODER_do_all_provided(app_get0_libctx(), collect_decoders,
597                                  decoders);
598     sk_OSSL_DECODER_sort(decoders);
599 
600     for (i = 0; i < sk_OSSL_DECODER_num(decoders); i++) {
601         OSSL_DECODER *k = sk_OSSL_DECODER_value(decoders, i);
602         STACK_OF(OPENSSL_CSTRING) *names = NULL;
603 
604         if (select_name != NULL && !OSSL_DECODER_is_a(k, select_name))
605             continue;
606 
607         names = sk_OPENSSL_CSTRING_new(name_cmp);
608         if (names != NULL && OSSL_DECODER_names_do_all(k, collect_names, names)) {
609             BIO_printf(bio_out, "  ");
610             print_names(bio_out, names);
611 
612             BIO_printf(bio_out, " @ %s (%s)\n",
613                        OSSL_PROVIDER_get0_name(OSSL_DECODER_get0_provider(k)),
614                        OSSL_DECODER_get0_properties(k));
615 
616             if (verbose) {
617                 const char *desc = OSSL_DECODER_get0_description(k);
618 
619                 if (desc != NULL)
620                     BIO_printf(bio_out, "    description: %s\n", desc);
621                 print_param_types("settable operation parameters",
622                                 OSSL_DECODER_settable_ctx_params(k), 4);
623             }
624         }
625         sk_OPENSSL_CSTRING_free(names);
626     }
627     sk_OSSL_DECODER_pop_free(decoders, OSSL_DECODER_free);
628 }
629 
DEFINE_STACK_OF(EVP_KEYMGMT)630 DEFINE_STACK_OF(EVP_KEYMGMT)
631 static int keymanager_cmp(const EVP_KEYMGMT * const *a,
632                           const EVP_KEYMGMT * const *b)
633 {
634     return strcmp(OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(*a)),
635                   OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(*b)));
636 }
637 
collect_keymanagers(EVP_KEYMGMT * km,void * stack)638 static void collect_keymanagers(EVP_KEYMGMT *km, void *stack)
639 {
640     STACK_OF(EVP_KEYMGMT) *km_stack = stack;
641 
642     if (is_keymgmt_fetchable(km)
643             && sk_EVP_KEYMGMT_push(km_stack, km) > 0)
644         EVP_KEYMGMT_up_ref(km);
645 }
646 
list_keymanagers(void)647 static void list_keymanagers(void)
648 {
649     int i;
650     STACK_OF(EVP_KEYMGMT) *km_stack = sk_EVP_KEYMGMT_new(keymanager_cmp);
651 
652     EVP_KEYMGMT_do_all_provided(app_get0_libctx(), collect_keymanagers,
653                                 km_stack);
654     sk_EVP_KEYMGMT_sort(km_stack);
655 
656     for (i = 0; i < sk_EVP_KEYMGMT_num(km_stack); i++) {
657         EVP_KEYMGMT *k = sk_EVP_KEYMGMT_value(km_stack, i);
658         STACK_OF(OPENSSL_CSTRING) *names = NULL;
659 
660         if (select_name != NULL && !EVP_KEYMGMT_is_a(k, select_name))
661             continue;
662 
663         names = sk_OPENSSL_CSTRING_new(name_cmp);
664         if (names != NULL && EVP_KEYMGMT_names_do_all(k, collect_names, names)) {
665             const char *desc = EVP_KEYMGMT_get0_description(k);
666 
667             BIO_printf(bio_out, "  Name: ");
668             if (desc != NULL)
669                 BIO_printf(bio_out, "%s", desc);
670             else
671                 BIO_printf(bio_out, "%s", sk_OPENSSL_CSTRING_value(names, 0));
672             BIO_printf(bio_out, "\n");
673             BIO_printf(bio_out, "    Type: Provider Algorithm\n");
674             BIO_printf(bio_out, "    IDs: ");
675             print_names(bio_out, names);
676             BIO_printf(bio_out, " @ %s\n",
677                     OSSL_PROVIDER_get0_name(EVP_KEYMGMT_get0_provider(k)));
678 
679             if (verbose) {
680                 print_param_types("settable key generation parameters",
681                                 EVP_KEYMGMT_gen_settable_params(k), 4);
682                 print_param_types("settable operation parameters",
683                                 EVP_KEYMGMT_settable_params(k), 4);
684                 print_param_types("retrievable operation parameters",
685                                 EVP_KEYMGMT_gettable_params(k), 4);
686             }
687         }
688         sk_OPENSSL_CSTRING_free(names);
689     }
690     sk_EVP_KEYMGMT_pop_free(km_stack, EVP_KEYMGMT_free);
691 }
692 
DEFINE_STACK_OF(EVP_SIGNATURE)693 DEFINE_STACK_OF(EVP_SIGNATURE)
694 static int signature_cmp(const EVP_SIGNATURE * const *a,
695                          const EVP_SIGNATURE * const *b)
696 {
697     return strcmp(OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(*a)),
698                   OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(*b)));
699 }
700 
collect_signatures(EVP_SIGNATURE * sig,void * stack)701 static void collect_signatures(EVP_SIGNATURE *sig, void *stack)
702 {
703     STACK_OF(EVP_SIGNATURE) *sig_stack = stack;
704 
705     if (is_signature_fetchable(sig)
706             && sk_EVP_SIGNATURE_push(sig_stack, sig) > 0)
707         EVP_SIGNATURE_up_ref(sig);
708 }
709 
list_signatures(void)710 static void list_signatures(void)
711 {
712     int i, count = 0;
713     STACK_OF(EVP_SIGNATURE) *sig_stack = sk_EVP_SIGNATURE_new(signature_cmp);
714 
715     EVP_SIGNATURE_do_all_provided(app_get0_libctx(), collect_signatures,
716                                   sig_stack);
717     sk_EVP_SIGNATURE_sort(sig_stack);
718 
719     for (i = 0; i < sk_EVP_SIGNATURE_num(sig_stack); i++) {
720         EVP_SIGNATURE *k = sk_EVP_SIGNATURE_value(sig_stack, i);
721         STACK_OF(OPENSSL_CSTRING) *names = NULL;
722 
723         if (select_name != NULL && !EVP_SIGNATURE_is_a(k, select_name))
724             continue;
725 
726         names = sk_OPENSSL_CSTRING_new(name_cmp);
727         if (names != NULL && EVP_SIGNATURE_names_do_all(k, collect_names, names)) {
728             count++;
729             BIO_printf(bio_out, "  ");
730             print_names(bio_out, names);
731 
732             BIO_printf(bio_out, " @ %s\n",
733                     OSSL_PROVIDER_get0_name(EVP_SIGNATURE_get0_provider(k)));
734 
735             if (verbose) {
736                 const char *desc = EVP_SIGNATURE_get0_description(k);
737 
738                 if (desc != NULL)
739                     BIO_printf(bio_out, "    description: %s\n", desc);
740                 print_param_types("settable operation parameters",
741                                 EVP_SIGNATURE_settable_ctx_params(k), 4);
742                 print_param_types("retrievable operation parameters",
743                                 EVP_SIGNATURE_gettable_ctx_params(k), 4);
744             }
745         }
746         sk_OPENSSL_CSTRING_free(names);
747     }
748     sk_EVP_SIGNATURE_pop_free(sig_stack, EVP_SIGNATURE_free);
749     if (count == 0)
750         BIO_printf(bio_out, " -\n");
751 }
752 
list_provider_tls_sigalgs(const OSSL_PARAM params[],void * data)753 static int list_provider_tls_sigalgs(const OSSL_PARAM params[], void *data)
754 {
755     const OSSL_PARAM *p;
756 
757     /* Get registered IANA name */
758     p = OSSL_PARAM_locate_const(params, OSSL_CAPABILITY_TLS_SIGALG_IANA_NAME);
759     if (p != NULL && p->data_type == OSSL_PARAM_UTF8_STRING) {
760         if (*((int *)data) > 0)
761             BIO_printf(bio_out, ":");
762         BIO_printf(bio_out, "%s", (char *)(p->data));
763         /* mark presence of a provider-based sigalg */
764         *((int *)data) = 2;
765     }
766     /* As built-in providers don't have this capability, never error */
767     return 1;
768 }
769 
list_tls_sigalg_caps(OSSL_PROVIDER * provider,void * cbdata)770 static int list_tls_sigalg_caps(OSSL_PROVIDER *provider, void *cbdata)
771 {
772     OSSL_PROVIDER_get_capabilities(provider, "TLS-SIGALG",
773                                    list_provider_tls_sigalgs,
774                                    cbdata);
775     /* As built-in providers don't have this capability, never error */
776     return 1;
777 }
778 
list_tls_signatures(void)779 static void list_tls_signatures(void)
780 {
781     int tls_sigalg_listed = 0;
782     char *builtin_sigalgs = SSL_get1_builtin_sigalgs(app_get0_libctx());
783 
784     if (builtin_sigalgs != NULL) {
785         if (builtin_sigalgs[0] != 0) {
786             BIO_printf(bio_out, "%s", builtin_sigalgs);
787             tls_sigalg_listed = 1;
788         }
789         OPENSSL_free(builtin_sigalgs);
790     }
791 
792     /* As built-in providers don't have this capability, never error */
793     OSSL_PROVIDER_do_all(NULL, list_tls_sigalg_caps, &tls_sigalg_listed);
794     if (tls_sigalg_listed < 2)
795         BIO_printf(bio_out,
796                    "\nNo TLS sig algs registered by currently active providers");
797     BIO_printf(bio_out, "\n");
798 }
799 
DEFINE_STACK_OF(EVP_KEM)800 DEFINE_STACK_OF(EVP_KEM)
801 static int kem_cmp(const EVP_KEM * const *a,
802                    const EVP_KEM * const *b)
803 {
804     return strcmp(OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(*a)),
805                   OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(*b)));
806 }
807 
collect_kem(EVP_KEM * kem,void * stack)808 static void collect_kem(EVP_KEM *kem, void *stack)
809 {
810     STACK_OF(EVP_KEM) *kem_stack = stack;
811 
812     if (is_kem_fetchable(kem)
813             && sk_EVP_KEM_push(kem_stack, kem) > 0)
814         EVP_KEM_up_ref(kem);
815 }
816 
list_kems(void)817 static void list_kems(void)
818 {
819     int i, count = 0;
820     STACK_OF(EVP_KEM) *kem_stack = sk_EVP_KEM_new(kem_cmp);
821 
822     EVP_KEM_do_all_provided(app_get0_libctx(), collect_kem, kem_stack);
823     sk_EVP_KEM_sort(kem_stack);
824 
825     for (i = 0; i < sk_EVP_KEM_num(kem_stack); i++) {
826         EVP_KEM *k = sk_EVP_KEM_value(kem_stack, i);
827         STACK_OF(OPENSSL_CSTRING) *names = NULL;
828 
829         if (select_name != NULL && !EVP_KEM_is_a(k, select_name))
830             continue;
831 
832         names = sk_OPENSSL_CSTRING_new(name_cmp);
833         if (names != NULL && EVP_KEM_names_do_all(k, collect_names, names)) {
834             count++;
835             BIO_printf(bio_out, "  ");
836             print_names(bio_out, names);
837 
838             BIO_printf(bio_out, " @ %s\n",
839                        OSSL_PROVIDER_get0_name(EVP_KEM_get0_provider(k)));
840 
841             if (verbose) {
842                 const char *desc = EVP_KEM_get0_description(k);
843 
844                 if (desc != NULL)
845                     BIO_printf(bio_out, "    description: %s\n", desc);
846                 print_param_types("settable operation parameters",
847                                 EVP_KEM_settable_ctx_params(k), 4);
848                 print_param_types("retrievable operation parameters",
849                                 EVP_KEM_gettable_ctx_params(k), 4);
850             }
851         }
852         sk_OPENSSL_CSTRING_free(names);
853     }
854     sk_EVP_KEM_pop_free(kem_stack, EVP_KEM_free);
855     if (count == 0)
856         BIO_printf(bio_out, " -\n");
857 }
858 
DEFINE_STACK_OF(EVP_ASYM_CIPHER)859 DEFINE_STACK_OF(EVP_ASYM_CIPHER)
860 static int asymcipher_cmp(const EVP_ASYM_CIPHER * const *a,
861                           const EVP_ASYM_CIPHER * const *b)
862 {
863     return strcmp(OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(*a)),
864                   OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(*b)));
865 }
866 
collect_asymciph(EVP_ASYM_CIPHER * asym_cipher,void * stack)867 static void collect_asymciph(EVP_ASYM_CIPHER *asym_cipher, void *stack)
868 {
869     STACK_OF(EVP_ASYM_CIPHER) *asym_cipher_stack = stack;
870 
871     if (is_asym_cipher_fetchable(asym_cipher)
872             && sk_EVP_ASYM_CIPHER_push(asym_cipher_stack, asym_cipher) > 0)
873         EVP_ASYM_CIPHER_up_ref(asym_cipher);
874 }
875 
list_asymciphers(void)876 static void list_asymciphers(void)
877 {
878     int i, count = 0;
879     STACK_OF(EVP_ASYM_CIPHER) *asymciph_stack =
880         sk_EVP_ASYM_CIPHER_new(asymcipher_cmp);
881 
882     EVP_ASYM_CIPHER_do_all_provided(app_get0_libctx(), collect_asymciph,
883                                     asymciph_stack);
884     sk_EVP_ASYM_CIPHER_sort(asymciph_stack);
885 
886     for (i = 0; i < sk_EVP_ASYM_CIPHER_num(asymciph_stack); i++) {
887         EVP_ASYM_CIPHER *k = sk_EVP_ASYM_CIPHER_value(asymciph_stack, i);
888         STACK_OF(OPENSSL_CSTRING) *names = NULL;
889 
890         if (select_name != NULL && !EVP_ASYM_CIPHER_is_a(k, select_name))
891             continue;
892 
893         names = sk_OPENSSL_CSTRING_new(name_cmp);
894         if (names != NULL
895                 && EVP_ASYM_CIPHER_names_do_all(k, collect_names, names)) {
896             count++;
897             BIO_printf(bio_out, "  ");
898             print_names(bio_out, names);
899 
900             BIO_printf(bio_out, " @ %s\n",
901                     OSSL_PROVIDER_get0_name(EVP_ASYM_CIPHER_get0_provider(k)));
902 
903             if (verbose) {
904                 const char *desc = EVP_ASYM_CIPHER_get0_description(k);
905 
906                 if (desc != NULL)
907                     BIO_printf(bio_out, "    description: %s\n", desc);
908                 print_param_types("settable operation parameters",
909                                 EVP_ASYM_CIPHER_settable_ctx_params(k), 4);
910                 print_param_types("retrievable operation parameters",
911                                 EVP_ASYM_CIPHER_gettable_ctx_params(k), 4);
912             }
913         }
914         sk_OPENSSL_CSTRING_free(names);
915     }
916     sk_EVP_ASYM_CIPHER_pop_free(asymciph_stack, EVP_ASYM_CIPHER_free);
917     if (count == 0)
918         BIO_printf(bio_out, " -\n");
919 }
920 
DEFINE_STACK_OF(EVP_KEYEXCH)921 DEFINE_STACK_OF(EVP_KEYEXCH)
922 static int kex_cmp(const EVP_KEYEXCH * const *a,
923                    const EVP_KEYEXCH * const *b)
924 {
925     return strcmp(OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(*a)),
926                   OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(*b)));
927 }
928 
collect_kex(EVP_KEYEXCH * kex,void * stack)929 static void collect_kex(EVP_KEYEXCH *kex, void *stack)
930 {
931     STACK_OF(EVP_KEYEXCH) *kex_stack = stack;
932 
933     if (is_keyexch_fetchable(kex)
934             && sk_EVP_KEYEXCH_push(kex_stack, kex) > 0)
935         EVP_KEYEXCH_up_ref(kex);
936 }
937 
list_keyexchanges(void)938 static void list_keyexchanges(void)
939 {
940     int i, count = 0;
941     STACK_OF(EVP_KEYEXCH) *kex_stack = sk_EVP_KEYEXCH_new(kex_cmp);
942 
943     EVP_KEYEXCH_do_all_provided(app_get0_libctx(), collect_kex, kex_stack);
944     sk_EVP_KEYEXCH_sort(kex_stack);
945 
946     for (i = 0; i < sk_EVP_KEYEXCH_num(kex_stack); i++) {
947         EVP_KEYEXCH *k = sk_EVP_KEYEXCH_value(kex_stack, i);
948         STACK_OF(OPENSSL_CSTRING) *names = NULL;
949 
950         if (select_name != NULL && !EVP_KEYEXCH_is_a(k, select_name))
951             continue;
952 
953         names = sk_OPENSSL_CSTRING_new(name_cmp);
954         if (names != NULL && EVP_KEYEXCH_names_do_all(k, collect_names, names)) {
955             count++;
956             BIO_printf(bio_out, "  ");
957             print_names(bio_out, names);
958 
959             BIO_printf(bio_out, " @ %s\n",
960                     OSSL_PROVIDER_get0_name(EVP_KEYEXCH_get0_provider(k)));
961 
962             if (verbose) {
963                 const char *desc = EVP_KEYEXCH_get0_description(k);
964 
965                 if (desc != NULL)
966                     BIO_printf(bio_out, "    description: %s\n", desc);
967                 print_param_types("settable operation parameters",
968                                 EVP_KEYEXCH_settable_ctx_params(k), 4);
969                 print_param_types("retrievable operation parameters",
970                                 EVP_KEYEXCH_gettable_ctx_params(k), 4);
971             }
972         }
973         sk_OPENSSL_CSTRING_free(names);
974     }
975     sk_EVP_KEYEXCH_pop_free(kex_stack, EVP_KEYEXCH_free);
976     if (count == 0)
977         BIO_printf(bio_out, " -\n");
978 }
979 
list_objects(void)980 static void list_objects(void)
981 {
982     int max_nid = OBJ_new_nid(0);
983     int i;
984     char *oid_buf = NULL;
985     int oid_size = 0;
986 
987     /* Skip 0, since that's NID_undef */
988     for (i = 1; i < max_nid; i++) {
989         const ASN1_OBJECT *obj = OBJ_nid2obj(i);
990         const char *sn = OBJ_nid2sn(i);
991         const char *ln = OBJ_nid2ln(i);
992         int n = 0;
993 
994         /*
995          * If one of the retrieved objects somehow generated an error,
996          * we ignore it.  The check for NID_undef below will detect the
997          * error and simply skip to the next NID.
998          */
999         ERR_clear_error();
1000 
1001         if (OBJ_obj2nid(obj) == NID_undef)
1002             continue;
1003 
1004         if ((n = OBJ_obj2txt(NULL, 0, obj, 1)) == 0) {
1005             BIO_printf(bio_out, "# None-OID object: %s, %s\n", sn, ln);
1006             continue;
1007         }
1008         if (n < 0)
1009             break;               /* Error */
1010 
1011         if (n > oid_size) {
1012             oid_buf = OPENSSL_realloc(oid_buf, n + 1);
1013             if (oid_buf == NULL) {
1014                 BIO_printf(bio_err, "ERROR: Memory allocation\n");
1015                 break;           /* Error */
1016             }
1017             oid_size = n + 1;
1018         }
1019         if (OBJ_obj2txt(oid_buf, oid_size, obj, 1) < 0)
1020             break;               /* Error */
1021         if (ln == NULL || strcmp(sn, ln) == 0)
1022             BIO_printf(bio_out, "%s = %s\n", sn, oid_buf);
1023         else
1024             BIO_printf(bio_out, "%s = %s, %s\n", sn, ln, oid_buf);
1025     }
1026 
1027     OPENSSL_free(oid_buf);
1028 }
1029 
list_options_for_command(const char * command)1030 static void list_options_for_command(const char *command)
1031 {
1032     const FUNCTION *fp;
1033     const OPTIONS *o;
1034 
1035     for (fp = functions; fp->name != NULL; fp++)
1036         if (strcmp(fp->name, command) == 0)
1037             break;
1038     if (fp->name == NULL) {
1039         BIO_printf(bio_err, "Invalid command '%s'; type \"help\" for a list.\n",
1040                    command);
1041         return;
1042     }
1043 
1044     if ((o = fp->help) == NULL)
1045         return;
1046 
1047     for ( ; o->name != NULL; o++) {
1048         char c = o->valtype;
1049 
1050         if (o->name == OPT_PARAM_STR)
1051             break;
1052 
1053         if (o->name == OPT_HELP_STR
1054                 || o->name == OPT_MORE_STR
1055                 || o->name == OPT_SECTION_STR
1056                 || o->name[0] == '\0')
1057             continue;
1058         BIO_printf(bio_out, "%s %c\n", o->name, c == '\0' ? '-' : c);
1059     }
1060     /* Always output the -- marker since it is sometimes documented. */
1061     BIO_printf(bio_out, "- -\n");
1062 }
1063 
is_md_available(const char * name)1064 static int is_md_available(const char *name)
1065 {
1066     EVP_MD *md;
1067     const char *propq = app_get0_propq();
1068 
1069     /* Look through providers' digests */
1070     ERR_set_mark();
1071     md = EVP_MD_fetch(app_get0_libctx(), name, propq);
1072     ERR_pop_to_mark();
1073     if (md != NULL) {
1074         EVP_MD_free(md);
1075         return 1;
1076     }
1077 
1078     return propq != NULL || get_digest_from_engine(name) == NULL ? 0 : 1;
1079 }
1080 
is_cipher_available(const char * name)1081 static int is_cipher_available(const char *name)
1082 {
1083     EVP_CIPHER *cipher;
1084     const char *propq = app_get0_propq();
1085 
1086     /* Look through providers' ciphers */
1087     ERR_set_mark();
1088     cipher = EVP_CIPHER_fetch(app_get0_libctx(), name, propq);
1089     ERR_pop_to_mark();
1090     if (cipher != NULL) {
1091         EVP_CIPHER_free(cipher);
1092         return 1;
1093     }
1094 
1095     return propq != NULL || get_cipher_from_engine(name) == NULL ? 0 : 1;
1096 }
1097 
list_type(FUNC_TYPE ft,int one)1098 static void list_type(FUNC_TYPE ft, int one)
1099 {
1100     FUNCTION *fp;
1101     int i = 0;
1102     DISPLAY_COLUMNS dc;
1103 
1104     memset(&dc, 0, sizeof(dc));
1105     if (!one)
1106         calculate_columns(functions, &dc);
1107 
1108     for (fp = functions; fp->name != NULL; fp++) {
1109         if (fp->type != ft)
1110             continue;
1111         switch (ft) {
1112         case FT_cipher:
1113             if (!is_cipher_available(fp->name))
1114                 continue;
1115             break;
1116         case FT_md:
1117             if (!is_md_available(fp->name))
1118                 continue;
1119             break;
1120         default:
1121             break;
1122         }
1123         if (one) {
1124             BIO_printf(bio_out, "%s\n", fp->name);
1125         } else {
1126             if (i % dc.columns == 0 && i > 0)
1127                 BIO_printf(bio_out, "\n");
1128             BIO_printf(bio_out, "%-*s", dc.width, fp->name);
1129             i++;
1130         }
1131     }
1132     if (!one)
1133         BIO_printf(bio_out, "\n\n");
1134 }
1135 
list_pkey(void)1136 static void list_pkey(void)
1137 {
1138 #ifndef OPENSSL_NO_DEPRECATED_3_0
1139     int i;
1140 
1141     if (select_name == NULL && include_legacy()) {
1142         BIO_printf(bio_out, "Legacy:\n");
1143         for (i = 0; i < EVP_PKEY_asn1_get_count(); i++) {
1144             const EVP_PKEY_ASN1_METHOD *ameth;
1145             int pkey_id, pkey_base_id, pkey_flags;
1146             const char *pinfo, *pem_str;
1147             ameth = EVP_PKEY_asn1_get0(i);
1148             EVP_PKEY_asn1_get0_info(&pkey_id, &pkey_base_id, &pkey_flags,
1149                                     &pinfo, &pem_str, ameth);
1150             if (pkey_flags & ASN1_PKEY_ALIAS) {
1151                 BIO_printf(bio_out, " Name: %s\n", OBJ_nid2ln(pkey_id));
1152                 BIO_printf(bio_out, "\tAlias for: %s\n",
1153                            OBJ_nid2ln(pkey_base_id));
1154             } else {
1155                 BIO_printf(bio_out, " Name: %s\n", pinfo);
1156                 BIO_printf(bio_out, "\tType: %s Algorithm\n",
1157                            pkey_flags & ASN1_PKEY_DYNAMIC ?
1158                            "External" : "Builtin");
1159                 BIO_printf(bio_out, "\tOID: %s\n", OBJ_nid2ln(pkey_id));
1160                 if (pem_str == NULL)
1161                     pem_str = "(none)";
1162                 BIO_printf(bio_out, "\tPEM string: %s\n", pem_str);
1163             }
1164         }
1165     }
1166 #endif
1167     BIO_printf(bio_out, "Provided:\n");
1168     BIO_printf(bio_out, " Key Managers:\n");
1169     list_keymanagers();
1170 }
1171 
list_pkey_meth(void)1172 static void list_pkey_meth(void)
1173 {
1174 #ifndef OPENSSL_NO_DEPRECATED_3_0
1175     size_t i;
1176     size_t meth_count = EVP_PKEY_meth_get_count();
1177 
1178     if (select_name == NULL && include_legacy()) {
1179         BIO_printf(bio_out, "Legacy:\n");
1180         for (i = 0; i < meth_count; i++) {
1181             const EVP_PKEY_METHOD *pmeth = EVP_PKEY_meth_get0(i);
1182             int pkey_id, pkey_flags;
1183 
1184             EVP_PKEY_meth_get0_info(&pkey_id, &pkey_flags, pmeth);
1185             BIO_printf(bio_out, " %s\n", OBJ_nid2ln(pkey_id));
1186             BIO_printf(bio_out, "\tType: %s Algorithm\n",
1187                        pkey_flags & ASN1_PKEY_DYNAMIC ?  "External" : "Builtin");
1188         }
1189     }
1190 #endif
1191     BIO_printf(bio_out, "Provided:\n");
1192     BIO_printf(bio_out, " Encryption:\n");
1193     list_asymciphers();
1194     BIO_printf(bio_out, " Key Exchange:\n");
1195     list_keyexchanges();
1196     BIO_printf(bio_out, " Signatures:\n");
1197     list_signatures();
1198     BIO_printf(bio_out, " Key encapsulation:\n");
1199     list_kems();
1200 }
1201 
DEFINE_STACK_OF(OSSL_STORE_LOADER)1202 DEFINE_STACK_OF(OSSL_STORE_LOADER)
1203 static int store_cmp(const OSSL_STORE_LOADER * const *a,
1204                      const OSSL_STORE_LOADER * const *b)
1205 {
1206     return strcmp(OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(*a)),
1207                   OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(*b)));
1208 }
1209 
collect_store_loaders(OSSL_STORE_LOADER * store,void * stack)1210 static void collect_store_loaders(OSSL_STORE_LOADER *store, void *stack)
1211 {
1212     STACK_OF(OSSL_STORE_LOADER) *store_stack = stack;
1213 
1214     if (sk_OSSL_STORE_LOADER_push(store_stack, store) > 0)
1215         OSSL_STORE_LOADER_up_ref(store);
1216 }
1217 
list_store_loaders(void)1218 static void list_store_loaders(void)
1219 {
1220     STACK_OF(OSSL_STORE_LOADER) *stores = sk_OSSL_STORE_LOADER_new(store_cmp);
1221     int i;
1222 
1223     if (stores == NULL) {
1224         BIO_printf(bio_err, "ERROR: Memory allocation\n");
1225         return;
1226     }
1227     BIO_printf(bio_out, "Provided STORE LOADERs:\n");
1228     OSSL_STORE_LOADER_do_all_provided(app_get0_libctx(), collect_store_loaders,
1229                                       stores);
1230     sk_OSSL_STORE_LOADER_sort(stores);
1231     for (i = 0; i < sk_OSSL_STORE_LOADER_num(stores); i++) {
1232         const OSSL_STORE_LOADER *m = sk_OSSL_STORE_LOADER_value(stores, i);
1233         STACK_OF(OPENSSL_CSTRING) *names = NULL;
1234 
1235         if (select_name != NULL && !OSSL_STORE_LOADER_is_a(m, select_name))
1236             continue;
1237 
1238         names = sk_OPENSSL_CSTRING_new(name_cmp);
1239         if (names != NULL && OSSL_STORE_LOADER_names_do_all(m, collect_names,
1240                                                             names)) {
1241             BIO_printf(bio_out, "  ");
1242             print_names(bio_out, names);
1243 
1244             BIO_printf(bio_out, " @ %s\n",
1245                        OSSL_PROVIDER_get0_name(OSSL_STORE_LOADER_get0_provider(m)));
1246         }
1247         sk_OPENSSL_CSTRING_free(names);
1248     }
1249     sk_OSSL_STORE_LOADER_pop_free(stores, OSSL_STORE_LOADER_free);
1250 }
1251 
DEFINE_STACK_OF(OSSL_PROVIDER)1252 DEFINE_STACK_OF(OSSL_PROVIDER)
1253 static int provider_cmp(const OSSL_PROVIDER * const *a,
1254                         const OSSL_PROVIDER * const *b)
1255 {
1256     return strcmp(OSSL_PROVIDER_get0_name(*a), OSSL_PROVIDER_get0_name(*b));
1257 }
1258 
collect_providers(OSSL_PROVIDER * provider,void * stack)1259 static int collect_providers(OSSL_PROVIDER *provider, void *stack)
1260 {
1261     STACK_OF(OSSL_PROVIDER) *provider_stack = stack;
1262 
1263     /*
1264      * If OK - result is the index of inserted data
1265      * Error - result is -1 or 0
1266      */
1267     return sk_OSSL_PROVIDER_push(provider_stack, provider) > 0 ? 1 : 0;
1268 }
1269 
list_provider_info(void)1270 static void list_provider_info(void)
1271 {
1272     STACK_OF(OSSL_PROVIDER) *providers = sk_OSSL_PROVIDER_new(provider_cmp);
1273     OSSL_PARAM params[5];
1274     char *name, *version, *buildinfo;
1275     int status;
1276     int i;
1277 
1278     if (providers == NULL) {
1279         BIO_printf(bio_err, "ERROR: Memory allocation\n");
1280         return;
1281     }
1282 
1283     if (OSSL_PROVIDER_do_all(NULL, &collect_providers, providers) != 1) {
1284         sk_OSSL_PROVIDER_free(providers);
1285         BIO_printf(bio_err, "ERROR: Memory allocation\n");
1286         return;
1287     }
1288 
1289     BIO_printf(bio_out, "Providers:\n");
1290     sk_OSSL_PROVIDER_sort(providers);
1291     for (i = 0; i < sk_OSSL_PROVIDER_num(providers); i++) {
1292         const OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(providers, i);
1293         const char *provname = OSSL_PROVIDER_get0_name(prov);
1294 
1295         BIO_printf(bio_out, "  %s\n", provname);
1296 
1297         /* Query the "known" information parameters, the order matches below */
1298         params[0] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_NAME,
1299                                                   &name, 0);
1300         params[1] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_VERSION,
1301                                                   &version, 0);
1302         params[2] = OSSL_PARAM_construct_int(OSSL_PROV_PARAM_STATUS, &status);
1303         params[3] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_BUILDINFO,
1304                                                   &buildinfo, 0);
1305         params[4] = OSSL_PARAM_construct_end();
1306         OSSL_PARAM_set_all_unmodified(params);
1307         if (!OSSL_PROVIDER_get_params(prov, params)) {
1308             BIO_printf(bio_err,
1309                        "WARNING: Unable to query provider parameters for %s\n",
1310                        provname);
1311         } else {
1312             /* Print out the provider information, the params order matches above */
1313             if (OSSL_PARAM_modified(params))
1314                 BIO_printf(bio_out, "    name: %s\n", name);
1315             if (OSSL_PARAM_modified(params + 1))
1316                 BIO_printf(bio_out, "    version: %s\n", version);
1317             if (OSSL_PARAM_modified(params + 2))
1318                 BIO_printf(bio_out, "    status: %sactive\n", status ? "" : "in");
1319             if (verbose) {
1320                 if (OSSL_PARAM_modified(params + 3))
1321                     BIO_printf(bio_out, "    build info: %s\n", buildinfo);
1322                 print_param_types("gettable provider parameters",
1323                                   OSSL_PROVIDER_gettable_params(prov), 4);
1324             }
1325         }
1326     }
1327     sk_OSSL_PROVIDER_free(providers);
1328 }
1329 
1330 #ifndef OPENSSL_NO_DEPRECATED_3_0
list_engines(void)1331 static void list_engines(void)
1332 {
1333 # ifndef OPENSSL_NO_ENGINE
1334     ENGINE *e;
1335 
1336     BIO_puts(bio_out, "Engines:\n");
1337     e = ENGINE_get_first();
1338     while (e) {
1339         BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
1340         e = ENGINE_get_next(e);
1341     }
1342 # else
1343     BIO_puts(bio_out, "Engine support is disabled.\n");
1344 # endif
1345 }
1346 #endif
1347 
list_disabled(void)1348 static void list_disabled(void)
1349 {
1350     BIO_puts(bio_out, "Disabled algorithms:\n");
1351 #ifdef OPENSSL_NO_ARGON2
1352     BIO_puts(bio_out, "ARGON2\n");
1353 #endif
1354 #ifdef OPENSSL_NO_ARIA
1355     BIO_puts(bio_out, "ARIA\n");
1356 #endif
1357 #ifdef OPENSSL_NO_BF
1358     BIO_puts(bio_out, "BF\n");
1359 #endif
1360 #ifdef OPENSSL_NO_BLAKE2
1361     BIO_puts(bio_out, "BLAKE2\n");
1362 #endif
1363 #ifdef OPENSSL_NO_CAMELLIA
1364     BIO_puts(bio_out, "CAMELLIA\n");
1365 #endif
1366 #ifdef OPENSSL_NO_CAST
1367     BIO_puts(bio_out, "CAST\n");
1368 #endif
1369 #ifdef OPENSSL_NO_CMAC
1370     BIO_puts(bio_out, "CMAC\n");
1371 #endif
1372 #ifdef OPENSSL_NO_CMS
1373     BIO_puts(bio_out, "CMS\n");
1374 #endif
1375 #ifdef OPENSSL_NO_COMP
1376     BIO_puts(bio_out, "COMP\n");
1377 #endif
1378 #ifdef OPENSSL_NO_DES
1379     BIO_puts(bio_out, "DES\n");
1380 #endif
1381 #ifdef OPENSSL_NO_DGRAM
1382     BIO_puts(bio_out, "DGRAM\n");
1383 #endif
1384 #ifdef OPENSSL_NO_DH
1385     BIO_puts(bio_out, "DH\n");
1386 #endif
1387 #ifdef OPENSSL_NO_DSA
1388     BIO_puts(bio_out, "DSA\n");
1389 #endif
1390 #if defined(OPENSSL_NO_DTLS)
1391     BIO_puts(bio_out, "DTLS\n");
1392 #endif
1393 #if defined(OPENSSL_NO_DTLS1)
1394     BIO_puts(bio_out, "DTLS1\n");
1395 #endif
1396 #if defined(OPENSSL_NO_DTLS1_2)
1397     BIO_puts(bio_out, "DTLS1_2\n");
1398 #endif
1399 #ifdef OPENSSL_NO_EC
1400     BIO_puts(bio_out, "EC\n");
1401 #endif
1402 #ifdef OPENSSL_NO_ECX
1403     BIO_puts(bio_out, "ECX\n");
1404 #endif
1405 #ifdef OPENSSL_NO_EC2M
1406     BIO_puts(bio_out, "EC2M\n");
1407 #endif
1408 #if defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
1409     BIO_puts(bio_out, "ENGINE\n");
1410 #endif
1411 #ifdef OPENSSL_NO_GOST
1412     BIO_puts(bio_out, "GOST\n");
1413 #endif
1414 #ifdef OPENSSL_NO_IDEA
1415     BIO_puts(bio_out, "IDEA\n");
1416 #endif
1417 #ifdef OPENSSL_NO_MD2
1418     BIO_puts(bio_out, "MD2\n");
1419 #endif
1420 #ifdef OPENSSL_NO_MD4
1421     BIO_puts(bio_out, "MD4\n");
1422 #endif
1423 #ifdef OPENSSL_NO_MD5
1424     BIO_puts(bio_out, "MD5\n");
1425 #endif
1426 #ifdef OPENSSL_NO_MDC2
1427     BIO_puts(bio_out, "MDC2\n");
1428 #endif
1429 #ifdef OPENSSL_NO_OCB
1430     BIO_puts(bio_out, "OCB\n");
1431 #endif
1432 #ifdef OPENSSL_NO_OCSP
1433     BIO_puts(bio_out, "OCSP\n");
1434 #endif
1435 #ifdef OPENSSL_NO_PSK
1436     BIO_puts(bio_out, "PSK\n");
1437 #endif
1438 #ifdef OPENSSL_NO_RC2
1439     BIO_puts(bio_out, "RC2\n");
1440 #endif
1441 #ifdef OPENSSL_NO_RC4
1442     BIO_puts(bio_out, "RC4\n");
1443 #endif
1444 #ifdef OPENSSL_NO_RC5
1445     BIO_puts(bio_out, "RC5\n");
1446 #endif
1447 #ifdef OPENSSL_NO_RMD160
1448     BIO_puts(bio_out, "RMD160\n");
1449 #endif
1450 #ifdef OPENSSL_NO_SCRYPT
1451     BIO_puts(bio_out, "SCRYPT\n");
1452 #endif
1453 #ifdef OPENSSL_NO_SCTP
1454     BIO_puts(bio_out, "SCTP\n");
1455 #endif
1456 #ifdef OPENSSL_NO_SEED
1457     BIO_puts(bio_out, "SEED\n");
1458 #endif
1459 #ifdef OPENSSL_NO_SM2
1460     BIO_puts(bio_out, "SM2\n");
1461 #endif
1462 #ifdef OPENSSL_NO_SM3
1463     BIO_puts(bio_out, "SM3\n");
1464 #endif
1465 #ifdef OPENSSL_NO_SM4
1466     BIO_puts(bio_out, "SM4\n");
1467 #endif
1468 #ifdef OPENSSL_NO_SOCK
1469     BIO_puts(bio_out, "SOCK\n");
1470 #endif
1471 #ifdef OPENSSL_NO_SRP
1472     BIO_puts(bio_out, "SRP\n");
1473 #endif
1474 #ifdef OPENSSL_NO_SRTP
1475     BIO_puts(bio_out, "SRTP\n");
1476 #endif
1477 #ifdef OPENSSL_NO_SSL3
1478     BIO_puts(bio_out, "SSL3\n");
1479 #endif
1480 #ifdef OPENSSL_NO_TLS1
1481     BIO_puts(bio_out, "TLS1\n");
1482 #endif
1483 #ifdef OPENSSL_NO_TLS1_1
1484     BIO_puts(bio_out, "TLS1_1\n");
1485 #endif
1486 #ifdef OPENSSL_NO_TLS1_2
1487     BIO_puts(bio_out, "TLS1_2\n");
1488 #endif
1489 #ifdef OPENSSL_NO_WHIRLPOOL
1490     BIO_puts(bio_out, "WHIRLPOOL\n");
1491 #endif
1492 #ifdef OPENSSL_NO_ZLIB
1493     BIO_puts(bio_out, "ZLIB\n");
1494 #endif
1495 #ifdef OPENSSL_NO_BROTLI
1496     BIO_puts(bio_out, "BROTLI\n");
1497 #endif
1498 #ifdef OPENSSL_NO_ZSTD
1499     BIO_puts(bio_out, "ZSTD\n");
1500 #endif
1501 }
1502 
1503 /* Unified enum for help and list commands. */
1504 typedef enum HELPLIST_CHOICE {
1505     OPT_COMMON,
1506     OPT_ONE, OPT_VERBOSE,
1507     OPT_ALL_ARGORITHMS,
1508     OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
1509     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
1510     OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
1511     OPT_KDF_ALGORITHMS, OPT_RANDOM_INSTANCES, OPT_RANDOM_GENERATORS,
1512     OPT_ENCODERS, OPT_DECODERS, OPT_KEYMANAGERS, OPT_KEYEXCHANGE_ALGORITHMS,
1513     OPT_KEM_ALGORITHMS, OPT_SIGNATURE_ALGORITHMS,
1514     OPT_TLS_SIGNATURE_ALGORITHMS, OPT_ASYM_CIPHER_ALGORITHMS,
1515     OPT_STORE_LOADERS, OPT_PROVIDER_INFO, OPT_OBJECTS,
1516     OPT_SELECT_NAME,
1517 #ifndef OPENSSL_NO_DEPRECATED_3_0
1518     OPT_ENGINES,
1519 #endif
1520     OPT_PROV_ENUM
1521 } HELPLIST_CHOICE;
1522 
1523 const OPTIONS list_options[] = {
1524 
1525     OPT_SECTION("General"),
1526     {"help", OPT_HELP, '-', "Display this summary"},
1527 
1528     OPT_SECTION("Output"),
1529     {"1", OPT_ONE, '-', "List in one column"},
1530     {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
1531     {"select", OPT_SELECT_NAME, 's', "Select a single algorithm"},
1532     {"commands", OPT_COMMANDS, '-', "List of standard commands"},
1533     {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
1534     {"all-algorithms", OPT_ALL_ARGORITHMS, '-', "List of all algorithms"},
1535 #ifndef OPENSSL_NO_DEPRECATED_3_0
1536     {"digest-commands", OPT_DIGEST_COMMANDS, '-',
1537      "List of message digest commands (deprecated)"},
1538 #endif
1539     {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
1540      "List of message digest algorithms"},
1541     {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
1542      "List of key derivation and pseudo random function algorithms"},
1543     {"random-instances", OPT_RANDOM_INSTANCES, '-',
1544      "List the primary, public and private random number generator details"},
1545     {"random-generators", OPT_RANDOM_GENERATORS, '-',
1546      "List of random number generators"},
1547     {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
1548      "List of message authentication code algorithms"},
1549 #ifndef OPENSSL_NO_DEPRECATED_3_0
1550     {"cipher-commands", OPT_CIPHER_COMMANDS, '-',
1551      "List of cipher commands (deprecated)"},
1552 #endif
1553     {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
1554      "List of symmetric cipher algorithms"},
1555     {"encoders", OPT_ENCODERS, '-', "List of encoding methods" },
1556     {"decoders", OPT_DECODERS, '-', "List of decoding methods" },
1557     {"key-managers", OPT_KEYMANAGERS, '-', "List of key managers" },
1558     {"key-exchange-algorithms", OPT_KEYEXCHANGE_ALGORITHMS, '-',
1559      "List of key exchange algorithms" },
1560     {"kem-algorithms", OPT_KEM_ALGORITHMS, '-',
1561      "List of key encapsulation mechanism algorithms" },
1562     {"signature-algorithms", OPT_SIGNATURE_ALGORITHMS, '-',
1563      "List of signature algorithms" },
1564     {"tls-signature-algorithms", OPT_TLS_SIGNATURE_ALGORITHMS, '-',
1565      "List of TLS signature algorithms" },
1566     {"asymcipher-algorithms", OPT_ASYM_CIPHER_ALGORITHMS, '-',
1567       "List of asymmetric cipher algorithms" },
1568     {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
1569      "List of public key algorithms"},
1570     {"public-key-methods", OPT_PK_METHOD, '-',
1571      "List of public key methods"},
1572     {"store-loaders", OPT_STORE_LOADERS, '-',
1573      "List of store loaders"},
1574     {"providers", OPT_PROVIDER_INFO, '-',
1575      "List of provider information"},
1576 #ifndef OPENSSL_NO_DEPRECATED_3_0
1577     {"engines", OPT_ENGINES, '-',
1578      "List of loaded engines"},
1579 #endif
1580     {"disabled", OPT_DISABLED, '-', "List of disabled features"},
1581     {"options", OPT_OPTIONS, 's',
1582      "List options for specified command"},
1583     {"objects", OPT_OBJECTS, '-',
1584      "List built in objects (OID<->name mappings)"},
1585 
1586     OPT_PROV_OPTIONS,
1587     {NULL}
1588 };
1589 
list_main(int argc,char ** argv)1590 int list_main(int argc, char **argv)
1591 {
1592     char *prog;
1593     HELPLIST_CHOICE o;
1594     int one = 0, done = 0;
1595     int print_newline = 0;
1596     struct {
1597         unsigned int commands:1;
1598         unsigned int all_algorithms:1;
1599         unsigned int random_instances:1;
1600         unsigned int random_generators:1;
1601         unsigned int digest_commands:1;
1602         unsigned int digest_algorithms:1;
1603         unsigned int kdf_algorithms:1;
1604         unsigned int mac_algorithms:1;
1605         unsigned int cipher_commands:1;
1606         unsigned int cipher_algorithms:1;
1607         unsigned int encoder_algorithms:1;
1608         unsigned int decoder_algorithms:1;
1609         unsigned int keymanager_algorithms:1;
1610         unsigned int signature_algorithms:1;
1611         unsigned int tls_signature_algorithms:1;
1612         unsigned int keyexchange_algorithms:1;
1613         unsigned int kem_algorithms:1;
1614         unsigned int asym_cipher_algorithms:1;
1615         unsigned int pk_algorithms:1;
1616         unsigned int pk_method:1;
1617         unsigned int store_loaders:1;
1618         unsigned int provider_info:1;
1619 #ifndef OPENSSL_NO_DEPRECATED_3_0
1620         unsigned int engines:1;
1621 #endif
1622         unsigned int disabled:1;
1623         unsigned int objects:1;
1624         unsigned int options:1;
1625     } todo = { 0, };
1626 
1627     verbose = 0;                 /* Clear a possible previous call */
1628 
1629     prog = opt_init(argc, argv, list_options);
1630     while ((o = opt_next()) != OPT_EOF) {
1631         switch (o) {
1632         case OPT_EOF:  /* Never hit, but suppresses warning */
1633         case OPT_ERR:
1634 opthelp:
1635             BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
1636             return 1;
1637         case OPT_HELP:
1638             opt_help(list_options);
1639             return 0;
1640         case OPT_ONE:
1641             one = 1;
1642             break;
1643         case OPT_ALL_ARGORITHMS:
1644             todo.all_algorithms = 1;
1645             break;
1646         case OPT_COMMANDS:
1647             todo.commands = 1;
1648             break;
1649         case OPT_DIGEST_COMMANDS:
1650             todo.digest_commands = 1;
1651             break;
1652         case OPT_DIGEST_ALGORITHMS:
1653             todo.digest_algorithms = 1;
1654             break;
1655         case OPT_KDF_ALGORITHMS:
1656             todo.kdf_algorithms = 1;
1657             break;
1658         case OPT_RANDOM_INSTANCES:
1659             todo.random_instances = 1;
1660             break;
1661         case OPT_RANDOM_GENERATORS:
1662             todo.random_generators = 1;
1663             break;
1664         case OPT_MAC_ALGORITHMS:
1665             todo.mac_algorithms = 1;
1666             break;
1667         case OPT_CIPHER_COMMANDS:
1668             todo.cipher_commands = 1;
1669             break;
1670         case OPT_CIPHER_ALGORITHMS:
1671             todo.cipher_algorithms = 1;
1672             break;
1673         case OPT_ENCODERS:
1674             todo.encoder_algorithms = 1;
1675             break;
1676         case OPT_DECODERS:
1677             todo.decoder_algorithms = 1;
1678             break;
1679         case OPT_KEYMANAGERS:
1680             todo.keymanager_algorithms = 1;
1681             break;
1682         case OPT_SIGNATURE_ALGORITHMS:
1683             todo.signature_algorithms = 1;
1684             break;
1685         case OPT_TLS_SIGNATURE_ALGORITHMS:
1686             todo.tls_signature_algorithms = 1;
1687             break;
1688         case OPT_KEYEXCHANGE_ALGORITHMS:
1689             todo.keyexchange_algorithms = 1;
1690             break;
1691         case OPT_KEM_ALGORITHMS:
1692             todo.kem_algorithms = 1;
1693             break;
1694         case OPT_ASYM_CIPHER_ALGORITHMS:
1695             todo.asym_cipher_algorithms = 1;
1696             break;
1697         case OPT_PK_ALGORITHMS:
1698             todo.pk_algorithms = 1;
1699             break;
1700         case OPT_PK_METHOD:
1701             todo.pk_method = 1;
1702             break;
1703         case OPT_STORE_LOADERS:
1704             todo.store_loaders = 1;
1705             break;
1706         case OPT_PROVIDER_INFO:
1707             todo.provider_info = 1;
1708             break;
1709 #ifndef OPENSSL_NO_DEPRECATED_3_0
1710         case OPT_ENGINES:
1711             todo.engines = 1;
1712             break;
1713 #endif
1714         case OPT_DISABLED:
1715             todo.disabled = 1;
1716             break;
1717         case OPT_OBJECTS:
1718             todo.objects = 1;
1719             break;
1720         case OPT_OPTIONS:
1721             list_options_for_command(opt_arg());
1722             break;
1723         case OPT_VERBOSE:
1724             verbose = 1;
1725             break;
1726         case OPT_SELECT_NAME:
1727             select_name = opt_arg();
1728             break;
1729         case OPT_PROV_CASES:
1730             if (!opt_provider(o))
1731                 return 1;
1732             break;
1733         }
1734         done = 1;
1735     }
1736 
1737     /* No extra arguments. */
1738     if (!opt_check_rest_arg(NULL))
1739         goto opthelp;
1740 
1741 #define MAYBE_ADD_NL(cmd) \
1742     do { \
1743         if (print_newline++) { \
1744             BIO_printf(bio_out, "\n"); \
1745         } \
1746         cmd; \
1747     } while (0)
1748 
1749     if (todo.commands)
1750         MAYBE_ADD_NL(list_type(FT_general, one));
1751     if (todo.all_algorithms) {
1752         MAYBE_ADD_NL({});
1753 
1754         BIO_printf(bio_out, "Digests:\n");
1755         list_digests(" ");
1756         BIO_printf(bio_out, "\nSymmetric Ciphers:\n");
1757         list_ciphers(" ");
1758         BIO_printf(bio_out, "\n");
1759         list_kdfs();
1760         BIO_printf(bio_out, "\n");
1761         list_macs();
1762 
1763         BIO_printf(bio_out, "\nProvided Asymmetric Encryption:\n");
1764         list_asymciphers();
1765         BIO_printf(bio_out, "\nProvided Key Exchange:\n");
1766         list_keyexchanges();
1767         BIO_printf(bio_out, "\nProvided Signatures:\n");
1768         list_signatures();
1769         BIO_printf(bio_out, "\nProvided Key encapsulation:\n");
1770         list_kems();
1771         BIO_printf(bio_out, "\nProvided Key managers:\n");
1772         list_keymanagers();
1773 
1774         BIO_printf(bio_out, "\n");
1775         list_encoders();
1776         BIO_printf(bio_out, "\n");
1777         list_decoders();
1778         BIO_printf(bio_out, "\n");
1779         list_store_loaders();
1780     }
1781     if (todo.random_instances)
1782         MAYBE_ADD_NL(list_random_instances());
1783     if (todo.random_generators)
1784         MAYBE_ADD_NL(list_random_generators());
1785     if (todo.digest_commands)
1786         MAYBE_ADD_NL(list_type(FT_md, one));
1787     if (todo.digest_algorithms)
1788         MAYBE_ADD_NL(list_digests(""));
1789     if (todo.kdf_algorithms)
1790         MAYBE_ADD_NL(list_kdfs());
1791     if (todo.mac_algorithms)
1792         MAYBE_ADD_NL(list_macs());
1793     if (todo.cipher_commands)
1794         MAYBE_ADD_NL(list_type(FT_cipher, one));
1795     if (todo.cipher_algorithms)
1796         MAYBE_ADD_NL(list_ciphers(""));
1797     if (todo.encoder_algorithms)
1798         MAYBE_ADD_NL(list_encoders());
1799     if (todo.decoder_algorithms)
1800         MAYBE_ADD_NL(list_decoders());
1801     if (todo.keymanager_algorithms)
1802         MAYBE_ADD_NL(list_keymanagers());
1803     if (todo.signature_algorithms)
1804         MAYBE_ADD_NL(list_signatures());
1805     if (todo.tls_signature_algorithms)
1806         MAYBE_ADD_NL(list_tls_signatures());
1807     if (todo.asym_cipher_algorithms)
1808         MAYBE_ADD_NL(list_asymciphers());
1809     if (todo.keyexchange_algorithms)
1810         MAYBE_ADD_NL(list_keyexchanges());
1811     if (todo.kem_algorithms)
1812         MAYBE_ADD_NL(list_kems());
1813     if (todo.pk_algorithms)
1814         MAYBE_ADD_NL(list_pkey());
1815     if (todo.pk_method)
1816         MAYBE_ADD_NL(list_pkey_meth());
1817     if (todo.store_loaders)
1818         MAYBE_ADD_NL(list_store_loaders());
1819     if (todo.provider_info)
1820         MAYBE_ADD_NL(list_provider_info());
1821 #ifndef OPENSSL_NO_DEPRECATED_3_0
1822     if (todo.engines)
1823         MAYBE_ADD_NL(list_engines());
1824 #endif
1825     if (todo.disabled)
1826         MAYBE_ADD_NL(list_disabled());
1827     if (todo.objects)
1828         MAYBE_ADD_NL(list_objects());
1829 
1830 #undef MAYBE_ADD_NL
1831 
1832     if (!done)
1833         goto opthelp;
1834 
1835     return 0;
1836 }
1837