From: Pablo de Lara Date: Thu, 31 Mar 2016 09:32:13 +0000 (+0100) Subject: examples/l2fwd-crypto: use key-value list of supported algorithms X-Git-Tag: spdx-start~7116 X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=00c58901f1b3df693e990a9ba64489bba6c4cb60;p=dpdk.git examples/l2fwd-crypto: use key-value list of supported algorithms 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 Acked-by: Declan Doherty --- diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index 6a284487d3..5fb33df55b 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 d01287cb85..913941a47e 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 */