DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] test/crypto: fix and improve ZUC cipher and auth tests
@ 2023-01-06 16:15 Ciara Power
  2023-01-06 16:24 ` Zhang, Fan
  0 siblings, 1 reply; 3+ messages in thread
From: Ciara Power @ 2023-01-06 16:15 UTC (permalink / raw)
  To: Akhil Goyal, Fan Zhang, Tejasree Kondoj, Ciara Power; +Cc: dev, kai.ji

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] test/crypto: fix and improve ZUC cipher and auth tests
  2023-01-06 16:15 [PATCH] test/crypto: fix and improve ZUC cipher and auth tests Ciara Power
@ 2023-01-06 16:24 ` Zhang, Fan
  2023-01-10  9:55   ` [EXT] " Akhil Goyal
  0 siblings, 1 reply; 3+ messages in thread
From: Zhang, Fan @ 2023-01-06 16:24 UTC (permalink / raw)
  To: Ciara Power, Akhil Goyal, Tejasree Kondoj; +Cc: dev, kai.ji

On 1/6/2023 4:15 PM, Ciara Power wrote:
> 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>
Acked-by: Fan Zhang <fanzhang.oss@gmail.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [EXT] Re: [PATCH] test/crypto: fix and improve ZUC cipher and auth tests
  2023-01-06 16:24 ` Zhang, Fan
@ 2023-01-10  9:55   ` Akhil Goyal
  0 siblings, 0 replies; 3+ messages in thread
From: Akhil Goyal @ 2023-01-10  9:55 UTC (permalink / raw)
  To: Zhang, Fan, Ciara Power, Tejasree Kondoj; +Cc: dev, kai.ji

> On 1/6/2023 4:15 PM, Ciara Power wrote:
> > 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>
> Acked-by: Fan Zhang <fanzhang.oss@gmail.com>

Squashed to original commit.

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-10  9:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-06 16:15 [PATCH] test/crypto: fix and improve ZUC cipher and auth tests Ciara Power
2023-01-06 16:24 ` Zhang, Fan
2023-01-10  9:55   ` [EXT] " Akhil Goyal

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).