Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp113150rdb; Mon, 4 Dec 2023 23:26:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjBH204P65jsCXwPiPvcMvUNWM0b0uc0xT+N003DFJFx4i0x2x4pC9N8Q9Ko87fxDpagJF X-Received: by 2002:aa7:9e87:0:b0:6cb:d24b:3568 with SMTP id p7-20020aa79e87000000b006cbd24b3568mr616438pfq.30.1701761209054; Mon, 04 Dec 2023 23:26:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701761209; cv=none; d=google.com; s=arc-20160816; b=mps/yOLogJLoM36RH5UN6Ps2+Q11edW2C5QTJYYI8qIuOasJ3jbG1dhGPZLbpBGTYc mdH1LjQRDE+nTHBOUMrQXTNVc+dYgis3zrVVi0JvYvrDmwoL7CMf2Sjjvpc5CxOe58y8 KEvZURzhx5de/7F2ZEMb1oazYgX3KkVeLV4QYSAEr2Xoa1BVz6pbcjwnFwzbAjy8bI/S p0wPh27LCCo5v2X7GP977fpPlWxroY6y0Ho9U2WDTO2GNoys3hJZ9+fBK0bbGqPyldRp mehYNgljiZJozZtkI5rJzJr4pSNTQ+shgO7VdaANlxW60t8EUbmAstEtMWVGJKAsJrhD k2ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=xQKCkGHsUPopRV47KPReEx2TlV4AAqf2La9wEpE2CuM=; fh=oKQ7odyGop4vOUyeCXS5syRPyLIMTAY3L3d2VgxMbck=; b=Pi6ObWv1b0uhacemGjvVQ3GzTrSwtNZOW1jpQF4cyTzayZMRCRXGrIrfYdG8AuYfnO W/ea2FuGwKfGAcYNuU/CBqDXxOpITnVbUQWMBcCq1tIXCwh7+h/tcVDqlt6Yzf0RaWyo aHrOcg2QhquXv04T1MLEfZnrAbYkkU8wK6eMb8sd4xF0UzabOph2KOYuFCVp1JlWSSB4 UhL49UBb5ssvAfw0mvhl1yoOl0uy1wTxDfDarHHHeottZTnmJQQgg0ffT6cdQGZywqcA keRnM3KpY9rGnf/tytJFDlgn2F9VQHBu6a1gynMmkWGnh2WvAAEIsUh5uwRp/cMm6dmB FT4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id k26-20020aa792da000000b006ce63e17f29si1561238pfa.341.2023.12.04.23.26.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 23:26:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 15E2380A14B2; Mon, 4 Dec 2023 23:26:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231688AbjLEH0T (ORCPT + 99 others); Tue, 5 Dec 2023 02:26:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjLEH0S (ORCPT ); Tue, 5 Dec 2023 02:26:18 -0500 Received: from mx2.zhaoxin.com (mx2.zhaoxin.com [203.110.167.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DCC1C9 for ; Mon, 4 Dec 2023 23:26:22 -0800 (PST) X-ASG-Debug-ID: 1701761167-1eb14e538b29f60002-xx1T2L Received: from ZXSHMBX2.zhaoxin.com (ZXSHMBX2.zhaoxin.com [10.28.252.164]) by mx2.zhaoxin.com with ESMTP id eaXEc7WsWmXBPLdu (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Tue, 05 Dec 2023 15:26:18 +0800 (CST) X-Barracuda-Envelope-From: LeoLiu-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 Received: from ZXBJMBX02.zhaoxin.com (10.29.252.6) by ZXSHMBX2.zhaoxin.com (10.28.252.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Dec 2023 15:26:07 +0800 Received: from [192.168.1.204] (125.76.214.122) by ZXBJMBX02.zhaoxin.com (10.29.252.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Tue, 5 Dec 2023 15:26:03 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.164 Message-ID: <96fe2155-5ba2-4b6b-9cf7-433a8d1d9e38@zhaoxin.com> X-Barracuda-RBL-Trusted-Forwarder: 192.168.1.204 Date: Tue, 5 Dec 2023 15:26:02 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] crypto: x86/sm2 -add Zhaoxin SM2 algorithm implementation To: Herbert Xu X-ASG-Orig-Subj: Re: [PATCH v3] crypto: x86/sm2 -add Zhaoxin SM2 algorithm implementation CC: , , , , , , , , , , , , , , , , , , , References: <20231109094744.545887-1-LeoLiu-oc@zhaoxin.com> <20231122064355.638946-1-LeoLiu-oc@zhaoxin.com> From: LeoLiu-oc In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [125.76.214.122] X-ClientProxiedBy: ZXSHCAS1.zhaoxin.com (10.28.252.161) To ZXBJMBX02.zhaoxin.com (10.29.252.6) X-Barracuda-Connect: ZXSHMBX2.zhaoxin.com[10.28.252.164] X-Barracuda-Start-Time: 1701761168 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.36:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 2329 X-Barracuda-BRTS-Status: 0 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.117671 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 04 Dec 2023 23:26:46 -0800 (PST) 在 2023/12/1 17:27, Herbert Xu 写道: > On Wed, Nov 22, 2023 at 02:43:55PM +0800, LeoLiu-oc wrote: >> From: LeoLiuoc >> >> Add support for SM2 (ShangMi 2) public key algorithm by Zhaoxin GMI >> Instruction. The purpose of this driver is to ensure that the application >> has both high performance and high security. >> >> --- >> >> v1 -> v2: >> 1. The assembly code is modified to be embedded in the .c file. >> 2. Optimize code style and details. >> >> v2 -> v3: >> 1. Increase compatibility with i386 architecture. >> 2. Optimize variable and return value types in some functions.. >> >> Signed-off-by: LeoLiuoc >> --- >> arch/x86/crypto/Kconfig | 11 ++ >> arch/x86/crypto/Makefile | 2 + >> arch/x86/crypto/sm2-zhaoxin-gmi_glue.c | 158 +++++++++++++++++++++++++ >> arch/x86/include/asm/cpufeatures.h | 2 + >> 4 files changed, 173 insertions(+) >> create mode 100644 arch/x86/crypto/sm2-zhaoxin-gmi_glue.c >> >> diff --git a/arch/x86/crypto/Kconfig b/arch/x86/crypto/Kconfig >> index 9bbfd01cfa2f..974d4c3806ff 100644 >> --- a/arch/x86/crypto/Kconfig >> +++ b/arch/x86/crypto/Kconfig >> @@ -519,4 +519,15 @@ config CRYPTO_CRCT10DIF_PCLMUL >> Architecture: x86_64 using: >> - PCLMULQDQ (carry-less multiplication) >> >> +config CRYPTO_SM2_ZHAOXIN_GMI >> + tristate "SM2 Cipher algorithm (Zhaoxin GMI Instruction)" >> + depends on X86 && (CPU_SUP_CENTAUR || CPU_SUP_ZHAOXIN) >> + select CRYPTO_AKCIPHER >> + select CRYPTO_MANAGER > > Why does this depend on CRYPTO_MANAGER? > Yes, this is redundant and will be removed in the next version. >> +static int zhaoxin_sm2_verify(struct akcipher_request *req) >> +{ >> + struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); >> + struct sm2_cipher_data *ec = akcipher_tfm_ctx(tfm); >> + unsigned char *buffer; >> + int ret, buf_len; >> + >> + buf_len = req->src_len + req->dst_len; > > What if this overflows? I know you copied this from the generic sm2 > code, but that's still broken and both should be fixed up. > > Thanks, Yes, you are right. Thank you for your advice. The variable types will be adjusted according to the actual needs of the code in the next version. Sincerely, LeoLiu-oc