DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
To: <dev@dpdk.org>
Cc: <anoobj@marvell.com>, Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <fanzhang.oss@gmail.com>,
	Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Subject: [PATCH] lib/cryptodev: set minimal output buffer size for RSA op
Date: Wed, 17 May 2023 22:17:43 +0530	[thread overview]
Message-ID: <4f603fb187e0ff7170b214ecd58da8bbc8f48f45.1684341286.git.gmuthukrishn@marvell.com> (raw)

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 <gmuthukrishn@marvell.com>
---
 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


             reply	other threads:[~2023-05-17 16:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-17 16:47 Gowrishankar Muthukrishnan [this message]
2023-05-25  8:05 ` Akhil Goyal
2023-05-30 14:41   ` Akhil Goyal

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=4f603fb187e0ff7170b214ecd58da8bbc8f48f45.1684341286.git.gmuthukrishn@marvell.com \
    --to=gmuthukrishn@marvell.com \
    --cc=anoobj@marvell.com \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    --cc=gakhil@marvell.com \
    /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).