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