From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id 14AC65AB9 for ; Fri, 6 May 2016 15:59:20 +0200 (CEST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga104.fm.intel.com with ESMTP; 06 May 2016 06:59:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,587,1455004800"; d="scan'208";a="98426507" Received: from sie-lab-212-116.ir.intel.com (HELO silpixa00378492.ir.intel.com) ([10.237.212.116]) by fmsmga004.fm.intel.com with ESMTP; 06 May 2016 06:59:20 -0700 From: Pablo de Lara To: dev@dpdk.org Cc: declan.doherty@intel.com, Pablo de Lara Date: Fri, 6 May 2016 15:03:46 +0100 Message-Id: <1462543429-26741-6-git-send-email-pablo.de.lara.guarch@intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1462543429-26741-1-git-send-email-pablo.de.lara.guarch@intel.com> References: <1462543429-26741-1-git-send-email-pablo.de.lara.guarch@intel.com> Subject: [dpdk-dev] [PATCH 5/8] test: fix buffer lengths for snow3G tests X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 06 May 2016 13:59:21 -0000 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 --- app/test/test_cryptodev.c | 136 ++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 71 deletions(-) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index f56e622..1656ad0 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -3008,6 +3008,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 */ @@ -3024,12 +3025,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, @@ -3065,6 +3067,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 */ @@ -3080,12 +3083,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, @@ -3391,7 +3395,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], @@ -3406,16 +3411,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); #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); @@ -3459,7 +3461,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], @@ -3480,20 +3483,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); #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); @@ -3538,7 +3535,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], @@ -3553,15 +3551,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); #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); @@ -3602,7 +3598,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], @@ -3626,19 +3623,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); #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len); @@ -3681,7 +3673,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], @@ -3697,13 +3690,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); #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); @@ -3762,7 +3755,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], @@ -3779,13 +3773,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); #ifdef RTE_APP_TEST_DEBUG rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); -- 2.5.0