test/crypto: fix and improve ZUC cipher and auth tests

Message ID 20230106161536.68058-1-ciara.power@intel.com (mailing list archive)
State Accepted, archived
Delegated to: akhil goyal
Headers
Series test/crypto: fix and improve ZUC cipher and auth tests |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-testing warning apply patch failure
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Power, Ciara Jan. 6, 2023, 4:15 p.m. UTC
  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(-)
  

Comments

Zhang, Fan Jan. 6, 2023, 4:24 p.m. UTC | #1
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>
  
Akhil Goyal Jan. 10, 2023, 9:55 a.m. UTC | #2
> 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.
  

Patch

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