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=-10.4 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY,USER_AGENT_SANE_1 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 0E48DC48BCF for ; Sun, 13 Jun 2021 10:14:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1ADA610C8 for ; Sun, 13 Jun 2021 10:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231444AbhFMKQw (ORCPT ); Sun, 13 Jun 2021 06:16:52 -0400 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:36401 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbhFMKQw (ORCPT ); Sun, 13 Jun 2021 06:16:52 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R391e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04420;MF=tianjia.zhang@linux.alibaba.com;NM=1;PH=DS;RN=17;SR=0;TI=SMTPD_---0UcDiZh1_1623579286; Received: from 30.25.254.38(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0UcDiZh1_1623579286) by smtp.aliyun-inc.com(127.0.0.1); Sun, 13 Jun 2021 18:14:48 +0800 Subject: Re: [PATCH 1/3] crypto: sm4 - create SM4 library based on sm4 generic code To: Eric Biggers 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 References: <20210610134459.28541-1-tianjia.zhang@linux.alibaba.com> <20210610134459.28541-2-tianjia.zhang@linux.alibaba.com> From: Tianjia Zhang Message-ID: Date: Sun, 13 Jun 2021 18:14:45 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Hi Eric, On 6/11/21 7:19 AM, Eric Biggers wrote: > 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. > Thanks for your suggestion, will do in the next version patch. >> 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. Ditto. thanks for pointing it out. > > - Eric > Best regards, Tianjia 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=-10.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_SANE_1 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 2C679C48BDF for ; Sun, 13 Jun 2021 10:16:50 +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 CE69E611C0 for ; Sun, 13 Jun 2021 10:16:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE69E611C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.alibaba.com 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-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WSY48rVvnWFwxbKJA7w14XzwiO11Vo/SpUfwjq5uQe8=; b=cuNzuiTsFqz73mRd4jbTn/+DP9 SW1V1bh2U0a4rhRgyupD4XO0wIKdAFqAyNQc++EPBERBZuGYDxsEgkf1KMkvZbK0QTuUooek+9XkT rDVxbs1XBvIb1T56x2qVith9GHKzHvfiS1QyzcnprXoT3pv3Fbum5HnLX10gOeXhgoOzNR14Fev2S J/+Br2NBtMP7d+QmVg059GEWpaOFGIbudkmfgG/Mq8gj74hHfKfaKUbJt+C+/ZlYJR4ac/u497RcH 1+yhiEwHBDd5ieP8J20SgosdzciBJDDDqtGg06Tw62Pr5M4r3M5CivteTkgwLZ8sWPVig8Je2/W9k muFgkprw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsN98-00ABZV-Pp; Sun, 13 Jun 2021 10:15:14 +0000 Received: from out4436.biz.mail.alibaba.com ([47.88.44.36]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lsN8x-00ABXf-Qt for linux-arm-kernel@lists.infradead.org; Sun, 13 Jun 2021 10:15:05 +0000 X-Alimail-AntiSpam: AC=PASS; BC=-1|-1; BR=01201311R391e4; CH=green; DM=||false|; DS=||; FP=0|-1|-1|-1|0|-1|-1|-1; HT=e01e04420; MF=tianjia.zhang@linux.alibaba.com; NM=1; PH=DS; RN=17; SR=0; TI=SMTPD_---0UcDiZh1_1623579286; Received: from 30.25.254.38(mailfrom:tianjia.zhang@linux.alibaba.com fp:SMTPD_---0UcDiZh1_1623579286) by smtp.aliyun-inc.com(127.0.0.1); Sun, 13 Jun 2021 18:14:48 +0800 Subject: Re: [PATCH 1/3] crypto: sm4 - create SM4 library based on sm4 generic code To: Eric Biggers 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 References: <20210610134459.28541-1-tianjia.zhang@linux.alibaba.com> <20210610134459.28541-2-tianjia.zhang@linux.alibaba.com> From: Tianjia Zhang Message-ID: Date: Sun, 13 Jun 2021 18:14:45 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210613_031504_028321_A2CC0C6F X-CRM114-Status: GOOD ( 19.62 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Eric, On 6/11/21 7:19 AM, Eric Biggers wrote: > 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. > Thanks for your suggestion, will do in the next version patch. >> 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. Ditto. thanks for pointing it out. > > - Eric > Best regards, Tianjia _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel