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