diff mbox series

[2.0,v1,3/5] linux-dpdk: crypto bug fixes

Message ID 1512547207-1806-4-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [2.0,v1,1/5] test: enable dpdk initialization before running validation on linux-dpdk | expand

Commit Message

Github ODP bot Dec. 6, 2017, 8 a.m. UTC
From: Balakrishna Garapati <balakrishna.garapati@linaro.org>


Signed-off-by: Balakrishna Garapati <balakrishna.garapati@linaro.org>

Reviewed-by: Yi He <yi.he@linaro.org>

---
/** Email created from pull request 323 (heyi-linaro:2.0-linux-dpdk-make-check)
 ** https://github.com/Linaro/odp/pull/323
 ** Patch: https://github.com/Linaro/odp/pull/323.patch
 ** Base sha: 00c7441fae53949dd87855d48102f932f8f64537
 ** Merge commit sha: 97e968c4c23266a903016fe9bda392687b44b08f
 **/
 platform/linux-dpdk/odp_crypto.c | 77 ++++++++++++++++++++++++----------------
 1 file changed, 46 insertions(+), 31 deletions(-)
diff mbox series

Patch

diff --git a/platform/linux-dpdk/odp_crypto.c b/platform/linux-dpdk/odp_crypto.c
index 9844f2dd7..ea014c8e8 100644
--- a/platform/linux-dpdk/odp_crypto.c
+++ b/platform/linux-dpdk/odp_crypto.c
@@ -808,40 +808,53 @@  int odp_crypto_session_create(odp_crypto_session_param_t *param,
 	/* Default to successful result */
 	*status = ODP_CRYPTO_SES_CREATE_ERR_NONE;
 
-	/* Cipher Data */
-	cipher_xform.cipher.key.data = rte_malloc("crypto key",
-						param->cipher_key.length, 0);
-	if (cipher_xform.cipher.key.data == NULL) {
-		ODP_ERR("Failed to allocate memory for cipher key\n");
-		/* remove the crypto_session_entry_t */
-		memset(entry, 0, sizeof(*entry));
-		free_session(entry);
-		return -1;
-	}
-
 	cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
 	cipher_xform.next = NULL;
-	cipher_xform.cipher.key.length = param->cipher_key.length;
-	memcpy(cipher_xform.cipher.key.data,
-	       param->cipher_key.data,
-	       param->cipher_key.length);
-
-	/* Authentication Data */
-	auth_xform.auth.key.data = rte_malloc("auth key",
-						param->auth_key.length, 0);
-	if (auth_xform.auth.key.data == NULL) {
-		ODP_ERR("Failed to allocate memory for auth key\n");
-		/* remove the crypto_session_entry_t */
-		memset(entry, 0, sizeof(*entry));
-		free_session(entry);
-		return -1;
+
+	if (param->cipher_key.length) {
+		/* Cipher Data */
+		cipher_xform.cipher.key.data = rte_malloc("crypto key",
+						   param->cipher_key.length, 0);
+		if (cipher_xform.cipher.key.data == NULL) {
+			ODP_ERR("Failed to allocate memory for cipher key\n");
+			/* remove the crypto_session_entry_t */
+			memset(entry, 0, sizeof(*entry));
+			free_session(entry);
+			return -1;
+		}
+
+		cipher_xform.cipher.key.length = param->cipher_key.length;
+		memcpy(cipher_xform.cipher.key.data,
+		       param->cipher_key.data,
+		       param->cipher_key.length);
+	} else {
+		cipher_xform.cipher.key.data = 0;
+		cipher_xform.cipher.key.length = 0;
 	}
+
 	auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
 	auth_xform.next = NULL;
-	auth_xform.auth.key.length = param->auth_key.length;
-	memcpy(auth_xform.auth.key.data,
-	       param->auth_key.data,
-	       param->auth_key.length);
+
+	if (param->auth_key.length) {
+		/* Authentication Data */
+		auth_xform.auth.key.data = rte_malloc("auth key",
+						     param->auth_key.length, 0);
+		if (auth_xform.auth.key.data == NULL) {
+			ODP_ERR("Failed to allocate memory for auth key\n");
+			/* remove the crypto_session_entry_t */
+			memset(entry, 0, sizeof(*entry));
+			free_session(entry);
+			return -1;
+		}
+		auth_xform.auth.key.length = param->auth_key.length;
+		memcpy(auth_xform.auth.key.data,
+		       param->auth_key.data,
+		       param->auth_key.length);
+	} else {
+		auth_xform.auth.key.data = 0;
+		auth_xform.auth.key.length = 0;
+	}
+
 
 	/* Derive order */
 	if (ODP_CRYPTO_OP_ENCODE == param->op)
@@ -1271,11 +1284,13 @@  int odp_crypto_int(odp_packet_t pkt_in,
 		memcpy(op->sym->cipher.iv.data,
 		       param->override_iv_ptr,
 		       entry->iv.length);
+		op->sym->cipher.iv.phys_addr =
+				rte_malloc_virt2phy(op->sym->cipher.iv.data);
+		op->sym->cipher.iv.length = entry->iv.length;
 	} else if (entry->iv.data) {
 		memcpy(op->sym->cipher.iv.data,
 		       entry->iv.data,
 		       entry->iv.length);
-
 		op->sym->cipher.iv.phys_addr =
 				rte_malloc_virt2phy(op->sym->cipher.iv.data);
 		op->sym->cipher.iv.length = entry->iv.length;
@@ -1326,7 +1341,7 @@  int odp_crypto_int(odp_packet_t pkt_in,
 		(rc_auth == ODP_CRYPTO_ALG_ERR_NONE);
 
 	_odp_buffer_event_subtype_set(packet_to_buffer(out_pkt),
-				      ODP_EVENT_PACKET_BASIC);
+				      ODP_EVENT_PACKET_CRYPTO);
 	op_result = get_op_result_from_packet(out_pkt);
 	*op_result = local_result;