[2/3] test/crypto: fix RSA test vector as per RFC 8017

Message ID 20250620081921.2145-2-gmuthukrishn@marvell.com (mailing list archive)
State Accepted
Delegated to: akhil goyal
Headers
Series [1/3] crypto/openssl: include private exponent in RSA session |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/aws-unit-testing success Unit Testing PASS

Commit Message

Gowrishankar Muthukrishnan June 20, 2025, 8:19 a.m. UTC
As per RFC 8017 (A.1.2), RSA private key should be represented
with both exponent and CRT forms of data for inter operability.

Fixes: a379799cbaaf ("test/crypto: add RSA key type CRT")
Cc: stable@dpdk.org

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 app/test/test_cryptodev_asym.c             | 16 ++++++++---
 app/test/test_cryptodev_rsa_test_vectors.h | 32 +++++-----------------
 2 files changed, 19 insertions(+), 29 deletions(-)
  

Patch

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index fcaf73aa1a..a5f3eae41d 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -260,6 +260,7 @@  test_rsa_sign_verify(void)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_cryptodev_asym_capability_idx idx;
 	uint8_t dev_id = ts_params->valid_devs[0];
+	struct rte_crypto_asym_xform xform;
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int ret, status = TEST_SUCCESS;
@@ -280,7 +281,10 @@  test_rsa_sign_verify(void)
 		return TEST_SKIPPED;
 	}
 
-	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
+	memcpy(&xform, &rsa_xform, sizeof(rsa_xform));
+	xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
+
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
 
 	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
@@ -306,6 +310,7 @@  test_rsa_enc_dec(void)
 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
 	struct rte_cryptodev_asym_capability_idx idx;
 	uint8_t dev_id = ts_params->valid_devs[0];
+	struct rte_crypto_asym_xform xform;
 	void *sess = NULL;
 	struct rte_cryptodev_info dev_info;
 	int ret, status = TEST_SUCCESS;
@@ -326,7 +331,10 @@  test_rsa_enc_dec(void)
 		return TEST_SKIPPED;
 	}
 
-	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
+	memcpy(&xform, &rsa_xform, sizeof(rsa_xform));
+	xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
+
+	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
 
 	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
@@ -371,7 +379,7 @@  test_rsa_sign_verify_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
 	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
@@ -417,7 +425,7 @@  test_rsa_enc_dec_crt(void)
 		return TEST_SKIPPED;
 	}
 
-	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
+	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
 
 	if (ret < 0) {
 		RTE_LOG(ERR, USER1, "Session creation failed for "
diff --git a/app/test/test_cryptodev_rsa_test_vectors.h b/app/test/test_cryptodev_rsa_test_vectors.h
index 1b7b451387..9652b0d43a 100644
--- a/app/test/test_cryptodev_rsa_test_vectors.h
+++ b/app/test/test_cryptodev_rsa_test_vectors.h
@@ -340,7 +340,7 @@  uint8_t rsa_qInv[] = {
 	0x71, 0x94, 0xdd, 0xa0, 0xf5, 0x1e, 0x6d, 0xcc
 };
 
-/** rsa xform using exponent key */
+/** rsa xform (of QT private key type by default) */
 struct rte_crypto_asym_xform rsa_xform = {
 	.next = NULL,
 	.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,
@@ -354,29 +354,6 @@  struct rte_crypto_asym_xform rsa_xform = {
 			.data = rsa_e,
 			.length = sizeof(rsa_e)
 		},
-		.key_type = RTE_RSA_KEY_TYPE_EXP,
-		.d = {
-			.data = rsa_d,
-			.length = sizeof(rsa_d)
-		}
-	}
-};
-
-/** rsa xform using quintuple key */
-struct rte_crypto_asym_xform rsa_xform_crt = {
-	.next = NULL,
-	.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA,
-	.rsa = {
-		.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5,
-		.n = {
-			.data = rsa_n,
-			.length = sizeof(rsa_n)
-		},
-		.e = {
-			.data = rsa_e,
-			.length = sizeof(rsa_e)
-		},
-		.key_type = RTE_RSA_KEY_TYPE_QT,
 		.qt = {
 			.p = {
 				.data = rsa_p,
@@ -398,7 +375,12 @@  struct rte_crypto_asym_xform rsa_xform_crt = {
 				.data = rsa_qInv,
 				.length = sizeof(rsa_qInv)
 			},
-		}
+		},
+		.d = {
+			.data = rsa_d,
+			.length = sizeof(rsa_d)
+		},
+		.key_type = RTE_RSA_KEY_TYPE_QT
 	}
 };