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 47AD342B2C; Wed, 17 May 2023 18:47:55 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3AD6A40EE1; Wed, 17 May 2023 18:47:55 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 3E9CC406B7 for ; Wed, 17 May 2023 18:47:53 +0200 (CEST) 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 34HGU8Rk020758; Wed, 17 May 2023 09:47:52 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=KGAopkBEKWIWAab3r+j34I8yeJvrJ1ZmfLegrUJwbfs=; b=d4mU+9gSz9am8UXcnzo/3QGxbS1E09TZCrA6Kgz5ix8w4Gf/YUtYMToFAzsq5eboEjfi BOonFcX0H44RTOXDOVAWmG/IYVAAsGpJzduFICAmu/7FedsSHlOJaALtbn6JZ+xB0loQ ODCtMYvtXkh8JDxj0wz0HDipuIEhUoRy6OtUuKnPi/Rd3TwvTz/j1tYMd5r76DqP3fUu vOV4yvrl1ke5/iw7CWe/soIgqPmPjdUfjH9l9tphPUIBNBID+oyh8ZfwED+1uoFizv7W SUU7/CR0+1vFalQVPkJFRitxZxktgWmHpIIIRKslOFw02bDOsi2kArM9Aw15WAp+KKaZ Wg== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3qmyex8tnu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 17 May 2023 09:47:52 -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.48; Wed, 17 May 2023 09:47:50 -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.48 via Frontend Transport; Wed, 17 May 2023 09:47:50 -0700 Received: from BG-LT91401.marvell.com (unknown [10.193.69.246]) by maili.marvell.com (Postfix) with ESMTP id CAA0B3F7071; Wed, 17 May 2023 09:47:47 -0700 (PDT) From: Gowrishankar Muthukrishnan To: CC: , Akhil Goyal , Fan Zhang , Gowrishankar Muthukrishnan Subject: [PATCH] lib/cryptodev: set minimal output buffer size for RSA op Date: Wed, 17 May 2023 22:17:43 +0530 Message-ID: <4f603fb187e0ff7170b214ecd58da8bbc8f48f45.1684341286.git.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-GUID: AOpDPKo_2TiQDDGKbGqzi8XkGFivL-0W X-Proofpoint-ORIG-GUID: AOpDPKo_2TiQDDGKbGqzi8XkGFivL-0W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-17_02,2023-05-17_02,2023-02-09_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 Depending on RSA op, the output buffer size could be set minimal expected memory, rather than 0 as today. This will allow PMD to do any validation on the size, in case an application did not create enough memory or even in case of any memory fault. Signed-off-by: Gowrishankar Muthukrishnan --- app/test/test_cryptodev_asym.c | 6 +++--- lib/cryptodev/rte_crypto_asym.h | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c index 9236817650..bb4c70deba 100644 --- a/app/test/test_cryptodev_asym.c +++ b/app/test/test_cryptodev_asym.c @@ -90,7 +90,7 @@ queue_ops_rsa_sign_verify(void *sess) asym_op->rsa.message.data = rsaplaintext.data; asym_op->rsa.message.length = rsaplaintext.len; - asym_op->rsa.sign.length = 0; + asym_op->rsa.sign.length = RTE_DIM(rsa_n); asym_op->rsa.sign.data = output_buf; asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5; @@ -181,7 +181,7 @@ queue_ops_rsa_enc_dec(void *sess) asym_op->rsa.message.data = rsaplaintext.data; asym_op->rsa.cipher.data = cipher_buf; - asym_op->rsa.cipher.length = 0; + asym_op->rsa.cipher.length = RTE_DIM(rsa_n); asym_op->rsa.message.length = rsaplaintext.len; asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5; @@ -213,7 +213,7 @@ queue_ops_rsa_enc_dec(void *sess) /* Use the resulted output as decryption Input vector*/ asym_op = result_op->asym; - asym_op->rsa.message.length = 0; + asym_op->rsa.message.length = RTE_DIM(rsa_n); asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT; asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5; diff --git a/lib/cryptodev/rte_crypto_asym.h b/lib/cryptodev/rte_crypto_asym.h index 989f38323f..bdf92d4358 100644 --- a/lib/cryptodev/rte_crypto_asym.h +++ b/lib/cryptodev/rte_crypto_asym.h @@ -414,7 +414,8 @@ struct rte_crypto_rsa_op_param { * In this case the underlying array should have been * allocated with enough memory to hold plaintext output * (i.e. must be at least RSA key size). The message.length - * field should be 0 and will be overwritten by the PMD + * field could be either 0 or minimal length expected from PMD. + * This could be validated and overwritten by the PMD * with the decrypted length. */ @@ -427,8 +428,10 @@ struct rte_crypto_rsa_op_param { * - for RSA public encrypt. * In this case the underlying array should have been allocated * with enough memory to hold ciphertext output (i.e. must be - * at least RSA key size). The cipher.length field should - * be 0 and will be overwritten by the PMD with the encrypted length. + * at least RSA key size). The cipher.length field could be + * either 0 or minimal length expected from PMD. + * This could be validated and overwritten by the PMD + * with the encrypted length. * * When RTE_CRYPTO_RSA_PADDING_NONE and RTE_CRYPTO_ASYM_OP_VERIFY * selected, this is an output of decrypted signature. @@ -443,8 +446,10 @@ struct rte_crypto_rsa_op_param { * - for RSA private encrypt. * In this case the underlying array should have been allocated * with enough memory to hold signature output (i.e. must be - * at least RSA key size). The sign.length field should - * be 0 and will be overwritten by the PMD with the signature length. + * at least RSA key size). The sign.length field could be + * either 0 or minimal length expected from PMD. + * This could be validated and overwritten by the PMD + * with the signature length. */ struct rte_crypto_rsa_padding padding; -- 2.25.1