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 7E74042B9A; Thu, 25 May 2023 12:08:46 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3D327427EE; Thu, 25 May 2023 12:08:41 +0200 (CEST) Received: from APC01-TYZ-obe.outbound.protection.outlook.com (mail-tyzapc01on2050.outbound.protection.outlook.com [40.107.117.50]) by mails.dpdk.org (Postfix) with ESMTP id 52C30427EE for ; Thu, 25 May 2023 12:08:39 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FNev3J2F7CSpg9flydpIfk6mNYQtshljHLC7nIpWj+nWsoJRUYyinIrpLvvZofU3pY6xqPP1qL352mre9lR8/rIVmb6u2xLadrjpQsjsdEBhWP9ExXdBnO4ItvBeDxEAIIcIO+pRvaxMHD22BPDzcxslps0D3V8oWO+QudMx0ucWTDr4+ACp8zthX/dXkQtanwn19lG/fEbkPIN7HWDxIGWn1BUHYo5IW4h+/dwlOXw//BgB/LaaTMkFzQDczZEEM5h8PHfnLhk0o0h1xHK/5jY5/Zwv5vOmQzkvk7+mIOXRVx3cNqVeBHp/sGZ8s2ohQNfXjXlZR7mi03jQVPdchQ== 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=Qv+N7m/W832ke+fY0q7Q1f1DnWhU9lSe3EANGPFN0vNxkoWg8dv7LXNnHDJX4W4lCGURh3MSfiC4s83bMqbFn0bN1nxN8fFVgyvkvc6o8qNFp1AesuAari/cXf6Oz6evt+Etk4lh7Hsxb/8irfulvUxU6F4razTrtAIo3so9A2JmpaonYFXRs1djbmv47tix3NTKXOvqCWoOI5pzJdaIGcyjuczQuRlKcZQ31Zi/m+QlN/Xu8aDmKXaYszN2CDYW1z20QS/sVwHSnmUD/vEeiOz/dZ2hYI+Udlucltc0o1oZro/7U7zPXQhPXfip48OycucfBhN/frsAfgKQkUZFig== 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=FnfjAipCBW6fBZ//5lxThaENXAezxmM6fOP8Y03NwU5Bzd3ixWSMcwNZGr7M0rfePALknOK2sUWTMgIJuor95c6CMTQzsARfUGNwuEOHpItZdYEbS4E3LUsaAbWLfi2f/3vk8SvbKmDtiVSwgh5ETrBLPbyxDT2OqCaLFbMiBBoqubHhmRcZtVZ5dm8hTiHRKFJkrJIsSUNCZ1IIOBuZz5Ckqp9nu+YJUSlGSsHzMrWFZNAY1AmYm8O/OZNoJ9nwYZFfPXOMFpiH+moqbN9LrsjRteLjamL63FgMxdIVuzn7RAI++kGLP16mYgsMicmqQ/AfZRhgV+O4r75MPWp5/A== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=jaguarmicro.com; Received: from KL1PR0601MB5567.apcprd06.prod.outlook.com (2603:1096:820:c5::14) by TYZPR06MB5025.apcprd06.prod.outlook.com (2603:1096:400:1cb::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.15; Thu, 25 May 2023 10:08:36 +0000 Received: from KL1PR0601MB5567.apcprd06.prod.outlook.com ([fe80::fc7c:ec5e:aa02:44e9]) by KL1PR0601MB5567.apcprd06.prod.outlook.com ([fe80::fc7c:ec5e:aa02:44e9%7]) with mapi id 15.20.6411.029; Thu, 25 May 2023 10:08:36 +0000 From: Sunyang Wu To: dev@dpdk.org Cc: kai.ji@intel.com, gakhil@marvell.com Subject: [PATCH v2 2/2] test/crypto: Add SM3/SM4 test vectors for verification in test app Date: Thu, 25 May 2023 18:08:06 +0800 Message-Id: <20230525100806.36992-2-sunyang.wu@jaguarmicro.com> X-Mailer: git-send-email 2.19.0.rc0.windows.1 In-Reply-To: <20230525100806.36992-1-sunyang.wu@jaguarmicro.com> References: <20230525100806.36992-1-sunyang.wu@jaguarmicro.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: TY2PR02CA0032.apcprd02.prod.outlook.com (2603:1096:404:a6::20) To KL1PR0601MB5567.apcprd06.prod.outlook.com (2603:1096:820:c5::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: KL1PR0601MB5567:EE_|TYZPR06MB5025:EE_ X-MS-Office365-Filtering-Correlation-Id: ebc8fefe-0cab-46da-33c6-08db5d0800d4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RZsPsE/k4KWb10CANu53kngmvrEMF7HPMR64CJ1dNihEbAJaXIzbxg2EWIbkxgN/yHu1bE1bXgm3veE/q2TanS6Xz7aSkBEGceILKM/V5R9DM1J+XWxtHOKGf+h9I9g090mA7IHoEpjU/7FFtHrLd2iwLT1CjFB72jgVe6Cfpc77bJS+wru4RRmHKLRflQCfq/HCiF7wRQitGKGHnkbNOq0KNTpUN/dPNPVTMsnNMClt5nE8IwJn9r3slhyJPNcnRvr9GfOlcqYvQ7XGIBET+D2zLvgjD2O5q9+Bpe+MIxxDKNAXXg5YwUkg0PbXAwQTbzSMP7vXlrE/LR+08zgwEuN5haeLtam++lF0wTbLqPtUwVGeMZRIRIKoXyUdN7NfrKxEE8+tzU3VvMW+u1l1FME7O8xa9eu/dlhnZlAYaXb7uWficY8zLe57Bq8+9aG/P85Jw6OkPIUXl7p9m40tPQAwnCzMHRNzmzYiDfdpBSLZgYYIPbkqXFeqk3zqsO1TVGynNMaoLf6cRAvoVQftQ83qDokPdAy86Up2cuHTqksJDcKa7WWXqI4TTde0R3puOcwLKhAhD5UbeQS4gM0ID+Ujb7tjDrC4ZQ8YYvUP9vHd+9Z46tXN9XnxUa0SrKf2 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:KL1PR0601MB5567.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(39830400003)(366004)(376002)(136003)(346002)(396003)(451199021)(86362001)(44832011)(8676002)(8936002)(66556008)(66476007)(66946007)(30864003)(6916009)(2906002)(4326008)(316002)(478600001)(15650500001)(5660300002)(41300700001)(38350700002)(38100700002)(6486002)(6666004)(52116002)(2616005)(26005)(1076003)(6512007)(6506007)(186003)(36756003)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?mkdVXNVCdIRmRyYfYEcrTbq59nsCrk3qMvEGYqjVmA6+E8AgAtZEEGjyGYN4?= =?us-ascii?Q?DRZDJJxHgZhKrX04kQxYZ7R51jOKCHQOc08fNgAcGtTxEXIWlrmn3eNxJ4LD?= =?us-ascii?Q?qctfjbh6llgzwoMqNuv4yNscCYCvP4RvSuJ6ng6ijrfiWbGFovBOJohhRWb+?= =?us-ascii?Q?xylmZsxOS3fHeqhwQHdjx9LhnIB34U6RukZUmKbyo+6gXSTNFkuz4y/+t/4O?= =?us-ascii?Q?c7hcw5TtpVR6RpLuj0b+sKfjRT6hbkKfjI6E3Fmo+SGF0EsEMAtKa0ts31fE?= =?us-ascii?Q?TO/gvuL8aX5K48cbXWZ077cEEYz0pH6UCDpnfhsw6ZdUcwXEl/6Sq02ZJLEg?= =?us-ascii?Q?aN3uV6oHPzkfJ/bZFI9+9MxwMMNYqYan+fbMN42XkEyugZ0C7+YImXtNNDCC?= =?us-ascii?Q?qU+jx0mSK4/iKL0Dn0pjaihsgnBfKifAl57F6IX8c/tn3jp391APXokfQ0Mj?= =?us-ascii?Q?O3qcllNIhCJE6zoL71Y2Z7p+U9UfEkbQVoKcoJpO650CRzcqpSUZAlQcUo1O?= =?us-ascii?Q?LZp7MCg6bxeZHP5nSCTSQTmhWDMuyKHC+PPnBqPsK4HrnqmSx21g2Xnptk54?= =?us-ascii?Q?U95X+AGUzzk9BgaLjgy5i5sZMRSGEOwj46z94BNAiG0YGvHjjNpsYad6DeWT?= =?us-ascii?Q?pOgS9bYmEYcH0hcn8tAP4U3eh2nCfvBPCv3sNz0Bi75hsuz4M6FmKskBrx9K?= =?us-ascii?Q?8FTz01Irv2z30x1maB9IDwMPuTZ+9KeCioMOm+vBPgXFFs45T8Ab/HuYWSAo?= =?us-ascii?Q?6F63Xb+CdYMX/eItJFRIjO5pd7tQkSX3VbTbKs4rupwZOLl+RIIrHIAa1Gpd?= =?us-ascii?Q?ZG/DBj7yBVohjsSMv560gO8V5oDZoi6J+jhSfpvhn7GbmX2H5tVUIhYUtvsz?= =?us-ascii?Q?tjR7KukZIxsEgosY5mNJ27bNXFymfTXj69KfrnhtKMRofO3LDVgblQYkRyQf?= =?us-ascii?Q?04qH8WZQgx4Exv5mJLZQu/ttYkALV0rfvYRUIw0BOOrteOXQBMzjhoF76yav?= =?us-ascii?Q?6dcCFl7HVaLVTaluOJ6oBuEn7Y75MU1DEbPW+gzBIifyBtLy02zX8gZ/O6Dv?= =?us-ascii?Q?BZaBJPW+v/bjcUc0cYdDYtCGqijBYjCIipRHC6kbdAO6KvIohcZHliKnHjKf?= =?us-ascii?Q?WeXEHTpx3tVbZlSxfLgXUGP1BLUPByyBg6xKtCQUgZazuWp6X9z6zG6Z09Dn?= =?us-ascii?Q?CZdHBuhNlwmsv0iYQtEC2KopRN9LYPLDOXE2xtXfJkXwNXSe+I2YxC0w2SPb?= =?us-ascii?Q?UDLqjj70qrC1HAr3l4kVsdmdtx2bVQoPwuvtk9NXXftArikBoQL/cAKe+3N9?= =?us-ascii?Q?6w+qRhgwTYE43/f5DFXV7EV5fGPgOVj6dr6PEh1ygrJ0xKBxSy1G6MQmdAfd?= =?us-ascii?Q?hjgu6WGzUf09G/jpp76ppMJnySffXnrhPvzthuaLxyJwtRtl9R6xv2RtxEx5?= =?us-ascii?Q?8js3tTp1ZgSup9pU2mzqX44EWB4b2SVYbVQkZSS6bG2nmPNSrkunAjDdeoOD?= =?us-ascii?Q?Lh8+jMYyUtRGy8Use1bXdQN6tlK5/QdHdW+GGabGhOLNCXHrjZ1vncWiRyRg?= =?us-ascii?Q?jTkfbEAoiLHx44oknk3u1vUpZRFrXBUZcrSXtr+Lxmrwx7LQThaYRyFT1Ooz?= =?us-ascii?Q?zg=3D=3D?= X-OriginatorOrg: jaguarmicro.com X-MS-Exchange-CrossTenant-Network-Message-Id: ebc8fefe-0cab-46da-33c6-08db5d0800d4 X-MS-Exchange-CrossTenant-AuthSource: KL1PR0601MB5567.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2023 10:08:36.0409 (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: SppVSfPXVW7yt5DbddHVbH/W6wD141xmVmEb7qlwS+cieb/d0EwfYUza+P5fTs0D2kz8ZZIsidLckhRY/iK+brG1hR5v3KUzbTmDb43VYak= X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB5025 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