From patchwork Thu Sep 21 13:11:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "De Lara Guarch, Pablo" X-Patchwork-Id: 29074 X-Patchwork-Delegate: pablo.de.lara.guarch@intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 114681B19D; Thu, 21 Sep 2017 23:11:49 +0200 (CEST) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id 9EB861B19C for ; Thu, 21 Sep 2017 23:11:45 +0200 (CEST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2017 14:11:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,426,1500966000"; d="scan'208";a="902703266" Received: from silpixa00399464.ir.intel.com (HELO silpixa00399464.ger.corp.intel.com) ([10.237.222.157]) by FMSMGA003.fm.intel.com with ESMTP; 21 Sep 2017 14:11:43 -0700 From: Pablo de Lara To: declan.doherty@intel.com, fiona.trahe@intel.com, deepak.k.jain@intel.com, john.griffin@intel.com Cc: dev@dpdk.org, Pablo de Lara Date: Thu, 21 Sep 2017 14:11:15 +0100 Message-Id: <20170921131123.16513-3-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170921131123.16513-1-pablo.de.lara.guarch@intel.com> References: <20170818080728.43248-1-pablo.de.lara.guarch@intel.com> <20170921131123.16513-1-pablo.de.lara.guarch@intel.com> Subject: [dpdk-dev] [PATCH v2 2/9] examples/l2fwd-crypto: add AES-CCM support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" According to the API, AES-CCM has special requirements when setting IV and AAD fields. The L2fwd-crypto app is updated to set the nonce (IV) and AAD in the right positions in these two fields (1 byte after start of IV field and 18 bytes after start of AAD). Signed-off-by: Pablo de Lara --- examples/l2fwd-crypto/main.c | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/examples/l2fwd-crypto/main.c b/examples/l2fwd-crypto/main.c index 17673a3..5aa71c8 100644 --- a/examples/l2fwd-crypto/main.c +++ b/examples/l2fwd-crypto/main.c @@ -86,6 +86,8 @@ enum cdev_type { #define MAX_STR_LEN 32 #define MAX_KEY_SIZE 128 +#define MAX_IV_SIZE 16 +#define MAX_AAD_SIZE 65535 #define MAX_PKT_BURST 32 #define BURST_TX_DRAIN_US 100 /* TX drain every ~100us */ #define MAX_SESSIONS 32 @@ -534,7 +536,16 @@ l2fwd_simple_crypto_enqueue(struct rte_mbuf *m, uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, uint8_t *, IV_OFFSET); /* Copy IV at the end of the crypto operation */ - rte_memcpy(iv_ptr, cparams->aead_iv.data, cparams->aead_iv.length); + /* + * If doing AES-CCM, nonce is copied one byte + * after the start of IV field + */ + if (cparams->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) + rte_memcpy(iv_ptr + 1, cparams->aead_iv.data, + cparams->aead_iv.length); + else + rte_memcpy(iv_ptr, cparams->aead_iv.data, + cparams->aead_iv.length); op->sym->aead.data.offset = ipdata_offset; op->sym->aead.data.length = data_len; @@ -796,6 +807,14 @@ l2fwd_main_loop(struct l2fwd_crypto_options *options) if (!options->aad_param) generate_random_key(port_cparams[i].aad.data, port_cparams[i].aad.length); + /* + * If doing AES-CCM, first 18 bytes has to be reserved, + * and actual AAD should start from byte 18 + */ + if (port_cparams[i].aead_algo == RTE_CRYPTO_AEAD_AES_CCM) + memmove(port_cparams[i].aad.data + 18, + port_cparams[i].aad.data, + port_cparams[i].aad.length); } else port_cparams[i].aad.length = 0; @@ -1081,16 +1100,16 @@ parse_cipher_op(enum rte_crypto_cipher_operation *op, char *optarg) return -1; } -/** Parse crypto key command line argument */ +/** Parse bytes from command line argument */ static int -parse_key(uint8_t *data, char *input_arg) +parse_bytes(uint8_t *data, char *input_arg, uint16_t max_size) { unsigned byte_count; char *token; errno = 0; for (byte_count = 0, token = strtok(input_arg, ":"); - (byte_count < MAX_KEY_SIZE) && (token != NULL); + (byte_count < max_size) && (token != NULL); token = strtok(NULL, ":")) { int number = (int)strtol(token, NULL, 16); @@ -1230,7 +1249,8 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, else if (strcmp(lgopts[option_index].name, "cipher_key") == 0) { options->ckey_param = 1; options->cipher_xform.cipher.key.length = - parse_key(options->cipher_xform.cipher.key.data, optarg); + parse_bytes(options->cipher_xform.cipher.key.data, optarg, + MAX_KEY_SIZE); if (options->cipher_xform.cipher.key.length > 0) return 0; else @@ -1243,7 +1263,7 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, else if (strcmp(lgopts[option_index].name, "cipher_iv") == 0) { options->cipher_iv_param = 1; options->cipher_iv.length = - parse_key(options->cipher_iv.data, optarg); + parse_bytes(options->cipher_iv.data, optarg, MAX_IV_SIZE); if (options->cipher_iv.length > 0) return 0; else @@ -1266,7 +1286,8 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, else if (strcmp(lgopts[option_index].name, "auth_key") == 0) { options->akey_param = 1; options->auth_xform.auth.key.length = - parse_key(options->auth_xform.auth.key.data, optarg); + parse_bytes(options->auth_xform.auth.key.data, optarg, + MAX_KEY_SIZE); if (options->auth_xform.auth.key.length > 0) return 0; else @@ -1280,7 +1301,7 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, else if (strcmp(lgopts[option_index].name, "auth_iv") == 0) { options->auth_iv_param = 1; options->auth_iv.length = - parse_key(options->auth_iv.data, optarg); + parse_bytes(options->auth_iv.data, optarg, MAX_IV_SIZE); if (options->auth_iv.length > 0) return 0; else @@ -1303,7 +1324,8 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, else if (strcmp(lgopts[option_index].name, "aead_key") == 0) { options->aead_key_param = 1; options->aead_xform.aead.key.length = - parse_key(options->aead_xform.aead.key.data, optarg); + parse_bytes(options->aead_xform.aead.key.data, optarg, + MAX_KEY_SIZE); if (options->aead_xform.aead.key.length > 0) return 0; else @@ -1317,7 +1339,7 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, else if (strcmp(lgopts[option_index].name, "aead_iv") == 0) { options->aead_iv_param = 1; options->aead_iv.length = - parse_key(options->aead_iv.data, optarg); + parse_bytes(options->aead_iv.data, optarg, MAX_IV_SIZE); if (options->aead_iv.length > 0) return 0; else @@ -1330,7 +1352,7 @@ l2fwd_crypto_parse_args_long_options(struct l2fwd_crypto_options *options, else if (strcmp(lgopts[option_index].name, "aad") == 0) { options->aad_param = 1; options->aad.length = - parse_key(options->aad.data, optarg); + parse_bytes(options->aad.data, optarg, MAX_AAD_SIZE); if (options->aad.length > 0) return 0; else