[dpdk-dev] [PATCH v3 3/3] app/test: add Kasumi tests in QAT test suite

2016-09-17 Thread De Lara Guarch, Pablo
Hi Deepak,

> -Original Message-
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Deepak Kumar Jain
> Sent: Thursday, September 15, 2016 3:06 AM
> To: dev at dpdk.org
> Cc: Jain, Deepak K
> Subject: [dpdk-dev] [PATCH v3 3/3] app/test: add Kasumi tests in QAT test
> suite
> 
> This patch adds Kausmi tests in the QAT tesuite.

This patch implements tests for authenticated encryption and encrypted 
authentication,
and  adds them in the testsuite for KASUMI SW PMD (thanks for that!).
Could you include this info in the commit message.

> 
> Signed-off-by: Deepak Kumar Jain 
> ---
>  app/test/test_cryptodev.c  | 244 
> +++--
>  app/test/test_cryptodev_kasumi_hash_test_vectors.h |  76 +++
>  app/test/test_cryptodev_kasumi_test_vectors.h  | 103 -
>  3 files changed, 401 insertions(+), 22 deletions(-)
> 
> diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
> index 89d627f..4751467 100644
> --- a/app/test/test_cryptodev.c
> +++ b/app/test/test_cryptodev.c

...

>  static int
> +test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
> +{

...

> +
> + /* Validate obuf */
> + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
> + ciphertext,
> + tdata->ciphertext.data,
> + tdata->validCipherLenInBits.len,
> + "Snow3G/Kasumi Ciphertext data not as expected");

This is in a kasumi test, so you can change the message to "Kasumi 
Ciphertext..."

> + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t
> *)
> + + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
> +
> + /* Validate obuf */
> + TEST_ASSERT_BUFFERS_ARE_EQUAL(
> + ut_params->digest,
> + tdata->digest.data,
> + DIGEST_BYTE_LENGTH_KASUMI_F9,
> + "Snow3G/KASUMI Generated auth tag not as
> expected");

Same here

> + return 0;
> +}
> +

...

>  /* * AES-GCM Tests * */
> 
>  static int
> @@ -4139,6 +4323,21 @@ static struct unit_test_suite
> cryptodev_qat_testsuite  = {
>   TEST_CASE_ST(ut_setup, ut_teardown,
>   test_null_auth_cipher_operation),
> 

If you include a comment down here for KASUMI encryption only,
you should include one for authentication only here, and maybe comments
for the other two cases (auth_cipher/cipher_auth). You can also group all of 
them into "KASUMI tests", easier :)


> + TEST_CASE_ST(ut_setup, ut_teardown,
> + test_kasumi_hash_generate_test_case_6),
> +
> + /** KASUMI encrypt only (F8) */
> + TEST_CASE_ST(ut_setup, ut_teardown,
> + test_kasumi_encryption_test_case_1),
> +
> + /** KASUMI encrypt only (F8) */
> + TEST_CASE_ST(ut_setup, ut_teardown,
> + test_kasumi_encryption_test_case_3),

You can combine both tests above, and have just one comment (or go for a single 
comment overall).

> + TEST_CASE_ST(ut_setup, ut_teardown,
> + test_kasumi_auth_cipher_test_case_1),
> + TEST_CASE_ST(ut_setup, ut_teardown,
> + test_kasumi_cipher_auth_test_case_1),
> +
>   TEST_CASES_END() /**< NULL terminate unit test array */
>   }
>  };

...

> diff --git a/app/test/test_cryptodev_kasumi_hash_test_vectors.h
> b/app/test/test_cryptodev_kasumi_hash_test_vectors.h
> index c080b9f..a4b0205 100644
> --- a/app/test/test_cryptodev_kasumi_hash_test_vectors.h
> +++ b/app/test/test_cryptodev_kasumi_hash_test_vectors.h
> @@ -257,4 +257,80 @@ struct kasumi_hash_test_data
> kasumi_hash_test_case_5 = {
>   .len  = 4
>   }
>  };

Add blank line here.

> +struct kasumi_hash_test_data kasumi_hash_test_case_6 = {
> + .key = {
> + .data = {
> + 0x83, 0xFD, 0x23, 0xA2, 0x44, 0xA7, 0x4C, 0xF3,
> + 0x58, 0xDA, 0x30, 0x19, 0xF1, 0x72, 0x26, 0x35
> + },
> + .len = 16
> + },
> + .aad = {
> + .data = {
> + 0x36, 0xAF, 0x61, 0x44, 0x4F, 0x30, 0x2A, 0xD2
> + },
> + .len = 8
> + },
> + .plaintext = {
> + .data = {
> + 0x35, 0xC6, 0x87, 0x16, 0x63, 0x3C, 0x66, 0xFB,
> + 0x75, 0x0C, 0x26, 0x68, 0x65, 0xD5, 0x3C, 0x11,
> + 0xEA, 0x05, 0xB1, 0xE9, 0xFA, 0x49, 0xC8, 0x39,
> + 0x8D, 0x48, 0xE1, 0xEF, 0xA5, 0x90, 0x9D, 0x39,
> +   

[dpdk-dev] [PATCH v3 3/3] app/test: add Kasumi tests in QAT test suite

2016-09-15 Thread Trahe, Fiona


> -Original Message-
> From: dev [mailto:dev-bounces at dpdk.org] On Behalf Of Deepak Kumar Jain
> Sent: Thursday, September 15, 2016 11:06 AM
> To: dev at dpdk.org
> Cc: Jain, Deepak K 
> Subject: [dpdk-dev] [PATCH v3 3/3] app/test: add Kasumi tests in QAT test
> suite
> 
> This patch adds Kausmi tests in the QAT tesuite.
> 
> Signed-off-by: Deepak Kumar Jain 
Acked-by: Fiona Trahe 


[dpdk-dev] [PATCH v3 3/3] app/test: add Kasumi tests in QAT test suite

2016-09-15 Thread Deepak Kumar Jain
This patch adds Kausmi tests in the QAT tesuite.

Signed-off-by: Deepak Kumar Jain 
---
 app/test/test_cryptodev.c  | 244 +++--
 app/test/test_cryptodev_kasumi_hash_test_vectors.h |  76 +++
 app/test/test_cryptodev_kasumi_test_vectors.h  | 103 -
 3 files changed, 401 insertions(+), 22 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 89d627f..4751467 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1560,22 +1560,6 @@ create_snow3g_kasumi_auth_cipher_operation(const 
unsigned auth_tag_len,
sym_op->auth.digest.data,
sym_op->auth.digest.length);

-   /* iv */
-   if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
-   iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
-   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);
-
/* aad */
/*
* Always allocate the aad up to the block size.
@@ -1588,7 +1572,6 @@ create_snow3g_kasumi_auth_cipher_operation(const unsigned 
auth_tag_len,
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_prepend(
ut_params->ibuf, aad_buffer_len);
TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
@@ -1596,13 +1579,27 @@ create_snow3g_kasumi_auth_cipher_operation(const 
unsigned auth_tag_len,
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);
rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
-
TEST_HEXDUMP(stdout, "aad:",
sym_op->auth.aad.data, aad_len);

+   /* iv */
+   if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
+   iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
+   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);
+
sym_op->cipher.data.length = cipher_len;
sym_op->cipher.data.offset = auth_offset + cipher_offset;

@@ -1960,6 +1957,12 @@ test_kasumi_hash_generate_test_case_5(void)
 }

 static int
+test_kasumi_hash_generate_test_case_6(void)
+{
+   return test_kasumi_authentication(_hash_test_case_6);
+}
+
+static int
 test_kasumi_hash_verify_test_case_1(void)
 {
return test_kasumi_authentication_verify(_hash_test_case_1);
@@ -2818,6 +2821,174 @@ test_snow3g_auth_cipher(const struct snow3g_test_data 
*tdata)
 }

 static int
+test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
+{
+   struct crypto_testsuite_params *ts_params = _params;
+   struct crypto_unittest_params *ut_params = _params;
+
+   int retval;
+
+   uint8_t *plaintext, *ciphertext;
+   unsigned plaintext_pad_len;
+   unsigned plaintext_len;
+
+   /* Create KASUMI session */
+   retval = create_snow3g_kasumi_auth_cipher_session(
+   ts_params->valid_devs[0],
+   RTE_CRYPTO_CIPHER_OP_ENCRYPT,
+   RTE_CRYPTO_AUTH_OP_GENERATE,
+   RTE_CRYPTO_AUTH_KASUMI_F9,
+   RTE_CRYPTO_CIPHER_KASUMI_F8,
+   tdata->key.data, tdata->key.len,
+   tdata->aad.len, tdata->digest.len);
+   if (retval < 0)
+   return retval;
+   ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
+
+   /* clear mbuf payload */
+   memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
+   rte_pktmbuf_tailroom(ut_params->ibuf));
+
+   plaintext_len = ceil_byte_length(tdata->plaintext.len);
+   /* Append data which is padded to a multiple of */
+   /* the algorithms block size */
+   plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
+   plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+   plaintext_pad_len);
+   memcpy(plaintext, tdata->plaintext.data, plaintext_len);
+
+   TEST_HEXDUMP(stdout,