From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2712C45501 for ; Wed, 26 Jun 2024 12:34:59 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 194BF42EC1; Wed, 26 Jun 2024 12:34:59 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 81CFF40B95; Wed, 26 Jun 2024 12:18:46 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45Q9jmmD020777; Wed, 26 Jun 2024 03:18:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=pfpt0220; bh=z8Z7hFzIQLqXVYX+OSdDRSR J2nE5CEYshJXbUIalTho=; b=T66tJSvwPBDBZ5xSJEfiu3WbF6jlMLFYHDGCJfZ xpv2rO3CzG9ImS2Dqz6orxahx9EyqS2d0XQn7RXaNb2fByZATnMxY1MqQiBEjmuM 22U8OAyB0jqubBXRAZdr9FwA5g6yniGqFYWnRs+nfxuCBHi/ti4rRDkdecr3KfXl 4z/4uz3VheCxXZbAL3kQSHeuowCsal8YEyH+/0d7uKatwLhbjmW5NMK2ePlslvNJ oYoBUhh/38CW5BEEO5xM8cwOFHvBee2dwcq9Qp3vFNTwVO9xX0MlY6bpXu7CeOQR g5c7F4Iw5KmLASUf3Ad21V3KyNjZ9cjOnUllFIxUjL0ecNw== Received: from dc5-exch05.marvell.com ([199.233.59.128]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 400ftng8jx-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 Jun 2024 03:18:45 -0700 (PDT) Received: from DC5-EXCH05.marvell.com (10.69.176.209) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.4; Wed, 26 Jun 2024 03:18:29 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH05.marvell.com (10.69.176.209) with Microsoft SMTP Server id 15.2.1544.4 via Frontend Transport; Wed, 26 Jun 2024 03:18:29 -0700 Received: from BG-LT91401.marvell.com (BG-LT91401.marvell.com [10.28.168.34]) by maili.marvell.com (Postfix) with ESMTP id B765F3F707B; Wed, 26 Jun 2024 03:18:24 -0700 (PDT) From: Gowrishankar Muthukrishnan To: , Ankur Dwivedi , Anoob Joseph , Tejasree Kondoj , Kiran Kumar K , Akhil Goyal CC: Gowrishankar Muthukrishnan , Subject: [PATCH v1] crypto/cnxk: minimal normalization on input Date: Wed, 26 Jun 2024 15:48:18 +0530 Message-ID: <20240626101821.1861-1-gmuthukrishn@marvell.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: w7zcNj1d73Xm1QJQ4JxBB3CeTRx4CQfX X-Proofpoint-GUID: w7zcNj1d73Xm1QJQ4JxBB3CeTRx4CQfX X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-26_04,2024-06-25_01,2024-05-17_01 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Fix modex to nomalize input only when MSW is zero. Fixes: 5a3513caeb45 ("crypto/cnxk: add asymmetric session") Cc: stable@dpdk.org Signed-off-by: Gowrishankar Muthukrishnan --- drivers/crypto/cnxk/cnxk_ae.h | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/crypto/cnxk/cnxk_ae.h b/drivers/crypto/cnxk/cnxk_ae.h index ea11e093bf..66277172c6 100644 --- a/drivers/crypto/cnxk/cnxk_ae.h +++ b/drivers/crypto/cnxk/cnxk_ae.h @@ -49,13 +49,22 @@ struct cnxk_ae_sess { }; static __rte_always_inline void -cnxk_ae_modex_param_normalize(uint8_t **data, size_t *len) +cnxk_ae_modex_param_normalize(uint8_t **data, size_t *len, size_t max) { + uint8_t msw_len = *len % 8; + uint64_t msw_val = 0; size_t i; - /* Strip leading NUL bytes */ - for (i = 0; i < *len; i++) { - if ((*data)[i] != 0) + if (*len <= 8) + return; + + memcpy(&msw_val, *data, msw_len); + if (msw_val != 0) + return; + + for (i = msw_len; i < *len && (*len - i) < max; i += 8) { + memcpy(&msw_val, &(*data)[i], 8); + if (msw_val != 0) break; } *data += i; @@ -72,8 +81,8 @@ cnxk_ae_fill_modex_params(struct cnxk_ae_sess *sess, uint8_t *exp = xform->modex.exponent.data; uint8_t *mod = xform->modex.modulus.data; - cnxk_ae_modex_param_normalize(&mod, &mod_len); - cnxk_ae_modex_param_normalize(&exp, &exp_len); + cnxk_ae_modex_param_normalize(&mod, &mod_len, SIZE_MAX); + cnxk_ae_modex_param_normalize(&exp, &exp_len, mod_len); if (unlikely(exp_len == 0 || mod_len == 0)) return -EINVAL; @@ -282,7 +291,7 @@ cnxk_ae_modex_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf, struct rte_crypto_mod_op_param mod_op; uint64_t total_key_len; union cpt_inst_w4 w4; - uint32_t base_len; + size_t base_len; uint32_t dlen; uint8_t *dptr; @@ -290,8 +299,11 @@ cnxk_ae_modex_prep(struct rte_crypto_op *op, struct roc_ae_buf_ptr *meta_buf, base_len = mod_op.base.length; if (unlikely(base_len > mod_len)) { - op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; - return -ENOTSUP; + cnxk_ae_modex_param_normalize(&mod_op.base.data, &base_len, mod_len); + if (base_len > mod_len) { + op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; + return -ENOTSUP; + } } total_key_len = mod_len + exp_len; -- 2.25.1