[dpdk-dev,v3,1/3] app/test: cleanup of test code for kasumi

Message ID 1473933815-185834-2-git-send-email-deepak.k.jain@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Pablo de Lara Guarch
Headers

Commit Message

Deepak Kumar JAIN Sept. 15, 2016, 10:03 a.m. UTC
  Cleanup for easier kasumi enabling.
Changed name of funcitons for clear understanding.

Signed-off-by: Deepak Kumar Jain <deepak.k.jain@intel.com>
---
 app/test/test_cryptodev.c | 117 ++++++++++++++++++++++------------------------
 1 file changed, 55 insertions(+), 62 deletions(-)
  

Comments

Fiona Trahe Sept. 15, 2016, 2:44 p.m. UTC | #1
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Deepak Kumar Jain
> Sent: Thursday, September 15, 2016 11:04 AM
> To: dev@dpdk.org
> Cc: De Lara Guarch, Pablo <pablo.de.lara.guarch@intel.com>; Jain, Deepak K
> <deepak.k.jain@intel.com>
> Subject: [dpdk-dev] [PATCH v3 1/3] app/test: cleanup of test code for kasumi
> 
> Cleanup for easier kasumi enabling.
> Changed name of funcitons for clear understanding.
> 
> Signed-off-by: Deepak Kumar Jain <deepak.k.jain@intel.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
  
De Lara Guarch, Pablo Sept. 17, 2016, 12:59 a.m. UTC | #2
Hi Deepak,

> -----Original Message-----
> From: Jain, Deepak K
> Sent: Thursday, September 15, 2016 3:04 AM
> To: dev@dpdk.org
> Cc: De Lara Guarch, Pablo; Jain, Deepak K
> Subject: [PATCH v3 1/3] app/test: cleanup of test code for kasumi
> 
> Cleanup for easier kasumi enabling.
> Changed name of funcitons for clear understanding.

Typo in "funcitons".

Could you split this patch in two? One for the rename the functions and another one for the rest.
Actually, are you doing something else apart from cleanup/reordering?

> 
> Signed-off-by: Deepak Kumar Jain <deepak.k.jain@intel.com>
> ---
>  app/test/test_cryptodev.c | 117 ++++++++++++++++++++++------------------------
>  1 file changed, 55 insertions(+), 62 deletions(-)
> 
> diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
> index 67ca912..89d627f 100644
> --- a/app/test/test_cryptodev.c
> +++ b/app/test/test_cryptodev.c
> @@ -1448,74 +1448,67 @@
> create_snow3g_kasumi_cipher_hash_operation(const uint8_t *auth_tag,

...

>  	TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
>  			"no room to prepend aad");
>  	sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
>  			ut_params->ibuf);
>  	sym_op->auth.aad.length = aad_len;
> -
> -	memset(sym_op->auth.aad.data, 0, aad_buffer_len);
> +		memset(sym_op->auth.aad.data, 0, aad_buffer_len);

No need to include extra tab.

>  	rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
> +		TEST_HEXDUMP(stdout, "aad:",
> +		sym_op->auth.aad.data, aad_len);

No need to include extra tab.

> 
> -	TEST_HEXDUMP(stdout, "aad:",
> -			sym_op->auth.aad.data, aad_len);
> -
> -	/* digest */
> -	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
> -			ut_params->ibuf, auth_tag_len);

...

> @@ -2714,12 +2707,12 @@ test_snow3g_authenticated_encryption(const
> struct snow3g_test_data *tdata)
>  	ut_params->obuf = ut_params->op->sym->m_src;
>  	if (ut_params->obuf)
>  		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
> -				+ tdata->iv.len;
> +				+ tdata->iv.len + tdata->aad.len;
>  	else
>  		ciphertext = plaintext;
> 
>  	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
> -
> +	TEST_HEXDUMP(stdout, "OUTPUT BUFFER:", ut_params->obuf, 512);

Magic number? What are you showing here?

>  	/* Validate obuf */
>  	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
>  			ciphertext,
> @@ -2728,7 +2721,7 @@ test_snow3g_authenticated_encryption(const
> struct snow3g_test_data *tdata)
>  			"Snow3G Ciphertext data not as expected");
>
  
Deepak Kumar JAIN Sept. 19, 2016, 9:17 a.m. UTC | #3
Hi Pablo,

> -----Original Message-----
> From: De Lara Guarch, Pablo
> Sent: Saturday, September 17, 2016 2:00 AM
> To: Jain, Deepak K <deepak.k.jain@intel.com>; dev@dpdk.org
> Subject: RE: [PATCH v3 1/3] app/test: cleanup of test code for kasumi
> 
> Hi Deepak,
> 
> > -----Original Message-----
> > From: Jain, Deepak K
> > Sent: Thursday, September 15, 2016 3:04 AM
> > To: dev@dpdk.org
> > Cc: De Lara Guarch, Pablo; Jain, Deepak K
> > Subject: [PATCH v3 1/3] app/test: cleanup of test code for kasumi
> >
> > Cleanup for easier kasumi enabling.
> > Changed name of funcitons for clear understanding.
> 
> Typo in "funcitons".
> 
> Could you split this patch in two? One for the rename the functions and
> another one for the rest.
> Actually, are you doing something else apart from cleanup/reordering?

Yes I can split the patch into two. One with name changes and one with reordering.
Other than this, cleaner usage of Additional Authentication data is included in the code.
Motivation behind this is to have code consistency across the wireless specific algorithms.
Will send another version with comments incorporated.
> 
> >
> > Signed-off-by: Deepak Kumar Jain <deepak.k.jain@intel.com>
> > ---
> >  app/test/test_cryptodev.c | 117
> > ++++++++++++++++++++++------------------------
> >  1 file changed, 55 insertions(+), 62 deletions(-)
> >
> > diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
> > index 67ca912..89d627f 100644
> > --- a/app/test/test_cryptodev.c
> > +++ b/app/test/test_cryptodev.c
> > @@ -1448,74 +1448,67 @@
> > create_snow3g_kasumi_cipher_hash_operation(const uint8_t *auth_tag,
> 
> ...
> 
> >  	TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
> >  			"no room to prepend aad");
> >  	sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
> >  			ut_params->ibuf);
> >  	sym_op->auth.aad.length = aad_len;
> > -
> > -	memset(sym_op->auth.aad.data, 0, aad_buffer_len);
> > +		memset(sym_op->auth.aad.data, 0, aad_buffer_len);
> 
> No need to include extra tab.
> 
> >  	rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
> > +		TEST_HEXDUMP(stdout, "aad:",
> > +		sym_op->auth.aad.data, aad_len);
> 
> No need to include extra tab.
> 
> >
> > -	TEST_HEXDUMP(stdout, "aad:",
> > -			sym_op->auth.aad.data, aad_len);
> > -
> > -	/* digest */
> > -	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
> > -			ut_params->ibuf, auth_tag_len);
> 
> ...
> 
> > @@ -2714,12 +2707,12 @@ test_snow3g_authenticated_encryption(const
> > struct snow3g_test_data *tdata)
> >  	ut_params->obuf = ut_params->op->sym->m_src;
> >  	if (ut_params->obuf)
> >  		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t
> *)
> > -				+ tdata->iv.len;
> > +				+ tdata->iv.len + tdata->aad.len;
> >  	else
> >  		ciphertext = plaintext;
> >
> >  	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
> > -
> > +	TEST_HEXDUMP(stdout, "OUTPUT BUFFER:", ut_params->obuf, 512);
> 
> Magic number? What are you showing here?
> 
> >  	/* Validate obuf */
> >  	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
> >  			ciphertext,
> > @@ -2728,7 +2721,7 @@ test_snow3g_authenticated_encryption(const
> > struct snow3g_test_data *tdata)
> >  			"Snow3G Ciphertext data not as expected");
> >
  

Patch

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 67ca912..89d627f 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1448,74 +1448,67 @@  create_snow3g_kasumi_cipher_hash_operation(const uint8_t *auth_tag,
 	/* set crypto operation source mbuf */
 	sym_op->m_src = ut_params->ibuf;
 
+	/* digest */
+	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
+			ut_params->ibuf, auth_tag_len);
 
-	/* iv */
-	if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
-		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
+	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
+			"no room to append auth tag");
+	ut_params->digest = sym_op->auth.digest.data;
+	sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
+			ut_params->ibuf, data_pad_len);
+	sym_op->auth.digest.length = auth_tag_len;
+	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
+		memset(sym_op->auth.digest.data, 0, auth_tag_len);
 	else
-		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
-
-	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
-		ut_params->ibuf, iv_pad_len);
-	TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
-
-	memset(sym_op->cipher.iv.data, 0, iv_pad_len);
-	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
-	sym_op->cipher.iv.length = iv_pad_len;
-
-	rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
+		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
 
-	sym_op->cipher.data.length = cipher_len;
-	sym_op->cipher.data.offset = cipher_offset;
+	TEST_HEXDUMP(stdout, "digest:",
+		sym_op->auth.digest.data,
+		sym_op->auth.digest.length);
 
 	/* aad */
-	/*
-	* Always allocate the aad up to the block size.
-	* The cryptodev API calls out -
-	*  - the array must be big enough to hold the AAD, plus any
-	*   space to round this up to the nearest multiple of the
-	*   block size (8 bytes for KASUMI and 16 bytes for SNOW3G).
-	*/
+		/*
+		* Always allocate the aad up to the block size.
+		* The cryptodev API calls out -
+		*  - the array must be big enough to hold the AAD, plus any
+		*   space to round this up to the nearest multiple of the
+		*   block size (8 bytes for KASUMI and 16 bytes for SNOW3G).
+		*/
 	if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
 		aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
 	else
 		aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
-
 	sym_op->auth.aad.data =
-			(uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
+		(uint8_t *)rte_pktmbuf_prepend(
+			ut_params->ibuf, aad_buffer_len);
 	TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
 			"no room to prepend aad");
 	sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
 			ut_params->ibuf);
 	sym_op->auth.aad.length = aad_len;
-
-	memset(sym_op->auth.aad.data, 0, aad_buffer_len);
+		memset(sym_op->auth.aad.data, 0, aad_buffer_len);
 	rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
+		TEST_HEXDUMP(stdout, "aad:",
+		sym_op->auth.aad.data, aad_len);
 
-	TEST_HEXDUMP(stdout, "aad:",
-			sym_op->auth.aad.data, aad_len);
-
-	/* digest */
-	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
-			ut_params->ibuf, auth_tag_len);
-
-	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
-			"no room to append auth tag");
-	ut_params->digest = sym_op->auth.digest.data;
-	sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
-			ut_params->ibuf, data_pad_len + aad_len);
-	sym_op->auth.digest.length = auth_tag_len;
-	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
-		memset(sym_op->auth.digest.data, 0, auth_tag_len);
+		/* iv */
+	if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
+		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
 	else
-		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
-
-	TEST_HEXDUMP(stdout, "digest:",
-		sym_op->auth.digest.data,
-		sym_op->auth.digest.length);
+		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
+	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
+		ut_params->ibuf, iv_pad_len);
 
-	sym_op->auth.data.length = auth_len;
-	sym_op->auth.data.offset = auth_offset;
+	TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
+	memset(sym_op->cipher.iv.data, 0, iv_pad_len);
+	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
+	sym_op->cipher.iv.length = iv_pad_len;
+		rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
+		sym_op->cipher.data.length = cipher_len;
+	sym_op->cipher.data.offset = cipher_offset + auth_offset;
+		sym_op->auth.data.length = auth_len;
+	sym_op->auth.data.offset = auth_offset + cipher_offset;
 
 	return 0;
 }
@@ -2655,7 +2648,7 @@  static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
 }
 
 static int
-test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
+test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
 {
 	struct crypto_testsuite_params *ts_params = &testsuite_params;
 	struct crypto_unittest_params *ut_params = &unittest_params;
@@ -2714,12 +2707,12 @@  test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
 	ut_params->obuf = ut_params->op->sym->m_src;
 	if (ut_params->obuf)
 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-				+ tdata->iv.len;
+				+ tdata->iv.len + tdata->aad.len;
 	else
 		ciphertext = plaintext;
 
 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
-
+	TEST_HEXDUMP(stdout, "OUTPUT BUFFER:", ut_params->obuf, 512);
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
 			ciphertext,
@@ -2728,7 +2721,7 @@  test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
 			"Snow3G Ciphertext data not as expected");
 
 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
-	    + plaintext_pad_len + tdata->aad.len;
+	    + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
 
 	/* Validate obuf */
 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
@@ -2739,7 +2732,7 @@  test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
 	return 0;
 }
 static int
-test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
+test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
 {
 	struct crypto_testsuite_params *ts_params = &testsuite_params;
 	struct crypto_unittest_params *ut_params = &unittest_params;
@@ -2973,15 +2966,15 @@  test_snow3g_decryption_test_case_5(void)
 	return test_snow3g_decryption(&snow3g_test_case_5);
 }
 static int
-test_snow3g_authenticated_encryption_test_case_1(void)
+test_snow3g_cipher_auth_test_case_1(void)
 {
-	return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
+	return test_snow3g_cipher_auth(&snow3g_test_case_3);
 }
 
 static int
-test_snow3g_encrypted_authentication_test_case_1(void)
+test_snow3g_auth_cipher_test_case_1(void)
 {
-	return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
+	return test_snow3g_auth_cipher(&snow3g_test_case_6);
 }
 
 /* ***** AES-GCM Tests ***** */
@@ -4122,9 +4115,9 @@  static struct unit_test_suite cryptodev_qat_testsuite  = {
 		TEST_CASE_ST(ut_setup, ut_teardown,
 			test_snow3g_hash_verify_test_case_3),
 		TEST_CASE_ST(ut_setup, ut_teardown,
-			test_snow3g_authenticated_encryption_test_case_1),
+			test_snow3g_cipher_auth_test_case_1),
 		TEST_CASE_ST(ut_setup, ut_teardown,
-			test_snow3g_encrypted_authentication_test_case_1),
+			test_snow3g_auth_cipher_test_case_1),
 
 		/** HMAC_MD5 Authentication */
 		TEST_CASE_ST(ut_setup, ut_teardown,
@@ -4323,9 +4316,9 @@  static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
 		TEST_CASE_ST(ut_setup, ut_teardown,
 			test_snow3g_hash_verify_test_case_6),
 		TEST_CASE_ST(ut_setup, ut_teardown,
-			test_snow3g_authenticated_encryption_test_case_1),
+			test_snow3g_cipher_auth_test_case_1),
 		TEST_CASE_ST(ut_setup, ut_teardown,
-			test_snow3g_encrypted_authentication_test_case_1),
+			test_snow3g_auth_cipher_test_case_1),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	}