Skip to contentSkip to conversation

test/crypto: enhance modex tests

PATCH Superseded Gowrishankar Muthukrishnan 3 participants 17 messages Jun 16, 2024 – Jun 27, 2024

lore
Share & tools
lore
#0 lore raw

cover test/crypto: enhance modex tests

This patch series enhances modex tests to:
* use common test function in existing test vectors
* add test for zero padded operands

Gowrishankar Muthukrishnan (4):
test/crypto: validate modex result from first nonzero value test/crypto: remove unused variable in modex test data test/crypto: use common test function for mod tests test/crypto: add modex tests for zero padded operands

 app/test/test_cryptodev_asym.c             | 279 ++++----------------
 app/test/test_cryptodev_asym_util.h        |  18 --
 app/test/test_cryptodev_mod_test_vectors.h | 287 ++++++++++++++-------
 3 files changed, 241 insertions(+), 343 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/4 test/crypto: validate modex result from first nonzero value

At present, there is no specification of whether modex op output can carry leading zeroes without changing the value. OpenSSL strips leading zeroes, but other hardware need not be. Hence, when output is compared against expected result, validation could start from first non-zero.

Fixes 1ffefe00f1 ("test/crypto: add modexp and modinv functions")
---
 app/test/test_cryptodev_asym.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
app/test/test_cryptodev_asym.c +23 -2
index 17daf734e8..c26be9b2bf 100644
@@ -3200,6 +3200,27 @@ static int send_one(void)
 	return TEST_SUCCESS;
 }
 
+static int
+modular_cmpeq(const uint8_t *a, const uint8_t *b, size_t len)
+{
+	const uint8_t *new_a = a, *new_b = b;
+	size_t i, j;
+
+	/* Strip leading NUL bytes */
+	for (i = 0; i < len; i++)
+		if (a[i] != 0)
+			new_a = &a[i];
+
+	for (j = 0; j < len; j++)
+		if (b[j] != 0)
+			new_b = &b[i];
+
+	if (i != j || memcmp(new_a, new_b, len - i))
+		return 1;
+
+	return 0;
+}
+
 static int
 modular_exponentiation(const void *test_data)
 {
@@ -3234,9 +3255,9 @@ modular_exponentiation(const void *test_data)
 
 	TEST_ASSERT_SUCCESS(send_one(),
 		"Failed to process crypto op");
-	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->reminder.data,
+	TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data,
 			self->result_op->asym->modex.result.data,
-			self->result_op->asym->modex.result.length,
+			self->result_op->asym->modex.result.length),
 			"operation verification failed\n");
 
 	return TEST_SUCCESS;
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/4 test/crypto: remove unused variable in modex test data

In reply to Gowrishankar Muthukrishnan

Remove unused result_len from modex test data.

---
 app/test/test_cryptodev_mod_test_vectors.h | 10 ----------
 1 file changed, 10 deletions(-)
app/test/test_cryptodev_mod_test_vectors.h +0 -10
index c773c37018..a4e06c0291 100644
@@ -27,7 +27,6 @@ struct modex_test_data {
 		uint8_t data[DATA_SIZE];
 		uint16_t len;
 	} reminder;
-	uint16_t result_len;
 };
 struct modinv_test_data {
 	enum rte_crypto_asym_xform_type xform_type;
@@ -44,7 +43,6 @@ struct modinv_test_data {
 		uint8_t data[DATA_SIZE];
 		uint16_t len;
 	} inverse;
-	uint16_t result_len;
 };
 
 /* ModExp #1 */
@@ -109,7 +107,6 @@ modex_test_data modex_test_case_m128_b20_e3 = {
 		},
 		.len = 128
 	},
-	.result_len = 128
 };
 
 /* ModInv #1 */
@@ -167,7 +164,6 @@ modinv_test_data modinv_test_case = {
 		},
 		.len = 128
 	},
-	.result_len = 128
 };
 
 /* modular operation test data */
@@ -347,7 +343,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 192
 	},
-	.result_len = 192
 },
 {
 	.description = "Modular Exponentiation tests for Group 14",
@@ -442,7 +437,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 256
 	},
-	.result_len = 256
 },
 {
 	.description = "Modular Exponentiation tests for Group 15",
@@ -571,7 +565,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 384
 	},
-	.result_len = 384
 },
 {
 	.description = "Modular Exponentiation tests for Group 16",
@@ -733,7 +726,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 512
 	},
-	.result_len = 512
 },
 {
 	.description = "Modular Exponentiation tests for Group 17",
@@ -960,7 +952,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 768
 	},
-	.result_len = 768
 },
 {
 	.description = "Modular Exponentiation tests for Group 18",
@@ -1252,7 +1243,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 1024
 	},
-	.result_len = 1024
 },
 };
 
Signature · 1 line
2.25.1
#3 lore raw

PATCH 3/4 test/crypto: use common test function for mod tests

In reply to Gowrishankar Muthukrishnan

Use common test function for modex and modinv tests.

---
 app/test/test_cryptodev_asym.c             | 238 ++-------------------
 app/test/test_cryptodev_asym_util.h        |  18 --
 app/test/test_cryptodev_mod_test_vectors.h | 206 ++++++++++--------
 3 files changed, 131 insertions(+), 331 deletions(-)
app/test/test_cryptodev_asym.c +12 -226
index c26be9b2bf..41e150ed17 100644
@@ -988,229 +988,6 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	return status;
 }
 
-static int
-test_mod_inv(void)
-{
-	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
-	struct rte_mempool *op_mpool = ts_params->op_mpool;
-	struct rte_mempool *sess_mpool = ts_params->session_mpool;
-	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_crypto_asym_op *asym_op = NULL;
-	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	void *sess = NULL;
-	int status = TEST_SUCCESS;
-	struct rte_cryptodev_asym_capability_idx cap_idx;
-	const struct rte_cryptodev_asymmetric_xform_capability *capability;
-	uint8_t input[TEST_DATA_SIZE] = {0};
-	int ret = 0;
-	uint8_t result[sizeof(mod_p)] = { 0 };
-
-	if (rte_cryptodev_asym_get_xform_enum(
-		&modinv_xform.xform_type, "modinv") < 0) {
-		RTE_LOG(ERR, USER1,
-				 "Invalid ASYM algorithm specified\n");
-		return -1;
-	}
-
-	cap_idx.type = modinv_xform.xform_type;
-	capability = rte_cryptodev_asym_capability_get(dev_id,
-					&cap_idx);
-
-	if (capability == NULL) {
-		RTE_LOG(INFO, USER1,
-			"Device doesn't support MOD INV. Test Skipped\n");
-		return TEST_SKIPPED;
-	}
-
-	if (rte_cryptodev_asym_xform_capability_check_modlen(
-		capability,
-		modinv_xform.modinv.modulus.length)) {
-		RTE_LOG(ERR, USER1,
-				 "Invalid MODULUS length specified\n");
-				return TEST_SKIPPED;
-		}
-
-	ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
-	if (ret < 0) {
-		RTE_LOG(ERR, USER1, "line %u "
-				"FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
-		goto error_exit;
-	}
-
-	/* generate crypto op data structure */
-	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
-	if (!op) {
-		RTE_LOG(ERR, USER1,
-			"line %u FAILED: %s",
-			__LINE__, "Failed to allocate asymmetric crypto "
-			"operation struct");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
-	asym_op = op->asym;
-	memcpy(input, base, sizeof(base));
-	asym_op->modinv.base.data = input;
-	asym_op->modinv.base.length = sizeof(base);
-	asym_op->modinv.result.data = result;
-	asym_op->modinv.result.length = sizeof(result);
-
-	/* attach asymmetric crypto session to crypto operations */
-	rte_crypto_op_attach_asym_session(op, sess);
-
-	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
-
-	/* Process crypto operation */
-	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
-		RTE_LOG(ERR, USER1,
-			"line %u FAILED: %s",
-			__LINE__, "Error sending packet for operation");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
-	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
-		rte_pause();
-
-	if (result_op == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "Failed to process asym crypto op");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
-	ret = verify_modinv(mod_inv, result_op);
-	if (ret) {
-		RTE_LOG(ERR, USER1,
-			 "operation verification failed\n");
-		status = TEST_FAILED;
-	}
-
-error_exit:
-	if (sess)
-		rte_cryptodev_asym_session_free(dev_id, sess);
-
-	rte_crypto_op_free(op);
-
-	TEST_ASSERT_EQUAL(status, 0, "Test failed");
-
-	return status;
-}
-
-static int
-test_mod_exp(void)
-{
-	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
-	struct rte_mempool *op_mpool = ts_params->op_mpool;
-	struct rte_mempool *sess_mpool = ts_params->session_mpool;
-	uint8_t dev_id = ts_params->valid_devs[0];
-	struct rte_crypto_asym_op *asym_op = NULL;
-	struct rte_crypto_op *op = NULL, *result_op = NULL;
-	void *sess = NULL;
-	int status = TEST_SUCCESS;
-	struct rte_cryptodev_asym_capability_idx cap_idx;
-	const struct rte_cryptodev_asymmetric_xform_capability *capability;
-	uint8_t input[TEST_DATA_SIZE] = {0};
-	int ret = 0;
-	uint8_t result[sizeof(mod_p)] = { 0 };
-
-	if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
-		"modexp")
-		< 0) {
-		RTE_LOG(ERR, USER1,
-				"Invalid ASYM algorithm specified\n");
-		return -1;
-	}
-
-	/* check for modlen capability */
-	cap_idx.type = modex_xform.xform_type;
-	capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
-
-	if (capability == NULL) {
-		RTE_LOG(INFO, USER1,
-			"Device doesn't support MOD EXP. Test Skipped\n");
-		return TEST_SKIPPED;
-	}
-
-	if (rte_cryptodev_asym_xform_capability_check_modlen(
-			capability, modex_xform.modex.modulus.length)) {
-		RTE_LOG(ERR, USER1,
-				"Invalid MODULUS length specified\n");
-				return TEST_SKIPPED;
-		}
-
-	/* Create op, create session, and process packets. 8< */
-	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
-	if (!op) {
-		RTE_LOG(ERR, USER1,
-			"line %u FAILED: %s",
-			__LINE__, "Failed to allocate asymmetric crypto "
-			"operation struct");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
-	ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
-	if (ret < 0) {
-		RTE_LOG(ERR, USER1,
-				 "line %u "
-				"FAILED: %s", __LINE__,
-				"Session creation failed");
-		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
-		goto error_exit;
-	}
-
-	asym_op = op->asym;
-	memcpy(input, base, sizeof(base));
-	asym_op->modex.base.data = input;
-	asym_op->modex.base.length = sizeof(base);
-	asym_op->modex.result.data = result;
-	asym_op->modex.result.length = sizeof(result);
-	/* attach asymmetric crypto session to crypto operations */
-	rte_crypto_op_attach_asym_session(op, sess);
-
-	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
-	/* Process crypto operation */
-	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "Error sending packet for operation");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-
-	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
-		rte_pause();
-
-	if (result_op == NULL) {
-		RTE_LOG(ERR, USER1,
-				"line %u FAILED: %s",
-				__LINE__, "Failed to process asym crypto op");
-		status = TEST_FAILED;
-		goto error_exit;
-	}
-	/* >8 End of create op, create session, and process packets section. */
-	ret = verify_modexp(mod_exp, result_op);
-	if (ret) {
-		RTE_LOG(ERR, USER1,
-			 "operation verification failed\n");
-		status = TEST_FAILED;
-	}
-
-error_exit:
-	if (sess != NULL)
-		rte_cryptodev_asym_session_free(dev_id, sess);
-
-	rte_crypto_op_free(op);
-
-	TEST_ASSERT_EQUAL(status, 0, "Test failed");
-
-	return status;
-}
-
 static int
 test_dh_key_generation(void)
 {
@@ -3508,8 +3285,14 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
 				test_rsa_enc_dec_crt),
 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
 				test_rsa_sign_verify_crt),
-		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
-		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modular Inverse",
+			ut_setup_asym, ut_teardown_asym,
+			modular_multiplicative_inverse, &modinv_test_cases[0]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[0]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
@@ -3584,7 +3367,10 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 				test_rsa_enc_dec_crt),
 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
 				test_rsa_sign_verify_crt),
-		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[0]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
app/test/test_cryptodev_asym_util.h +0 -18
index 07e6e831e8..72908055cf 100644
@@ -17,24 +17,6 @@ static inline int rsa_verify(struct rsa_test_data *rsa_param,
 	return 0;
 }
 
-static inline int verify_modinv(uint8_t *mod_inv,
-		struct rte_crypto_op *result_op)
-{
-	if (memcmp(mod_inv, result_op->asym->modinv.result.data,
-				result_op->asym->modinv.result.length))
-		return -1;
-	return 0;
-}
-
-static inline int verify_modexp(uint8_t *mod_exp,
-		struct rte_crypto_op *result_op)
-{
-	if (memcmp(mod_exp, result_op->asym->modex.result.data,
-				result_op->asym->modex.result.length))
-		return -1;
-	return 0;
-}
-
 static inline int verify_ecdsa_sign(uint8_t *sign_r,
 		uint8_t *sign_s, struct rte_crypto_op *result_op)
 {
app/test/test_cryptodev_mod_test_vectors.h +119 -87

222 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

PATCH 4/4 test/crypto: add modex tests for zero padded operands

In reply to Gowrishankar Muthukrishnan

Add modex tests for zero padded operands, as in ASN encoding.

---
 app/test/test_cryptodev_asym.c             | 16 +++++
 app/test/test_cryptodev_mod_test_vectors.h | 71 ++++++++++++++++++++++
 2 files changed, 87 insertions(+)
app/test/test_cryptodev_asym.c +16 -0
index 41e150ed17..0c05a34e10 100644
@@ -3293,6 +3293,14 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
 			"Modex test",
 			ut_setup_asym, ut_teardown_asym,
 			modular_exponentiation, &modex_test_cases[0]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[1]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding (2)",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[2]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
@@ -3371,6 +3379,14 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 			"Modex test",
 			ut_setup_asym, ut_teardown_asym,
 			modular_exponentiation, &modex_test_cases[0]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[1]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding (2)",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[2]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
app/test/test_cryptodev_mod_test_vectors.h +71 -0

77 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw
In reply to Gowrishankar Muthukrishnan
Quoted 10 lines

This patch series enhances modex tests to:
* use common test function in existing test vectors
* add test for zero padded operands

Gowrishankar Muthukrishnan (4):
test/crypto: validate modex result from first nonzero value test/crypto: remove unused variable in modex test data test/crypto: use common test function for mod tests test/crypto: add modex tests for zero padded operands

Series Acked-by: Anoob Joseph <[email protected]>

#6 lore raw
In reply to Gowrishankar Muthukrishnan
Quoted 12 lines

Subject: [PATCH v1 0/4] test/crypto: enhance modex tests

This patch series enhances modex tests to:
* use common test function in existing test vectors
* add test for zero padded operands

Gowrishankar Muthukrishnan (4):
test/crypto: validate modex result from first nonzero value test/crypto: remove unused variable in modex test data test/crypto: use common test function for mod tests test/crypto: add modex tests for zero padded operands

Quoted 5 lines
 app/test/test_cryptodev_asym.c             | 279 ++++----------------
 app/test/test_cryptodev_asym_util.h        |  18 --
 app/test/test_cryptodev_mod_test_vectors.h | 287 ++++++++++++++-------
 3 files changed, 241 insertions(+), 343 deletions(-)

Please check compilation issues reported by CI.

#7 lore raw

v2 cover test/crypto: enhance modex tests

In reply to Gowrishankar Muthukrishnan

This patch series enhances modex tests to:
* use common test function in existing test vectors
* add test for zero padded operands

v2:
- Retain old modex test functions to avoid doc updates.

Gowrishankar Muthukrishnan (4):
test/crypto: validate modex result from first nonzero value test/crypto: remove unused variable in modex test data test/crypto: use common test function for mod tests test/crypto: add modex tests for zero padded operands

 app/test/test_cryptodev_asym.c             |  62 ++++++-
 app/test/test_cryptodev_mod_test_vectors.h | 205 ++++++++++++++++++++-
 2 files changed, 250 insertions(+), 17 deletions(-)
Signature · 1 line
2.25.1
#8 lore raw

PATCH v2 1/4 test/crypto: validate modex result from first nonzero value

At present, there is no specification of whether modex op output can carry leading zeroes without changing the value. OpenSSL strips leading zeroes, but other hardware need not be. Hence, when output is compared against expected result, validation could start from first non-zero.

Fixes 1ffefe00f1 ("test/crypto: add modexp and modinv functions")
---
 app/test/test_cryptodev_asym.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
app/test/test_cryptodev_asym.c +23 -2
index 2c745a7f7c..fec53f87db 100644
@@ -3200,6 +3200,27 @@ static int send_one(void)
 	return TEST_SUCCESS;
 }
 
+static int
+modular_cmpeq(const uint8_t *a, const uint8_t *b, size_t len)
+{
+	const uint8_t *new_a = a, *new_b = b;
+	size_t i, j;
+
+	/* Strip leading NUL bytes */
+	for (i = 0; i < len; i++)
+		if (a[i] != 0)
+			new_a = &a[i];
+
+	for (j = 0; j < len; j++)
+		if (b[j] != 0)
+			new_b = &b[i];
+
+	if (i != j || memcmp(new_a, new_b, len - i))
+		return 1;
+
+	return 0;
+}
+
 static int
 modular_exponentiation(const void *test_data)
 {
@@ -3234,9 +3255,9 @@ modular_exponentiation(const void *test_data)
 
 	TEST_ASSERT_SUCCESS(send_one(),
 		"Failed to process crypto op");
-	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->reminder.data,
+	TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data,
 			self->result_op->asym->modex.result.data,
-			self->result_op->asym->modex.result.length,
+			self->result_op->asym->modex.result.length),
 			"operation verification failed\n");
 
 	return TEST_SUCCESS;
Signature · 1 line
2.25.1
#9 lore raw

PATCH v2 2/4 test/crypto: remove unused variable in modex test data

In reply to Gowrishankar Muthukrishnan

Remove unused result_len from modex test data.

---
 app/test/test_cryptodev_mod_test_vectors.h | 10 ----------
 1 file changed, 10 deletions(-)
app/test/test_cryptodev_mod_test_vectors.h +0 -10
index c773c37018..a4e06c0291 100644
@@ -27,7 +27,6 @@ struct modex_test_data {
 		uint8_t data[DATA_SIZE];
 		uint16_t len;
 	} reminder;
-	uint16_t result_len;
 };
 struct modinv_test_data {
 	enum rte_crypto_asym_xform_type xform_type;
@@ -44,7 +43,6 @@ struct modinv_test_data {
 		uint8_t data[DATA_SIZE];
 		uint16_t len;
 	} inverse;
-	uint16_t result_len;
 };
 
 /* ModExp #1 */
@@ -109,7 +107,6 @@ modex_test_data modex_test_case_m128_b20_e3 = {
 		},
 		.len = 128
 	},
-	.result_len = 128
 };
 
 /* ModInv #1 */
@@ -167,7 +164,6 @@ modinv_test_data modinv_test_case = {
 		},
 		.len = 128
 	},
-	.result_len = 128
 };
 
 /* modular operation test data */
@@ -347,7 +343,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 192
 	},
-	.result_len = 192
 },
 {
 	.description = "Modular Exponentiation tests for Group 14",
@@ -442,7 +437,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 256
 	},
-	.result_len = 256
 },
 {
 	.description = "Modular Exponentiation tests for Group 15",
@@ -571,7 +565,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 384
 	},
-	.result_len = 384
 },
 {
 	.description = "Modular Exponentiation tests for Group 16",
@@ -733,7 +726,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 512
 	},
-	.result_len = 512
 },
 {
 	.description = "Modular Exponentiation tests for Group 17",
@@ -960,7 +952,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 768
 	},
-	.result_len = 768
 },
 {
 	.description = "Modular Exponentiation tests for Group 18",
@@ -1252,7 +1243,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 1024
 	},
-	.result_len = 1024
 },
 };
 
Signature · 1 line
2.25.1
#10 lore raw

PATCH v2 3/4 test/crypto: use common test function for mod tests

In reply to Gowrishankar Muthukrishnan

Use common test function for modex and modinv tests.

---
v2:
- Old functions not removed.

---
 app/test/test_cryptodev_asym.c             |  21 +++-
 app/test/test_cryptodev_mod_test_vectors.h | 124 +++++++++++++++++++++
 2 files changed, 140 insertions(+), 5 deletions(-)
app/test/test_cryptodev_asym.c +16 -5
index fec53f87db..32fb198f96 100644
@@ -988,7 +988,8 @@ test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
 	return status;
 }
 
-static int
+/* Below function is in use by cryptodev doc */
+static int __rte_unused
 test_mod_inv(void)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
@@ -1100,7 +1101,8 @@ test_mod_inv(void)
 	return status;
 }
 
-static int
+/* Below function is in use by cryptodev doc */
+static int __rte_unused
 test_mod_exp(void)
 {
 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
@@ -3508,8 +3510,14 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
 				test_rsa_enc_dec_crt),
 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
 				test_rsa_sign_verify_crt),
-		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
-		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modinv test",
+			ut_setup_asym, ut_teardown_asym,
+			modular_multiplicative_inverse, &modinv_test_cases[0]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[0]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
@@ -3584,7 +3592,10 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 				test_rsa_enc_dec_crt),
 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
 				test_rsa_sign_verify_crt),
-		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[0]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
app/test/test_cryptodev_mod_test_vectors.h +124 -0

130 lines not on this page · raw message

Signature · 1 line
2.25.1
#11 lore raw

PATCH v2 4/4 test/crypto: add modex tests for zero padded operands

In reply to Gowrishankar Muthukrishnan

Add modex tests for zero padded operands, as in ASN encoding.

---
 app/test/test_cryptodev_asym.c             | 16 +++++
 app/test/test_cryptodev_mod_test_vectors.h | 71 ++++++++++++++++++++++
 2 files changed, 87 insertions(+)
app/test/test_cryptodev_asym.c +16 -0
index 32fb198f96..26afa082af 100644
@@ -3518,6 +3518,14 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
 			"Modex test",
 			ut_setup_asym, ut_teardown_asym,
 			modular_exponentiation, &modex_test_cases[0]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[1]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding (2)",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[2]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
@@ -3596,6 +3604,14 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 			"Modex test",
 			ut_setup_asym, ut_teardown_asym,
 			modular_exponentiation, &modex_test_cases[0]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[1]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding (2)",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[2]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
app/test/test_cryptodev_mod_test_vectors.h +71 -0

77 lines not on this page · raw message

Signature · 1 line
2.25.1
#12 lore raw

v3 cover test/crypto: add modex test for zero padding

In reply to Gowrishankar Muthukrishnan

This patch series add modex test for zero padded operands

v3:
- removed patch to use common test function which will be addressed seperately due to document conflict.

Gowrishankar Muthukrishnan (3):
test/crypto: validate modex result from first nonzero value test/crypto: remove unused variable in modex test data test/crypto: add modex tests for zero padded operands

 app/test/test_cryptodev_asym.c             | 41 ++++++++++-
 app/test/test_cryptodev_mod_test_vectors.h | 85 +++++++++++++++++++---
 2 files changed, 114 insertions(+), 12 deletions(-)
Signature · 1 line
2.25.1
#13 lore raw

PATCH v3 1/3 test/crypto: validate modex result from first nonzero value

At present, there is no specification of whether modex op output can carry leading zeroes without changing the value. OpenSSL strips leading zeroes, but other hardware need not be. Hence, when output is compared against expected result, validation could start from first non-zero.

Fixes 1ffefe00f1 ("test/crypto: add modexp and modinv functions")
---
 app/test/test_cryptodev_asym.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)
app/test/test_cryptodev_asym.c +23 -2
index 2c745a7f7c..fec53f87db 100644
@@ -3200,6 +3200,27 @@ static int send_one(void)
 	return TEST_SUCCESS;
 }
 
+static int
+modular_cmpeq(const uint8_t *a, const uint8_t *b, size_t len)
+{
+	const uint8_t *new_a = a, *new_b = b;
+	size_t i, j;
+
+	/* Strip leading NUL bytes */
+	for (i = 0; i < len; i++)
+		if (a[i] != 0)
+			new_a = &a[i];
+
+	for (j = 0; j < len; j++)
+		if (b[j] != 0)
+			new_b = &b[i];
+
+	if (i != j || memcmp(new_a, new_b, len - i))
+		return 1;
+
+	return 0;
+}
+
 static int
 modular_exponentiation(const void *test_data)
 {
@@ -3234,9 +3255,9 @@ modular_exponentiation(const void *test_data)
 
 	TEST_ASSERT_SUCCESS(send_one(),
 		"Failed to process crypto op");
-	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->reminder.data,
+	TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data,
 			self->result_op->asym->modex.result.data,
-			self->result_op->asym->modex.result.length,
+			self->result_op->asym->modex.result.length),
 			"operation verification failed\n");
 
 	return TEST_SUCCESS;
Signature · 1 line
2.25.1
#14 lore raw

PATCH v3 2/3 test/crypto: remove unused variable in modex test data

In reply to Gowrishankar Muthukrishnan

Remove unused result_len from modex test data.

---
 app/test/test_cryptodev_mod_test_vectors.h | 10 ----------
 1 file changed, 10 deletions(-)
app/test/test_cryptodev_mod_test_vectors.h +0 -10
index c773c37018..a4e06c0291 100644
@@ -27,7 +27,6 @@ struct modex_test_data {
 		uint8_t data[DATA_SIZE];
 		uint16_t len;
 	} reminder;
-	uint16_t result_len;
 };
 struct modinv_test_data {
 	enum rte_crypto_asym_xform_type xform_type;
@@ -44,7 +43,6 @@ struct modinv_test_data {
 		uint8_t data[DATA_SIZE];
 		uint16_t len;
 	} inverse;
-	uint16_t result_len;
 };
 
 /* ModExp #1 */
@@ -109,7 +107,6 @@ modex_test_data modex_test_case_m128_b20_e3 = {
 		},
 		.len = 128
 	},
-	.result_len = 128
 };
 
 /* ModInv #1 */
@@ -167,7 +164,6 @@ modinv_test_data modinv_test_case = {
 		},
 		.len = 128
 	},
-	.result_len = 128
 };
 
 /* modular operation test data */
@@ -347,7 +343,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 192
 	},
-	.result_len = 192
 },
 {
 	.description = "Modular Exponentiation tests for Group 14",
@@ -442,7 +437,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 256
 	},
-	.result_len = 256
 },
 {
 	.description = "Modular Exponentiation tests for Group 15",
@@ -571,7 +565,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 384
 	},
-	.result_len = 384
 },
 {
 	.description = "Modular Exponentiation tests for Group 16",
@@ -733,7 +726,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 512
 	},
-	.result_len = 512
 },
 {
 	.description = "Modular Exponentiation tests for Group 17",
@@ -960,7 +952,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 768
 	},
-	.result_len = 768
 },
 {
 	.description = "Modular Exponentiation tests for Group 18",
@@ -1252,7 +1243,6 @@ modex_test_data modex_group_test_cases[] = {
 		},
 		.len = 1024
 	},
-	.result_len = 1024
 },
 };
 
Signature · 1 line
2.25.1
#15 lore raw

PATCH v3 3/3 test/crypto: add modex tests for zero padded operands

In reply to Gowrishankar Muthukrishnan

Add modex tests for zero padded operands, as in ASN encoding.

---
 app/test/test_cryptodev_asym.c             | 16 +++++
 app/test/test_cryptodev_mod_test_vectors.h | 75 ++++++++++++++++++++++
 2 files changed, 91 insertions(+)
app/test/test_cryptodev_asym.c +16 -0
index fec53f87db..ef926c6229 100644
@@ -3510,6 +3510,14 @@ static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
 				test_rsa_sign_verify_crt),
 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[0]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding (2)",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[1]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
@@ -3585,6 +3593,14 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
 				test_rsa_sign_verify_crt),
 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[0]),
+		TEST_CASE_NAMED_WITH_DATA(
+			"Modex test for zero padding (2)",
+			ut_setup_asym, ut_teardown_asym,
+			modular_exponentiation, &modex_test_cases[1]),
 		TEST_CASE_NAMED_WITH_DATA(
 			"Modex Group 5 test",
 			ut_setup_asym, ut_teardown_asym,
app/test/test_cryptodev_mod_test_vectors.h +75 -0

81 lines not on this page · raw message

Signature · 1 line
2.25.1
#16 lore raw

RE: [PATCH v3 0/3] test/crypto: add modex test for zero padding

In reply to Gowrishankar Muthukrishnan
Quoted 11 lines

This patch series add modex test for zero padded operands

v3:
- removed patch to use common test function which will be addressed seperately due to document conflict.

Gowrishankar Muthukrishnan (3):
test/crypto: validate modex result from first nonzero value test/crypto: remove unused variable in modex test data test/crypto: add modex tests for zero padded operands

Quoted 4 lines
 app/test/test_cryptodev_asym.c             | 41 ++++++++++-
 app/test/test_cryptodev_mod_test_vectors.h | 85 +++++++++++++++++++-
--
 2 files changed, 114 insertions(+), 12 deletions(-)

Series applied to dpdk-next-crypto
Thanks.