Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp110169pxj; Thu, 10 Jun 2021 16:21:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypygomUkk6s0k74gPi0LXVkTka5+1/vj/YHnzvVGHErbZkmUD99oc2Fc6XJKUI9EVLfRDy X-Received: by 2002:aa7:d602:: with SMTP id c2mr806067edr.317.1623367307671; Thu, 10 Jun 2021 16:21:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623367307; cv=none; d=google.com; s=arc-20160816; b=MJWzJilkBLc4vYRjLJWUFFDZYj02e1Wbe06kdhWDyXdg0Am7iVjcSAGAlU39daKRre bxsVxlfWC+UiJ7ALoHGNqMx02N8KyR2SrisXtu1ncIdzsGZKvTvrXW/09VXN0BD850xE CEfRTckDoK2BO4Fy7ALTsx3Ld9djnyhMOsAGUZtgmEy44nq/44dHCIQGZ+We0T6+GooT W/vXrTq3QKkMFUs5lCpSJDZB+a1SppfHJ7gCsGdc0WGp6qbSSFwnYLdurgR85yqWqpBO 0c0fX318SRfMBEkgZxDL4/qCIpL6h8gdJJv8t0tTdlCy1cRXC4v8+TgUzjBsv95d0sS8 8Nww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=QnnJMwjMokS30AoTYiaZglpCfjAgndRv5b5NzzehoCs=; b=nBlrDQrR0oGs204MQApMcixYlQ1AAjRtyi4n9jkUq27pBSh3e52TGduXWWIOl+RaP7 UL5PX90W0TnE4++9mqpCTKRtvFEn1mrLRP7a5PROs+U7xGpR4/brIzhsHQFSypattXgJ OJdGsV9CFvWRxVWC+SE5iKaH0TrVkBZNjjM5yIcbyvBgXi3k8VpqZlytLUB0R5/y4b2b mYvZ3owFy1xlv0YPrN8y225oEgOlq2CWrJHSQd69Jzv3wQ53qGpBr5+j876i844z4sjE uDGTsoiXXRTOSPz1B0/Il6UTo3OW6PxkwKg3vSiN5zRswOl/6xL/If0qe0aGQtOSW2nO hEZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gJQk4dL+; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h3si3686958edf.193.2021.06.10.16.21.23; Thu, 10 Jun 2021 16:21:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gJQk4dL+; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231152AbhFJXVg (ORCPT + 99 others); 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