From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BFEFC48BDF for ; Thu, 10 Jun 2021 23:19:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C6E5613F5 for ; Thu, 10 Jun 2021 23:19:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231152AbhFJXVg (ORCPT ); Thu, 10 Jun 2021 19:21:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:52178 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbhFJXVf (ORCPT ); Thu, 10 Jun 2021 19:21:35 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5DE0D613CB; Thu, 10 Jun 2021 23:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623367178; bh=ABUBXcQetZjJYDHEJU4gE1xB6jxKYpJ007+1HHni69k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gJQk4dL+oaaSh7lv0haLYu3WPkfNq8qxzgzF2ItGERpIMb3/lT2YE7U500XG7FJLT UkQCXOJX5JPCIijZMKJd9Px1oVQ3LWfoKqRYM7GvDSwnMPi6YpkPhECW3FFrII6/dL nu+I1vSGPcELw+IP1IxvsY+sR4Avp7ouN5XqDQZ9yLZnYl4lB+zZnpRjO53hiSsTKI yMx94mFgcHqpaog4X7wbFZ9ruwfAdP1qvqmApmCza4hCCxhyEsp0wsTk1Na761+f7E +YGOPx6bSI6NbAOa/JLfykAUcwzt6XHNR/RwJq6oXj5XoXxYG/fwQo0MIyh/SNtQ8b pYCqtklYF48tg== Date: Thu, 10 Jun 2021 16:19:36 -0700 From: Eric Biggers To: Tianjia Zhang Cc: Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Gilad Ben-Yossef , Ard Biesheuvel , "Markku-Juhani O . Saarinen" , Jussi Kivilinna , x86@kernel.org, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] crypto: sm4 - create SM4 library based on sm4 generic code Message-ID: References: <20210610134459.28541-1-tianjia.zhang@linux.alibaba.com> <20210610134459.28541-2-tianjia.zhang@linux.alibaba.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210610134459.28541-2-tianjia.zhang@linux.alibaba.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Thu, Jun 10, 2021 at 09:44:57PM +0800, Tianjia Zhang wrote: > Take the existing small footprint and mostly time invariant C code It is using an S-box without any prefetching. That doesn't look very "time invariant" to me. > diff --git a/lib/crypto/sm4.c b/lib/crypto/sm4.c > new file mode 100644 > index 000000000000..cbdd14a254d0 [..] > +/** > + * crypto_sm4_expand_key - Expands the SM4 key as described in GB/T 32907-2016 > + * @ctx: The location where the computed key will be stored. > + * @in_key: The supplied key. > + * @key_len: The length of the supplied key. > + * > + * Returns 0 on success. The function fails only if an invalid key size (or > + * pointer) is supplied. > + */ > +int crypto_sm4_expand_key(struct crypto_sm4_ctx *ctx, const u8 *in_key, > + unsigned int key_len) [...] > +/** > + * crypto_sm4_do_crypt - Encrypt or decrypt a single SM4 block > + * @rk: The rkey_enc for encrypt or rkey_dec for decrypt > + * @out: Buffer to store output data > + * @in: Buffer containing the input data > + */ > +void crypto_sm4_do_crypt(const u32 *rk, u8 *out, const u8 *in) Calling these "sm4_expandkey()" and "sm4_crypt_block()" would be more consistent with the other lib/crypto/ functions such as the AES ones. The other lib/crypto/ functions don't have a "crypto_" prefix, as that is used for functions related to the traditional crypto API rather than the library API. - Eric From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF551C48BDF for ; Thu, 10 Jun 2021 23:23:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9C685613E9 for ; Thu, 10 Jun 2021 23:23:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9C685613E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Sx8sQB0V8ykp4mekvupLXef2ZQXEO1UKGJi8a7Idazs=; b=0XFfs/Hj4GITG0 DNR+RFee8OTjbnWOkZKDKK0ApZGbYLT3MqNbptB2ICQPsQDe9wiKmsb7DBimjX5BFE9cTu9p57iEk GwfuLNHja7WvaiWAW1E7tGrD/MmO+VPhxPw1OK6fcENQqZ1122OZ6e+4Whxh/1w+rnKoBIbBn3UCw TgyzBGgzj3nFDG4r2KUswDBRMr6CEkeEMEJ32L1RV//XsEdUDNZPcbRk0B4enm9OQ6gTYCN5NRgNE TpuolmcmOCLpyl2lcq5vBOS5aSJN/ISSI+nSsApyZDBNK2t9Bd+v36p036IaV//k2srxGMR0kydX6 uwAy4JbZIg8xG3Os0K9w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lrTxe-002sCV-TP; Thu, 10 Jun 2021 23:19:43 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lrTxc-002sBi-2B for linux-arm-kernel@lists.infradead.org; Thu, 10 Jun 2021 23:19:41 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5DE0D613CB; Thu, 10 Jun 2021 23:19:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623367178; bh=ABUBXcQetZjJYDHEJU4gE1xB6jxKYpJ007+1HHni69k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gJQk4dL+oaaSh7lv0haLYu3WPkfNq8qxzgzF2ItGERpIMb3/lT2YE7U500XG7FJLT UkQCXOJX5JPCIijZMKJd9Px1oVQ3LWfoKqRYM7GvDSwnMPi6YpkPhECW3FFrII6/dL nu+I1vSGPcELw+IP1IxvsY+sR4Avp7ouN5XqDQZ9yLZnYl4lB+zZnpRjO53hiSsTKI yMx94mFgcHqpaog4X7wbFZ9ruwfAdP1qvqmApmCza4hCCxhyEsp0wsTk1Na761+f7E +YGOPx6bSI6NbAOa/JLfykAUcwzt6XHNR/RwJq6oXj5XoXxYG/fwQo0MIyh/SNtQ8b pYCqtklYF48tg== Date: Thu, 10 Jun 2021 16:19:36 -0700 From: Eric Biggers To: Tianjia Zhang Cc: Herbert Xu , "David S. Miller" , Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Gilad Ben-Yossef , Ard Biesheuvel , "Markku-Juhani O . Saarinen" , Jussi Kivilinna , x86@kernel.org, linux-crypto@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/3] crypto: sm4 - create SM4 library based on sm4 generic code Message-ID: References: <20210610134459.28541-1-tianjia.zhang@linux.alibaba.com> <20210610134459.28541-2-tianjia.zhang@linux.alibaba.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210610134459.28541-2-tianjia.zhang@linux.alibaba.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210610_161940_146897_F8568089 X-CRM114-Status: GOOD ( 14.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Jun 10, 2021 at 09:44:57PM +0800, Tianjia Zhang wrote: > Take the existing small footprint and mostly time invariant C code It is using an S-box without any prefetching. That doesn't look very "time invariant" to me. > diff --git a/lib/crypto/sm4.c b/lib/crypto/sm4.c > new file mode 100644 > index 000000000000..cbdd14a254d0 [..] > +/** > + * crypto_sm4_expand_key - Expands the SM4 key as described in GB/T 32907-2016 > + * @ctx: The location where the computed key will be stored. > + * @in_key: The supplied key. > + * @key_len: The length of the supplied key. > + * > + * Returns 0 on success. The function fails only if an invalid key size (or > + * pointer) is supplied. > + */ > +int crypto_sm4_expand_key(struct crypto_sm4_ctx *ctx, const u8 *in_key, > + unsigned int key_len) [...] > +/** > + * crypto_sm4_do_crypt - Encrypt or decrypt a single SM4 block > + * @rk: The rkey_enc for encrypt or rkey_dec for decrypt > + * @out: Buffer to store output data > + * @in: Buffer containing the input data > + */ > +void crypto_sm4_do_crypt(const u32 *rk, u8 *out, const u8 *in) Calling these "sm4_expandkey()" and "sm4_crypt_block()" would be more consistent with the other lib/crypto/ functions such as the AES ones. The other lib/crypto/ functions don't have a "crypto_" prefix, as that is used for functions related to the traditional crypto API rather than the library API. - Eric _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel