patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Ankur Dwivedi <adwivedi@marvell.com>
To: <stable@dpdk.org>
Cc: <anoobj@marvell.com>, <gakhil@marvell.com>,
	<ktejasree@marvell.com>, <jerinj@marvell.com>,
	Ankur Dwivedi <adwivedi@marvell.com>
Subject: [PATCH 1/2] common/cnxk: swap zuc-256 key
Date: Fri, 3 Jun 2022 16:48:22 +0530	[thread overview]
Message-ID: <20220603111823.311-2-adwivedi@marvell.com> (raw)
In-Reply-To: <20220603111823.311-1-adwivedi@marvell.com>

The microcode expects zuc-256 key to be in reverse of what is
provided by dpdk test app. This patch swaps the zuc-256 key.

Signed-off-by: Ankur Dwivedi <adwivedi@marvell.com>
Reviewed-by: Jerin Jacob Kollanukkaran <jerinj@marvell.com>
---
 drivers/common/cnxk/roc_se.c |  7 +++++--
 drivers/common/cnxk/roc_se.h | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/drivers/common/cnxk/roc_se.c b/drivers/common/cnxk/roc_se.c
index ffe537af30..3f0821e400 100644
--- a/drivers/common/cnxk/roc_se.c
+++ b/drivers/common/cnxk/roc_se.c
@@ -283,6 +283,8 @@ roc_se_auth_key_set(struct roc_se_ctx *se_ctx, roc_se_auth_type type,
 				return ret;
 			se_ctx->pdcp_alg_type = ROC_SE_PDCP_ALG_TYPE_ZUC;
 			memcpy(ci_key, key, key_len);
+			if (key_len == 32)
+				roc_se_zuc_bytes_swap(ci_key, key_len);
 			cpt_pdcp_update_zuc_const(zuc_const, key_len, mac_len);
 			se_ctx->fc_type = ROC_SE_PDCP;
 			se_ctx->zsk_flags = 0x1;
@@ -459,9 +461,10 @@ roc_se_ciph_key_set(struct roc_se_ctx *se_ctx, roc_se_cipher_type type,
 		zs_ctx->zuc.otk_ctx.w0.s.alg_type = ROC_SE_PDCP_ALG_TYPE_ZUC;
 		se_ctx->pdcp_alg_type = ROC_SE_PDCP_ALG_TYPE_ZUC;
 		memcpy(ci_key, key, key_len);
-		if (key_len == 32)
+		if (key_len == 32) {
+			roc_se_zuc_bytes_swap(ci_key, key_len);
 			memcpy(zuc_const, zuc_key256, 16);
-		else
+		} else
 			memcpy(zuc_const, zuc_key128, 32);
 
 		se_ctx->zsk_flags = 0;
diff --git a/drivers/common/cnxk/roc_se.h b/drivers/common/cnxk/roc_se.h
index 5be832fa75..500f94ac11 100644
--- a/drivers/common/cnxk/roc_se.h
+++ b/drivers/common/cnxk/roc_se.h
@@ -297,6 +297,27 @@ struct roc_se_ctx {
 	uint8_t *auth_key;
 };
 
+static inline void
+roc_se_zuc_bytes_swap(uint8_t *arr, int len)
+{
+	int start, end;
+	uint8_t tmp;
+
+	if (len <= 0)
+		return;
+
+	start = 0;
+	end = len - 1;
+
+	while (start < end) {
+		tmp = arr[start];
+		arr[start] = arr[end];
+		arr[end] = tmp;
+		start++;
+		end--;
+	}
+}
+
 int __roc_api roc_se_auth_key_set(struct roc_se_ctx *se_ctx,
 				  roc_se_auth_type type, const uint8_t *key,
 				  uint16_t key_len, uint16_t mac_len);
@@ -306,4 +327,5 @@ int __roc_api roc_se_ciph_key_set(struct roc_se_ctx *se_ctx,
 				  uint16_t key_len, uint8_t *salt);
 
 void __roc_api roc_se_ctx_swap(struct roc_se_ctx *se_ctx);
+
 #endif /* __ROC_SE_H__ */
-- 
2.28.0


  reply	other threads:[~2022-06-03 11:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-03 11:18 [PATCH 0/2] add zuc-256 support Ankur Dwivedi
2022-06-03 11:18 ` Ankur Dwivedi [this message]
2022-06-03 11:18 ` [PATCH 2/2] crypto/cnxk: swap zuc-256 iv Ankur Dwivedi
2022-06-23 14:25 ` [PATCH 0/2] add zuc-256 support Kevin Traynor
2022-06-23 14:42   ` [EXT] " Ankur Dwivedi

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=20220603111823.311-2-adwivedi@marvell.com \
    --to=adwivedi@marvell.com \
    --cc=anoobj@marvell.com \
    --cc=gakhil@marvell.com \
    --cc=jerinj@marvell.com \
    --cc=ktejasree@marvell.com \
    --cc=stable@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).