DPDK patches and discussions
 help / color / mirror / Atom feed
From: Pablo de Lara <pablo.de.lara.guarch@intel.com>
To: dev@dpdk.org
Cc: declan.doherty@intel.com, Pablo de Lara <pablo.de.lara.guarch@intel.com>
Subject: [dpdk-dev] [PATCH 6/7] l2fwd-crypto: use key-value list of supported algorithms
Date: Wed, 30 Mar 2016 14:02:29 +0100	[thread overview]
Message-ID: <1459342950-52434-7-git-send-email-pablo.de.lara.guarch@intel.com> (raw)
In-Reply-To: <1459342950-52434-1-git-send-email-pablo.de.lara.guarch@intel.com>

In order to ease the parsing and display of supported algorithms
in the application, two new arrays are created, which contains
the strings of the different cipher and authentication algorithms,

These lists are used to parse the algorithms from the command line,
and will be used to display crypto information to the user.

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 examples/l2fwd-crypto/main.c          | 106 +++++++++++++++++-----------------
 lib/librte_cryptodev/rte_crypto_sym.h |   6 +-
 2 files changed, 58 insertions(+), 54 deletions(-)

diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c
index c561270..6de29c5 100644
--- a/examples/l2fwd-crypto/main.c
+++ b/examples/l2fwd-crypto/main.c
@@ -133,6 +133,9 @@ struct l2fwd_key {
 	phys_addr_t phys_addr;
 };
 
+char supported_auth_algo[RTE_CRYPTO_AUTH_LIST_END][MAX_STR_LEN];
+char supported_cipher_algo[RTE_CRYPTO_CIPHER_LIST_END][MAX_STR_LEN];
+
 /** l2fwd crypto application command line options */
 struct l2fwd_crypto_options {
 	unsigned portmask;
@@ -164,8 +167,6 @@ struct l2fwd_crypto_options {
 	int digest_size;
 
 	uint16_t block_size;
-	char string_auth_algo[MAX_STR_LEN];
-	char string_cipher_algo[MAX_STR_LEN];
 	char string_type[MAX_STR_LEN];
 };
 
@@ -328,6 +329,32 @@ print_stats(void)
 	printf("\n====================================================\n");
 }
 
+static void
+fill_supported_algorithm_tables(void)
+{
+	unsigned i;
+
+	for (i = 0; i < RTE_CRYPTO_AUTH_LIST_END; i++)
+		strcpy(supported_auth_algo[i], "NOT_SUPPORTED");
+
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_AES_GCM], "AES_GCM");
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_MD5_HMAC], "MD5_HMAC");
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_NULL], "NULL");
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_SHA1_HMAC], "SHA1_HMAC");
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_SHA224_HMAC], "SHA224_HMAC");
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_SHA256_HMAC], "SHA256_HMAC");
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_SHA384_HMAC], "SHA384_HMAC");
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_SHA512_HMAC], "SHA512_HMAC");
+	strcpy(supported_auth_algo[RTE_CRYPTO_AUTH_SNOW3G_UIA2], "SNOW3G_UIA2");
+
+	for (i = 0; i < RTE_CRYPTO_CIPHER_LIST_END; i++)
+		strcpy(supported_cipher_algo[i], "NOT_SUPPORTED");
+
+	strcpy(supported_cipher_algo[RTE_CRYPTO_CIPHER_AES_CBC], "AES_CBC");
+	strcpy(supported_cipher_algo[RTE_CRYPTO_CIPHER_AES_GCM], "AES_GCM");
+	strcpy(supported_cipher_algo[RTE_CRYPTO_CIPHER_NULL], "NULL");
+	strcpy(supported_cipher_algo[RTE_CRYPTO_CIPHER_SNOW3G_UEA2], "SNOW3G_UEA2");
+}
 
 
 static int
@@ -864,18 +891,13 @@ parse_crypto_opt_chain(struct l2fwd_crypto_options *options, char *optarg)
 static int
 parse_cipher_algo(enum rte_crypto_cipher_algorithm *algo, char *optarg)
 {
-	if (strcmp("AES_CBC", optarg) == 0) {
-		*algo = RTE_CRYPTO_CIPHER_AES_CBC;
-		return 0;
-	} else if (strcmp("AES_GCM", optarg) == 0) {
-		*algo = RTE_CRYPTO_CIPHER_AES_GCM;
-		return 0;
-	} else if (strcmp("NULL", optarg) == 0) {
-		*algo = RTE_CRYPTO_CIPHER_NULL;
-		return 0;
-	} else if (strcmp("SNOW3G_UEA2", optarg) == 0) {
-		*algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
-		return 0;
+	unsigned i;
+
+	for (i = 0; i < RTE_CRYPTO_CIPHER_LIST_END; i++) {
+		if (!strcmp(supported_cipher_algo[i], optarg)) {
+			*algo = i;
+			return 0;
+		}
 	}
 
 	printf("Cipher algorithm  not supported!\n");
@@ -945,33 +967,13 @@ parse_size(int *size, const char *q_arg)
 static int
 parse_auth_algo(enum rte_crypto_auth_algorithm *algo, char *optarg)
 {
-	if (strcmp("AES_GCM", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_AES_GCM;
-		return 0;
-	} else if (strcmp("MD5_HMAC", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_MD5_HMAC;
-		return 0;
-	} else if (strcmp("NULL", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_NULL;
-		return 0;
-	} else if (strcmp("SHA1_HMAC", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
-		return 0;
-	} else if (strcmp("SHA224_HMAC", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_SHA224_HMAC;
-		return 0;
-	} else if (strcmp("SHA256_HMAC", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
-		return 0;
-	}  else if (strcmp("SHA384_HMAC", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_SHA384_HMAC;
-		return 0;
-	} else if (strcmp("SHA512_HMAC", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
-		return 0;
-	} else if (strcmp("SNOW3G_UIA2", optarg) == 0) {
-		*algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
-		return 0;
+	unsigned i;
+
+	for (i = 0; i < RTE_CRYPTO_AUTH_LIST_END; i++) {
+		if (!strcmp(supported_auth_algo[i], optarg)) {
+			*algo = i;
+			return 0;
+		}
 	}
 
 	printf("Authentication algorithm specified not supported!\n");
@@ -1011,13 +1013,9 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options,
 		return parse_crypto_opt_chain(options, optarg);
 
 	/* Cipher options */
-	else if (strcmp(lgopts[option_index].name, "cipher_algo") == 0) {
-		retval = parse_cipher_algo(&options->cipher_xform.cipher.algo,
+	else if (strcmp(lgopts[option_index].name, "cipher_algo") == 0)
+		return parse_cipher_algo(&options->cipher_xform.cipher.algo,
 				optarg);
-		if (retval == 0)
-			strcpy(options->string_cipher_algo, optarg);
-		return retval;
-	}
 
 	else if (strcmp(lgopts[option_index].name, "cipher_op") == 0)
 		return parse_cipher_op(&options->cipher_xform.cipher.op,
@@ -1051,11 +1049,8 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options,
 
 	/* Authentication options */
 	else if (strcmp(lgopts[option_index].name, "auth_algo") == 0) {
-		retval = parse_auth_algo(&options->auth_xform.auth.algo,
+		return parse_auth_algo(&options->auth_xform.auth.algo,
 				optarg);
-		if (retval == 0)
-			strcpy(options->string_auth_algo, optarg);
-		return retval;
 	}
 
 	else if (strcmp(lgopts[option_index].name, "auth_op") == 0)
@@ -1474,7 +1469,8 @@ initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
 			if (cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) {
 				printf("Algorithm %s not supported by cryptodev %u"
 					" or device not of preferred type (%s)\n",
-					options->string_cipher_algo, cdev_id,
+					supported_cipher_algo[opt_cipher_algo],
+					cdev_id,
 					options->string_type);
 				continue;
 			}
@@ -1573,7 +1569,8 @@ initialize_cryptodevs(struct l2fwd_crypto_options *options, unsigned nb_ports,
 			if (cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED) {
 				printf("Algorithm %s not supported by cryptodev %u"
 					" or device not of preferred type (%s)\n",
-					options->string_auth_algo, cdev_id,
+					supported_auth_algo[opt_auth_algo],
+					cdev_id,
 					options->string_type);
 				continue;
 			}
@@ -1848,6 +1845,9 @@ main(int argc, char **argv)
 	/* reserve memory for Cipher/Auth key and IV */
 	reserve_key_memory(&options);
 
+	/* fill out the supported algorithm tables */
+	fill_supported_algorithm_tables();
+
 	/* parse application arguments (after the EAL ones) */
 	ret = l2fwd_crypto_parse_args(&options, argc, argv);
 	if (ret < 0)
diff --git a/lib/librte_cryptodev/rte_crypto_sym.h b/lib/librte_cryptodev/rte_crypto_sym.h
index d01287c..913941a 100644
--- a/lib/librte_cryptodev/rte_crypto_sym.h
+++ b/lib/librte_cryptodev/rte_crypto_sym.h
@@ -101,8 +101,10 @@ enum rte_crypto_cipher_algorithm {
 	RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
 	/**< SNOW3G algorithm in UEA2 mode */
 
-	RTE_CRYPTO_CIPHER_ZUC_EEA3
+	RTE_CRYPTO_CIPHER_ZUC_EEA3,
 	/**< ZUC algorithm in EEA3 mode */
+
+	RTE_CRYPTO_CIPHER_LIST_END
 };
 
 /** Symmetric Cipher Direction */
@@ -234,6 +236,8 @@ enum rte_crypto_auth_algorithm {
 
 	RTE_CRYPTO_AUTH_ZUC_EIA3,
 	/**< ZUC algorithm in EIA3 mode */
+
+	RTE_CRYPTO_AUTH_LIST_END
 };
 
 /** Symmetric Authentication / Hash Operations */
-- 
2.5.5

  parent reply	other threads:[~2016-03-30 13:02 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-30 13:02 [dpdk-dev] [PATCH 0/7] L2fwd-crypto fixes/enhancements Pablo de Lara
2016-03-30 13:02 ` [dpdk-dev] [PATCH 1/7] l2fwd-crypto: add missing new line character in help Pablo de Lara
2016-03-30 13:02 ` [dpdk-dev] [PATCH 2/7] l2fwd-crypto: rename period parameter Pablo de Lara
2016-03-30 13:02 ` [dpdk-dev] [PATCH 3/7] l2fwd-crypto: add missing string initialization Pablo de Lara
2016-03-30 13:02 ` [dpdk-dev] [PATCH 4/7] l2fwd-crypto: fix length of random IV/AAD Pablo de Lara
2016-03-30 13:02 ` [dpdk-dev] [PATCH 5/7] l2fwd-crypto: fix ambiguous input key size Pablo de Lara
2016-03-30 13:02 ` Pablo de Lara [this message]
2016-03-30 13:02 ` [dpdk-dev] [PATCH 7/7] l2fwd-crypto: extend crypto information Pablo de Lara
2016-03-31  8:53 ` [dpdk-dev] [PATCH 0/7] L2fwd-crypto fixes/enhancements Cao, Min
2016-03-31  9:01 ` [dpdk-dev] [PATCH v2 0/8] " Pablo de Lara
2016-03-31  9:01   ` [dpdk-dev] [PATCH v2 1/8] l2fwd-crypto: add missing new line character in help Pablo de Lara
2016-03-31  9:01   ` [dpdk-dev] [PATCH v2 2/8] l2fwd-crypto: rename period parameter Pablo de Lara
2016-03-31  9:01   ` [dpdk-dev] [PATCH v2 3/8] l2fwd-crypto: add missing string initialization Pablo de Lara
2016-03-31  9:01   ` [dpdk-dev] [PATCH v2 4/8] l2fwd-crypto: fix length of random IV/AAD Pablo de Lara
2016-03-31  9:01   ` [dpdk-dev] [PATCH v2 5/8] l2fwd-crypto: fix ambiguous input key size Pablo de Lara
2016-03-31  9:01   ` [dpdk-dev] [PATCH v2 6/8] l2fwd-crypto: clarify key parsing in help Pablo de Lara
2016-03-31  9:01   ` [dpdk-dev] [PATCH v2 7/8] l2fwd-crypto: use key-value list of supported algorithms Pablo de Lara
2016-03-31  9:01   ` [dpdk-dev] [PATCH v2 8/8] l2fwd-crypto: extend crypto information Pablo de Lara
2016-03-31  9:19   ` [dpdk-dev] [PATCH v2 0/8] L2fwd-crypto fixes/enhancements Thomas Monjalon
2016-03-31  9:33     ` De Lara Guarch, Pablo
2016-03-31  9:32   ` [dpdk-dev] [PATCH v3 " Pablo de Lara
2016-03-31  9:32     ` [dpdk-dev] [PATCH v3 1/8] l2fwd-crypto: add missing new line character in help Pablo de Lara
2016-03-31  9:32     ` [dpdk-dev] [PATCH v3 2/8] l2fwd-crypto: rename period parameter Pablo de Lara
2016-03-31  9:32     ` [dpdk-dev] [PATCH v3 3/8] l2fwd-crypto: add missing string initialization Pablo de Lara
2016-03-31  9:32     ` [dpdk-dev] [PATCH v3 4/8] l2fwd-crypto: fix length of random IV/AAD Pablo de Lara
2016-03-31  9:32     ` [dpdk-dev] [PATCH v3 5/8] l2fwd-crypto: fix ambiguous input key size Pablo de Lara
2016-03-31  9:32     ` [dpdk-dev] [PATCH v3 6/8] l2fwd-crypto: clarify key parsing in help Pablo de Lara
2016-03-31  9:32     ` [dpdk-dev] [PATCH v3 7/8] l2fwd-crypto: use key-value list of supported algorithms Pablo de Lara
2016-03-31  9:32     ` [dpdk-dev] [PATCH v3 8/8] l2fwd-crypto: extend crypto information Pablo de Lara
2016-03-31 12:14     ` [dpdk-dev] [PATCH v3 0/8] L2fwd-crypto fixes/enhancements Bruce Richardson
2016-03-31 12:19       ` Thomas Monjalon
2016-03-31 12:22     ` Declan Doherty
2016-03-31 20:22       ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459342950-52434-7-git-send-email-pablo.de.lara.guarch@intel.com \
    --to=pablo.de.lara.guarch@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).