summaryrefslogtreecommitdiffstats
path: root/apps/list.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2019-08-02 10:40:30 +0200
committerRichard Levitte <levitte@openssl.org>2019-08-15 22:12:25 +0200
commit467b8e56753e53ed2b9a9f1ad35970a5ceb837d9 (patch)
treee54606b99eb2d9c4509f36f643d29d2712bee09a /apps/list.c
parentd1cafb083d0cb84b2081dd5ca4ba6bed05b8c6ac (diff)
Re-implement 'openssl list -mac-algorithms'
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/8877)
Diffstat (limited to 'apps/list.c')
-rw-r--r--apps/list.c59
1 files changed, 44 insertions, 15 deletions
diff --git a/apps/list.c b/apps/list.c
index 555ce7e815..0d93f5498f 100644
--- a/apps/list.c
+++ b/apps/list.c
@@ -229,21 +229,52 @@ static void list_digests(void)
sk_EVP_MD_pop_free(digests, EVP_MD_meth_free);
}
-#if 0 /* Temporarly disabled */
-static void list_mac_fn(const EVP_MAC *m,
- const char *from, const char *to, void *arg)
+DEFINE_STACK_OF(EVP_MAC)
+static int mac_cmp(const EVP_MAC * const *a, const EVP_MAC * const *b)
{
- if (m != NULL) {
- BIO_printf(arg, "%s\n", EVP_MAC_name(m));
- } else {
- if (from == NULL)
- from = "<undefined>";
- if (to == NULL)
- to = "<undefined>";
- BIO_printf(arg, "%s => %s\n", from, to);
+ int ret = strcasecmp(EVP_MAC_name(*a), EVP_MAC_name(*b));
+
+ if (ret == 0)
+ ret = strcmp(OSSL_PROVIDER_name(EVP_MAC_provider(*a)),
+ OSSL_PROVIDER_name(EVP_MAC_provider(*b)));
+
+ return ret;
+}
+
+static void collect_macs(EVP_MAC *mac, void *stack)
+{
+ STACK_OF(EVP_MAC) *mac_stack = stack;
+
+ sk_EVP_MAC_push(mac_stack, mac);
+ EVP_MAC_up_ref(mac);
+}
+
+static void list_macs(void)
+{
+ STACK_OF(EVP_MAC) *macs = sk_EVP_MAC_new(mac_cmp);
+ int i;
+
+ BIO_printf(bio_out, "Provided MACs:\n");
+ EVP_MAC_do_all_ex(NULL, collect_macs, macs);
+ sk_EVP_MAC_sort(macs);
+ for (i = 0; i < sk_EVP_MAC_num(macs); i++) {
+ const EVP_MAC *m = sk_EVP_MAC_value(macs, i);
+
+ BIO_printf(bio_out, " %s", EVP_MAC_name(m));
+ BIO_printf(bio_out, " @ %s\n",
+ OSSL_PROVIDER_name(EVP_MAC_provider(m)));
+
+ if (verbose) {
+ print_param_types("retrievable algorithm parameters",
+ EVP_MAC_gettable_params(m));
+ print_param_types("retrievable operation parameters",
+ EVP_MAC_CTX_gettable_params(m));
+ print_param_types("settable operation parameters",
+ EVP_MAC_CTX_settable_params(m));
+ }
}
+ sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
}
-#endif
static void list_missing_help(void)
{
@@ -706,10 +737,8 @@ opthelp:
list_type(FT_md, one);
if (todo.digest_algorithms)
list_digests();
-#if 0 /* Temporarly disabled */
if (todo.mac_algorithms)
- EVP_MAC_do_all_sorted(list_mac_fn, bio_out);
-#endif
+ list_macs();
if (todo.cipher_commands)
list_type(FT_cipher, one);
if (todo.cipher_algorithms)