From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pablo de Lara Subject: [PATCH v3 10/11] test: add Snow3G UEA2 test with offset Date: Mon, 20 Jun 2016 10:27:52 +0100 Message-ID: <1466414873-23506-11-git-send-email-pablo.de.lara.guarch@intel.com> References: <1466162692-24654-1-git-send-email-pablo.de.lara.guarch@intel.com> <1466414873-23506-1-git-send-email-pablo.de.lara.guarch@intel.com> Cc: declan.doherty@intel.com, deepak.k.jain@intel.com, Pablo de Lara To: dev@dpdk.org Return-path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id C772B9AF6 for ; Mon, 20 Jun 2016 11:21:56 +0200 (CEST) In-Reply-To: <1466414873-23506-1-git-send-email-pablo.de.lara.guarch@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" With the new libsso library, buffers can be encrypted/decrypted, providing an offset in bits, so an extra unit test has been added to cover this case. Signed-off-by: Pablo de Lara Acked-by: Jain, Deepak K --- app/test/test_cryptodev.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 546ae92..7a8fda0 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -2553,6 +2553,118 @@ test_snow3g_encryption_oop(const struct snow3g_test_data *tdata) return 0; } +/* Shift right a buffer by "offset" bits, "offset" < 8 */ +static void +buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset) +{ + uint8_t curr_byte, prev_byte; + uint32_t length_in_bytes = ceil_byte_length(length + offset); + uint8_t lower_byte_mask = (1 << offset) - 1; + unsigned i; + + prev_byte = buffer[0]; + buffer[0] >>= offset; + + for (i = 1; i < length_in_bytes; i++) { + curr_byte = buffer[i]; + buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) | + (curr_byte >> offset); + prev_byte = curr_byte; + } +} + +static int +test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata) +{ + struct crypto_testsuite_params *ts_params = &testsuite_params; + struct crypto_unittest_params *ut_params = &unittest_params; + uint8_t *plaintext, *ciphertext; + int retval; + uint32_t plaintext_len; + uint32_t plaintext_pad_len; + uint8_t extra_offset = 4; + uint8_t *expected_ciphertext_shifted; + + /* Create SNOW3G session */ + retval = create_snow3g_cipher_session(ts_params->valid_devs[0], + RTE_CRYPTO_CIPHER_OP_ENCRYPT, + tdata->key.data, tdata->key.len); + if (retval < 0) + return retval; + + ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); + ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); + + TEST_ASSERT_NOT_NULL(ut_params->ibuf, + "Failed to allocate input buffer in mempool"); + TEST_ASSERT_NOT_NULL(ut_params->obuf, + "Failed to allocate output buffer in mempool"); + + /* 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 + extra_offset); + /* + * 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, (tdata->plaintext.len >> 3)); + buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset); + +#ifdef RTE_APP_TEST_DEBUG + rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len); +#endif + /* Create SNOW3G operation */ + retval = create_snow3g_cipher_operation_oop(tdata->iv.data, + tdata->iv.len, + tdata->validCipherLenInBits.len, + tdata->validCipherOffsetLenInBits.len + + extra_offset); + if (retval < 0) + return retval; + + 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_dst; + if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + + tdata->iv.len; + else + ciphertext = plaintext; + +#ifdef RTE_APP_TEST_DEBUG + rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); +#endif + + expected_ciphertext_shifted = rte_malloc(NULL, + ceil_byte_length(plaintext_len + extra_offset), 0); + + TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted, + "failed to reserve memory for ciphertext shifted\n"); + + memcpy(expected_ciphertext_shifted, tdata->ciphertext.data, + ceil_byte_length(tdata->ciphertext.len)); + buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len, + extra_offset); + /* Validate obuf */ + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET( + ciphertext, + expected_ciphertext_shifted, + tdata->validDataLenInBits.len, + extra_offset, + "Snow3G Ciphertext data not as expected"); + return 0; +} static int test_snow3g_decryption(const struct snow3g_test_data *tdata) { @@ -2932,6 +3044,12 @@ test_snow3g_encryption_test_case_1_oop(void) } static int +test_snow3g_encryption_test_case_1_offset_oop(void) +{ + return test_snow3g_encryption_offset_oop(&snow3g_test_case_1); +} + +static int test_snow3g_encryption_test_case_2(void) { return test_snow3g_encryption(&snow3g_test_case_2); @@ -4098,6 +4216,9 @@ static struct unit_test_suite cryptodev_sw_snow3g_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_snow3g_decryption_test_case_1_oop), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_encryption_test_case_1_offset_oop), + /** Snow3G decrypt only (UEA2) */ TEST_CASE_ST(ut_setup, ut_teardown, test_snow3g_decryption_test_case_1), -- 2.5.0