From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 78A22A00BE; Mon, 25 Apr 2022 06:15:45 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C939242809; Mon, 25 Apr 2022 06:15:16 +0200 (CEST) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-eopbgr140077.outbound.protection.outlook.com [40.107.14.77]) by mails.dpdk.org (Postfix) with ESMTP id 5FF3242803 for ; Mon, 25 Apr 2022 06:15:15 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bmZ0fLx12VR0273YV9u5vL++L2sQQAcdhZwU0ZDx83p1HcEldaQfjQFTMFSfv+njqO0FUSpo5960fxtN3WH6rdxToSkMpZ6Ge6rF8fYliWz9I4/zjYDMcOPgbgHh0h9dASbtnLRx8i6zgQWTQiBq/Y8esf+B6V5uK9UZfqoTQ+0cwo2T6zkOi+IPiqP+5Sn4IQkFiGaS+uDWqMzb1vEQeF6gHii8xzHQefrV7DZYys1uBIBwrSMpu8EfvmJpXY1SlwbEWFLr/4G1BMg4DQaPa+obp6RE/DNz57SUzNEupc2NcCxqzyz6LvkbHXzcbaOMf29unkinZBlcCkisPwituw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Cj/hIRJFq6lXWgQ8O1z49GCBGm0S5Wp7Pg/1Za6hyBQ=; b=fak4kJyXvsaBPLO/226qk1ZPJ83Ti/AbPo9RJN1Bk/JgbmH7GLBNEevLEaQRBkZtwfKXp4YhXdof+NkyC9yOtqxvTd8W3rFTNo30QAh4Hx0FqPEhVYBVnNjLPdYpHLJFjEkTQaQOVFgFXN+Qr60ABKT0ydi+t2DJk+WS5ETbn1AzIODoKU9mK0a20A4rDqu043GXwD3BORx70eoexb2+s1AEExNK6z0M3ccuQA7dzaYFAUjktYJCFYEgqeI80jii9STqMseL+DBdCdYIlMBw1XNX9B7YjI5TmdVfUTxgDfcsJS5sgCFRFvhwS+KBfpI2xfDoUjQ0FDSWtPETBNMxTA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Cj/hIRJFq6lXWgQ8O1z49GCBGm0S5Wp7Pg/1Za6hyBQ=; b=bcH6Uxw2WgCbBIo2MYuR55Qr1M6nNBd4cVO1L3BkcIv3fg7eAKX8l6YSRNtYbwy9JpX+148ifYNyGqqE5Ugi9GL5S1iOstnyGB93+wHr6M2Dw6oNNQJaRgOi7Bsfh9Ly7P+MooT86CYUtkbi4rFFdfVDNUQhmhMKPEEueDUzeVQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8198.eurprd04.prod.outlook.com (2603:10a6:20b:3b0::14) by PA4PR04MB9416.eurprd04.prod.outlook.com (2603:10a6:102:2ab::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5186.21; Mon, 25 Apr 2022 04:15:14 +0000 Received: from AS8PR04MB8198.eurprd04.prod.outlook.com ([fe80::8cf1:93b:c340:3be2]) by AS8PR04MB8198.eurprd04.prod.outlook.com ([fe80::8cf1:93b:c340:3be2%7]) with mapi id 15.20.5186.021; Mon, 25 Apr 2022 04:15:14 +0000 From: Gagandeep Singh To: gakhil@marvell.com, dev@dpdk.org Cc: Gagandeep Singh Subject: [PATCH 7/8] test/crypto: add external buffer test case Date: Mon, 25 Apr 2022 09:44:22 +0530 Message-Id: <20220425041423.2232034-7-g.singh@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220425041423.2232034-1-g.singh@nxp.com> References: <20220425041423.2232034-1-g.singh@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2PR01CA0165.apcprd01.prod.exchangelabs.com (2603:1096:4:28::21) To AS8PR04MB8198.eurprd04.prod.outlook.com (2603:10a6:20b:3b0::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8791c43d-1f37-4162-6317-08da2672325f X-MS-TrafficTypeDiagnostic: PA4PR04MB9416:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1jQNeDmxFBJG0sEVyp2siR7S0sLN1WVclNE59IXcc6TyJApVY9tKv+B1LEmw9gB/lNoVV/OfmbdI9u/21pjO/r2E+fz45rDW8Li9wnL49lM4FDsU8G/VQeSM7fInP9kt4oQnhsrtlRECskaEmeBhOii1UwAyVvHVeZAk1GUk9TuElGbDapyglYEG9UOq8ELg3vhwNp75ezGuo84aB6NUyOpzN29rODRhDBlX3txln8LzFrO1okBao2aLjb1rdgewcLCYNEnH25qU3rtjIQziugeR7I9e0L10SBzU0iIOYhcqO1mrRnhNSxiLbYpgr5tomTbFehARTo/HSR4kA6E2XhO1a65GsV4hfmBbjmF/gAS3IJoVenIuELak9/XfaDEsI+/a95/c9SzZIeNA/m3WxraY41rspkXNZfQGSaF5ZNxPT5jcbI4PJuGBIakqhDK43vbBPE7UaM5HrrrcdRcOwoNEAg+QDHQybZHvv2Qcjdt/EF+NqwXQl2fqupIjXxAr+Z8accGt4a0Fe5w9bFHkmtGR6qAzdNbpNDLwHu2a4nMf0I9VMHVheRELQvCJ3ocd/T7Dg1PNuKUYMoW3i6D6nTtvpF2vFnEYWts9rK92/uivAIc2MPA1zL49LHUPZhm4vEBULJHHQxxiLMR1p8n/y1xai6YnYHw+5SqtHxXJCTM9177hpasZyWIE9bw7qcBY9zB567qUHNtxoikpUmo9Gg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8198.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(4636009)(366004)(4326008)(66556008)(6666004)(2616005)(5660300002)(66946007)(6512007)(8936002)(26005)(2906002)(38350700002)(86362001)(1076003)(38100700002)(52116002)(508600001)(6486002)(83380400001)(66476007)(8676002)(186003)(316002)(55236004)(6506007)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?msNM1z/SBB76TwoBMNPNzTJMr2FSn+wggTzZtFr4XeF9CUvdT11cwL5it4VM?= =?us-ascii?Q?0wTgKdjHs/PC67NScyP7WtRgJNOU2QMVpl8Q1Hc1K64bShn0FebSJqIP9Gh6?= =?us-ascii?Q?e3yx0ntQG4bwH3af3nIYS+Sp44xePJoI439Kv4oZmTk5bZqMd71BK3bS1800?= =?us-ascii?Q?Eq9TCfErYeUMBSax4vX8jBvHlPrkOkA+avI5DBEfZM3F0ldcTQjAHXh97LaG?= =?us-ascii?Q?nI44/pBIHeOBU6qltZqV6dGkRw+7f8xpoxicfAta5Z8n9kiLoXowl6+xNGvP?= =?us-ascii?Q?SIwJu+lOMLOD9dm1Io6zEBevsRtDCeFBJCxlAYOFhxbymQZ+poZ1DkA3Je2g?= =?us-ascii?Q?YK8Ak8HhNtyJihT4v8Y9XeXAMG6LlZsyYnHERBsfCDCPnaoYLBT9kL7kzmm2?= =?us-ascii?Q?55WlIwDNGiYraDmAcoav1yuwNtfdhImgd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H85jE83dQmSQHCsszccjHLj9olFHFd/n3wC25DWwuizOG/y7po9u2dCiHvKT?= =?us-ascii?Q?XcUHP9xFx4wdg/s5+BH8fCYnOVMRpGqdtiNYFi7eDWtjrAWaeqxc0XMnu3Bx?= =?us-ascii?Q?sNbuOPmPr3mDYdN5jyU3xqJrfTs7qG4QfSBQMY4yTJ2fqKRftxsJ+1+YJOTm?= =?us-ascii?Q?A/voMLsTkDwfVzg2z0sK0yJIIxoUcvhCHRmk+dNCNMFfCWI9eOmO+nnQvLQ/?= =?us-ascii?Q?d2VEunAGPJB/LQ4AmG1XVc4MlerPwhbgP3lItqLDfshSUyST1+D6ibTPaYcY?= =?us-ascii?Q?W9uV7UnT1NjsY+sSDfQjUqsocufza4zI5zztV/vVa281WXNPF4wm8Ts3l4ik?= =?us-ascii?Q?zP3tsrtaSqsuxIH+dDaWwQSJPbO+C/Sbq/w1SnsGGyK8iERj7kV1hD0okJus?= =?us-ascii?Q?52H5HBXDfw=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8791c43d-1f37-4162-6317-08da2672325f X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8198.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Apr 2022 04:15:14.3191 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: NidHkMRZazRaVDTCe3lf1aUTvm0Fl8UOh7OIy0GXcRYHQcgKQPZqFdRTubA2l7QJ X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB9416 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 Add a test case to verify crypto functionality with external buffer. Signed-off-by: Gagandeep Singh --- app/test/test_cryptodev.c | 163 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 0b53ec0078..b4ffb4fd94 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -2270,6 +2270,167 @@ test_AES_CBC_HMAC_SHA1_encrypt_digest(void) return TEST_SUCCESS; } +static inline void +ext_buf_free_callback_fn(void *addr, + void *ext_buf_ptr __rte_unused) +{ + rte_free(addr); +} + +static int +test_AES_CBC_HMAC_SHA1_encrypt_digest_ext_buffer(void) +{ + struct crypto_testsuite_params *ts_params = &testsuite_params; + struct crypto_unittest_params *ut_params = &unittest_params; + int status; + void *buf; + rte_iova_t iova; + uint16_t buf_len = QUOTE_1024_BYTES; + struct rte_mbuf_ext_shared_info *shinfo = NULL; + struct rte_mbuf *m; + + + /* Verify the capabilities */ + struct rte_cryptodev_sym_capability_idx cap_idx; + cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH; + cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC; + if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], + &cap_idx) == NULL) + return TEST_SKIPPED; + cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER; + cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC; + if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0], + &cap_idx) == NULL) + return TEST_SKIPPED; + + buf = rte_malloc(NULL, buf_len, RTE_CACHE_LINE_SIZE); + if (buf == NULL) + return TEST_SKIPPED; + + rte_memcpy(buf, catch_22_quote, QUOTE_512_BYTES); + shinfo = rte_pktmbuf_ext_shinfo_init_helper(buf, &buf_len, + ext_buf_free_callback_fn, NULL); + if (unlikely(shinfo == NULL)) { + rte_free(buf); + return -1; + } + iova = rte_malloc_virt2iova(buf); + m = rte_pktmbuf_alloc(ts_params->mbuf_pool); + if (m == NULL) + return TEST_SKIPPED; + rte_pktmbuf_attach_extbuf(m, buf, iova, buf_len, shinfo); + rte_pktmbuf_reset_headroom(m); + m->pkt_len = QUOTE_512_BYTES; + m->data_len = QUOTE_512_BYTES; + m->data_off = 0; + + ut_params->ibuf = m; + + ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, + DIGEST_BYTE_LENGTH_SHA1); + TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest"); + + /* Setup Cipher Parameters */ + ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; + ut_params->cipher_xform.next = &ut_params->auth_xform; + + ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC; + ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; + ut_params->cipher_xform.cipher.key.data = aes_cbc_key; + ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC; + ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET; + ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC; + + /* Setup HMAC Parameters */ + ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; + + ut_params->auth_xform.next = NULL; + + ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE; + ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC; + ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1; + ut_params->auth_xform.auth.key.data = hmac_sha1_key; + ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1; + + ut_params->sess = rte_cryptodev_sym_session_create( + ts_params->session_mpool); + TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed"); + + /* Create crypto session*/ + status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0], + ut_params->sess, &ut_params->cipher_xform, + ts_params->session_priv_mpool); + + if (status == -ENOTSUP) + return TEST_SKIPPED; + + TEST_ASSERT_EQUAL(status, 0, "Session init failed"); + + /* Generate crypto op data structure */ + ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, + RTE_CRYPTO_OP_TYPE_SYMMETRIC); + TEST_ASSERT_NOT_NULL(ut_params->op, + "Failed to allocate symmetric crypto operation struct"); + + rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess); + + struct rte_crypto_sym_op *sym_op = ut_params->op->sym; + + /* set crypto operation source mbuf */ + sym_op->m_src = ut_params->ibuf; + + /* Set crypto operation authentication parameters */ + sym_op->auth.digest.data = ut_params->digest; + sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset( + ut_params->ibuf, QUOTE_512_BYTES); + + sym_op->auth.data.offset = 0; + sym_op->auth.data.length = QUOTE_512_BYTES; + + /* Copy IV at the end of the crypto operation */ + rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET), + aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC); + + /* Set crypto operation cipher parameters */ + sym_op->cipher.data.offset = 0; + sym_op->cipher.data.length = QUOTE_512_BYTES; + + /* Process crypto operation */ + if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) + process_cpu_crypt_auth_op(ts_params->valid_devs[0], + ut_params->op); + else + TEST_ASSERT_NOT_NULL( + process_crypto_request(ts_params->valid_devs[0], + ut_params->op), + "failed to process sym crypto op"); + + TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS, + "crypto op processing failed"); + + /* Validate obuf */ + uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, + uint8_t *); + + TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext, + catch_22_quote_2_512_bytes_AES_CBC_ciphertext, + QUOTE_512_BYTES, + "ciphertext data not as expected"); + + uint8_t *digest = ciphertext + QUOTE_512_BYTES; + + TEST_ASSERT_BUFFERS_ARE_EQUAL(digest, + catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest, + gbl_driver_id == rte_cryptodev_driver_id_get( + RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ? + TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 : + DIGEST_BYTE_LENGTH_SHA1, + "Generated digest data not as expected"); + + return TEST_SUCCESS; +} + + /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */ #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512) @@ -15458,6 +15619,8 @@ static struct unit_test_suite cryptodev_gen_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_stats), TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup), TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup), + TEST_CASE_ST(ut_setup, ut_teardown, + test_AES_CBC_HMAC_SHA1_encrypt_digest_ext_buffer), TEST_CASES_END() /**< NULL terminate unit test array */ } }; -- 2.25.1