From patchwork Fri Jun 3 07:13:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankur Dwivedi X-Patchwork-Id: 112288 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 09B48A0555; Fri, 3 Jun 2022 09:13:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EFF4C427F3; Fri, 3 Jun 2022 09:13:34 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 5C8084021E for ; Fri, 3 Jun 2022 09:13:33 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2533qIm2032524 for ; Fri, 3 Jun 2022 00:13:32 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=MubRLGiUcId56UNnyCnRQeHdKMdiGAID60ckigr3FJM=; b=i5OTj1OGEiey/GYVowmdHxVjbsnHb5PUZLpjREfKP2hWEVzPNwvrjzLe9MdK/nRXspwB VVTaOX55Wyc/ppVzgQAh71/8i31+BZ5BsWPTwkuE6CXILUtDoyNltyeAMmNQRA3j6joy kFr0lNZhuPSMZAAlICHia316tl41hV8miNhW7cPqHwgvJcxwQ73QmaJd9jKZHJQl44El vYlWiLW/pv/lYlQtAYWreSThJsFuxbh7hyeUF+lNCQKHFvhCrE+m/r/mKyVE9L/shSBW XpgtP+MTvRPU6zOion3k8pA1zXFSS1ZwAaAOhn4/lOGxINYMd37vPqqgPk4QV0i0lIcP tg== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3geu3ecbmv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 03 Jun 2022 00:13:32 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 3 Jun 2022 00:13:30 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 3 Jun 2022 00:13:30 -0700 Received: from hyd1349.t110.caveonetworks.com.com (unknown [10.29.45.13]) by maili.marvell.com (Postfix) with ESMTP id 54CF43F7065; Fri, 3 Jun 2022 00:13:28 -0700 (PDT) From: Ankur Dwivedi To: CC: , , , , Ankur Dwivedi Subject: [PATCH 1/2] common/cnxk: swap zuc-256 key Date: Fri, 3 Jun 2022 12:43:06 +0530 Message-ID: <20220603071307.14360-2-adwivedi@marvell.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20220603071307.14360-1-adwivedi@marvell.com> References: <20220603071307.14360-1-adwivedi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: gbINHZp-2lZYOeKFuGOm1nqVGuSpcj4d X-Proofpoint-ORIG-GUID: gbINHZp-2lZYOeKFuGOm1nqVGuSpcj4d X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-03_02,2022-06-02_01,2022-02-23_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 Reviewed-by: Jerin Jacob Kollanukkaran --- 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 145a1825bd..fde69ceb9e 100644 --- a/drivers/common/cnxk/roc_se.h +++ b/drivers/common/cnxk/roc_se.h @@ -301,6 +301,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); @@ -310,4 +331,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__ */ From patchwork Fri Jun 3 07:13:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ankur Dwivedi X-Patchwork-Id: 112289 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EB700A0555; Fri, 3 Jun 2022 09:13:40 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DCCAD427F2; Fri, 3 Jun 2022 09:13:40 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 0A1624021E for ; Fri, 3 Jun 2022 09:13:39 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 2533rCl6000812 for ; Fri, 3 Jun 2022 00:13:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=7vWBhA8z6pWYEmBYrhdcZRomUEN6ixkx1wUi2sSA5+8=; b=VG8vQY+JdJhiFmMMY6QbS9+f5arKnfwtQF0GuMaDWyVzrSWR6H8S4sqz++hAr2AFboAm FLJY9G+qItsHgtHbUBSGE7yGzf1dU7UajFduE7lKtz6eYhR6MJjHhaDcD7W+4nYTp1XP k4ljdLTbbyYL8F53pfwAtZGlhJUUTEASDLhwu5WQmp3w8MpXPkXn59dMvZHy5PVL2I/V ctMEIvnleA9A52GMsNPooI6wrOE4EwpbMvWY57vMl66FijTy1IXu1nAbIIj0vpcPNvtc IA4+KKD0zeLKzeyfszFO68pxq3P+ZzaZXMuSESDPlCJ2lJfQun1B8CM2EpXJD8v4KjZv tA== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3geu3ecbne-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 03 Jun 2022 00:13:39 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Fri, 3 Jun 2022 00:13:36 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 3 Jun 2022 00:13:36 -0700 Received: from hyd1349.t110.caveonetworks.com.com (unknown [10.29.45.13]) by maili.marvell.com (Postfix) with ESMTP id A9D1E3F706D; Fri, 3 Jun 2022 00:13:34 -0700 (PDT) From: Ankur Dwivedi To: CC: , , , , Ankur Dwivedi Subject: [PATCH 2/2] crypto/cnxk: swap zuc-256 iv Date: Fri, 3 Jun 2022 12:43:07 +0530 Message-ID: <20220603071307.14360-3-adwivedi@marvell.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20220603071307.14360-1-adwivedi@marvell.com> References: <20220603071307.14360-1-adwivedi@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: 2aXuykOzD_RXuSo67ieo-2bZBWfW1Ura X-Proofpoint-ORIG-GUID: 2aXuykOzD_RXuSo67ieo-2bZBWfW1Ura X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.517,FMLib:17.11.64.514 definitions=2022-06-03_02,2022-06-02_01,2022-02-23_01 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The microcode expects the iv to be in reverse of what is provided by dpdk test app. Also the first 8 bytes of reversed iv is compressed to 6 bytes. Signed-off-by: Ankur Dwivedi Reviewed-by: Jerin Jacob Kollanukkaran --- drivers/crypto/cnxk/cnxk_se.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/crypto/cnxk/cnxk_se.h b/drivers/crypto/cnxk/cnxk_se.h index a339b80a87..8ed3a8b2ef 100644 --- a/drivers/crypto/cnxk/cnxk_se.h +++ b/drivers/crypto/cnxk/cnxk_se.h @@ -44,17 +44,16 @@ fill_sess_gmac(struct rte_crypto_sym_xform *xform, struct cnxk_se_sess *sess); static inline void cpt_pack_iv(uint8_t *iv_src, uint8_t *iv_dst) { - iv_dst[16] = iv_src[16]; - /* pack the last 8 bytes of IV to 6 bytes. + /* pack the first 8 bytes of IV to 6 bytes. * discard the 2 MSB bits of each byte */ - iv_dst[17] = (((iv_src[17] & 0x3f) << 2) | ((iv_src[18] >> 4) & 0x3)); - iv_dst[18] = (((iv_src[18] & 0xf) << 4) | ((iv_src[19] >> 2) & 0xf)); - iv_dst[19] = (((iv_src[19] & 0x3) << 6) | (iv_src[20] & 0x3f)); + iv_dst[0] = (((iv_src[0] & 0x3f) << 2) | ((iv_src[1] >> 4) & 0x3)); + iv_dst[1] = (((iv_src[1] & 0xf) << 4) | ((iv_src[2] >> 2) & 0xf)); + iv_dst[2] = (((iv_src[2] & 0x3) << 6) | (iv_src[3] & 0x3f)); - iv_dst[20] = (((iv_src[21] & 0x3f) << 2) | ((iv_src[22] >> 4) & 0x3)); - iv_dst[21] = (((iv_src[22] & 0xf) << 4) | ((iv_src[23] >> 2) & 0xf)); - iv_dst[22] = (((iv_src[23] & 0x3) << 6) | (iv_src[24] & 0x3f)); + iv_dst[3] = (((iv_src[4] & 0x3f) << 2) | ((iv_src[5] >> 4) & 0x3)); + iv_dst[4] = (((iv_src[5] & 0xf) << 4) | ((iv_src[6] >> 2) & 0xf)); + iv_dst[5] = (((iv_src[6] & 0x3) << 6) | (iv_src[7] & 0x3f)); } static inline void @@ -76,10 +75,11 @@ pdcp_iv_copy(uint8_t *iv_d, uint8_t *iv_s, const uint8_t pdcp_alg_type, iv_temp[j] = iv_s_temp[3 - j]; memcpy(iv_d, iv_temp, 16); } else if (pdcp_alg_type == ROC_SE_PDCP_ALG_TYPE_ZUC) { - /* ZUC doesn't need a swap */ - memcpy(iv_d, iv_s, 16); - if (pack_iv) + if (pack_iv) { cpt_pack_iv(iv_s, iv_d); + memcpy(iv_d + 6, iv_s + 8, 17); + } else + memcpy(iv_d, iv_s, 16); } else { /* AES-CMAC EIA2, microcode expects 16B zeroized IV */ for (j = 0; j < 4; j++) @@ -1037,6 +1037,7 @@ cpt_pdcp_alg_prep(uint32_t req_flags, uint64_t d_offs, uint64_t d_lens, iv_len = params->auth_iv_len; if (iv_len == 25) { + roc_se_zuc_bytes_swap(iv_s, iv_len); iv_len -= 2; pack_iv = 1; } @@ -1068,6 +1069,7 @@ cpt_pdcp_alg_prep(uint32_t req_flags, uint64_t d_offs, uint64_t d_lens, iv_len = params->cipher_iv_len; if (iv_len == 25) { + roc_se_zuc_bytes_swap(iv_s, iv_len); iv_len -= 2; pack_iv = 1; }