Re: [PATCH v3] crypto: x86/sm2 -add Zhaoxin SM2 algorithm implementation

From: Herbert Xu
Date: Fri Dec 01 2023 - 04:31:35 EST


On Wed, Nov 22, 2023 at 02:43:55PM +0800, LeoLiu-oc wrote:
> From: LeoLiuoc <LeoLiu-oc@xxxxxxxxxxx>
>
> 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 <LeoLiu-oc@xxxxxxxxxxx>
> ---
> 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?

> +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,
--
Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt