summaryrefslogtreecommitdiffstats
path: root/apps/mac.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-05-07 15:48:27 +1000
committerPauli <pauli@openssl.org>2021-05-08 22:15:56 +1000
commit0f4fb64785dbdb074b6a0e7f415697ad74596c0c (patch)
tree93b86d5852486eed4eda769440686a71b0258466 /apps/mac.c
parent29f5727b83c4ec26ff8e183c1b0dc707a3719588 (diff)
apps/mac: Add digest and cipher command line options
Add -cipher and -digest as short forms of -macopt cipher: and -macopt digest: respectively. Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15189)
Diffstat (limited to 'apps/mac.c')
-rw-r--r--apps/mac.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/apps/mac.c b/apps/mac.c
index b9610f3a18..ca02a781e5 100644
--- a/apps/mac.c
+++ b/apps/mac.c
@@ -15,6 +15,7 @@
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/params.h>
+#include <openssl/core_names.h>
#undef BUFSIZE
#define BUFSIZE 1024*8
@@ -22,6 +23,7 @@
typedef enum OPTION_choice {
OPT_COMMON,
OPT_MACOPT, OPT_BIN, OPT_IN, OPT_OUT,
+ OPT_CIPHER, OPT_DIGEST,
OPT_PROV_ENUM
} OPTION_CHOICE;
@@ -31,6 +33,8 @@ const OPTIONS mac_options[] = {
OPT_SECTION("General"),
{"help", OPT_HELP, '-', "Display this summary"},
{"macopt", OPT_MACOPT, 's', "MAC algorithm parameters in n:v form"},
+ {"cipher", OPT_CIPHER, 's', "Cipher"},
+ {"digest", OPT_DIGEST, 's', "Digest"},
{OPT_MORE_STR, 1, '-', "See 'PARAMETER NAMES' in the EVP_MAC_ docs"},
OPT_SECTION("Input"),
@@ -48,6 +52,24 @@ const OPTIONS mac_options[] = {
{NULL}
};
+static char *alloc_mac_algorithm_name(STACK_OF(OPENSSL_STRING) **optp,
+ const char *name, const char *arg)
+{
+ size_t len = strlen(name) + strlen(arg) + 2;
+ char *res = app_malloc(len, "algorithm name");
+
+ if (*optp == NULL)
+ *optp = sk_OPENSSL_STRING_new_null();
+ if (*optp == NULL)
+ return NULL;
+
+ BIO_snprintf(res, len, "%s:%s", name, arg);
+ if (sk_OPENSSL_STRING_push(*optp, res))
+ return res;
+ OPENSSL_free(res);
+ return NULL;
+}
+
int mac_main(int argc, char **argv)
{
int ret = 1;
@@ -64,6 +86,7 @@ int mac_main(int argc, char **argv)
const char *infile = NULL;
int out_bin = 0;
int inform = FORMAT_BINARY;
+ char *digest = NULL, *cipher = NULL;
OSSL_PARAM *params = NULL;
prog = opt_init(argc, argv, mac_options);
@@ -93,6 +116,18 @@ opthelp:
if (opts == NULL || !sk_OPENSSL_STRING_push(opts, opt_arg()))
goto opthelp;
break;
+ case OPT_CIPHER:
+ OPENSSL_free(cipher);
+ cipher = alloc_mac_algorithm_name(&opts, "cipher", opt_arg());
+ if (cipher == NULL)
+ goto opthelp;
+ break;
+ case OPT_DIGEST:
+ OPENSSL_free(digest);
+ digest = alloc_mac_algorithm_name(&opts, "digest", opt_arg());
+ if (digest == NULL)
+ goto opthelp;
+ break;
case OPT_PROV_CASES:
if (!opt_provider(o))
goto err;
@@ -193,6 +228,8 @@ err:
if (ret != 0)
ERR_print_errors(bio_err);
OPENSSL_clear_free(buf, BUFSIZE);
+ OPENSSL_free(cipher);
+ OPENSSL_free(digest);
sk_OPENSSL_STRING_free(opts);
BIO_free(in);
BIO_free(out);