From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id AF6F7A0096 for ; Mon, 3 Jun 2019 16:54:34 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C5FB61B99E; Mon, 3 Jun 2019 16:54:19 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 947B71B965 for ; Mon, 3 Jun 2019 16:54:11 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Jun 2019 07:54:10 -0700 X-ExtLoop1: 1 Received: from damiannx-mobl1.ger.corp.intel.com ([10.103.104.100]) by fmsmga001.fm.intel.com with ESMTP; 03 Jun 2019 07:54:09 -0700 From: Nowak To: dev@dpdk.org Cc: fiona.trahe@intel.com, arkadiuszx.kusztal@intel.com, Damian Nowak Date: Mon, 3 Jun 2019 16:50:41 +0200 Message-Id: <20190603145048.2596-3-damianx.nowak@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20190603145048.2596-1-damianx.nowak@intel.com> References: <20190603145048.2596-1-damianx.nowak@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 2/9] test/crypto: add snow3g test cases for oop operation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Damian Nowak This patch adds test cases for snow3g out of place auth-cipher operations. Test cases include digest generation with buffer encryption and buffer decryption with digest verification. Signed-off-by: Damian Nowak --- app/test/test_cryptodev.c | 228 ++++++++++++++++++++------ app/test/test_cryptodev_snow3g_test_vectors.h | 100 ++++++++++- 2 files changed, 272 insertions(+), 56 deletions(-) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 9f31aaa..56ab0cf 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2015-2017 Intel Corporation + * Copyright(c) 2015-2019 Intel Corporation */ #include @@ -40,7 +40,10 @@ #include "test_cryptodev_hmac_test_vectors.h" #define VDEV_ARGS_SIZE 100 -#define MAX_NB_SESSIONS 4 +#define MAX_NB_SESSIONS 4 + +#define IN_PLACE 0 +#define OUT_OF_PLACE 1 static int gbl_driver_id; @@ -2814,7 +2817,8 @@ create_wireless_algo_auth_cipher_operation(unsigned int auth_tag_len, const uint8_t *auth_iv, uint8_t auth_iv_len, unsigned int data_pad_len, unsigned int cipher_len, unsigned int cipher_offset, - unsigned int auth_len, unsigned int auth_offset) + unsigned int auth_len, unsigned int auth_offset, + uint8_t op_mode) { struct crypto_testsuite_params *ts_params = &testsuite_params; struct crypto_unittest_params *ut_params = &unittest_params; @@ -2830,24 +2834,31 @@ create_wireless_algo_auth_cipher_operation(unsigned int auth_tag_len, struct rte_crypto_sym_op *sym_op = ut_params->op->sym; - /* set crypto operation source mbuf */ + /* set crypto operation mbufs */ sym_op->m_src = ut_params->ibuf; + if (op_mode == OUT_OF_PLACE) + sym_op->m_dst = ut_params->obuf; /* digest */ - sym_op->auth.digest.data = (uint8_t *) rte_pktmbuf_mtod_offset( - ut_params->ibuf, uint8_t *, data_pad_len); + sym_op->auth.digest.data = rte_pktmbuf_mtod_offset( + (op_mode == IN_PLACE ? + ut_params->ibuf : ut_params->obuf), + uint8_t *, data_pad_len); TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data, "no room to append auth tag"); sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( - ut_params->ibuf, data_pad_len); + (op_mode == IN_PLACE ? + ut_params->ibuf : ut_params->obuf), + data_pad_len); memset(sym_op->auth.digest.data, 0, auth_tag_len); /* Copy cipher and auth IVs at the end of the crypto operation */ - uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, - IV_OFFSET); + uint8_t *iv_ptr = rte_crypto_op_ctod_offset( + ut_params->op, uint8_t *, IV_OFFSET); + rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len); iv_ptr += cipher_iv_len; rte_memcpy(iv_ptr, auth_iv, auth_iv_len); @@ -4312,90 +4323,153 @@ test_snow3g_cipher_auth(const struct snow3g_test_data *tdata) "SNOW 3G Generated auth tag not as expected"); return 0; } + static int -test_snow3g_auth_cipher(const struct snow3g_test_data *tdata) +test_snow3g_auth_cipher(const struct snow3g_test_data *tdata, + uint8_t op_mode, uint8_t verify) { struct crypto_testsuite_params *ts_params = &testsuite_params; struct crypto_unittest_params *ut_params = &unittest_params; int retval; - uint8_t *plaintext, *ciphertext; - unsigned plaintext_pad_len; - unsigned plaintext_len; + uint8_t *plaintext = NULL, *ciphertext = NULL; + unsigned int plaintext_pad_len; + unsigned int plaintext_len; + unsigned int ciphertext_pad_len; + unsigned int ciphertext_len; /* Create SNOW 3G session */ - retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0], - RTE_CRYPTO_CIPHER_OP_ENCRYPT, - RTE_CRYPTO_AUTH_OP_GENERATE, + retval = create_wireless_algo_auth_cipher_session( + ts_params->valid_devs[0], + (verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT + : RTE_CRYPTO_CIPHER_OP_ENCRYPT), + (verify ? RTE_CRYPTO_AUTH_OP_VERIFY + : RTE_CRYPTO_AUTH_OP_GENERATE), RTE_CRYPTO_AUTH_SNOW3G_UIA2, RTE_CRYPTO_CIPHER_SNOW3G_UEA2, tdata->key.data, tdata->key.len, tdata->auth_iv.len, tdata->digest.len, tdata->cipher_iv.len); + if (retval < 0) return retval; ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); + if (op_mode == OUT_OF_PLACE) + ut_params->obuf = 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)); + rte_pktmbuf_tailroom(ut_params->ibuf)); + if (op_mode == OUT_OF_PLACE) + memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0, + rte_pktmbuf_tailroom(ut_params->obuf)); + ciphertext_len = ceil_byte_length(tdata->ciphertext.len); plaintext_len = ceil_byte_length(tdata->plaintext.len); /* Append data which is padded to a multiple of */ /* the algorithms block size */ + ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16); 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); - debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); + if (verify) { + ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, + ciphertext_pad_len); + memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len); + if (op_mode == OUT_OF_PLACE) + rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len); + debug_hexdump(stdout, "ciphertext:", ciphertext, + ciphertext_len); + } else { + plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, + plaintext_pad_len); + memcpy(plaintext, tdata->plaintext.data, plaintext_len); + if (op_mode == OUT_OF_PLACE) + rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len); + debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len); + } /* Create SNOW 3G operation */ retval = create_wireless_algo_auth_cipher_operation( tdata->digest.len, tdata->cipher_iv.data, tdata->cipher_iv.len, tdata->auth_iv.data, tdata->auth_iv.len, - tdata->digest.offset_bytes == 0 ? - plaintext_pad_len : tdata->digest.offset_bytes, + (tdata->digest.offset_bytes == 0 ? + (verify ? ciphertext_pad_len : plaintext_pad_len) + : tdata->digest.offset_bytes), tdata->validCipherLenInBits.len, tdata->cipher.offset_bits, tdata->validAuthLenInBits.len, - tdata->auth.offset_bits); + tdata->auth.offset_bits, + op_mode); 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_src; - if (ut_params->obuf) - ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *); - else - ciphertext = plaintext; - ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + ut_params->obuf = (op_mode == IN_PLACE ? + ut_params->op->sym->m_src : ut_params->op->sym->m_dst); + + if (verify) { + if (ut_params->obuf) + plaintext = rte_pktmbuf_mtod(ut_params->obuf, + uint8_t *); + else + plaintext = ciphertext + + (tdata->cipher.offset_bits >> 3); + + debug_hexdump(stdout, "plaintext:", plaintext, + (tdata->plaintext.len >> 3) - tdata->digest.len); + debug_hexdump(stdout, "plaintext expected:", + tdata->plaintext.data, + (tdata->plaintext.len >> 3) - tdata->digest.len); + } else { + if (ut_params->obuf) + ciphertext = rte_pktmbuf_mtod(ut_params->obuf, + uint8_t *); + else + ciphertext = plaintext; + + debug_hexdump(stdout, "ciphertext:", ciphertext, + ciphertext_len); + debug_hexdump(stdout, "ciphertext expected:", + tdata->ciphertext.data, tdata->ciphertext.len >> 3); + + ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + (tdata->digest.offset_bytes == 0 ? - plaintext_pad_len : tdata->digest.offset_bytes); + plaintext_pad_len : tdata->digest.offset_bytes); - debug_hexdump(stdout, "digest:", ut_params->digest, tdata->digest.len); - debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); + debug_hexdump(stdout, "digest:", ut_params->digest, + tdata->digest.len); + debug_hexdump(stdout, "digest expected:", tdata->digest.data, + tdata->digest.len); + } /* Validate obuf */ - TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( - ciphertext, - tdata->ciphertext.data, - tdata->validDataLenInBits.len, - "SNOW 3G Ciphertext data not as expected"); + if (verify) { + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( + plaintext, + tdata->plaintext.data, + tdata->plaintext.len >> 3, + "SNOW 3G Plaintext data not as expected"); + } else { + TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( + ciphertext, + tdata->ciphertext.data, + tdata->validDataLenInBits.len, + "SNOW 3G Ciphertext data not as expected"); - /* Validate obuf */ - TEST_ASSERT_BUFFERS_ARE_EQUAL( - ut_params->digest, - tdata->digest.data, - DIGEST_BYTE_LENGTH_SNOW3G_UIA2, - "SNOW 3G Generated auth tag not as expected"); + TEST_ASSERT_BUFFERS_ARE_EQUAL( + ut_params->digest, + tdata->digest.data, + DIGEST_BYTE_LENGTH_SNOW3G_UIA2, + "SNOW 3G Generated auth tag not as expected"); + } return 0; } @@ -4447,8 +4521,8 @@ test_kasumi_auth_cipher(const struct kasumi_test_data *tdata) tdata->validCipherLenInBits.len, tdata->validCipherOffsetInBits.len, tdata->validAuthLenInBits.len, - 0 - ); + 0, + IN_PLACE); if (retval < 0) return retval; @@ -5038,13 +5112,50 @@ test_snow3g_cipher_auth_test_case_1(void) static int test_snow3g_auth_cipher_test_case_1(void) { - return test_snow3g_auth_cipher(&snow3g_test_case_6); + return test_snow3g_auth_cipher( + &snow3g_auth_cipher_test_case_1, IN_PLACE, 0); +} + +static int +test_snow3g_auth_cipher_test_case_2(void) +{ + return test_snow3g_auth_cipher( + &snow3g_auth_cipher_test_case_2, IN_PLACE, 0); +} + +static int +test_snow3g_auth_cipher_test_case_2_oop(void) +{ + return test_snow3g_auth_cipher( + &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0); +} + +static int +test_snow3g_auth_cipher_verify_test_case_1(void) +{ + return test_snow3g_auth_cipher( + &snow3g_auth_cipher_test_case_1, IN_PLACE, 1); +} + +static int +test_snow3g_auth_cipher_verify_test_case_2(void) +{ + return test_snow3g_auth_cipher( + &snow3g_auth_cipher_test_case_2, IN_PLACE, 1); +} + +static int +test_snow3g_auth_cipher_verify_test_case_2_oop(void) +{ + return test_snow3g_auth_cipher( + &snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1); } static int test_snow3g_auth_cipher_with_digest_test_case_1(void) { - return test_snow3g_auth_cipher(&snow3g_test_case_7); + return test_snow3g_auth_cipher( + &snow3g_test_case_7, IN_PLACE, 0); } static int @@ -8650,9 +8761,6 @@ test_authenticated_encryption_SGL(const struct aead_test_data *tdata, return 0; } -#define IN_PLACE 0 -#define OUT_OF_PLACE 1 - static int test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void) { @@ -9189,6 +9297,22 @@ static struct unit_test_suite cryptodev_qat_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_snow3g_decryption_test_case_1_oop), + /** SNOW 3G generate auth, then encrypt (UEA2) */ + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_auth_cipher_test_case_1), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_auth_cipher_test_case_2), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_auth_cipher_test_case_2_oop), + + /** SNOW 3G decrypt (UEA2), then verify auth */ + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_auth_cipher_verify_test_case_1), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_auth_cipher_verify_test_case_2), + TEST_CASE_ST(ut_setup, ut_teardown, + test_snow3g_auth_cipher_verify_test_case_2_oop), + /** SNOW 3G decrypt only (UEA2) */ TEST_CASE_ST(ut_setup, ut_teardown, test_snow3g_decryption_test_case_1), @@ -9217,8 +9341,6 @@ static struct unit_test_suite cryptodev_qat_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_snow3g_cipher_auth_test_case_1), TEST_CASE_ST(ut_setup, ut_teardown, - test_snow3g_auth_cipher_test_case_1), - TEST_CASE_ST(ut_setup, ut_teardown, test_snow3g_auth_cipher_with_digest_test_case_1), /** ZUC encrypt only (EEA3) */ diff --git a/app/test/test_cryptodev_snow3g_test_vectors.h b/app/test/test_cryptodev_snow3g_test_vectors.h index 3e55ac1..191bae6 100644 --- a/app/test/test_cryptodev_snow3g_test_vectors.h +++ b/app/test/test_cryptodev_snow3g_test_vectors.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright(c) 2015-2017 Intel Corporation + * Copyright(c) 2015-2019 Intel Corporation */ #ifndef TEST_CRYPTODEV_SNOW3G_TEST_VECTORS_H_ @@ -59,6 +59,7 @@ struct snow3g_test_data { unsigned int offset_bits; } auth; }; + struct snow3g_test_data snow3g_test_case_1 = { .key = { .data = { @@ -347,7 +348,8 @@ struct snow3g_test_data snow3g_test_case_5 = { .len = 840 }, }; -struct snow3g_test_data snow3g_test_case_6 = { + +struct snow3g_test_data snow3g_auth_cipher_test_case_1 = { .key = { .data = { 0xC7, 0x36, 0xC6, 0xAA, 0xB2, 0x2B, 0xFF, 0xF9, @@ -415,7 +417,6 @@ struct snow3g_test_data snow3g_test_case_6 = { }, }; - struct snow3g_test_data snow3g_test_case_7 = { .key = { .data = { @@ -508,4 +509,97 @@ struct snow3g_test_data snow3g_test_case_7 = { }, }; +struct snow3g_test_data snow3g_auth_cipher_test_case_2 = { + .key = { + .data = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10 + + }, + .len = 16 + }, + .cipher_iv = { + .data = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 + }, + .len = 16 + }, + .auth_iv = { + .data = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }, + .len = 16 + }, + .plaintext = { + .data = { + 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xCE, 0x54, 0xE3, + 0x29, 0x00, 0x3C, 0xA4, 0xAD, 0x74, 0xEE, 0x05, + 0xA3, 0x6C, 0xD4, 0xAC, 0xC6, 0x30, 0x33, 0xC9, + 0x37, 0x57, 0x41, 0x9B, 0xD4, 0x73, 0xB9, 0x77, + 0x70, 0x8B, 0x63, 0xDD, 0x22, 0xB8, 0xE1, 0x85, + 0xB2, 0x92, 0x7C, 0x37, 0xD3, 0x2E, 0xD9, 0xF4, + 0x4A, 0x69, 0x25, 0x30, 0xE3, 0x5B, 0x8B, 0xF6, + 0x0F, 0xDE, 0x0B, 0x92, 0xD5, 0x25, 0x52, 0x6D, + 0x26, 0xEB, 0x2F, 0x8A, 0x3B, 0x8B, 0x38, 0xE2, + 0x48, 0xD3, 0x4A, 0x98, 0xF7, 0x3A, 0xC2, 0x46, + 0x69, 0x8D, 0x73, 0x3E, 0x57, 0x88, 0x2C, 0x80, + 0xF0, 0xF2, 0x75, 0xB8, 0x7D, 0x27, 0xC6, 0xDA, + + }, + .len = 128 << 3 + }, + .cipher = { + .len_bits = 126 << 3, + .offset_bits = 2 << 3 + }, + .auth = { + .len_bits = 124 << 3, + .offset_bits = 0 + }, + .digest = { + .data = { + 0x7D, 0x27, 0xC6, 0xDA + }, + .len = 4, + .offset_bytes = 124 + }, + .validDataLenInBits = { + .len = 128 << 3 + }, + .validCipherLenInBits = { + .len = 126 << 3 + }, + .validAuthLenInBits = { + .len = 124 << 3 + }, +}; + #endif /* TEST_CRYPTODEV_SNOW3G_TEST_VECTORS_H_ */ -- 2.7.4