list.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706
  1. /*
  2. * Copyright 1995-2021 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. || 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(void)
  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, "Legacy:\n");
  106. EVP_CIPHER_do_all_sorted(legacy_cipher_fn, bio_out);
  107. }
  108. #endif
  109. BIO_printf(bio_out, "Provided:\n");
  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(void)
  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, "Legacy:\n");
  178. EVP_MD_do_all_sorted(legacy_md_fn, bio_out);
  179. }
  180. #endif
  181. BIO_printf(bio_out, "Provided:\n");
  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 = 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. && 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 (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. #ifndef ZLIB
  1238. BIO_puts(bio_out, "ZLIB\n");
  1239. #endif
  1240. }
  1241. /* Unified enum for help and list commands. */
  1242. typedef enum HELPLIST_CHOICE {
  1243. OPT_COMMON,
  1244. OPT_ONE, OPT_VERBOSE,
  1245. OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
  1246. OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
  1247. OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_DISABLED,
  1248. OPT_KDF_ALGORITHMS, OPT_RANDOM_INSTANCES, OPT_RANDOM_GENERATORS,
  1249. OPT_ENCODERS, OPT_DECODERS, OPT_KEYMANAGERS, OPT_KEYEXCHANGE_ALGORITHMS,
  1250. OPT_KEM_ALGORITHMS, OPT_SIGNATURE_ALGORITHMS, OPT_ASYM_CIPHER_ALGORITHMS,
  1251. OPT_STORE_LOADERS, OPT_PROVIDER_INFO,
  1252. OPT_OBJECTS, OPT_SELECT_NAME,
  1253. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1254. OPT_ENGINES,
  1255. #endif
  1256. OPT_PROV_ENUM
  1257. } HELPLIST_CHOICE;
  1258. const OPTIONS list_options[] = {
  1259. OPT_SECTION("General"),
  1260. {"help", OPT_HELP, '-', "Display this summary"},
  1261. OPT_SECTION("Output"),
  1262. {"1", OPT_ONE, '-', "List in one column"},
  1263. {"verbose", OPT_VERBOSE, '-', "Verbose listing"},
  1264. {"select", OPT_SELECT_NAME, 's', "Select a single algorithm"},
  1265. {"commands", OPT_COMMANDS, '-', "List of standard commands"},
  1266. {"standard-commands", OPT_COMMANDS, '-', "List of standard commands"},
  1267. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1268. {"digest-commands", OPT_DIGEST_COMMANDS, '-',
  1269. "List of message digest commands (deprecated)"},
  1270. #endif
  1271. {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
  1272. "List of message digest algorithms"},
  1273. {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
  1274. "List of key derivation and pseudo random function algorithms"},
  1275. {"random-instances", OPT_RANDOM_INSTANCES, '-',
  1276. "List the primary, public and private random number generator details"},
  1277. {"random-generators", OPT_RANDOM_GENERATORS, '-',
  1278. "List of random number generators"},
  1279. {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
  1280. "List of message authentication code algorithms"},
  1281. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1282. {"cipher-commands", OPT_CIPHER_COMMANDS, '-',
  1283. "List of cipher commands (deprecated)"},
  1284. #endif
  1285. {"cipher-algorithms", OPT_CIPHER_ALGORITHMS, '-',
  1286. "List of cipher algorithms"},
  1287. {"encoders", OPT_ENCODERS, '-', "List of encoding methods" },
  1288. {"decoders", OPT_DECODERS, '-', "List of decoding methods" },
  1289. {"key-managers", OPT_KEYMANAGERS, '-', "List of key managers" },
  1290. {"key-exchange-algorithms", OPT_KEYEXCHANGE_ALGORITHMS, '-',
  1291. "List of key exchange algorithms" },
  1292. {"kem-algorithms", OPT_KEM_ALGORITHMS, '-',
  1293. "List of key encapsulation mechanism algorithms" },
  1294. {"signature-algorithms", OPT_SIGNATURE_ALGORITHMS, '-',
  1295. "List of signature algorithms" },
  1296. {"asymcipher-algorithms", OPT_ASYM_CIPHER_ALGORITHMS, '-',
  1297. "List of asymmetric cipher algorithms" },
  1298. {"public-key-algorithms", OPT_PK_ALGORITHMS, '-',
  1299. "List of public key algorithms"},
  1300. {"public-key-methods", OPT_PK_METHOD, '-',
  1301. "List of public key methods"},
  1302. {"store-loaders", OPT_STORE_LOADERS, '-',
  1303. "List of store loaders"},
  1304. {"providers", OPT_PROVIDER_INFO, '-',
  1305. "List of provider information"},
  1306. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1307. {"engines", OPT_ENGINES, '-',
  1308. "List of loaded engines"},
  1309. #endif
  1310. {"disabled", OPT_DISABLED, '-', "List of disabled features"},
  1311. {"options", OPT_OPTIONS, 's',
  1312. "List options for specified command"},
  1313. {"objects", OPT_OBJECTS, '-',
  1314. "List built in objects (OID<->name mappings)"},
  1315. OPT_PROV_OPTIONS,
  1316. {NULL}
  1317. };
  1318. int list_main(int argc, char **argv)
  1319. {
  1320. char *prog;
  1321. HELPLIST_CHOICE o;
  1322. int one = 0, done = 0;
  1323. struct {
  1324. unsigned int commands:1;
  1325. unsigned int random_instances:1;
  1326. unsigned int random_generators:1;
  1327. unsigned int digest_commands:1;
  1328. unsigned int digest_algorithms:1;
  1329. unsigned int kdf_algorithms:1;
  1330. unsigned int mac_algorithms:1;
  1331. unsigned int cipher_commands:1;
  1332. unsigned int cipher_algorithms:1;
  1333. unsigned int encoder_algorithms:1;
  1334. unsigned int decoder_algorithms:1;
  1335. unsigned int keymanager_algorithms:1;
  1336. unsigned int signature_algorithms:1;
  1337. unsigned int keyexchange_algorithms:1;
  1338. unsigned int kem_algorithms:1;
  1339. unsigned int asym_cipher_algorithms:1;
  1340. unsigned int pk_algorithms:1;
  1341. unsigned int pk_method:1;
  1342. unsigned int store_loaders:1;
  1343. unsigned int provider_info:1;
  1344. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1345. unsigned int engines:1;
  1346. #endif
  1347. unsigned int disabled:1;
  1348. unsigned int objects:1;
  1349. unsigned int options:1;
  1350. } todo = { 0, };
  1351. verbose = 0; /* Clear a possible previous call */
  1352. prog = opt_init(argc, argv, list_options);
  1353. while ((o = opt_next()) != OPT_EOF) {
  1354. switch (o) {
  1355. case OPT_EOF: /* Never hit, but suppresses warning */
  1356. case OPT_ERR:
  1357. opthelp:
  1358. BIO_printf(bio_err, "%s: Use -help for summary.\n", prog);
  1359. return 1;
  1360. case OPT_HELP:
  1361. opt_help(list_options);
  1362. return 0;
  1363. case OPT_ONE:
  1364. one = 1;
  1365. break;
  1366. case OPT_COMMANDS:
  1367. todo.commands = 1;
  1368. break;
  1369. case OPT_DIGEST_COMMANDS:
  1370. todo.digest_commands = 1;
  1371. break;
  1372. case OPT_DIGEST_ALGORITHMS:
  1373. todo.digest_algorithms = 1;
  1374. break;
  1375. case OPT_KDF_ALGORITHMS:
  1376. todo.kdf_algorithms = 1;
  1377. break;
  1378. case OPT_RANDOM_INSTANCES:
  1379. todo.random_instances = 1;
  1380. break;
  1381. case OPT_RANDOM_GENERATORS:
  1382. todo.random_generators = 1;
  1383. break;
  1384. case OPT_MAC_ALGORITHMS:
  1385. todo.mac_algorithms = 1;
  1386. break;
  1387. case OPT_CIPHER_COMMANDS:
  1388. todo.cipher_commands = 1;
  1389. break;
  1390. case OPT_CIPHER_ALGORITHMS:
  1391. todo.cipher_algorithms = 1;
  1392. break;
  1393. case OPT_ENCODERS:
  1394. todo.encoder_algorithms = 1;
  1395. break;
  1396. case OPT_DECODERS:
  1397. todo.decoder_algorithms = 1;
  1398. break;
  1399. case OPT_KEYMANAGERS:
  1400. todo.keymanager_algorithms = 1;
  1401. break;
  1402. case OPT_SIGNATURE_ALGORITHMS:
  1403. todo.signature_algorithms = 1;
  1404. break;
  1405. case OPT_KEYEXCHANGE_ALGORITHMS:
  1406. todo.keyexchange_algorithms = 1;
  1407. break;
  1408. case OPT_KEM_ALGORITHMS:
  1409. todo.kem_algorithms = 1;
  1410. break;
  1411. case OPT_ASYM_CIPHER_ALGORITHMS:
  1412. todo.asym_cipher_algorithms = 1;
  1413. break;
  1414. case OPT_PK_ALGORITHMS:
  1415. todo.pk_algorithms = 1;
  1416. break;
  1417. case OPT_PK_METHOD:
  1418. todo.pk_method = 1;
  1419. break;
  1420. case OPT_STORE_LOADERS:
  1421. todo.store_loaders = 1;
  1422. break;
  1423. case OPT_PROVIDER_INFO:
  1424. todo.provider_info = 1;
  1425. break;
  1426. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1427. case OPT_ENGINES:
  1428. todo.engines = 1;
  1429. break;
  1430. #endif
  1431. case OPT_DISABLED:
  1432. todo.disabled = 1;
  1433. break;
  1434. case OPT_OBJECTS:
  1435. todo.objects = 1;
  1436. break;
  1437. case OPT_OPTIONS:
  1438. list_options_for_command(opt_arg());
  1439. break;
  1440. case OPT_VERBOSE:
  1441. verbose = 1;
  1442. break;
  1443. case OPT_SELECT_NAME:
  1444. select_name = opt_arg();
  1445. break;
  1446. case OPT_PROV_CASES:
  1447. if (!opt_provider(o))
  1448. return 1;
  1449. break;
  1450. }
  1451. done = 1;
  1452. }
  1453. /* No extra arguments. */
  1454. if (opt_num_rest() != 0)
  1455. goto opthelp;
  1456. if (todo.commands)
  1457. list_type(FT_general, one);
  1458. if (todo.random_instances)
  1459. list_random_instances();
  1460. if (todo.random_generators)
  1461. list_random_generators();
  1462. if (todo.digest_commands)
  1463. list_type(FT_md, one);
  1464. if (todo.digest_algorithms)
  1465. list_digests();
  1466. if (todo.kdf_algorithms)
  1467. list_kdfs();
  1468. if (todo.mac_algorithms)
  1469. list_macs();
  1470. if (todo.cipher_commands)
  1471. list_type(FT_cipher, one);
  1472. if (todo.cipher_algorithms)
  1473. list_ciphers();
  1474. if (todo.encoder_algorithms)
  1475. list_encoders();
  1476. if (todo.decoder_algorithms)
  1477. list_decoders();
  1478. if (todo.keymanager_algorithms)
  1479. list_keymanagers();
  1480. if (todo.signature_algorithms)
  1481. list_signatures();
  1482. if (todo.asym_cipher_algorithms)
  1483. list_asymciphers();
  1484. if (todo.keyexchange_algorithms)
  1485. list_keyexchanges();
  1486. if (todo.kem_algorithms)
  1487. list_kems();
  1488. if (todo.pk_algorithms)
  1489. list_pkey();
  1490. if (todo.pk_method)
  1491. list_pkey_meth();
  1492. if (todo.store_loaders)
  1493. list_store_loaders();
  1494. if (todo.provider_info)
  1495. list_provider_info();
  1496. #ifndef OPENSSL_NO_DEPRECATED_3_0
  1497. if (todo.engines)
  1498. list_engines();
  1499. #endif
  1500. if (todo.disabled)
  1501. list_disabled();
  1502. if (todo.objects)
  1503. list_objects();
  1504. if (!done)
  1505. goto opthelp;
  1506. return 0;
  1507. }