lib/cryptodev: set minimal output buffer size for RSA op

Message ID 4f603fb187e0ff7170b214ecd58da8bbc8f48f45.1684341286.git.gmuthukrishn@marvell.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series lib/cryptodev: set minimal output buffer size for RSA op |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/github-robot: build success github build: passed
ci/intel-Functional success Functional PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Gowrishankar Muthukrishnan May 17, 2023, 4:47 p.m. UTC
  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(-)
  

Comments

Akhil Goyal May 25, 2023, 8:05 a.m. UTC | #1
> Subject: [PATCH] lib/cryptodev: set minimal output buffer size for RSA op
> 
> 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>
Acked-by: Akhil Goyal <gakhil@marvell.com>
  
Akhil Goyal May 30, 2023, 2:41 p.m. UTC | #2
> > Subject: [PATCH] lib/cryptodev: set minimal output buffer size for RSA op
> >
> > 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>
> Acked-by: Akhil Goyal <gakhil@marvell.com>
Applied to dpdk-next-crypto
  

Patch

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;