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 1F24D42BA2; Fri, 26 May 2023 03:18:51 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1140F4114B; Fri, 26 May 2023 03:18:51 +0200 (CEST) Received: from APC01-SG2-obe.outbound.protection.outlook.com (mail-sgaapc01on2074.outbound.protection.outlook.com [40.107.215.74]) by mails.dpdk.org (Postfix) with ESMTP id 400D64114A for ; Fri, 26 May 2023 03:18:50 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Iif75mbFEjbTGZAuH0umqAn1qA6IqwNz02CpoENIJsyBFRoSjRW2BoCtmJ3eJLerUcv3h/hi7fwbfGKeCxcn5VgrnAhx9gtH2bilGkT+5jmNYmwWLgRnMzARI1M1ijm1FT+Uh2v0oAA9ylFn+ontLzYqwd0BEHzwNQmfM8UeyLoQquVmzg9qemou/KQDcwqIc2Bh4GDl2RB08OCtTUhgxra2YusXGtqGX/SfJWQSr9kmofpzMkZTcZ33zkMLHnvPE94I36EvNE+/Awnm6OwgEuEEJmlqYISdRWUWbvxQlzWrRf8Zi706TdC1Inbp/Zj6gh5wsd+FgSvxUz6nw/ViOg== 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=2wwiaQSTQn7Oh5uN3xkgP9kKmw91DmPQ36FlVQX7RGg=; b=FTqK65dnQYtP7w3YkWVa9wFVCv+2apz/Jmm3x9t9rFxJMWggPf2fmJ0+pFcbPgz+NwhD3ZkE/NeTQtm1xunmWAQNkgI3YLSz9rClhdgiCMttJ1YyMLwbfnMfltIgqr/WDqrgA75GCVesvkhDQjYuQYTtFp+FdLJgHm3m5h3VRdVmIcU34xF4K2RWntBmbof9mEWz6dEjv7i1pyWRXIMWxaRViRPwm9NkNkrD6ut6iFYJMPA+YTlkm0fDlalBRXDcu/n/t9SIpo7bob4vq0z4TIvfJehde58xgfhYhuLLoISeiIaZSXX6HxBn/HkRd5oZFHfDzytxrLxdAmzLRp84+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=jaguarmicro.com; dmarc=pass action=none header.from=jaguarmicro.com; dkim=pass header.d=jaguarmicro.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaguarmicro.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2wwiaQSTQn7Oh5uN3xkgP9kKmw91DmPQ36FlVQX7RGg=; b=Kf9EmQj4Cj0u1k5q1U3B/Q7+eqUG6b9ZMVWCCli9EF/jgethfh0X3Gjv2E3Cq4Z2b/bd1Fl6U0IQRAfUTqisalC4JuuUDm4doPSQNOdDrJJz71RjWImoaM6la6NTaD9zAndCgpQwkuMg3Rp/Syq4bBYYfD8zS4xRqk3H7Y3korhpiXsloXbw9/48vHNgCq8ibijkl9Yl8r4JkCIHxAVIgAQBbp1zntqP1Bond2fCgyRwToziEOUS8R/ywvNlSwi0WHxFVh7WsAw0qMnEdPhBNR6koS1mb9n1FDM3wqb2xXKmyHkkUP3J/dnkdFLOFdBwwTw6BIozMaTSDbg5AyPR7Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=jaguarmicro.com; Received: from TY0PR06MB5563.apcprd06.prod.outlook.com (2603:1096:400:328::14) by SI2PR06MB4347.apcprd06.prod.outlook.com (2603:1096:4:15b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.18; Fri, 26 May 2023 01:18:46 +0000 Received: from TY0PR06MB5563.apcprd06.prod.outlook.com ([fe80::d13f:abd4:563b:337c]) by TY0PR06MB5563.apcprd06.prod.outlook.com ([fe80::d13f:abd4:563b:337c%6]) with mapi id 15.20.6433.018; Fri, 26 May 2023 01:18:46 +0000 From: Sunyang Wu To: dev@dpdk.org Cc: kai.ji@intel.com, gakhil@marvell.com Subject: [PATCH v3 2/2] test/crypto: Add SM3/SM4 test vectors for verification in test app Date: Fri, 26 May 2023 09:18:11 +0800 Message-Id: <20230526011811.3628-2-sunyang.wu@jaguarmicro.com> X-Mailer: git-send-email 2.19.0.rc0.windows.1 In-Reply-To: <20230526011811.3628-1-sunyang.wu@jaguarmicro.com> References: <20230526011811.3628-1-sunyang.wu@jaguarmicro.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2PR01CA0175.apcprd01.prod.exchangelabs.com (2603:1096:4:28::31) To TY0PR06MB5563.apcprd06.prod.outlook.com (2603:1096:400:328::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: TY0PR06MB5563:EE_|SI2PR06MB4347:EE_ X-MS-Office365-Filtering-Correlation-Id: 20acea9a-dc61-4eed-7e11-08db5d8726b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uzWYhgx+VAZOmNUmPkTAt9wNWWz8q9ZeOYyLQ+8od4aSGg6QFOfb+eFSl+gLBDfsG2klQomWP/VpP7v9+b8NItOydpDJkK/8cT8t2sMz7O82+o/qfsgk7niH8lKYre1ttVvkbzuEbvlMSjomMSmggYynLb1JYU9qFaBLsziXLq6FFVjF+QFxc0OUc9hGEU7LkkKzQzgQjzkI+pIdPwTNrqWaBQW+QkrbeRu8Azi/LiaYGVpO9e/ZtJ6LsItDXZvdRs3Tm3sWBNkfjs/HqDxqo2Qy0lDsjfI6ONNtbgiWem+9bh8dbMOrirrIlochgIOPD6cjUPm+M+6p1RqWx/calxwkSKWvo+aleKWtgCqWuLkQZdHDmcc228Yb2PEGURVujiE4BRy6CAKkZ4i17sjBqx/a+z5Dob/28x5MUrqvoZLdb8AZ/2gnj6BQRIPcgie/mU8cJW+YyFBnX+6TNN9O7CX2dVkNqzAUhs10LOeS6XTBwSk44TKD+ealXOGpxVx84t1WjDc1o5a7KNHH6JMu/h3GzcR8fxqtbfKuO4VSu2e6m+Q+04sMkxk58ye7pYi6ush8QuQv2F6IBNh9GPHcXz6nz0W3eQYsMdfF21Ct9Bf19SiXkZYu1E1Ybr0hH+7m X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:TY0PR06MB5563.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(136003)(396003)(39840400004)(366004)(376002)(346002)(451199021)(15650500001)(83380400001)(186003)(6916009)(4326008)(41300700001)(30864003)(2906002)(66946007)(66556008)(66476007)(36756003)(6506007)(6512007)(26005)(1076003)(86362001)(2616005)(44832011)(5660300002)(8936002)(8676002)(38350700002)(38100700002)(6486002)(52116002)(316002)(6666004)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?05Cs7p5HVx1BsOtRyXq7XeZxt5rHlXfM7NVOiXUw8Gr/aaiUANZRUpjGav9Z?= =?us-ascii?Q?adQRPRAm2e1U7sdyCbYwPoN0QyGoS4p4wn861itB1q9cM7cyNjCKWMa6oZG+?= =?us-ascii?Q?HXuLlG4KARfXvLBfmb3P2VmWvucRILg5gjBDHMceHxaP4y2OWPd26my7qm0T?= =?us-ascii?Q?CxgR1X6gwgKCQmnLbHYwtXb3C1EOO0s2CbFhawXxRJt0pUMaVh1xMMzvnt5G?= =?us-ascii?Q?uzgbklvPi2Lkss4BN9oPQ929ZvQFoXHZhnS3Tn4UJlmpezn4PpR8gY5fcqul?= =?us-ascii?Q?8Ciu413OooOfRhJ9reKBvW58QiPZhQNOadKklr/mgF19sU1e98FX+effKxn7?= =?us-ascii?Q?KdicHSBPzsLr0odOf+7UDuQQVcoE7+mQYW1RU/fO9Ok+vL/DrynkjFC8X4Fo?= =?us-ascii?Q?XzOoon1/jBMzT1bn0XFdBCQF7gDHZmqZOB7osK4mJ80MRtnFIRp+8QFhSw/j?= =?us-ascii?Q?kn88z1MUbArJSjlKWixPbTZDCU4svWX3BxQCtdC9rEj2RyG93BLpS8XdUiPH?= =?us-ascii?Q?rr8jWo5VceUO97r2G1hz8MYA2PHwoU3aChlU0w4dpFc0VVZqHv1BF0qrSFp+?= =?us-ascii?Q?YwsSWvfZU0lzT80Sh0mBxMSY9FS/EuHOnN+a54CZmaL7ryPLWUuwi+Ovb02E?= =?us-ascii?Q?vqavulCrTKU5VBSUrUM3Gzf9zazQGB+QtVVtZP99x71+vKp08GwrbFlPcLE5?= =?us-ascii?Q?fe4crwmyzdscm5HW0NSS7HqbbRv/LFWxiWOTooMs9f/OHcQptHcxXPgD2ugJ?= =?us-ascii?Q?+peF5e2xLWniFgwiQwK4LnekGmHOG5u9MJG+SfHTNnRK+x5SJ4YBcNB+C/aR?= =?us-ascii?Q?EyIsZ+QB0T3PNxSsNfPNyDoQvN257p2L+jckQxs6PofrujMKrTupsh/jzjms?= =?us-ascii?Q?VCMrK6qorcB8aVQtWBkh3SAmZXQCSQamC+EbRznLDF1NjOxPm0E4Dq5KMUyk?= =?us-ascii?Q?de1xKloKXenh39MMslSFlO1o7gOtAOgWM7tCh7g3cD7MxE7HFUroEEkLYONU?= =?us-ascii?Q?xz17Je3bOp2CnR1aPnPzpXsif5hYvlWWAGgPiMq45+wfsv10O5ve2tazUAkv?= =?us-ascii?Q?H6tuYTV2xumQV5dI2ttcZb+j9kabNFHGKmj8Mb2OC94Wy6lC53K6R7CQSZfm?= =?us-ascii?Q?ZXHP91GOpG/5NzufLIQ1mCsp/6Euu/KtBuTJtbvkWLVgInFWcS5pI5pAtjBF?= =?us-ascii?Q?6cPWX0VsEUSfWw9u7MpNWv4EfGSTHf9iOQFPK6tm4UPBrJPWdWXfSVAuG40B?= =?us-ascii?Q?fMCKFM/VwwXvG2mbM1LmwFxD60qHod5jsS3NSflN7fIOcU7jmxHh7OJIsrD0?= =?us-ascii?Q?ABf4dzPxNJ8lJKXGyLZBc2ywinGd9l+vrXe3wIVfYMFfY76COdEVtWDLF2H5?= =?us-ascii?Q?ydnO2ENQ4R3EuZq53tiQFLlBL05/r59llONOpU9ocImcECGXm7ucZ7yrxl7F?= =?us-ascii?Q?+rnK1SvbPkZ16QmRl99PkTyVlflBCMbnau1/uzhDw6qCjYlmLcimt4Y7BK3t?= =?us-ascii?Q?tSA1i/A5mVenjbea2gg9UZ03lHvQcBg1Z6c8Et22cx2bpcMmhU/5a9nD+6O5?= =?us-ascii?Q?JR+FLNIddxGIpwlCZFyToZzsLBLxlOzpXAwN4Sn0P3hAKQwAVhXLR7gWiWI2?= =?us-ascii?Q?Hw=3D=3D?= X-OriginatorOrg: jaguarmicro.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20acea9a-dc61-4eed-7e11-08db5d8726b4 X-MS-Exchange-CrossTenant-AuthSource: TY0PR06MB5563.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2023 01:18:45.9405 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 1e45a5c2-d3e1-46b3-a0e6-c5ebf6d8ba7b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tZMItOQRDcGMtbUFWSzP25EnFzfG6H45MgA810xZnmbaikcAocWYUbqk8Ne+VVs1V3I7qfPCbkB1noNlfMkQZqYoEbkLm1XInlE6KG32JTw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI2PR06MB4347 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 SM3/SM4 test vectors for verification in test app. Signed-off-by: Sunyang Wu --- The test results of using openssl are as follows: + SM4 Chain : 24/24 passed, 0/24 skipped, 0/24 failed, 0/24 unsupported + SM4 Cipher Only : 10/10 passed, 0/10 skipped, 0/10 failed, 0/10 unsupported + Auth Only : 36/62 passed, 26/62 skipped, 0/62 failed, 0/62 unsupported --- app/test/test_cryptodev.c | 3 + app/test/test_cryptodev_blockcipher.c | 81 +++ app/test/test_cryptodev_blockcipher.h | 4 +- app/test/test_cryptodev_hash_test_vectors.h | 82 +++ app/test/test_cryptodev_sm4_test_vectors.h | 710 ++++++++++++++++++++ 5 files changed, 879 insertions(+), 1 deletion(-) create mode 100644 app/test/test_cryptodev_sm4_test_vectors.h diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 9c670e9a35..73238a447d 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -44,6 +44,7 @@ #include "test_cryptodev_aead_test_vectors.h" #include "test_cryptodev_hmac_test_vectors.h" #include "test_cryptodev_mixed_test_vectors.h" +#include "test_cryptodev_sm4_test_vectors.h" #ifdef RTE_LIB_SECURITY #include "test_cryptodev_security_ipsec.h" #include "test_cryptodev_security_ipsec_test_vectors.h" @@ -16928,6 +16929,8 @@ run_cryptodev_testsuite(const char *pmd_name) BLKCIPHER_3DES_CIPHERONLY_TYPE, BLKCIPHER_DES_CIPHERONLY_TYPE, BLKCIPHER_DES_DOCSIS_TYPE, + BLKCIPHER_SM4_CHAIN_TYPE, + BLKCIPHER_SM4_CIPHERONLY_TYPE, BLKCIPHER_AUTHONLY_TYPE}; struct unit_test_suite *static_suites[] = { &cryptodev_multi_session_testsuite, diff --git a/app/test/test_cryptodev_blockcipher.c b/app/test/test_cryptodev_blockcipher.c index 6c9a5964ea..341cf1a54b 100644 --- a/app/test/test_cryptodev_blockcipher.c +++ b/app/test/test_cryptodev_blockcipher.c @@ -18,6 +18,7 @@ #include "test_cryptodev_aes_test_vectors.h" #include "test_cryptodev_des_test_vectors.h" #include "test_cryptodev_hash_test_vectors.h" +#include "test_cryptodev_sm4_test_vectors.h" static int verify_algo_support(const struct blockcipher_test_case *t, @@ -1119,6 +1120,74 @@ authonly_setup(void) return 0; } +static int +sm4_chain_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_SM4_CTR, + RTE_CRYPTO_CIPHER_SM4_CBC, + RTE_CRYPTO_CIPHER_SM4_OFB, + RTE_CRYPTO_CIPHER_SM4_CFB + }; + const enum rte_crypto_auth_algorithm auths[] = { + RTE_CRYPTO_AUTH_SM3, + RTE_CRYPTO_AUTH_SM3_HMAC, + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + (global_api_test_type == CRYPTODEV_RAW_API_TEST && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { + RTE_LOG(INFO, USER1, "Feature flag for SM4 Chain testsuite not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0 && + check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) { + RTE_LOG(INFO, USER1, "Capability for SM4 Chain testsuite not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + +static int +sm4_cipheronly_setup(void) +{ + uint8_t dev_id = p_testsuite_params->valid_devs[0]; + struct rte_cryptodev_info dev_info; + uint64_t feat_flags; + const enum rte_crypto_cipher_algorithm ciphers[] = { + RTE_CRYPTO_CIPHER_SM4_CBC, + RTE_CRYPTO_CIPHER_SM4_ECB, + RTE_CRYPTO_CIPHER_SM4_CTR, + RTE_CRYPTO_CIPHER_SM4_OFB, + RTE_CRYPTO_CIPHER_SM4_CFB + }; + + rte_cryptodev_info_get(dev_id, &dev_info); + feat_flags = dev_info.feature_flags; + + if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) || + (global_api_test_type == CRYPTODEV_RAW_API_TEST && + !(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) { + RTE_LOG(INFO, USER1, "Feature flag for SM4 Cipheronly not met\n"); + return TEST_SKIPPED; + } + + if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) { + RTE_LOG(INFO, USER1, "Capability for SM4 Cipheronly not met\n"); + return TEST_SKIPPED; + } + + return 0; +} + struct unit_test_suite * build_blockcipher_test_suite(enum blockcipher_test_type test_type) { @@ -1172,6 +1241,18 @@ build_blockcipher_test_suite(enum blockcipher_test_type test_type) ts_name = "DES Docsis"; ts_setup = des_docsis_setup; break; + case BLKCIPHER_SM4_CHAIN_TYPE: + n_test_cases = RTE_DIM(sm4_chain_test_cases); + blk_tcs = sm4_chain_test_cases; + ts_name = "SM4 Chain"; + ts_setup = sm4_chain_setup; + break; + case BLKCIPHER_SM4_CIPHERONLY_TYPE: + n_test_cases = RTE_DIM(sm4_cipheronly_test_cases); + blk_tcs = sm4_cipheronly_test_cases; + ts_name = "SM4 Cipher Only"; + ts_setup = sm4_cipheronly_setup; + break; case BLKCIPHER_AUTHONLY_TYPE: n_test_cases = RTE_DIM(hash_test_cases); blk_tcs = hash_test_cases; diff --git a/app/test/test_cryptodev_blockcipher.h b/app/test/test_cryptodev_blockcipher.h index bad93a5ec1..e6f6c18067 100644 --- a/app/test/test_cryptodev_blockcipher.h +++ b/app/test/test_cryptodev_blockcipher.h @@ -49,7 +49,9 @@ enum blockcipher_test_type { BLKCIPHER_3DES_CIPHERONLY_TYPE, /* triple_des_cipheronly_test_cases[] */ BLKCIPHER_AUTHONLY_TYPE, /* use hash_test_cases[] */ BLKCIPHER_DES_CIPHERONLY_TYPE, /* use des_cipheronly_test_cases[] */ - BLKCIPHER_DES_DOCSIS_TYPE /* use des_docsis_test_cases[] */ + BLKCIPHER_DES_DOCSIS_TYPE, /* use des_docsis_test_cases[] */ + BLKCIPHER_SM4_CHAIN_TYPE, /* use sm4_chain_test_cases[] */ + BLKCIPHER_SM4_CIPHERONLY_TYPE /* use sm4_cipheronly_test_cases[] */ }; struct blockcipher_test_case { diff --git a/app/test/test_cryptodev_hash_test_vectors.h b/app/test/test_cryptodev_hash_test_vectors.h index fa9986a4da..65dd6bf81b 100644 --- a/app/test/test_cryptodev_hash_test_vectors.h +++ b/app/test/test_cryptodev_hash_test_vectors.h @@ -682,6 +682,56 @@ cmac_test_vector_12 = { } }; +static const struct blockcipher_test_data +sm3_test_vector = { + .auth_algo = RTE_CRYPTO_AUTH_SM3, + .ciphertext = { + .data = plaintext_hash, + .len = 512 + }, + .digest = { + .data = { + 0x9E, 0x86, 0xAB, 0x68, 0xD7, 0x8F, 0xD6, 0xFF, + 0x1C, 0x57, 0x12, 0x48, 0xC4, 0xA8, 0x26, 0xDE, + 0x9E, 0x53, 0xE9, 0xC4, 0xA6, 0xBB, 0xE7, 0x52, + 0x53, 0x9C, 0xDE, 0xC1, 0xD5, 0x7C, 0x43, 0xAB + }, + .len = 32 + } +}; + +static const struct blockcipher_test_data +hmac_sm3_test_vector = { + .auth_algo = RTE_CRYPTO_AUTH_SM3_HMAC, + .ciphertext = { + .data = plaintext_hash, + .len = 512 + }, + .auth_key = { + .data = { + 0x12, 0x70, 0x87, 0xd9, 0x76, 0x9e, 0xe0, 0xf0, + 0x14, 0xfb, 0xca, 0x5a, 0xb6, 0xcb, 0x8f, 0x9d, + 0x42, 0xd3, 0x1e, 0x09, 0x9a, 0x25, 0x9a, 0x3c, + 0x87, 0xee, 0x55, 0x63, 0x56, 0x33, 0x75, 0x69, + 0xa3, 0xfc, 0x42, 0x19, 0x9a, 0x22, 0x09, 0xae, + 0x1d, 0xd3, 0x09, 0xd3, 0x9e, 0x98, 0x71, 0xe1, + 0x6b, 0x8f, 0xea, 0x05, 0xb4, 0x85, 0x41, 0x3b, + 0x73, 0x97, 0x9e, 0xc9, 0xca, 0x13, 0x32, 0x6d + }, + .len = 64 + }, + .digest = { + .data = { + 0xBC, 0x71, 0xF5, 0x3B, 0x43, 0x28, 0x11, 0x7A, + 0x32, 0xD2, 0xC9, 0x2D, 0x3B, 0xFA, 0xE0, 0x47, + 0xA4, 0xD5, 0xEC, 0x81, 0xFB, 0x86, 0x6A, 0x11, + 0x64, 0xF3, 0xF5, 0x82, 0x3B, 0x8E, 0x0A, 0xBB + }, + .len = 32, + .truncated_len = 16 + } +}; + static const struct blockcipher_test_case hash_test_cases[] = { { .test_descr = "MD5 Digest", @@ -971,6 +1021,38 @@ static const struct blockcipher_test_case hash_test_cases[] = { .test_data = &aes_xcbc_mac_test_vector, .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY, }, + { + .test_descr = "SM3 Digest", + .test_data = &sm3_test_vector, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_GEN, + }, + { + .test_descr = "SM3 Digest Verify", + .test_data = &sm3_test_vector, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY, + }, + { + .test_descr = "HMAC-SM3 Digest", + .test_data = &hmac_sm3_test_vector, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_GEN, + }, + { + .test_descr = "HMAC-SM3 Digest Scatter Gather", + .test_data = &hmac_sm3_test_vector, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG, + }, + { + .test_descr = "HMAC-SM3 Digest Verify", + .test_data = &hmac_sm3_test_vector, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY, + }, + { + .test_descr = "HMAC-SM3 Digest Verify Scatter Gather", + .test_data = &hmac_sm3_test_vector, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG, + }, }; diff --git a/app/test/test_cryptodev_sm4_test_vectors.h b/app/test/test_cryptodev_sm4_test_vectors.h new file mode 100644 index 0000000000..582b333296 --- /dev/null +++ b/app/test/test_cryptodev_sm4_test_vectors.h @@ -0,0 +1,710 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2016-2019 Intel Corporation + */ + +#ifndef TEST_CRYPTODEV_SM4_TEST_VECTORS_H_ +#define TEST_CRYPTODEV_SM4_TEST_VECTORS_H_ + +static const uint8_t plaintext_sm4[] = { + 0x81, 0x70, 0x99, 0x44, 0xE0, 0xCB, 0x2E, 0x1D, + 0xB5, 0xB0, 0xA4, 0x77, 0xD1, 0xA8, 0x53, 0x9B, + 0x0A, 0x87, 0x86, 0xE3, 0x4E, 0xAA, 0xED, 0x99, + 0x30, 0x3E, 0xA6, 0x97, 0x55, 0x95, 0xB2, 0x45, + 0x4D, 0x5D, 0x7F, 0x91, 0xEB, 0xBD, 0x4A, 0xCD, + 0x72, 0x6C, 0x0E, 0x0E, 0x5E, 0x3E, 0xB5, 0x5E, + 0xF6, 0xB1, 0x5A, 0x13, 0x8E, 0x22, 0x6E, 0xCD, + 0x1B, 0x23, 0x5A, 0xB5, 0xBB, 0x52, 0x51, 0xC1, + 0x33, 0x76, 0xB2, 0x64, 0x48, 0xA9, 0xAC, 0x1D, + 0xE8, 0xBD, 0x52, 0x64, 0x8C, 0x0B, 0x5F, 0xFA, + 0x94, 0x44, 0x86, 0x82, 0xE3, 0xCB, 0x4D, 0xE9, + 0xCB, 0x8A, 0xE7, 0xF4, 0xBD, 0x41, 0x0E, 0xD5, + 0x02, 0xB1, 0x25, 0x3A, 0xD0, 0x8B, 0xB2, 0x79, + 0x69, 0xB5, 0xF0, 0x2B, 0x10, 0x02, 0x9D, 0x67, + 0xD0, 0x7E, 0x18, 0x64, 0xD9, 0x4D, 0x4F, 0xCA, + 0x20, 0x81, 0x51, 0xE2, 0x6F, 0x5F, 0xEE, 0x26 +}; + +static const uint8_t ciphertext_sm4_ecb[] = { + 0xCC, 0x62, 0x37, 0xA6, 0xA1, 0x35, 0x39, 0x75, + 0xFF, 0xF5, 0xEE, 0x6A, 0xFD, 0xD7, 0x70, 0x15, + 0xE1, 0x32, 0x23, 0x1F, 0x18, 0xB8, 0xC9, 0x16, + 0x07, 0x27, 0x9C, 0x6C, 0x7F, 0x8F, 0x7F, 0xF6, + 0xFD, 0xF1, 0xE4, 0x01, 0xEC, 0x7E, 0xD2, 0x60, + 0xFD, 0xE7, 0x5C, 0xE5, 0xCF, 0x6E, 0xE7, 0x87, + 0x97, 0x13, 0xCC, 0x01, 0x92, 0x1A, 0xC5, 0x62, + 0xB5, 0x0C, 0x45, 0xE4, 0xDC, 0x9A, 0x30, 0xC2, + 0x35, 0xED, 0x7D, 0x1A, 0x93, 0x0D, 0x33, 0x96, + 0xD6, 0xE1, 0x8B, 0x77, 0x64, 0x40, 0x25, 0x3D, + 0x9F, 0x4B, 0x8E, 0xFF, 0x3F, 0x11, 0x41, 0x58, + 0x3B, 0x55, 0x4F, 0x59, 0x38, 0x2E, 0xAA, 0xBB, + 0x8B, 0x42, 0xFA, 0x30, 0x38, 0x0D, 0x05, 0x3B, + 0x86, 0x7C, 0xB0, 0xF2, 0x77, 0xCE, 0xEE, 0x1B, + 0x78, 0xE8, 0x64, 0x7D, 0x59, 0xE3, 0xDA, 0x61, + 0x05, 0x27, 0x56, 0x12, 0x95, 0x6D, 0x34, 0x9C +}; + +static const uint8_t ciphertext_sm4_cbc[] = { + 0x60, 0x7A, 0xBE, 0xC9, 0xDA, 0xD7, 0x90, 0x73, + 0xC7, 0x96, 0xDB, 0x34, 0x26, 0xFD, 0x2C, 0x2F, + 0x8E, 0x39, 0xC7, 0x0B, 0x60, 0xB2, 0x3D, 0xBE, + 0xF3, 0xA9, 0xA5, 0x46, 0x65, 0x26, 0x41, 0xB7, + 0xAE, 0xC9, 0xC3, 0xAD, 0x8C, 0x9B, 0x95, 0x8D, + 0x17, 0x53, 0x15, 0x35, 0x40, 0x2A, 0x8C, 0x6B, + 0x02, 0x5C, 0xBD, 0x13, 0xA6, 0x7E, 0xB7, 0x63, + 0xC0, 0x3F, 0xA8, 0xBC, 0x73, 0xDD, 0x0B, 0x7A, + 0x88, 0x0E, 0xF8, 0xC5, 0x5B, 0x00, 0x07, 0xFF, + 0x53, 0x7B, 0xF1, 0x6A, 0xA0, 0xFD, 0x0B, 0x89, + 0x03, 0x91, 0x4D, 0xD8, 0xC4, 0xB3, 0xC0, 0x12, + 0x41, 0xEB, 0xF7, 0xCB, 0x0A, 0xFB, 0x68, 0xE7, + 0x8E, 0x0C, 0x14, 0x33, 0x1A, 0x34, 0x55, 0xDA, + 0x04, 0xE2, 0xA3, 0xFC, 0xBE, 0xB6, 0xDF, 0x2B, + 0x61, 0x33, 0x05, 0xBD, 0xBC, 0x0A, 0xB5, 0x8B, + 0x6D, 0x0F, 0x1B, 0x7D, 0x5F, 0x24, 0x46, 0x0E +}; + +static const uint8_t ciphertext_sm4_cfb[] = { + 0xC1, 0x27, 0x47, 0xC7, 0x44, 0x0C, 0x9A, 0x5C, + 0x7D, 0x51, 0x26, 0x0D, 0x1B, 0xDB, 0x0D, 0x9D, + 0x52, 0x59, 0xAD, 0x56, 0x05, 0xBE, 0x92, 0xD2, + 0xB7, 0x62, 0xF5, 0xD7, 0x53, 0xD3, 0x12, 0x2A, + 0x3C, 0x9A, 0x6E, 0x75, 0x80, 0xAB, 0x18, 0xE5, + 0x72, 0x49, 0x9A, 0xD9, 0x80, 0x99, 0xC2, 0xE7, + 0xCA, 0xD9, 0xDC, 0xD1, 0x45, 0x2F, 0xDD, 0xFC, + 0x01, 0x7F, 0xB8, 0x01, 0x51, 0xCF, 0x43, 0x74, + 0xC0, 0xBA, 0xFE, 0xB0, 0x28, 0xFE, 0xA4, 0xCD, + 0x35, 0x0E, 0xEC, 0xE5, 0x70, 0xA2, 0x7F, 0x5D, + 0x38, 0x1B, 0x50, 0xEB, 0x46, 0xBE, 0x61, 0x6E, + 0x6C, 0x76, 0xF3, 0x65, 0x75, 0xCD, 0xA1, 0xBB, + 0x9F, 0xFA, 0x7B, 0x86, 0x12, 0x87, 0x04, 0xEB, + 0x00, 0x24, 0x81, 0xE7, 0x91, 0xFC, 0x1B, 0xC7, + 0xA6, 0xB2, 0x67, 0xE2, 0x6E, 0x88, 0x8F, 0xB6, + 0x4C, 0x45, 0x96, 0xEF, 0xBF, 0x4C, 0x26, 0x69 +}; + +static const uint8_t ciphertext_sm4_ofb[] = { + 0xC1, 0x27, 0x47, 0xC7, 0x44, 0x0C, 0x9A, 0x5C, + 0x7D, 0x51, 0x26, 0x0D, 0x1B, 0xDB, 0x0D, 0x9D, + 0x0F, 0x0C, 0xAD, 0xA0, 0x2D, 0x18, 0x0B, 0x3C, + 0x54, 0xA9, 0x87, 0x86, 0xBC, 0x6B, 0xF9, 0xFB, + 0x18, 0x68, 0x51, 0x1E, 0xB2, 0x53, 0x1D, 0xD5, + 0x7F, 0x4B, 0xED, 0xB8, 0xCA, 0x8E, 0x81, 0xCE, + 0xE1, 0x16, 0x7F, 0x84, 0x69, 0xD1, 0x15, 0xCE, + 0x84, 0xF0, 0xB0, 0x3A, 0x21, 0xF2, 0x85, 0xA2, + 0xEB, 0x2F, 0xDF, 0x34, 0x52, 0x62, 0x42, 0x87, + 0xFA, 0x7F, 0x02, 0x2A, 0xC2, 0xD9, 0xE4, 0xB0, + 0x8D, 0xC5, 0x52, 0xEC, 0x3D, 0x96, 0x3F, 0xD3, + 0x8C, 0x39, 0x9C, 0x0F, 0xD9, 0x66, 0xDD, 0x29, + 0x90, 0x00, 0x5D, 0x4F, 0x4D, 0x82, 0x2A, 0x47, + 0x9E, 0x7E, 0x46, 0x87, 0x84, 0xE8, 0xDD, 0xAE, + 0xB3, 0x03, 0xF8, 0xE8, 0x7B, 0xA6, 0xC9, 0x9A, + 0x56, 0x9C, 0xC7, 0x82, 0x1E, 0x9A, 0x9D, 0x13 +}; + +static const uint8_t ciphertext_sm4_ctr[] = { + 0xC1, 0x27, 0x47, 0xC7, 0x44, 0x0C, 0x9A, 0x5C, + 0x7D, 0x51, 0x26, 0x0D, 0x1B, 0xDB, 0x0D, 0x9D, + 0xC3, 0x75, 0xCE, 0xBB, 0x63, 0x9A, 0x5B, 0x0C, + 0xED, 0x64, 0x3F, 0x33, 0x80, 0x8F, 0x97, 0x40, + 0xB7, 0x5C, 0xA7, 0xFE, 0x2F, 0x7F, 0xFB, 0x20, + 0x13, 0xEC, 0xDC, 0xBC, 0x96, 0xC8, 0x05, 0xF0, + 0xA4, 0x95, 0xC4, 0x0A, 0xB7, 0x1B, 0x18, 0xB4, + 0xDA, 0x35, 0xFF, 0xA5, 0xB5, 0x90, 0x1B, 0x07, + 0x5C, 0x5B, 0x91, 0x36, 0xF0, 0xC9, 0xFE, 0xFB, + 0xC4, 0x71, 0xD6, 0x3B, 0x03, 0x28, 0x62, 0xB9, + 0x22, 0x7A, 0x97, 0xC9, 0x54, 0xC0, 0x8C, 0x71, + 0xEC, 0x8F, 0xE1, 0xBB, 0x56, 0xAE, 0xAB, 0x16, + 0xF6, 0x57, 0x76, 0x65, 0xC2, 0x4B, 0xE0, 0x46, + 0x4E, 0x13, 0x77, 0x50, 0x91, 0x24, 0x76, 0xD9, + 0xB7, 0x16, 0xFF, 0x9E, 0xD0, 0x2E, 0x14, 0x23, + 0x27, 0xF4, 0x99, 0x03, 0xDA, 0x1C, 0x52, 0x04 +}; + +static const struct blockcipher_test_data +sm4_test_data_cbc = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_CBC, + .cipher_key = { + .data = { + 0xE0, 0x70, 0x99, 0xF1, 0xBF, 0xAF, 0xFD, 0x7F, + 0x24, 0x0C, 0xD7, 0x90, 0xCA, 0x4F, 0xE1, 0x34 + }, + .len = 16 + }, + .iv = { + .data = { + 0xC7, 0x2B, 0x65, 0x91, 0xA0, 0xD7, 0xDE, 0x8F, + 0x6B, 0x40, 0x72, 0x33, 0xAD, 0x35, 0x81, 0xD6 + }, + .len = 16 + }, + .plaintext = { + .data = plaintext_sm4, + .len = 128 + }, + .ciphertext = { + .data = ciphertext_sm4_cbc, + .len = 128 + }, +}; + +static const struct blockcipher_test_data +sm4_test_data_ctr = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_CTR, + .cipher_key = { + .data = { + 0xE0, 0x70, 0x99, 0xF1, 0xBF, 0xAF, 0xFD, 0x7F, + 0x24, 0x0C, 0xD7, 0x90, 0xCA, 0x4F, 0xE1, 0x34 + }, + .len = 16 + }, + .iv = { + .data = { + 0xC7, 0x2B, 0x65, 0x91, 0xA0, 0xD7, 0xDE, 0x8F, + 0x6B, 0x40, 0x72, 0x33, 0xAD, 0x35, 0x81, 0xD6 + }, + .len = 16 + }, + .plaintext = { + .data = plaintext_sm4, + .len = 128 + }, + .ciphertext = { + .data = ciphertext_sm4_ctr, + .len = 128 + }, +}; + +static const struct blockcipher_test_data +sm4_test_data_ecb = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_ECB, + .cipher_key = { + .data = { + 0xE0, 0x70, 0x99, 0xF1, 0xBF, 0xAF, 0xFD, 0x7F, + 0x24, 0x0C, 0xD7, 0x90, 0xCA, 0x4F, 0xE1, 0x34 + }, + .len = 16 + }, + .plaintext = { + .data = plaintext_sm4, + .len = 128 + }, + .ciphertext = { + .data = ciphertext_sm4_ecb, + .len = 128 + }, +}; + +static const struct blockcipher_test_data +sm4_test_data_ofb = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_OFB, + .cipher_key = { + .data = { + 0xE0, 0x70, 0x99, 0xF1, 0xBF, 0xAF, 0xFD, 0x7F, + 0x24, 0x0C, 0xD7, 0x90, 0xCA, 0x4F, 0xE1, 0x34 + }, + .len = 16 + }, + .iv = { + .data = { + 0xC7, 0x2B, 0x65, 0x91, 0xA0, 0xD7, 0xDE, 0x8F, + 0x6B, 0x40, 0x72, 0x33, 0xAD, 0x35, 0x81, 0xD6 + }, + .len = 16 + }, + .plaintext = { + .data = plaintext_sm4, + .len = 128 + }, + .ciphertext = { + .data = ciphertext_sm4_ofb, + .len = 128 + }, +}; + +static const struct blockcipher_test_data +sm4_test_data_cfb = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_CFB, + .cipher_key = { + .data = { + 0xE0, 0x70, 0x99, 0xF1, 0xBF, 0xAF, 0xFD, 0x7F, + 0x24, 0x0C, 0xD7, 0x90, 0xCA, 0x4F, 0xE1, 0x34 + }, + .len = 16 + }, + .iv = { + .data = { + 0xC7, 0x2B, 0x65, 0x91, 0xA0, 0xD7, 0xDE, 0x8F, + 0x6B, 0x40, 0x72, 0x33, 0xAD, 0x35, 0x81, 0xD6 + }, + .len = 16 + }, + .plaintext = { + .data = plaintext_sm4, + .len = 128 + }, + .ciphertext = { + .data = ciphertext_sm4_cfb, + .len = 128 + }, +}; + +static const struct blockcipher_test_case sm4_cipheronly_test_cases[] = { + { + .test_descr = "SM4-CBC Encryption", + .test_data = &sm4_test_data_cbc, + .op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT, + }, + { + .test_descr = "SM4-CBC Decryption", + .test_data = &sm4_test_data_cbc, + .op_mask = BLOCKCIPHER_TEST_OP_DECRYPT, + }, + { + .test_descr = "SM4-CTR Encryption", + .test_data = &sm4_test_data_ctr, + .op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT, + }, + { + .test_descr = "SM4-CTR Decryption", + .test_data = &sm4_test_data_ctr, + .op_mask = BLOCKCIPHER_TEST_OP_DECRYPT, + }, + { + .test_descr = "SM4-ECB Encryption", + .test_data = &sm4_test_data_ecb, + .op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT, + }, + { + .test_descr = "SM4-ECB Decryption", + .test_data = &sm4_test_data_ecb, + .op_mask = BLOCKCIPHER_TEST_OP_DECRYPT, + }, + { + .test_descr = "SM4-OFB Encryption", + .test_data = &sm4_test_data_ofb, + .op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT, + }, + { + .test_descr = "SM4-OFB Decryption", + .test_data = &sm4_test_data_ofb, + .op_mask = BLOCKCIPHER_TEST_OP_DECRYPT, + }, + { + .test_descr = "SM4-CFB Encryption", + .test_data = &sm4_test_data_cfb, + .op_mask = BLOCKCIPHER_TEST_OP_ENCRYPT, + }, + { + .test_descr = "SM4-CFB Decryption", + .test_data = &sm4_test_data_cfb, + .op_mask = BLOCKCIPHER_TEST_OP_DECRYPT, + }, +}; + +static const uint8_t plaintext_sm4_common[] = { + "What a lousy earth! He wondered how many people were destitute that" +}; + +static const uint8_t ciphertext64_sm4_cbc[] = { + 0x5D, 0x93, 0x4E, 0x50, 0xDC, 0x26, 0x03, 0xB5, + 0x6C, 0xFC, 0xB7, 0x09, 0x11, 0x28, 0x2F, 0xF7, + 0x6C, 0xB6, 0xE6, 0xCC, 0xB8, 0xC5, 0x01, 0x5F, + 0xBE, 0x89, 0xF8, 0xD3, 0xE8, 0xCD, 0x51, 0xC6, + 0x17, 0x31, 0x07, 0xDE, 0xA5, 0x8F, 0xFD, 0x79, + 0x2A, 0xAC, 0xAC, 0x90, 0x47, 0x8D, 0x0F, 0x16, + 0x66, 0xCF, 0x16, 0xF1, 0xE2, 0x4C, 0x79, 0x4A, + 0x6B, 0x5D, 0x6C, 0xAB, 0x98, 0x2B, 0xDB, 0xF8 +}; + +/* test vectors */ +static const uint8_t plaintext64_sm4_ctr[] = { + 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, + 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, + 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, + 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, + 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, + 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, + 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, + 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 +}; + +static const uint8_t ciphertext64_sm4_ctr[] = { + 0x14, 0xAE, 0x4A, 0x72, 0xB9, 0x7A, 0x93, 0xCE, + 0x12, 0x16, 0xCC, 0xD9, 0x98, 0xE3, 0x71, 0xC1, + 0x60, 0xF7, 0xEF, 0x8B, 0x63, 0x44, 0xBD, 0x6D, + 0xA1, 0x99, 0x25, 0x05, 0xE5, 0xFC, 0x21, 0x9B, + 0x0B, 0xF0, 0x57, 0xF8, 0x6C, 0x5D, 0x75, 0x10, + 0x3C, 0x0F, 0x46, 0x51, 0x9C, 0x7F, 0xB2, 0xE7, + 0x29, 0x28, 0x05, 0x03, 0x5A, 0xDB, 0x9A, 0x90, + 0xEC, 0xEF, 0x14, 0x53, 0x59, 0xD7, 0xCF, 0x0E +}; + +static const struct blockcipher_test_data sm4_test_data_1 = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_CTR, + .cipher_key = { + .data = { + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, + 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C + }, + .len = 16 + }, + .iv = { + .data = { + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF + }, + .len = 16 + }, + .plaintext = { + .data = plaintext64_sm4_ctr, + .len = 64 + }, + .ciphertext = { + .data = ciphertext64_sm4_ctr, + .len = 64 + }, + .auth_algo = RTE_CRYPTO_AUTH_SM3_HMAC, + .auth_key = { + .data = { + 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, + 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, + 0xDE, 0xF4, 0xDE, 0xAD + }, + .len = 20 + }, + .digest = { + .data = { + 0x3A, 0x90, 0x8E, 0x9E, 0x07, 0x48, 0xBE, 0xFE, + 0x29, 0xB9, 0x61, 0xD8, 0x1A, 0x01, 0x5E, 0x34, + 0x98, 0x1A, 0x35, 0xE5, 0x26, 0x1A, 0x28, 0x1E, + 0xB1, 0xDC, 0xDB, 0xEB, 0xC7, 0x16, 0xF9, 0x9E + }, + .len = 32, + .truncated_len = 16 + } +}; + +/* test vectors */ +static const uint8_t plaintext64_sm4_cfb[] = { + 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, + 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, + 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, + 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, + 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, + 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, + 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, + 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 +}; + +static const uint8_t ciphertext64_sm4_cfb[] = { + 0x14, 0xAE, 0x4A, 0x72, 0xB9, 0x7A, 0x93, 0xCE, + 0x12, 0x16, 0xCC, 0xD9, 0x98, 0xE3, 0x71, 0xC1, + 0xAA, 0x8A, 0x2C, 0x8C, 0x61, 0x89, 0x6B, 0x8B, + 0x7C, 0xF8, 0x32, 0x6A, 0xEB, 0xAC, 0xD4, 0x0C, + 0xD1, 0x5D, 0xFA, 0x1D, 0xFD, 0x17, 0x67, 0x02, + 0x06, 0xCD, 0x38, 0x2C, 0x4D, 0x04, 0xF3, 0x96, + 0x2F, 0x85, 0x5C, 0x3F, 0xBB, 0x79, 0x56, 0xA9, + 0xC4, 0x6F, 0x34, 0xB3, 0xBE, 0xEC, 0xCA, 0x40 +}; + +static const struct blockcipher_test_data sm4_test_data_2 = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_CFB, + .cipher_key = { + .data = { + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, + 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C + }, + .len = 16 + }, + .iv = { + .data = { + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF + }, + .len = 16 + }, + .plaintext = { + .data = plaintext64_sm4_cfb, + .len = 64 + }, + .ciphertext = { + .data = ciphertext64_sm4_cfb, + .len = 64 + }, + .auth_algo = RTE_CRYPTO_AUTH_SM3_HMAC, + .auth_key = { + .data = { + 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, + 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, + 0xDE, 0xF4, 0xDE, 0xAD + }, + .len = 20 + }, + .digest = { + .data = { + 0x6F, 0x7C, 0xFA, 0x6D, 0x02, 0x5D, 0xE2, 0x4B, + 0x4A, 0xEE, 0xC6, 0x67, 0x0B, 0xD3, 0xCF, 0xBD, + 0x64, 0x8F, 0x01, 0x17, 0x19, 0xD6, 0xFB, 0xEC, + 0x3A, 0x27, 0xE8, 0x0F, 0x51, 0xA3, 0xE2, 0x3F + }, + .len = 32, + .truncated_len = 16 + } +}; + +/* test vectors */ +static const uint8_t plaintext64_sm4_ofb[] = { + 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96, + 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A, + 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C, + 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51, + 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11, + 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF, + 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17, + 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10 +}; + +static const uint8_t ciphertext64_sm4_ofb[] = { + 0x14, 0xAE, 0x4A, 0x72, 0xB9, 0x7A, 0x93, 0xCE, + 0x12, 0x16, 0xCC, 0xD9, 0x98, 0xE3, 0x71, 0xC1, + 0x94, 0x54, 0x3E, 0x9A, 0x3A, 0x0A, 0x22, 0x63, + 0x22, 0xE8, 0xA5, 0xF3, 0x82, 0xB9, 0x14, 0x2D, + 0xEF, 0x5F, 0x94, 0xCB, 0x49, 0x17, 0xEF, 0xA4, + 0xD9, 0xCF, 0x3F, 0xC3, 0x32, 0x30, 0x90, 0x11, + 0x12, 0x61, 0x52, 0xCC, 0xEC, 0x43, 0x61, 0xF2, + 0x6F, 0x1E, 0x1A, 0x8D, 0xB4, 0x9D, 0x2F, 0xC4 +}; + +static const struct blockcipher_test_data sm4_test_data_3 = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_OFB, + .cipher_key = { + .data = { + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, + 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C + }, + .len = 16 + }, + .iv = { + .data = { + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF + }, + .len = 16 + }, + .plaintext = { + .data = plaintext64_sm4_ofb, + .len = 64 + }, + .ciphertext = { + .data = ciphertext64_sm4_ofb, + .len = 64 + }, + .auth_algo = RTE_CRYPTO_AUTH_SM3_HMAC, + .auth_key = { + .data = { + 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, + 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, + 0xDE, 0xF4, 0xDE, 0xAD + }, + .len = 20 + }, + .digest = { + .data = { + 0xA7, 0x6F, 0x7D, 0xB5, 0xFB, 0x35, 0x92, 0x82, + 0x97, 0xB7, 0x9B, 0xBF, 0xA9, 0xCE, 0xA8, 0x4C, + 0x5A, 0xC5, 0x53, 0x62, 0x9F, 0x03, 0x54, 0x88, + 0x7D, 0xFE, 0x2D, 0xD3, 0x9C, 0xFB, 0x56, 0xED + }, + .len = 32, + .truncated_len = 16 + } +}; + +static const struct blockcipher_test_data sm4_test_data_4 = { + .crypto_algo = RTE_CRYPTO_CIPHER_SM4_CBC, + .cipher_key = { + .data = { + 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2, + 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A + }, + .len = 16 + }, + .iv = { + .data = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F + }, + .len = 16 + }, + .plaintext = { + .data = plaintext_sm4_common, + .len = 64 + }, + .ciphertext = { + .data = ciphertext64_sm4_cbc, + .len = 64 + }, + .auth_algo = RTE_CRYPTO_AUTH_SM3_HMAC, + .auth_key = { + .data = { + 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA, + 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD, + 0xDE, 0xF4, 0xDE, 0xAD + }, + .len = 20 + }, + .digest = { + .data = { + 0xA7, 0x87, 0x94, 0x53, 0x17, 0xAE, 0xF9, 0xCD, + 0x8A, 0x60, 0x34, 0xFB, 0x9F, 0x07, 0xED, 0x28, + 0x04, 0x13, 0x8C, 0xD4, 0x48, 0x83, 0x4A, 0xBA, + 0xB8, 0xE8, 0x45, 0xDB, 0xE0, 0x66, 0xF9, 0xDA + }, + .len = 32, + .truncated_len = 16 + } +}; + +static const struct blockcipher_test_case sm4_chain_test_cases[] = { + { + .test_descr = "SM4-CBC HMAC-SM3 Encryption Digest", + .test_data = &sm4_test_data_4, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + }, + { + .test_descr = "SM4-CBC HMAC-SM3 Decryption Digest Verify", + .test_data = &sm4_test_data_4, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + }, + { + .test_descr = "SM4-CBC HMAC-SM3 Encryption Digest Scatter Gather", + .test_data = &sm4_test_data_4, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG | + BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-CBC HMAC-SM3 Decryption Digest Verify Scatter Gather", + .test_data = &sm4_test_data_4, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG, + }, + { + .test_descr = "SM4-CBC HMAC-SM3 Encryption Digest OOP", + .test_data = &sm4_test_data_4, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-CBC HMAC-SM3 Decryption Digest Verify OOP", + .test_data = &sm4_test_data_4, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-CTR HMAC-SM3 Encryption Digest", + .test_data = &sm4_test_data_1, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + }, + { + .test_descr = "SM4-CTR HMAC-SM3 Decryption Digest Verify", + .test_data = &sm4_test_data_1, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + }, + { + .test_descr = "SM4-CTR HMAC-SM3 Encryption Digest Scatter Gather", + .test_data = &sm4_test_data_1, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG | + BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-CTR HMAC-SM3 Decryption Digest Verify Scatter Gather", + .test_data = &sm4_test_data_1, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG, + }, + { + .test_descr = "SM4-CTR HMAC-SM3 Encryption Digest OOP", + .test_data = &sm4_test_data_1, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-CTR HMAC-SM3 Decryption Digest Verify OOP", + .test_data = &sm4_test_data_1, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-CFB HMAC-SM3 Encryption Digest", + .test_data = &sm4_test_data_2, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + }, + { + .test_descr = "SM4-CFB HMAC-SM3 Decryption Digest Verify", + .test_data = &sm4_test_data_2, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + }, + { + .test_descr = "SM4-CFB HMAC-SM3 Encryption Digest Scatter Gather", + .test_data = &sm4_test_data_2, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG | + BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-CFB HMAC-SM3 Decryption Digest Verify Scatter Gather", + .test_data = &sm4_test_data_2, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG, + }, + { + .test_descr = "SM4-CFB HMAC-SM3 Encryption Digest OOP", + .test_data = &sm4_test_data_2, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-CFB HMAC-SM3 Decryption Digest Verify OOP", + .test_data = &sm4_test_data_2, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-OFB HMAC-SM3 Encryption Digest", + .test_data = &sm4_test_data_3, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + }, + { + .test_descr = "SM4-OFB HMAC-SM3 Decryption Digest Verify", + .test_data = &sm4_test_data_3, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + }, + { + .test_descr = "SM4-OFB HMAC-SM3 Encryption Digest Scatter Gather", + .test_data = &sm4_test_data_3, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG | + BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-OFB HMAC-SM3 Decryption Digest Verify Scatter Gather", + .test_data = &sm4_test_data_3, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_SG, + }, + { + .test_descr = "SM4-OFB HMAC-SM3 Encryption Digest OOP", + .test_data = &sm4_test_data_3, + .op_mask = BLOCKCIPHER_TEST_OP_ENC_AUTH_GEN, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_OOP, + }, + { + .test_descr = "SM4-OFB HMAC-SM3 Decryption Digest Verify OOP", + .test_data = &sm4_test_data_3, + .op_mask = BLOCKCIPHER_TEST_OP_AUTH_VERIFY_DEC, + .feature_mask = BLOCKCIPHER_TEST_FEATURE_OOP, + }, +}; + +#endif -- 2.19.0.rc0.windows.1