list.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776
  1. /*
  2. * Copyright 1995-2023 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. /*
  1034. * If OK - result is the index of inserted data
  1035. * Error - result is -1 or 0
  1036. */
  1037. return sk_OSSL_PROVIDER_push(provider_stack, provider) > 0 ? 1 : 0;
  1038. }
  1039. static void list_provider_info(void)
  1040. {
  1041. STACK_OF(OSSL_PROVIDER) *providers = sk_OSSL_PROVIDER_new(provider_cmp);
  1042. OSSL_PARAM params[5];
  1043. char *name, *version, *buildinfo;
  1044. int status;
  1045. int i;
  1046. if (providers == NULL) {
  1047. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  1048. return;
  1049. }
  1050. if (OSSL_PROVIDER_do_all(NULL, &collect_providers, providers) != 1) {
  1051. sk_OSSL_PROVIDER_free(providers);
  1052. BIO_printf(bio_err, "ERROR: Memory allocation\n");
  1053. return;
  1054. }
  1055. BIO_printf(bio_out, "Providers:\n");
  1056. sk_OSSL_PROVIDER_sort(providers);
  1057. for (i = 0; i < sk_OSSL_PROVIDER_num(providers); i++) {
  1058. const OSSL_PROVIDER *prov = sk_OSSL_PROVIDER_value(providers, i);
  1059. const char *provname = OSSL_PROVIDER_get0_name(prov);
  1060. BIO_printf(bio_out, " %s\n", provname);
  1061. /* Query the "known" information parameters, the order matches below */
  1062. params[0] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_NAME,
  1063. &name, 0);
  1064. params[1] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_VERSION,
  1065. &version, 0);
  1066. params[2] = OSSL_PARAM_construct_int(OSSL_PROV_PARAM_STATUS, &status);
  1067. params[3] = OSSL_PARAM_construct_utf8_ptr(OSSL_PROV_PARAM_BUILDINFO,
  1068. &buildinfo, 0);
  1069. params[4] = OSSL_PARAM_construct_end();
  1070. OSSL_PARAM_set_all_unmodified(params);
  1071. if (!OSSL_PROVIDER_get_params(prov, params)) {
  1072. BIO_printf(bio_err,
  1073. "WARNING: Unable to query provider parameters for %s\n",
  1074. provname);
  1075. } else {
  1076. /* Print out the provider information, the params order matches above */
  1077. if (OSSL_PARAM_modified(params))
  1078. BIO_printf(bio_out, " name: %s\n", name);
  1079. if (OSSL_PARAM_modified(params + 1))
  1080. BIO_printf(bio_out, " version: %s\n", version);
  1081. if (OSSL_PARAM_modified(params + 2))
  1082. BIO_printf(bio_out, " status: %sactive\n", status ? "" : "in");
  1083. if (verbose) {
  1084. if (OSSL_PARAM_modified(params + 3))
  1085. BIO_printf(bio_out, " build info: %s\n", buildinfo);
  1086. print_param_types("gettable provider parameters",
  1087. OSSL_PROVIDER_gettable_params(prov), 4);
  1088. }
  1089. }
  1090. }
  1091. sk_OSSL_PROVIDER_free(providers);
  1092. }
  1093. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1094. static void list_engines(void)
  1095. {
  1096. # ifndef OPENSSL_NO_ENGINE
  1097. ENGINE *e;
  1098. BIO_puts(bio_out, "Engines:\n");
  1099. e = ENGINE_get_first();
  1100. while (e) {
  1101. BIO_printf(bio_out, "%s\n", ENGINE_get_id(e));
  1102. e = ENGINE_get_next(e);
  1103. }
  1104. # else
  1105. BIO_puts(bio_out, "Engine support is disabled.\n");
  1106. # endif
  1107. }
  1108. #endif
  1109. static void list_disabled(void)
  1110. {
  1111. BIO_puts(bio_out, "Disabled algorithms:\n");
  1112. #ifdef OPENSSL_NO_ARGON2
  1113. BIO_puts(bio_out, "ARGON2\n");
  1114. #endif
  1115. #ifdef OPENSSL_NO_ARIA
  1116. BIO_puts(bio_out, "ARIA\n");
  1117. #endif
  1118. #ifdef OPENSSL_NO_BF
  1119. BIO_puts(bio_out, "BF\n");
  1120. #endif
  1121. #ifdef OPENSSL_NO_BLAKE2
  1122. BIO_puts(bio_out, "BLAKE2\n");
  1123. #endif
  1124. #ifdef OPENSSL_NO_CAMELLIA
  1125. BIO_puts(bio_out, "CAMELLIA\n");
  1126. #endif
  1127. #ifdef OPENSSL_NO_CAST
  1128. BIO_puts(bio_out, "CAST\n");
  1129. #endif
  1130. #ifdef OPENSSL_NO_CMAC
  1131. BIO_puts(bio_out, "CMAC\n");
  1132. #endif
  1133. #ifdef OPENSSL_NO_CMS
  1134. BIO_puts(bio_out, "CMS\n");
  1135. #endif
  1136. #ifdef OPENSSL_NO_COMP
  1137. BIO_puts(bio_out, "COMP\n");
  1138. #endif
  1139. #ifdef OPENSSL_NO_DES
  1140. BIO_puts(bio_out, "DES\n");
  1141. #endif
  1142. #ifdef OPENSSL_NO_DGRAM
  1143. BIO_puts(bio_out, "DGRAM\n");
  1144. #endif
  1145. #ifdef OPENSSL_NO_DH
  1146. BIO_puts(bio_out, "DH\n");
  1147. #endif
  1148. #ifdef OPENSSL_NO_DSA
  1149. BIO_puts(bio_out, "DSA\n");
  1150. #endif
  1151. #if defined(OPENSSL_NO_DTLS)
  1152. BIO_puts(bio_out, "DTLS\n");
  1153. #endif
  1154. #if defined(OPENSSL_NO_DTLS1)
  1155. BIO_puts(bio_out, "DTLS1\n");
  1156. #endif
  1157. #if defined(OPENSSL_NO_DTLS1_2)
  1158. BIO_puts(bio_out, "DTLS1_2\n");
  1159. #endif
  1160. #ifdef OPENSSL_NO_EC
  1161. BIO_puts(bio_out, "EC\n");
  1162. #endif
  1163. #ifdef OPENSSL_NO_ECX
  1164. BIO_puts(bio_out, "ECX\n");
  1165. #endif
  1166. #ifdef OPENSSL_NO_EC2M
  1167. BIO_puts(bio_out, "EC2M\n");
  1168. #endif
  1169. #if defined(OPENSSL_NO_ENGINE) && !defined(OPENSSL_NO_DEPRECATED_3_0)
  1170. BIO_puts(bio_out, "ENGINE\n");
  1171. #endif
  1172. #ifdef OPENSSL_NO_GOST
  1173. BIO_puts(bio_out, "GOST\n");
  1174. #endif
  1175. #ifdef OPENSSL_NO_IDEA
  1176. BIO_puts(bio_out, "IDEA\n");
  1177. #endif
  1178. #ifdef OPENSSL_NO_MD2
  1179. BIO_puts(bio_out, "MD2\n");
  1180. #endif
  1181. #ifdef OPENSSL_NO_MD4
  1182. BIO_puts(bio_out, "MD4\n");
  1183. #endif
  1184. #ifdef OPENSSL_NO_MD5
  1185. BIO_puts(bio_out, "MD5\n");
  1186. #endif
  1187. #ifdef OPENSSL_NO_MDC2
  1188. BIO_puts(bio_out, "MDC2\n");
  1189. #endif
  1190. #ifdef OPENSSL_NO_OCB
  1191. BIO_puts(bio_out, "OCB\n");
  1192. #endif
  1193. #ifdef OPENSSL_NO_OCSP
  1194. BIO_puts(bio_out, "OCSP\n");
  1195. #endif
  1196. #ifdef OPENSSL_NO_PSK
  1197. BIO_puts(bio_out, "PSK\n");
  1198. #endif
  1199. #ifdef OPENSSL_NO_RC2
  1200. BIO_puts(bio_out, "RC2\n");
  1201. #endif
  1202. #ifdef OPENSSL_NO_RC4
  1203. BIO_puts(bio_out, "RC4\n");
  1204. #endif
  1205. #ifdef OPENSSL_NO_RC5
  1206. BIO_puts(bio_out, "RC5\n");
  1207. #endif
  1208. #ifdef OPENSSL_NO_RMD160
  1209. BIO_puts(bio_out, "RMD160\n");
  1210. #endif
  1211. #ifdef OPENSSL_NO_SCRYPT
  1212. BIO_puts(bio_out, "SCRYPT\n");
  1213. #endif
  1214. #ifdef OPENSSL_NO_SCTP
  1215. BIO_puts(bio_out, "SCTP\n");
  1216. #endif
  1217. #ifdef OPENSSL_NO_SEED
  1218. BIO_puts(bio_out, "SEED\n");
  1219. #endif
  1220. #ifdef OPENSSL_NO_SM2
  1221. BIO_puts(bio_out, "SM2\n");
  1222. #endif
  1223. #ifdef OPENSSL_NO_SM3
  1224. BIO_puts(bio_out, "SM3\n");
  1225. #endif
  1226. #ifdef OPENSSL_NO_SM4
  1227. BIO_puts(bio_out, "SM4\n");
  1228. #endif
  1229. #ifdef OPENSSL_NO_SOCK
  1230. BIO_puts(bio_out, "SOCK\n");
  1231. #endif
  1232. #ifdef OPENSSL_NO_SRP
  1233. BIO_puts(bio_out, "SRP\n");
  1234. #endif
  1235. #ifdef OPENSSL_NO_SRTP
  1236. BIO_puts(bio_out, "SRTP\n");
  1237. #endif
  1238. #ifdef OPENSSL_NO_SSL3
  1239. BIO_puts(bio_out, "SSL3\n");
  1240. #endif
  1241. #ifdef OPENSSL_NO_TLS1
  1242. BIO_puts(bio_out, "TLS1\n");
  1243. #endif
  1244. #ifdef OPENSSL_NO_TLS1_1
  1245. BIO_puts(bio_out, "TLS1_1\n");
  1246. #endif
  1247. #ifdef OPENSSL_NO_TLS1_2
  1248. BIO_puts(bio_out, "TLS1_2\n");
  1249. #endif
  1250. #ifdef OPENSSL_NO_WHIRLPOOL
  1251. BIO_puts(bio_out, "WHIRLPOOL\n");
  1252. #endif
  1253. #ifdef OPENSSL_NO_ZLIB
  1254. BIO_puts(bio_out, "ZLIB\n");
  1255. #endif
  1256. #ifdef OPENSSL_NO_BROTLI
  1257. BIO_puts(bio_out, "BROTLI\n");
  1258. #endif
  1259. #ifdef OPENSSL_NO_ZSTD
  1260. BIO_puts(bio_out, "ZSTD\n");
  1261. #endif
  1262. }
  1263. /* Unified enum for help and list commands. */
  1264. typedef enum HELPLIST_CHOICE {
  1265. OPT_COMMON,
  1266. OPT_ONE, OPT_VERBOSE,
  1267. OPT_ALL_ARGORITHMS,
  1268. OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
  1269. OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
  1270. OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
  1271. OPT_KDF_ALGORITHMS, OPT_RANDOM_INSTANCES, OPT_RANDOM_GENERATORS,
  1272. OPT_ENCODERS, OPT_DECODERS, OPT_KEYMANAGERS, OPT_KEYEXCHANGE_ALGORITHMS,
  1273. OPT_KEM_ALGORITHMS, OPT_SIGNATURE_ALGORITHMS, OPT_ASYM_CIPHER_ALGORITHMS,
  1274. OPT_STORE_LOADERS, OPT_PROVIDER_INFO,
  1275. OPT_OBJECTS, OPT_SELECT_NAME,
  1276. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1277. OPT_ENGINES,
  1278. #endif
  1279. OPT_PROV_ENUM
  1280. } HELPLIST_CHOICE;
  1281. const OPTIONS list_options[] = {
  1282. OPT_SECTION("General"),
  1283. {"help", OPT_HELP, '-', "Display this summary"},
  1284. OPT_SECTION("Output"),
  1285. {"1", OPT_ONE, '-', "List in one column"},
  1286. {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
  1287. {"select", OPT_SELECT_NAME, 's', "Select a single algorithm"},
  1288. {"commands", OPT_COMMANDS, '-', "List of standard commands"},
  1289. {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
  1290. {"all-algorithms", OPT_ALL_ARGORITHMS, '-', "List of all algorithms"},
  1291. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1292. {"digest-commands", OPT_DIGEST_COMMANDS, '-',
  1293. "List of message digest commands (deprecated)"},
  1294. #endif
  1295. {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
  1296. "List of message digest algorithms"},
  1297. {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
  1298. "List of key derivation and pseudo random function algorithms"},
  1299. {"random-instances", OPT_RANDOM_INSTANCES, '-',
  1300. "List the primary, public and private random number generator details"},
  1301. {"random-generators", OPT_RANDOM_GENERATORS, '-',
  1302. "List of random number generators"},
  1303. {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
  1304. "List of message authentication code algorithms"},
  1305. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1306. {"cipher-commands", OPT_CIPHER_COMMANDS, '-',
  1307. "List of cipher commands (deprecated)"},
  1308. #endif
  1309. {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
  1310. "List of symmetric cipher algorithms"},
  1311. {"encoders", OPT_ENCODERS, '-', "List of encoding methods" },
  1312. {"decoders", OPT_DECODERS, '-', "List of decoding methods" },
  1313. {"key-managers", OPT_KEYMANAGERS, '-', "List of key managers" },
  1314. {"key-exchange-algorithms", OPT_KEYEXCHANGE_ALGORITHMS, '-',
  1315. "List of key exchange algorithms" },
  1316. {"kem-algorithms", OPT_KEM_ALGORITHMS, '-',
  1317. "List of key encapsulation mechanism algorithms" },
  1318. {"signature-algorithms", OPT_SIGNATURE_ALGORITHMS, '-',
  1319. "List of signature algorithms" },
  1320. {"asymcipher-algorithms", OPT_ASYM_CIPHER_ALGORITHMS, '-',
  1321. "List of asymmetric cipher algorithms" },
  1322. {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
  1323. "List of public key algorithms"},
  1324. {"public-key-methods", OPT_PK_METHOD, '-',
  1325. "List of public key methods"},
  1326. {"store-loaders", OPT_STORE_LOADERS, '-',
  1327. "List of store loaders"},
  1328. {"providers", OPT_PROVIDER_INFO, '-',
  1329. "List of provider information"},
  1330. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1331. {"engines", OPT_ENGINES, '-',
  1332. "List of loaded engines"},
  1333. #endif
  1334. {"disabled", OPT_DISABLED, '-', "List of disabled features"},
  1335. {"options", OPT_OPTIONS, 's',
  1336. "List options for specified command"},
  1337. {"objects", OPT_OBJECTS, '-',
  1338. "List built in objects (OID<->name mappings)"},
  1339. OPT_PROV_OPTIONS,
  1340. {NULL}
  1341. };
  1342. int list_main(int argc, char **argv)
  1343. {
  1344. char *prog;
  1345. HELPLIST_CHOICE o;
  1346. int one = 0, done = 0;
  1347. int print_newline = 0;
  1348. struct {
  1349. unsigned int commands:1;
  1350. unsigned int all_algorithms:1;
  1351. unsigned int random_instances:1;
  1352. unsigned int random_generators:1;
  1353. unsigned int digest_commands:1;
  1354. unsigned int digest_algorithms:1;
  1355. unsigned int kdf_algorithms:1;
  1356. unsigned int mac_algorithms:1;
  1357. unsigned int cipher_commands:1;
  1358. unsigned int cipher_algorithms:1;
  1359. unsigned int encoder_algorithms:1;
  1360. unsigned int decoder_algorithms:1;
  1361. unsigned int keymanager_algorithms:1;
  1362. unsigned int signature_algorithms:1;
  1363. unsigned int keyexchange_algorithms:1;
  1364. unsigned int kem_algorithms:1;
  1365. unsigned int asym_cipher_algorithms:1;
  1366. unsigned int pk_algorithms:1;
  1367. unsigned int pk_method:1;
  1368. unsigned int store_loaders:1;
  1369. unsigned int provider_info:1;
  1370. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1371. unsigned int engines:1;
  1372. #endif
  1373. unsigned int disabled:1;
  1374. unsigned int objects:1;
  1375. unsigned int options:1;
  1376. } todo = { 0, };
  1377. verbose = 0; /* Clear a possible previous call */
  1378. prog = opt_init(argc, argv, list_options);
  1379. while ((o = opt_next()) != OPT_EOF) {
  1380. switch (o) {
  1381. case OPT_EOF: /* Never hit, but suppresses warning */
  1382. case OPT_ERR:
  1383. opthelp:
  1384. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  1385. return 1;
  1386. case OPT_HELP:
  1387. opt_help(list_options);
  1388. return 0;
  1389. case OPT_ONE:
  1390. one = 1;
  1391. break;
  1392. case OPT_ALL_ARGORITHMS:
  1393. todo.all_algorithms = 1;
  1394. break;
  1395. case OPT_COMMANDS:
  1396. todo.commands = 1;
  1397. break;
  1398. case OPT_DIGEST_COMMANDS:
  1399. todo.digest_commands = 1;
  1400. break;
  1401. case OPT_DIGEST_ALGORITHMS:
  1402. todo.digest_algorithms = 1;
  1403. break;
  1404. case OPT_KDF_ALGORITHMS:
  1405. todo.kdf_algorithms = 1;
  1406. break;
  1407. case OPT_RANDOM_INSTANCES:
  1408. todo.random_instances = 1;
  1409. break;
  1410. case OPT_RANDOM_GENERATORS:
  1411. todo.random_generators = 1;
  1412. break;
  1413. case OPT_MAC_ALGORITHMS:
  1414. todo.mac_algorithms = 1;
  1415. break;
  1416. case OPT_CIPHER_COMMANDS:
  1417. todo.cipher_commands = 1;
  1418. break;
  1419. case OPT_CIPHER_ALGORITHMS:
  1420. todo.cipher_algorithms = 1;
  1421. break;
  1422. case OPT_ENCODERS:
  1423. todo.encoder_algorithms = 1;
  1424. break;
  1425. case OPT_DECODERS:
  1426. todo.decoder_algorithms = 1;
  1427. break;
  1428. case OPT_KEYMANAGERS:
  1429. todo.keymanager_algorithms = 1;
  1430. break;
  1431. case OPT_SIGNATURE_ALGORITHMS:
  1432. todo.signature_algorithms = 1;
  1433. break;
  1434. case OPT_KEYEXCHANGE_ALGORITHMS:
  1435. todo.keyexchange_algorithms = 1;
  1436. break;
  1437. case OPT_KEM_ALGORITHMS:
  1438. todo.kem_algorithms = 1;
  1439. break;
  1440. case OPT_ASYM_CIPHER_ALGORITHMS:
  1441. todo.asym_cipher_algorithms = 1;
  1442. break;
  1443. case OPT_PK_ALGORITHMS:
  1444. todo.pk_algorithms = 1;
  1445. break;
  1446. case OPT_PK_METHOD:
  1447. todo.pk_method = 1;
  1448. break;
  1449. case OPT_STORE_LOADERS:
  1450. todo.store_loaders = 1;
  1451. break;
  1452. case OPT_PROVIDER_INFO:
  1453. todo.provider_info = 1;
  1454. break;
  1455. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1456. case OPT_ENGINES:
  1457. todo.engines = 1;
  1458. break;
  1459. #endif
  1460. case OPT_DISABLED:
  1461. todo.disabled = 1;
  1462. break;
  1463. case OPT_OBJECTS:
  1464. todo.objects = 1;
  1465. break;
  1466. case OPT_OPTIONS:
  1467. list_options_for_command(opt_arg());
  1468. break;
  1469. case OPT_VERBOSE:
  1470. verbose = 1;
  1471. break;
  1472. case OPT_SELECT_NAME:
  1473. select_name = opt_arg();
  1474. break;
  1475. case OPT_PROV_CASES:
  1476. if (!opt_provider(o))
  1477. return 1;
  1478. break;
  1479. }
  1480. done = 1;
  1481. }
  1482. /* No extra arguments. */
  1483. if (!opt_check_rest_arg(NULL))
  1484. goto opthelp;
  1485. #define MAYBE_ADD_NL(cmd) \
  1486. do { \
  1487. if (print_newline++) { \
  1488. BIO_printf(bio_out, "\n"); \
  1489. } \
  1490. cmd; \
  1491. } while(0)
  1492. if (todo.commands)
  1493. MAYBE_ADD_NL(list_type(FT_general, one));
  1494. if (todo.all_algorithms) {
  1495. MAYBE_ADD_NL({});
  1496. BIO_printf(bio_out, "Digests:\n");
  1497. list_digests(" ");
  1498. BIO_printf(bio_out, "\nSymmetric Ciphers:\n");
  1499. list_ciphers(" ");
  1500. BIO_printf(bio_out, "\n");
  1501. list_kdfs();
  1502. BIO_printf(bio_out, "\n");
  1503. list_macs();
  1504. BIO_printf(bio_out, "\nProvided Asymmetric Encryption:\n");
  1505. list_asymciphers();
  1506. BIO_printf(bio_out, "\nProvided Key Exchange:\n");
  1507. list_keyexchanges();
  1508. BIO_printf(bio_out, "\nProvided Signatures:\n");
  1509. list_signatures();
  1510. BIO_printf(bio_out, "\nProvided Key encapsulation:\n");
  1511. list_kems();
  1512. BIO_printf(bio_out, "\nProvided Key managers:\n");
  1513. list_keymanagers();
  1514. BIO_printf(bio_out, "\n");
  1515. list_encoders();
  1516. BIO_printf(bio_out, "\n");
  1517. list_decoders();
  1518. BIO_printf(bio_out, "\n");
  1519. list_store_loaders();
  1520. }
  1521. if (todo.random_instances)
  1522. MAYBE_ADD_NL(list_random_instances());
  1523. if (todo.random_generators)
  1524. MAYBE_ADD_NL(list_random_generators());
  1525. if (todo.digest_commands)
  1526. MAYBE_ADD_NL(list_type(FT_md, one));
  1527. if (todo.digest_algorithms)
  1528. MAYBE_ADD_NL(list_digests(""));
  1529. if (todo.kdf_algorithms)
  1530. MAYBE_ADD_NL(list_kdfs());
  1531. if (todo.mac_algorithms)
  1532. MAYBE_ADD_NL(list_macs());
  1533. if (todo.cipher_commands)
  1534. MAYBE_ADD_NL(list_type(FT_cipher, one));
  1535. if (todo.cipher_algorithms)
  1536. MAYBE_ADD_NL(list_ciphers(""));
  1537. if (todo.encoder_algorithms)
  1538. MAYBE_ADD_NL(list_encoders());
  1539. if (todo.decoder_algorithms)
  1540. MAYBE_ADD_NL(list_decoders());
  1541. if (todo.keymanager_algorithms)
  1542. MAYBE_ADD_NL(list_keymanagers());
  1543. if (todo.signature_algorithms)
  1544. MAYBE_ADD_NL(list_signatures());
  1545. if (todo.asym_cipher_algorithms)
  1546. MAYBE_ADD_NL(list_asymciphers());
  1547. if (todo.keyexchange_algorithms)
  1548. MAYBE_ADD_NL(list_keyexchanges());
  1549. if (todo.kem_algorithms)
  1550. MAYBE_ADD_NL(list_kems());
  1551. if (todo.pk_algorithms)
  1552. MAYBE_ADD_NL(list_pkey());
  1553. if (todo.pk_method)
  1554. MAYBE_ADD_NL(list_pkey_meth());
  1555. if (todo.store_loaders)
  1556. MAYBE_ADD_NL(list_store_loaders());
  1557. if (todo.provider_info)
  1558. MAYBE_ADD_NL(list_provider_info());
  1559. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1560. if (todo.engines)
  1561. MAYBE_ADD_NL(list_engines());
  1562. #endif
  1563. if (todo.disabled)
  1564. MAYBE_ADD_NL(list_disabled());
  1565. if (todo.objects)
  1566. MAYBE_ADD_NL(list_objects());
  1567. #undef MAYBE_ADD_NL
  1568. if (!done)
  1569. goto opthelp;
  1570. return 0;
  1571. }