[v2,2/2] test/crypto: add CPU crypto mode for AESNI MB
diff mbox series

Message ID 20200403155553.22818-3-konstantin.ananyev@intel.com
State Superseded, archived
Delegated to: akhil goyal
Headers show
Series
  • support CPU crypto for AESNI MB PMD
Related show

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/travis-robot success Travis build: passed
ci/checkpatch success coding style OK

Commit Message

Ananyev, Konstantin April 3, 2020, 3:55 p.m. UTC
This patch adds ability to run unit tests in cpu crypto mode
for AESNI MB cryptodev.

Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
---
 app/test/test_cryptodev.c | 146 ++++++++++++++++++++++++++++++--------
 1 file changed, 115 insertions(+), 31 deletions(-)

Comments

Pablo de Lara April 15, 2020, 9:13 a.m. UTC | #1
> -----Original Message-----
> From: Ananyev, Konstantin <konstantin.ananyev@intel.com>
> Sent: Friday, April 3, 2020 4:56 PM
> To: dev@dpdk.org
> Cc: akhil.goyal@nxp.com; De Lara Guarch, Pablo
> <pablo.de.lara.guarch@intel.com>; Doherty, Declan
> <declan.doherty@intel.com>; Ananyev, Konstantin
> <konstantin.ananyev@intel.com>
> Subject: [PATCH v2 2/2] test/crypto: add CPU crypto mode for AESNI MB
> 
> This patch adds ability to run unit tests in cpu crypto mode for AESNI MB
> cryptodev.
> 
> Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
> ---
>  app/test/test_cryptodev.c | 146 ++++++++++++++++++++++++++++++--------

Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Akhil Goyal April 15, 2020, 6:25 p.m. UTC | #2
> >
> > This patch adds ability to run unit tests in cpu crypto mode for AESNI MB
> > cryptodev.
> >
> > Signed-off-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
> > ---
> >  app/test/test_cryptodev.c | 146 ++++++++++++++++++++++++++++++--------
> 
> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>

Acked-by: Akhil Goyal <akhil.goyal@nxp.com>

Patch
diff mbox series

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 7b1ef5c86..7235b701b 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -143,7 +143,7 @@  ceil_byte_length(uint32_t num_bits)
 }
 
 static void
-process_cpu_gmac_op(uint8_t dev_id, struct rte_crypto_op *op)
+process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
 {
 	int32_t n, st;
 	void *iv;
@@ -155,8 +155,8 @@  process_cpu_gmac_op(uint8_t dev_id, struct rte_crypto_op *op)
 
 	sop = op->sym;
 
-	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
-		sop->auth.data.length, vec, RTE_DIM(vec));
+	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
+		sop->aead.data.length, vec, RTE_DIM(vec));
 
 	if (n < 0 || n != sop->m_src->nb_segs) {
 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
@@ -168,8 +168,8 @@  process_cpu_gmac_op(uint8_t dev_id, struct rte_crypto_op *op)
 	symvec.sgl = &sgl;
 	iv = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
 	symvec.iv = &iv;
-	symvec.aad = NULL;
-	symvec.digest = (void **)&sop->auth.digest.data;
+	symvec.aad = (void **)&sop->aead.aad.data;
+	symvec.digest = (void **)&sop->aead.digest.data;
 	symvec.status = &st;
 	symvec.num = 1;
 
@@ -184,9 +184,8 @@  process_cpu_gmac_op(uint8_t dev_id, struct rte_crypto_op *op)
 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
 }
 
-
 static void
-process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
+process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
 {
 	int32_t n, st;
 	void *iv;
@@ -198,8 +197,8 @@  process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
 
 	sop = op->sym;
 
-	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
-		sop->aead.data.length, vec, RTE_DIM(vec));
+	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
+		sop->auth.data.length, vec, RTE_DIM(vec));
 
 	if (n < 0 || n != sop->m_src->nb_segs) {
 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
@@ -212,11 +211,14 @@  process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
 	iv = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
 	symvec.iv = &iv;
 	symvec.aad = (void **)&sop->aead.aad.data;
-	symvec.digest = (void **)&sop->aead.digest.data;
+	symvec.digest = (void **)&sop->auth.digest.data;
 	symvec.status = &st;
 	symvec.num = 1;
 
 	ofs.raw = 0;
+	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
+	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
+		(sop->cipher.data.offset + sop->cipher.data.length);
 
 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
 		&symvec);
@@ -1538,8 +1540,14 @@  test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
 	sym_op->cipher.data.length = QUOTE_512_BYTES;
 
 	/* Process crypto operation */
-	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
-			ut_params->op), "failed to process sym crypto op");
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
+	else
+		TEST_ASSERT_NOT_NULL(
+			process_crypto_request(ts_params->valid_devs[0],
+				ut_params->op),
+				"failed to process sym crypto op");
 
 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
 			"crypto op processing failed");
@@ -1689,8 +1697,14 @@  test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
 	sym_op->cipher.data.length = QUOTE_512_BYTES;
 
 	/* Process crypto operation */
-	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
-			ut_params->op), "failed to process sym crypto op");
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
+	else
+		TEST_ASSERT_NOT_NULL(
+				process_crypto_request(ts_params->valid_devs[0],
+					ut_params->op),
+					"failed to process sym crypto op");
 
 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
 			"crypto op processing failed");
@@ -2637,8 +2651,13 @@  test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
 	if (retval < 0)
 		return retval;
 
-	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
-				ut_params->op);
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
+	else
+		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+			ut_params->op);
+
 	ut_params->obuf = ut_params->op->sym->m_src;
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
@@ -8715,6 +8734,9 @@  test_stats(void)
 	struct rte_cryptodev *dev;
 	cryptodev_stats_get_t temp_pfn;
 
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
+		return -ENOTSUP;
+
 	/* Verify the capabilities */
 	struct rte_cryptodev_sym_capability_idx cap_idx;
 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
@@ -8886,8 +8908,14 @@  test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
 		return TEST_FAILED;
 
-	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
-			ut_params->op), "failed to process sym crypto op");
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
+	else
+		TEST_ASSERT_NOT_NULL(
+			process_crypto_request(ts_params->valid_devs[0],
+				ut_params->op),
+				"failed to process sym crypto op");
 
 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
 			"crypto op processing failed");
@@ -8938,8 +8966,14 @@  test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
 		return TEST_FAILED;
 
-	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
-			ut_params->op), "failed to process sym crypto op");
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
+	else
+		TEST_ASSERT_NOT_NULL(
+			process_crypto_request(ts_params->valid_devs[0],
+				ut_params->op),
+				"failed to process sym crypto op");
 
 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
 			"HMAC_MD5 crypto op processing failed");
@@ -9852,7 +9886,8 @@  test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
 	ut_params->op->sym->m_src = ut_params->ibuf;
 
 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
-		process_cpu_gmac_op(ts_params->valid_devs[0], ut_params->op);
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
 	else
 		TEST_ASSERT_NOT_NULL(
 			process_crypto_request(ts_params->valid_devs[0],
@@ -9968,7 +10003,8 @@  test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
 	ut_params->op->sym->m_src = ut_params->ibuf;
 
 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
-		process_cpu_gmac_op(ts_params->valid_devs[0], ut_params->op);
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
 	else
 		TEST_ASSERT_NOT_NULL(
 			process_crypto_request(ts_params->valid_devs[0],
@@ -10528,10 +10564,17 @@  test_authentication_verify_fail_when_data_corruption(
 	else
 		tag_corruption(plaintext, reference->plaintext.len);
 
-	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
 			ut_params->op);
-
-	TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
+		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
+			RTE_CRYPTO_OP_STATUS_SUCCESS,
+			"authentication not failed");
+	} else {
+		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+			ut_params->op);
+		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
+	}
 
 	return 0;
 }
@@ -10593,7 +10636,8 @@  test_authentication_verify_GMAC_fail_when_corruption(
 		tag_corruption(plaintext, reference->aad.len);
 
 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
-		process_cpu_gmac_op(ts_params->valid_devs[0], ut_params->op);
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
 			RTE_CRYPTO_OP_STATUS_SUCCESS,
 			"authentication not failed");
@@ -10666,10 +10710,17 @@  test_authenticated_decryption_fail_when_corruption(
 	else
 		tag_corruption(ciphertext, reference->ciphertext.len);
 
-	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
 			ut_params->op);
-
-	TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
+		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
+			RTE_CRYPTO_OP_STATUS_SUCCESS,
+			"authentication not failed");
+	} else {
+		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+			ut_params->op);
+		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
+	}
 
 	return 0;
 }
@@ -10757,8 +10808,12 @@  test_authenticated_encryt_with_esn(
 	if (retval < 0)
 		return retval;
 
-	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
 			ut_params->op);
+	else
+		ut_params->op = process_crypto_request(
+			ts_params->valid_devs[0], ut_params->op);
 
 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
 
@@ -10873,7 +10928,11 @@  test_authenticated_decrypt_with_esn(
 	if (retval < 0)
 		return retval;
 
-	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
+	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
+		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
+			ut_params->op);
+	else
+		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
 			ut_params->op);
 
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
@@ -13377,6 +13436,29 @@  test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
 	return unit_test_suite_runner(&cryptodev_testsuite);
 }
 
+static int
+test_cryptodev_cpu_aesni_mb(void)
+{
+	int32_t rc;
+	enum rte_security_session_action_type at;
+
+	gbl_driver_id =	rte_cryptodev_driver_id_get(
+			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
+
+	if (gbl_driver_id == -1) {
+		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded. Check if "
+				"CONFIG_RTE_LIBRTE_PMD_AESNI_MB is enabled "
+				"in config file to run this testsuite.\n");
+		return TEST_SKIPPED;
+	}
+
+	at = gbl_action_type;
+	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
+	rc = unit_test_suite_runner(&cryptodev_testsuite);
+	gbl_action_type = at;
+	return rc;
+}
+
 static int
 test_cryptodev_openssl(void)
 {
@@ -13668,6 +13750,8 @@  test_cryptodev_nitrox(void)
 
 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
+REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
+	test_cryptodev_cpu_aesni_mb);
 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,