From patchwork Fri Jan 6 16:15:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Power, Ciara" X-Patchwork-Id: 121683 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DB47CA00C2; Fri, 6 Jan 2023 17:15:44 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8367A40141; Fri, 6 Jan 2023 17:15:44 +0100 (CET) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by mails.dpdk.org (Postfix) with ESMTP id BE9DB400EF for ; Fri, 6 Jan 2023 17:15:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1673021743; x=1704557743; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=mmLqcb9x39XwBDFv0CHAQqZ/EaL4biOn895mJuH/vYg=; b=UE5j6ftZRzdkOdRRm1+oA2VGMAOZpbWD3GV6vqmpZXdwt4OpLIJ+5UVh e2UpjjnMlvFOKLpX3ovF0hauieV90+wgo6f/29/iwedxmD9xtRGFN49W/ hp/yl6WzZl2jIqe30rVMztOblCIgMvjHttejRBNXZrX461iqRUtcAlzFH T8mu5FUvooFBYLdQIPfvWCXe0bBhHb2IN/E3AB0gUf1QhPjNyIjq8hRcN W5Odz5vbirO3Lkqw0b97xp7/8vY/R4BI8GT3a2T7QfaOdZpmXPlIR0ybS K/Q9xKAOLHN9kfvi351xi75GYDYJG8Xy+hQ2UYDFSdMbic4+uj9z2Kxux g==; X-IronPort-AV: E=McAfee;i="6500,9779,10582"; a="321207930" X-IronPort-AV: E=Sophos;i="5.96,305,1665471600"; d="scan'208";a="321207930" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jan 2023 08:15:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10582"; a="984705591" X-IronPort-AV: E=Sophos;i="5.96,305,1665471600"; d="scan'208";a="984705591" Received: from silpixa00400355.ir.intel.com (HELO silpixa00400355.ger.corp.intel.com) ([10.237.222.219]) by fmsmga005.fm.intel.com with ESMTP; 06 Jan 2023 08:15:39 -0800 From: Ciara Power To: Akhil Goyal , Fan Zhang , Tejasree Kondoj , Ciara Power Cc: dev@dpdk.org, kai.ji@intel.com Subject: [PATCH] test/crypto: fix and improve ZUC cipher and auth tests Date: Fri, 6 Jan 2023 16:15:36 +0000 Message-Id: <20230106161536.68058-1-ciara.power@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The incorrect value was used for the reference plaintext offset in ZUC cipher function. This is now fixed to convert to byte length, rather than bits. Also, to cleanup the ZUC test code, some small improvements are made. The authentication function takes the auth op enum as a parameter instead of a new variable, this can then be used directly. The cipher SGL function does not need to buffers allocated for ciphertext and plaintext, one can be used for both. Fixes: be8e5d957366 ("test/crypto: add further ZUC testcases") Signed-off-by: Ciara Power Acked-by: Fan Zhang --- app/test/test_cryptodev.c | 92 +++++++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index a824ed3511..aa831d79a2 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -6059,7 +6059,7 @@ test_zuc_cipher(const struct wireless_test_data *tdata, debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); const uint8_t *reference_plaintext = tdata->plaintext.data + - (tdata->validCipherOffsetInBits.len); + (tdata->validCipherOffsetInBits.len >> 3); /* Validate obuf */ TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT( @@ -6085,7 +6085,7 @@ test_zuc_cipher_sgl(const struct wireless_test_data *tdata, unsigned int plaintext_len = 0; unsigned int ciphertext_len = 0; const uint8_t *ciphertext, *plaintext; - uint8_t ciphertext_buffer[2048], plaintext_buffer[2048]; + uint8_t buffer[2048]; struct rte_cryptodev_info dev_info; /* Check if device supports ZUC EEA3 */ @@ -6174,10 +6174,10 @@ test_zuc_cipher_sgl(const struct wireless_test_data *tdata, if (direction == RTE_CRYPTO_CIPHER_OP_ENCRYPT) { if (ut_params->obuf) ciphertext = rte_pktmbuf_read(ut_params->obuf, - 0, plaintext_len, ciphertext_buffer); + 0, plaintext_len, buffer); else ciphertext = rte_pktmbuf_read(ut_params->ibuf, - 0, plaintext_len, ciphertext_buffer); + 0, plaintext_len, buffer); /* Validate obuf */ debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len); @@ -6191,10 +6191,10 @@ test_zuc_cipher_sgl(const struct wireless_test_data *tdata, } else { if (ut_params->obuf) plaintext = rte_pktmbuf_read(ut_params->obuf, - 0, ciphertext_len, plaintext_buffer); + 0, ciphertext_len, buffer); else plaintext = rte_pktmbuf_read(ut_params->ibuf, - 0, ciphertext_len, plaintext_buffer); + 0, ciphertext_len, buffer); /* Validate obuf */ debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len); @@ -6211,7 +6211,8 @@ test_zuc_cipher_sgl(const struct wireless_test_data *tdata, } static int -test_zuc_authentication(const struct wireless_test_data *tdata, uint8_t verify) +test_zuc_authentication(const struct wireless_test_data *tdata, + enum rte_crypto_auth_operation auth_op) { struct crypto_testsuite_params *ts_params = &testsuite_params; struct crypto_unittest_params *ut_params = &unittest_params; @@ -6251,9 +6252,7 @@ test_zuc_authentication(const struct wireless_test_data *tdata, uint8_t verify) retval = create_wireless_algo_hash_session(ts_params->valid_devs[0], tdata->key.data, tdata->key.len, tdata->auth_iv.len, tdata->digest.len, - (verify ? RTE_CRYPTO_AUTH_OP_VERIFY - : RTE_CRYPTO_AUTH_OP_GENERATE), - RTE_CRYPTO_AUTH_ZUC_EIA3); + auth_op, RTE_CRYPTO_AUTH_ZUC_EIA3); if (retval != 0) return retval; @@ -6276,10 +6275,7 @@ test_zuc_authentication(const struct wireless_test_data *tdata, uint8_t verify) tdata->digest.len, tdata->auth_iv.data, tdata->auth_iv.len, plaintext_pad_len, - (verify ? RTE_CRYPTO_AUTH_OP_VERIFY - : RTE_CRYPTO_AUTH_OP_GENERATE), - tdata->validAuthLenInBits.len, - 0); + auth_op, tdata->validAuthLenInBits.len, 0); if (retval < 0) return retval; @@ -6294,7 +6290,7 @@ test_zuc_authentication(const struct wireless_test_data *tdata, uint8_t verify) ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) + plaintext_pad_len; - if (!verify) { + if (auth_op != RTE_CRYPTO_AUTH_OP_VERIFY) { /* Validate obuf */ TEST_ASSERT_BUFFERS_ARE_EQUAL( ut_params->digest, @@ -7336,133 +7332,155 @@ test_zuc_decryption_test_case_6_sgl(void) static int test_zuc_hash_generate_test_case_1(void) { - return test_zuc_authentication(&zuc_test_case_auth_1b, 0); + return test_zuc_authentication(&zuc_test_case_auth_1b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_2(void) { - return test_zuc_authentication(&zuc_test_case_auth_90b, 0); + return test_zuc_authentication(&zuc_test_case_auth_90b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_3(void) { - return test_zuc_authentication(&zuc_test_case_auth_577b, 0); + return test_zuc_authentication(&zuc_test_case_auth_577b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_4(void) { - return test_zuc_authentication(&zuc_test_case_auth_2079b, 0); + return test_zuc_authentication(&zuc_test_case_auth_2079b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_5(void) { - return test_zuc_authentication(&zuc_test_auth_5670b, 0); + return test_zuc_authentication(&zuc_test_auth_5670b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_6(void) { - return test_zuc_authentication(&zuc_test_case_auth_128b, 0); + return test_zuc_authentication(&zuc_test_case_auth_128b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_7(void) { - return test_zuc_authentication(&zuc_test_case_auth_2080b, 0); + return test_zuc_authentication(&zuc_test_case_auth_2080b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_8(void) { - return test_zuc_authentication(&zuc_test_case_auth_584b, 0); + return test_zuc_authentication(&zuc_test_case_auth_584b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_9(void) { - return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 0); + return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_10(void) { - return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 0); + return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_generate_test_case_11(void) { - return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 0); + return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, + RTE_CRYPTO_AUTH_OP_GENERATE); } static int test_zuc_hash_verify_test_case_1(void) { - return test_zuc_authentication(&zuc_test_case_auth_1b, 1); + return test_zuc_authentication(&zuc_test_case_auth_1b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_2(void) { - return test_zuc_authentication(&zuc_test_case_auth_90b, 1); + return test_zuc_authentication(&zuc_test_case_auth_90b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_3(void) { - return test_zuc_authentication(&zuc_test_case_auth_577b, 1); + return test_zuc_authentication(&zuc_test_case_auth_577b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_4(void) { - return test_zuc_authentication(&zuc_test_case_auth_2079b, 1); + return test_zuc_authentication(&zuc_test_case_auth_2079b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_5(void) { - return test_zuc_authentication(&zuc_test_auth_5670b, 1); + return test_zuc_authentication(&zuc_test_auth_5670b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_6(void) { - return test_zuc_authentication(&zuc_test_case_auth_128b, 1); + return test_zuc_authentication(&zuc_test_case_auth_128b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_7(void) { - return test_zuc_authentication(&zuc_test_case_auth_2080b, 1); + return test_zuc_authentication(&zuc_test_case_auth_2080b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_8(void) { - return test_zuc_authentication(&zuc_test_case_auth_584b, 1); + return test_zuc_authentication(&zuc_test_case_auth_584b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_9(void) { - return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, 1); + return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_10(void) { - return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, 1); + return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int test_zuc_hash_verify_test_case_11(void) { - return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, 1); + return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b, + RTE_CRYPTO_AUTH_OP_VERIFY); } static int