From patchwork Tue Dec 20 14:32:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejasree Kondoj X-Patchwork-Id: 121076 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 AAC7DA0545; Tue, 20 Dec 2022 15:32:55 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F2B1C42D1A; Tue, 20 Dec 2022 15:32:46 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 49B3542D1A for ; Tue, 20 Dec 2022 15:32:45 +0100 (CET) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2BKEOQ0t018991 for ; Tue, 20 Dec 2022 06:32:44 -0800 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=sjAYvoU/vMhUCh3BNLR/HWH5hRO73VsHcWTIGdzI9f4=; b=cRWjQ99p0mUC0HcwXofT0CN15+zYCktLg2TIgNuZMapppMykHQ/o3X3EA4PS0P0iPkO+ /eUCQxTniWDfj9TGo1UqAiScBJLX9ua70EpJSIUFcIw9LE11OlZ2cIyI5dAaIUCdaEyJ Fc174CkAIXm5wx/ebFWCq0DRzaZMoCHL5MNlKZDUl89wkRmICMAW53oq6xFSmX6ClFyC uVh1rM9zD/pugqatsg2yJqwkH2vxDkLdC2yl2Wwuvx2XO5fl/QcUhRDE/e+GI+WvglHD tvqDkkYayBh1dhripWLgpJoBwyWbHcgZ87Bz5kaCAMKn+0wpwWzYGZz//KuSN+p/VSVQ cg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3mhe5rnb54-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Tue, 20 Dec 2022 06:32:44 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Tue, 20 Dec 2022 06:32:42 -0800 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.42 via Frontend Transport; Tue, 20 Dec 2022 06:32:42 -0800 Received: from hyd1554.marvell.com (unknown [10.29.57.11]) by maili.marvell.com (Postfix) with ESMTP id CFBFC3F7063; Tue, 20 Dec 2022 06:32:39 -0800 (PST) From: Tejasree Kondoj To: Akhil Goyal CC: Aakash Sasidharan , Anoob Joseph , Vidya Sagar Velumuri , Gowrishankar Muthukrishnan , Volodymyr Fialko , Subject: [PATCH 02/17] common/cnxk: generate opad and ipad in driver Date: Tue, 20 Dec 2022 20:02:17 +0530 Message-ID: <20221220143232.2519650-3-ktejasree@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221220143232.2519650-1-ktejasree@marvell.com> References: <20221220143232.2519650-1-ktejasree@marvell.com> MIME-Version: 1.0 X-Proofpoint-GUID: JPAxUSOVnReXw8U5yrvq2wm2INfHDALD X-Proofpoint-ORIG-GUID: JPAxUSOVnReXw8U5yrvq2wm2INfHDALD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-20_05,2022-12-20_01,2022-06-22_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 From: Aakash Sasidharan Generate opad and ipad in driver for SHA based crypto algos Signed-off-by: Aakash Sasidharan --- drivers/common/cnxk/cnxk_security.c | 4 +-- drivers/common/cnxk/roc_hash.c | 12 ++++--- drivers/common/cnxk/roc_hash.h | 2 +- drivers/common/cnxk/roc_se.c | 52 +++++++++++++++++++++++++++-- 4 files changed, 60 insertions(+), 10 deletions(-) diff --git a/drivers/common/cnxk/cnxk_security.c b/drivers/common/cnxk/cnxk_security.c index 85105472a1..5034c76938 100644 --- a/drivers/common/cnxk/cnxk_security.c +++ b/drivers/common/cnxk/cnxk_security.c @@ -37,8 +37,8 @@ ipsec_hmac_opad_ipad_gen(struct rte_crypto_sym_xform *auth_xform, roc_hash_sha1_gen(ipad, (uint32_t *)&hmac_opad_ipad[24]); break; case RTE_CRYPTO_AUTH_SHA256_HMAC: - roc_hash_sha256_gen(opad, (uint32_t *)&hmac_opad_ipad[0]); - roc_hash_sha256_gen(ipad, (uint32_t *)&hmac_opad_ipad[64]); + roc_hash_sha256_gen(opad, (uint32_t *)&hmac_opad_ipad[0], 256); + roc_hash_sha256_gen(ipad, (uint32_t *)&hmac_opad_ipad[64], 256); break; case RTE_CRYPTO_AUTH_SHA384_HMAC: roc_hash_sha512_gen(opad, (uint64_t *)&hmac_opad_ipad[0], 384); diff --git a/drivers/common/cnxk/roc_hash.c b/drivers/common/cnxk/roc_hash.c index 1b9030e693..8c451440b1 100644 --- a/drivers/common/cnxk/roc_hash.c +++ b/drivers/common/cnxk/roc_hash.c @@ -232,7 +232,7 @@ roc_hash_sha1_gen(uint8_t *msg, uint32_t *hash) * Based on implementation from RFC 3174 */ void -roc_hash_sha256_gen(uint8_t *msg, uint32_t *hash) +roc_hash_sha256_gen(uint8_t *msg, uint32_t *hash, int hash_size) { const uint32_t _K[] = { /* Round Constants defined in SHA-256 */ @@ -250,13 +250,17 @@ roc_hash_sha256_gen(uint8_t *msg, uint32_t *hash) 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; - const uint32_t _H[] = {/* Initial Hash constants defined in SHA-256 */ - 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, - 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; + const uint32_t _H224[] = {/* Initial Hash constants defined in SHA-224 */ + 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, + 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4}; + const uint32_t _H256[] = {/* Initial Hash constants defined in SHA-256 */ + 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, + 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19}; int i; uint32_t temp[4], S0, S1; /* Temporary word value */ uint32_t W[64]; /* Word sequence */ uint32_t A, B, C, D, E, F, G, H; /* Word buffers */ + const uint32_t *_H = (hash_size == 224) ? _H224 : _H256; /* Initialize the first 16 words in the array W */ memcpy(&W[0], msg, 16 * sizeof(W[0])); diff --git a/drivers/common/cnxk/roc_hash.h b/drivers/common/cnxk/roc_hash.h index 8940faa6eb..c3ddb9407b 100644 --- a/drivers/common/cnxk/roc_hash.h +++ b/drivers/common/cnxk/roc_hash.h @@ -11,7 +11,7 @@ */ void __roc_api roc_hash_md5_gen(uint8_t *msg, uint32_t *hash); void __roc_api roc_hash_sha1_gen(uint8_t *msg, uint32_t *hash); -void __roc_api roc_hash_sha256_gen(uint8_t *msg, uint32_t *hash); +void __roc_api roc_hash_sha256_gen(uint8_t *msg, uint32_t *hash, int hash_size); void __roc_api roc_hash_sha512_gen(uint8_t *msg, uint64_t *hash, int hash_size); #endif /* _ROC_HASH_H_ */ diff --git a/drivers/common/cnxk/roc_se.c b/drivers/common/cnxk/roc_se.c index 2663480099..22df61f5f0 100644 --- a/drivers/common/cnxk/roc_se.c +++ b/drivers/common/cnxk/roc_se.c @@ -149,6 +149,53 @@ cpt_ciph_aes_key_type_set(struct roc_se_context *fctx, uint16_t key_len) fctx->enc.aes_key = aes_key_type; } +static void +cpt_hmac_opad_ipad_gen(roc_se_auth_type auth_type, const uint8_t *key, uint16_t length, + struct roc_se_hmac_context *hmac) +{ + uint8_t opad[128] = {[0 ... 127] = 0x5c}; + uint8_t ipad[128] = {[0 ... 127] = 0x36}; + uint32_t i; + + /* HMAC OPAD and IPAD */ + for (i = 0; i < 128 && i < length; i++) { + opad[i] = opad[i] ^ key[i]; + ipad[i] = ipad[i] ^ key[i]; + } + + /* Precompute hash of HMAC OPAD and IPAD to avoid + * per packet computation + */ + switch (auth_type) { + case ROC_SE_MD5_TYPE: + roc_hash_md5_gen(opad, (uint32_t *)hmac->opad); + roc_hash_md5_gen(ipad, (uint32_t *)hmac->ipad); + break; + case ROC_SE_SHA1_TYPE: + roc_hash_sha1_gen(opad, (uint32_t *)hmac->opad); + roc_hash_sha1_gen(ipad, (uint32_t *)hmac->ipad); + break; + case ROC_SE_SHA2_SHA224: + roc_hash_sha256_gen(opad, (uint32_t *)hmac->opad, 224); + roc_hash_sha256_gen(ipad, (uint32_t *)hmac->ipad, 224); + break; + case ROC_SE_SHA2_SHA256: + roc_hash_sha256_gen(opad, (uint32_t *)hmac->opad, 256); + roc_hash_sha256_gen(ipad, (uint32_t *)hmac->ipad, 256); + break; + case ROC_SE_SHA2_SHA384: + roc_hash_sha512_gen(opad, (uint64_t *)hmac->opad, 384); + roc_hash_sha512_gen(ipad, (uint64_t *)hmac->ipad, 384); + break; + case ROC_SE_SHA2_SHA512: + roc_hash_sha512_gen(opad, (uint64_t *)hmac->opad, 512); + roc_hash_sha512_gen(ipad, (uint64_t *)hmac->ipad, 512); + break; + default: + break; + } +} + static int cpt_pdcp_key_type_set(struct roc_se_zuc_snow3g_ctx *zs_ctx, uint16_t key_len) { @@ -434,9 +481,8 @@ roc_se_auth_key_set(struct roc_se_ctx *se_ctx, roc_se_auth_type type, memset(fctx->hmac.ipad, 0, sizeof(fctx->hmac.ipad)); memset(fctx->hmac.opad, 0, sizeof(fctx->hmac.opad)); - if (key_len <= 64) - memcpy(fctx->hmac.opad, key, key_len); - fctx->enc.auth_input_type = 1; + cpt_hmac_opad_ipad_gen(type, key, key_len, &fctx->hmac); + fctx->enc.auth_input_type = 0; } return 0; }