list.c 47 KB

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