All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo de Lara <pablo.de.lara.guarch@intel.com>
To: dev@dpdk.org
Cc: declan.doherty@intel.com, Pablo de Lara <pablo.de.lara.guarch@intel.com>
Subject: [PATCH v2 07/11] test: fix buffer lengths for snow3G tests
Date: Fri, 17 Jun 2016 12:24:48 +0100	[thread overview]
Message-ID: <1466162692-24654-8-git-send-email-pablo.de.lara.guarch@intel.com> (raw)
In-Reply-To: <1466162692-24654-1-git-send-email-pablo.de.lara.guarch@intel.com>

No padding was added in the input buffers for snow3G tests,
due to a wrong calculation of the length (should be multiple
of the block size). This fix takes into account the case
where the length is not byte multiple.

Fixes: 8bdf665fe6c0 ("app/test: add SNOW 3G")

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
---
 app/test/test_cryptodev.c | 139 ++++++++++++++++++++++------------------------
 1 file changed, 66 insertions(+), 73 deletions(-)

diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c
index 3ff74cd..7dc5648 100644
--- a/app/test/test_cryptodev.c
+++ b/app/test/test_cryptodev.c
@@ -1801,6 +1801,7 @@ test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
 
 	int retval;
 	unsigned plaintext_pad_len;
+	unsigned plaintext_len;
 	uint8_t *plaintext;
 
 	/* Create SNOW3G session */
@@ -1817,12 +1818,13 @@ test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
 	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 = tdata->plaintext.len >> 3;
+	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, tdata->plaintext.len >> 3);
+	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
 
 	/* Create SNOW3G opertaion */
 	retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
@@ -1858,6 +1860,7 @@ test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
 
 	int retval;
 	unsigned plaintext_pad_len;
+	unsigned plaintext_len;
 	uint8_t *plaintext;
 
 	/* Create SNOW3G session */
@@ -1873,12 +1876,13 @@ test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
 	rte_pktmbuf_tailroom(ut_params->ibuf));
 
-	/* Append data which is padded to a multiple */
-	/* of the algorithms block size */
-	plaintext_pad_len = tdata->plaintext.len >> 3;
+	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, tdata->plaintext.len >> 3);
+				plaintext_pad_len);
+	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
 
 	/* Create SNOW3G operation */
 	retval = create_snow3g_hash_operation(tdata->digest.data,
@@ -2386,7 +2390,8 @@ test_snow3g_encryption(const struct snow3g_test_data *tdata)
 
 	int retval;
 	uint8_t *plaintext, *ciphertext;
-	uint8_t plaintext_pad_len;
+	unsigned plaintext_pad_len;
+	unsigned plaintext_len;
 
 	/* Create SNOW3G session */
 	retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2401,16 +2406,13 @@ test_snow3g_encryption(const struct snow3g_test_data *tdata)
 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
 	       rte_pktmbuf_tailroom(ut_params->ibuf));
 
-	/*
-	 * Append data which is padded to a
-	 * multiple of the algorithms block size
-	 */
-	/*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
-	plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
-
-	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
-						plaintext_pad_len);
-	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
+	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, "plaintext:", plaintext, tdata->plaintext.len);
 
@@ -2452,7 +2454,8 @@ test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
 	uint8_t *plaintext, *ciphertext;
 
 	int retval;
-	uint8_t plaintext_pad_len;
+	unsigned plaintext_pad_len;
+	unsigned plaintext_len;
 
 	/* Create SNOW3G session */
 	retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2473,20 +2476,14 @@ test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
 	       rte_pktmbuf_tailroom(ut_params->ibuf));
 
-	/*
-	 * Append data which is padded to a
-	 * multiple of the algorithms block size
-	 */
-	/*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
-	plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
-
-	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
-						plaintext_pad_len);
-
-	rte_pktmbuf_append(ut_params->obuf,
-						plaintext_pad_len);
-
-	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
+	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);
+	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
+	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
 
 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
 
@@ -2529,7 +2526,8 @@ static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
 	int retval;
 
 	uint8_t *plaintext, *ciphertext;
-	uint8_t ciphertext_pad_len;
+	unsigned ciphertext_pad_len;
+	unsigned ciphertext_len;
 
 	/* Create SNOW3G session */
 	retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2544,15 +2542,13 @@ static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
 	       rte_pktmbuf_tailroom(ut_params->ibuf));
 
-	/*
-	 * Append data which is padded to a
-	 * multiple of the algorithms block size
-	 */
-	ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
-
-	ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
-						ciphertext_pad_len);
-	memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
+	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
+	/* Append data which is padded to a multiple of */
+	/* the algorithms block size */
+	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
+	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+				ciphertext_pad_len);
+	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
 
 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
 
@@ -2566,7 +2562,7 @@ static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
 						ut_params->op);
 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
-	ut_params->obuf = ut_params->op->sym->m_src;
+	ut_params->obuf = ut_params->op->sym->m_dst;
 	if (ut_params->obuf)
 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
 				+ tdata->iv.len;
@@ -2591,7 +2587,8 @@ static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
 	int retval;
 
 	uint8_t *plaintext, *ciphertext;
-	uint8_t ciphertext_pad_len;
+	unsigned ciphertext_pad_len;
+	unsigned ciphertext_len;
 
 	/* Create SNOW3G session */
 	retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
@@ -2615,19 +2612,14 @@ static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
 		       rte_pktmbuf_tailroom(ut_params->obuf));
 
-	/*
-	 * Append data which is padded to a
-	 * multiple of the algorithms block size
-	 */
-	ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
-
-	ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
-						ciphertext_pad_len);
-
-	rte_pktmbuf_append(ut_params->obuf,
-						ciphertext_pad_len);
-
-	memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
+	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
+	/* Append data which is padded to a multiple of */
+	/* the algorithms block size */
+	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
+	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
+				ciphertext_pad_len);
+	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
+	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
 
 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
 
@@ -2668,7 +2660,8 @@ test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
 	int retval;
 
 	uint8_t *plaintext, *ciphertext;
-	uint8_t plaintext_pad_len;
+	unsigned plaintext_pad_len;
+	unsigned plaintext_len;
 
 	/* Create SNOW3G session */
 	retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
@@ -2684,13 +2677,13 @@ test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
 			rte_pktmbuf_tailroom(ut_params->ibuf));
 
-	/* Append data which is padded to a multiple */
-	/*  of the algorithms block size */
-	plaintext_pad_len = tdata->plaintext.len >> 3;
-
+	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, tdata->plaintext.len >> 3);
+				plaintext_pad_len);
+	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
 
 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
 
@@ -2746,7 +2739,8 @@ test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
 	int retval;
 
 	uint8_t *plaintext, *ciphertext;
-	uint8_t plaintext_pad_len;
+	unsigned plaintext_pad_len;
+	unsigned plaintext_len;
 
 	/* Create SNOW3G session */
 	retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
@@ -2763,13 +2757,13 @@ test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
 			rte_pktmbuf_tailroom(ut_params->ibuf));
 
-	/* Append data which is padded to a multiple */
-	/* of the algorithms block size */
-	plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
-
+	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, tdata->plaintext.len >> 3);
+				plaintext_pad_len);
+	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
 
 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
 
@@ -4063,7 +4057,6 @@ static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
 		TEST_CASE_ST(ut_setup, ut_teardown,
 			test_snow3g_encryption_test_case_5),
 
-
 		/** Snow3G decrypt only (UEA2) */
 		TEST_CASE_ST(ut_setup, ut_teardown,
 			test_snow3g_decryption_test_case_1),
-- 
2.5.0

  parent reply	other threads:[~2016-06-17 11:18 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06 14:03 [PATCH 0/8] Snow3G bit-level support Pablo de Lara
2016-05-06 14:03 ` [PATCH 1/8] snow3g: rename libsso reference due to library update Pablo de Lara
2016-05-06 14:03 ` [PATCH 2/8] doc: update build instructions for libsso_snow3g Pablo de Lara
2016-06-09 12:07   ` Mcnamara, John
2016-05-06 14:03 ` [PATCH 3/8] snow3g: support bit-level operations Pablo de Lara
2016-05-06 14:03 ` [PATCH 4/8] test: use new bit-level memcmp macro Pablo de Lara
2016-05-06 14:03 ` [PATCH 5/8] test: fix buffer lengths for snow3G tests Pablo de Lara
2016-05-06 14:03 ` [PATCH 6/8] test: add out-of-place crypto op tests for Snow3G PMD Pablo de Lara
2016-05-06 14:03 ` [PATCH 7/8] test: add bit-level Snow3G UIA2 tests Pablo de Lara
2016-05-06 14:03 ` [PATCH 8/8] test: add Snow3G UEA2 test with offset Pablo de Lara
2016-06-17 11:24 ` [PATCH v2 00/11] Snow3G bit-level support Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 01/11] snow3g: rename libsso reference due to library update Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 02/11] doc: update build instructions for libsso_snow3g Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 03/11] snow3g: define IV/digest length macros Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 04/11] snow3g: support bit-level operations Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 05/11] snow3g: add missing feature flags Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 06/11] test: use new bit-level memcmp macro Pablo de Lara
2016-06-17 11:24   ` Pablo de Lara [this message]
2016-06-17 11:24   ` [PATCH v2 08/11] test: add out-of-place crypto op tests for Snow3G PMD Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 09/11] test: add bit-level Snow3G UIA2 tests Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 10/11] test: add Snow3G UEA2 test with offset Pablo de Lara
2016-06-17 11:24   ` [PATCH v2 11/11] test: refactor snow3g/kasumi tests Pablo de Lara
2016-06-17 13:41   ` [PATCH v2 00/11] Snow3G bit-level support Jain, Deepak K
2016-06-20  9:27   ` [PATCH v3 " Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 01/11] snow3g: rename libsso reference due to library update Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 02/11] doc: update build instructions for libsso_snow3g Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 03/11] snow3g: define IV/digest length macros Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 04/11] snow3g: support bit-level operations Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 05/11] snow3g: add missing feature flags Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 06/11] test: use new bit-level memcmp macro Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 07/11] test: fix buffer lengths for snow3G tests Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 08/11] test: add out-of-place crypto op tests for Snow3G PMD Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 09/11] test: add bit-level Snow3G UIA2 tests Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 10/11] test: add Snow3G UEA2 test with offset Pablo de Lara
2016-06-20  9:27     ` [PATCH v3 11/11] test: refactor snow3g/kasumi tests Pablo de Lara
2016-06-20 14:44     ` [PATCH v4 00/11] Snow3G bit-level support Pablo de Lara
2016-06-20 14:44       ` [PATCH v4 01/11] snow3g: rename libsso reference due to library update Pablo de Lara
2016-06-20 14:44       ` [PATCH v4 02/11] doc: update build instructions for libsso_snow3g Pablo de Lara
2016-06-20 14:44       ` [PATCH v4 03/11] snow3g: define IV/digest length macros Pablo de Lara
2016-06-20 14:44       ` [PATCH v4 04/11] snow3g: support bit-level operations Pablo de Lara
2016-06-20 14:44       ` [PATCH v4 05/11] snow3g: add missing feature flags Pablo de Lara
2016-06-20 14:44       ` [PATCH v4 06/11] test: use new bit-level memcmp macro Pablo de Lara
2016-06-20 14:44       ` [PATCH v4 07/11] test: fix buffer lengths for snow3G tests Pablo de Lara
2016-06-20 14:44       ` [PATCH v4 08/11] test: add out-of-place crypto op tests for Snow3G PMD Pablo de Lara
2016-06-20 14:45       ` [PATCH v4 09/11] test: add bit-level Snow3G UIA2 tests Pablo de Lara
2016-06-20 14:45       ` [PATCH v4 10/11] test: add Snow3G UEA2 test with offset Pablo de Lara
2016-06-20 14:45       ` [PATCH v4 11/11] test: refactor snow3g/kasumi tests Pablo de Lara
2016-06-20 20:41       ` [PATCH v4 00/11] Snow3G bit-level support Thomas Monjalon

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=1466162692-24654-8-git-send-email-pablo.de.lara.guarch@intel.com \
    --to=pablo.de.lara.guarch@intel.com \
    --cc=declan.doherty@intel.com \
    --cc=dev@dpdk.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.