list.c 56 KB

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