DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ciara Power <ciara.power@intel.com>
To: Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <fanzhang.oss@gmail.com>,
	Tejasree Kondoj <ktejasree@marvell.com>,
	Ciara Power <ciara.power@intel.com>
Cc: dev@dpdk.org, kai.ji@intel.com
Subject: [PATCH] test/crypto: fix and improve ZUC cipher and auth tests
Date: Fri,  6 Jan 2023 16:15:36 +0000	[thread overview]
Message-ID: <20230106161536.68058-1-ciara.power@intel.com> (raw)

The incorrect value was used for the reference plaintext offset
in ZUC cipher function. This is now fixed to convert to byte length,
rather than bits.

Also, to cleanup the ZUC test code, some small improvements are made.
The authentication function takes the auth op enum as a parameter
instead of a new variable, this can then be used directly.
The cipher SGL function does not need to buffers allocated for
ciphertext and plaintext, one can be used for both.

Fixes: be8e5d957366 ("test/crypto: add further ZUC testcases")

Signed-off-by: Ciara Power <ciara.power@intel.com>
---
 app/test/test_cryptodev.c | 92 +++++++++++++++++++++++----------------
 1 file changed, 55 insertions(+), 37 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index a824ed3511..aa831d79a2 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -6059,7 +6059,7 @@ test_zuc_cipher(const struct wireless_test_data *tdata,
 		debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
 
 		const uint8_t *reference_plaintext = tdata->plaintext.data +
-				(tdata->validCipherOffsetInBits.len);
+				(tdata->validCipherOffsetInBits.len >> 3);
 
 		/* Validate obuf */
 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
@@ -6085,7 +6085,7 @@ test_zuc_cipher_sgl(const struct wireless_test_data *tdata,
 	unsigned int plaintext_len = 0;
 	unsigned int ciphertext_len = 0;
 	const uint8_t *ciphertext, *plaintext;
-	uint8_t ciphertext_buffer[2048], plaintext_buffer[2048];
+	uint8_t buffer[2048];
 	struct rte_cryptodev_info dev_info;
 
 	/* Check if device supports ZUC EEA3 */
@@ -6174,10 +6174,10 @@ test_zuc_cipher_sgl(const struct wireless_test_data *tdata,
 	if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
 		if (ut_params->obuf)
 			ciphertext = rte_pktmbuf_read(ut_params->obuf,
-				0, plaintext_len, ciphertext_buffer);
+				0, plaintext_len, buffer);
 		else
 			ciphertext = rte_pktmbuf_read(ut_params->ibuf,
-				0, plaintext_len, ciphertext_buffer);
+				0, plaintext_len, buffer);
 
 		/* Validate obuf */
 		debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
@@ -6191,10 +6191,10 @@ test_zuc_cipher_sgl(const struct wireless_test_data *tdata,
 	} else {
 		if (ut_params->obuf)
 			plaintext = rte_pktmbuf_read(ut_params->obuf,
-				0, ciphertext_len, plaintext_buffer);
+				0, ciphertext_len, buffer);
 		else
 			plaintext = rte_pktmbuf_read(ut_params->ibuf,
-				0, ciphertext_len, plaintext_buffer);
+				0, ciphertext_len, buffer);
 
 		/* Validate obuf */
 		debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
@@ -6211,7 +6211,8 @@ test_zuc_cipher_sgl(const struct wireless_test_data *tdata,
 }
 
 static int
-test_zuc_authentication(const struct wireless_test_data *tdata, uint8_t verify)
+test_zuc_authentication(const struct wireless_test_data *tdata,
+		enum rte_crypto_auth_operation auth_op)
 {
 	struct crypto_testsuite_params *ts_params = &testsuite_params;
 	struct crypto_unittest_params *ut_params = &unittest_params;
@@ -6251,9 +6252,7 @@ test_zuc_authentication(const struct wireless_test_data *tdata, uint8_t verify)
 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
 			tdata->key.data, tdata->key.len,
 			tdata->auth_iv.len, tdata->digest.len,
-			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
-					: RTE_CRYPTO_AUTH_OP_GENERATE),
-			RTE_CRYPTO_AUTH_ZUC_EIA3);
+			auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3);
 	if (retval != 0)
 		return retval;
 
@@ -6276,10 +6275,7 @@ test_zuc_authentication(const struct wireless_test_data *tdata, uint8_t verify)
 			tdata->digest.len,
 			tdata->auth_iv.data, tdata->auth_iv.len,
 			plaintext_pad_len,
-			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
-					: RTE_CRYPTO_AUTH_OP_GENERATE),
-			tdata->validAuthLenInBits.len,
-			0);
+			auth_op, tdata->validAuthLenInBits.len, 0);
 	if (retval < 0)
 		return retval;
 
@@ -6294,7 +6290,7 @@ test_zuc_authentication(const struct wireless_test_data *tdata, uint8_t verify)
 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
 			+ plaintext_pad_len;
 
-	if (!verify) {
+	if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) {
 		/* Validate obuf */
 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
 				ut_params->digest,
@@ -7336,133 +7332,155 @@ test_zuc_decryption_test_case_6_sgl(void)
 static int
 test_zuc_hash_generate_test_case_1(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_1b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_1b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_2(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_90b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_90b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_3(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_577b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_577b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_4(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_2079b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_2079b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_5(void)
 {
-	return test_zuc_authentication(&zuc_test_auth_5670b, 0);
+	return test_zuc_authentication(&zuc_test_auth_5670b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_6(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_128b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_128b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_7(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_2080b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_2080b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_8(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_584b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_584b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_9(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_10(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_generate_test_case_11(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 0);
+	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b,
+			RTE_CRYPTO_AUTH_OP_GENERATE);
 }
 
 static int
 test_zuc_hash_verify_test_case_1(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_1b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_1b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_2(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_90b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_90b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_3(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_577b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_577b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_4(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_2079b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_2079b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_5(void)
 {
-	return test_zuc_authentication(&zuc_test_auth_5670b, 1);
+	return test_zuc_authentication(&zuc_test_auth_5670b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_6(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_128b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_128b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_7(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_2080b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_2080b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_8(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_584b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_584b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_9(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_10(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
 test_zuc_hash_verify_test_case_11(void)
 {
-	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 1);
+	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b,
+			RTE_CRYPTO_AUTH_OP_VERIFY);
 }
 
 static int
-- 
2.34.1


             reply	other threads:[~2023-01-06 16:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-06 16:15 Ciara Power [this message]
2023-01-06 16:24 ` Zhang, Fan
2023-01-10  9:55   ` [EXT] " 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=20230106161536.68058-1-ciara.power@intel.com \
    --to=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    --cc=gakhil@marvell.com \
    --cc=kai.ji@intel.com \
    --cc=ktejasree@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).