From 467b8e56753e53ed2b9a9f1ad35970a5ceb837d9 Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Fri, 2 Aug 2019 10:40:30 +0200 Subject: [PATCH] Re-implement 'openssl list -mac-algorithms' Reviewed-by: Matt Caswell Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/8877) --- apps/list.c | 59 +++++++++++++++++++++++++++++++++++++++-------------- 1 file 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 = ""; - if (to == NULL) - to = ""; - 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) -- 2.25.1