Also mention -- flag and ignore if undocumented
[openssl.git] / apps / list.c
index 446a6e1ab98b7c5f1a86e3be95451db0fc0f4116..77fd20e1e19fdcf8d7321d575ef7a99d226ffe7b 100644 (file)
@@ -12,6 +12,7 @@
 #include <openssl/err.h>
 #include <openssl/provider.h>
 #include <openssl/safestack.h>
+#include <openssl/kdf.h>
 #include "apps.h"
 #include "app_params.h"
 #include "progs.h"
@@ -75,12 +76,12 @@ static void list_ciphers(void)
             print_param_types("retrievable algorithm parameters",
                               EVP_CIPHER_gettable_params(c), 4);
             print_param_types("retrievable operation parameters",
-                              EVP_CIPHER_CTX_gettable_params(c), 4);
+                              EVP_CIPHER_gettable_ctx_params(c), 4);
             print_param_types("settable operation parameters",
-                              EVP_CIPHER_CTX_settable_params(c), 4);
+                              EVP_CIPHER_settable_ctx_params(c), 4);
         }
     }
-    sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_meth_free);
+    sk_EVP_CIPHER_pop_free(ciphers, EVP_CIPHER_free);
 }
 
 static void list_md_fn(const EVP_MD *m,
@@ -138,12 +139,12 @@ static void list_digests(void)
             print_param_types("retrievable algorithm parameters",
                               EVP_MD_gettable_params(m), 4);
             print_param_types("retrievable operation parameters",
-                              EVP_MD_CTX_gettable_params(m), 4);
+                              EVP_MD_gettable_ctx_params(m), 4);
             print_param_types("settable operation parameters",
-                              EVP_MD_CTX_settable_params(m), 4);
+                              EVP_MD_settable_ctx_params(m), 4);
         }
     }
-    sk_EVP_MD_pop_free(digests, EVP_MD_meth_free);
+    sk_EVP_MD_pop_free(digests, EVP_MD_free);
 }
 
 DEFINE_STACK_OF(EVP_MAC)
@@ -185,14 +186,64 @@ static void list_macs(void)
             print_param_types("retrievable algorithm parameters",
                               EVP_MAC_gettable_params(m), 4);
             print_param_types("retrievable operation parameters",
-                              EVP_MAC_CTX_gettable_params(m), 4);
+                              EVP_MAC_gettable_ctx_params(m), 4);
             print_param_types("settable operation parameters",
-                              EVP_MAC_CTX_settable_params(m), 4);
+                              EVP_MAC_settable_ctx_params(m), 4);
         }
     }
     sk_EVP_MAC_pop_free(macs, EVP_MAC_free);
 }
 
+/*
+ * KDFs and PRFs
+ */
+DEFINE_STACK_OF(EVP_KDF)
+static int kdf_cmp(const EVP_KDF * const *a, const EVP_KDF * const *b)
+{
+    int ret = strcasecmp(EVP_KDF_name(*a), EVP_KDF_name(*b));
+
+    if (ret == 0)
+        ret = strcmp(OSSL_PROVIDER_name(EVP_KDF_provider(*a)),
+                     OSSL_PROVIDER_name(EVP_KDF_provider(*b)));
+
+    return ret;
+}
+
+static void collect_kdfs(EVP_KDF *kdf, void *stack)
+{
+    STACK_OF(EVP_KDF) *kdf_stack = stack;
+
+    sk_EVP_KDF_push(kdf_stack, kdf);
+    EVP_KDF_up_ref(kdf);
+}
+
+static void list_kdfs(void)
+{
+    STACK_OF(EVP_KDF) *kdfs = sk_EVP_KDF_new(kdf_cmp);
+    int i;
+
+    BIO_printf(bio_out, "Provided KDFs and PDFs:\n");
+    EVP_KDF_do_all_ex(NULL, collect_kdfs, kdfs);
+    sk_EVP_KDF_sort(kdfs);
+    for (i = 0; i < sk_EVP_KDF_num(kdfs); i++) {
+        const EVP_KDF *m = sk_EVP_KDF_value(kdfs, i);
+
+        BIO_printf(bio_out, "  %s", EVP_KDF_name(m));
+        BIO_printf(bio_out, " @ %s\n",
+                   OSSL_PROVIDER_name(EVP_KDF_provider(m)));
+
+        if (verbose) {
+            print_param_types("retrievable algorithm parameters",
+                              EVP_KDF_gettable_params(m), 4);
+            print_param_types("retrievable operation parameters",
+                              EVP_KDF_gettable_ctx_params(m), 4);
+            print_param_types("settable operation parameters",
+                              EVP_KDF_settable_ctx_params(m), 4);
+        }
+    }
+    sk_EVP_KDF_pop_free(kdfs, EVP_KDF_free);
+}
+
 static void list_missing_help(void)
 {
     const FUNCTION *fp;
@@ -286,6 +337,8 @@ static void list_options_for_command(const char *command)
             continue;
         BIO_printf(bio_out, "%s %c\n", o->name, o->valtype);
     }
+    /* Always output the -- marker since it is sometimes documented. */
+    BIO_printf(bio_out, "- -\n");
 }
 
 static void list_type(FUNC_TYPE ft, int one)
@@ -527,7 +580,7 @@ typedef enum HELPLIST_CHOICE {
     OPT_COMMANDS, OPT_DIGEST_COMMANDS, OPT_MAC_ALGORITHMS, OPT_OPTIONS,
     OPT_DIGEST_ALGORITHMS, OPT_CIPHER_COMMANDS, OPT_CIPHER_ALGORITHMS,
     OPT_PK_ALGORITHMS, OPT_PK_METHOD, OPT_ENGINES, OPT_DISABLED,
-    OPT_MISSING_HELP, OPT_OBJECTS
+    OPT_KDF_ALGORITHMS, OPT_MISSING_HELP, OPT_OBJECTS
 } HELPLIST_CHOICE;
 
 const OPTIONS list_options[] = {
@@ -539,6 +592,8 @@ const OPTIONS list_options[] = {
      "List of message digest commands"},
     {"digest-algorithms", OPT_DIGEST_ALGORITHMS, '-',
      "List of message digest algorithms"},
+    {"kdf-algorithms", OPT_KDF_ALGORITHMS, '-',
+     "List of key derivation and pseudo random function algorithms"},
     {"mac-algorithms", OPT_MAC_ALGORITHMS, '-',
      "List of message authentication code algorithms"},
     {"cipher-commands", OPT_CIPHER_COMMANDS, '-', "List of cipher commands"},
@@ -570,6 +625,7 @@ int list_main(int argc, char **argv)
         unsigned int commands:1;
         unsigned int digest_commands:1;
         unsigned int digest_algorithms:1;
+        unsigned int kdf_algorithms:1;
         unsigned int mac_algorithms:1;
         unsigned int cipher_commands:1;
         unsigned int cipher_algorithms:1;
@@ -607,6 +663,9 @@ opthelp:
         case OPT_DIGEST_ALGORITHMS:
             todo.digest_algorithms = 1;
             break;
+        case OPT_KDF_ALGORITHMS:
+            todo.kdf_algorithms = 1;
+            break;
         case OPT_MAC_ALGORITHMS:
             todo.mac_algorithms = 1;
             break;
@@ -654,6 +713,8 @@ opthelp:
         list_type(FT_md, one);
     if (todo.digest_algorithms)
         list_digests();
+    if (todo.kdf_algorithms)
+        list_kdfs();
     if (todo.mac_algorithms)
         list_macs();
     if (todo.cipher_commands)