Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1930161pxj; Sun, 13 Jun 2021 03:15:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlT1D7XdK8JuaFU8KMPCDqvYPqFMaB/RHTqDk0T30HVRizkQW2zLOW6qrAHv2OldKfJTrs X-Received: by 2002:a05:6402:1d0f:: with SMTP id dg15mr12139261edb.137.1623579332473; Sun, 13 Jun 2021 03:15:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623579332; cv=none; d=google.com; s=arc-20160816; b=b2z54hbRgjy7xG/J1rXANMHD4WSohK8TVERuSaaD6x11L9+ViC1C7nykJobicZRQEu 9O6JL/UgVfx8tTdMTTXJZctkb3HwsNHQTjpSLB2hSFtUDfL8/QtV/j6rnARv+s2sZgFt KJh/KTYGT0PB12Jdex8LR6ZK56g96hvP6Cd+FTKnTfDf4YGSsABJzyA8+QTf82VIkkHY /Ko5eKBFaMP8FGrwfNZV0KdxUx8UFiEAg5cDrX9Owv57KJVzzzBhu34U9SMJkfW5K0Lk N/HIJdsO1Kwu1BkibJ44WQh1bsVKXKIM13PwgRyNxOeDZVYD+Tvmf7IcWJSYNe3r8rKx pfkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=3/iD7gBvQ29x7zIAbupB+FJsFVfOafbmXktPQ8aVAJU=; b=xfwVClX28ifphztWEkUKe8aRSaTbnF6Bh5PD84cl/iODBNlF7fHGXEakB/N5oK/TL9 bXxEGwnV9jKqtRDRmkS9tS1pOGkgK4Z7bFxiDm3sLyBCPjCiYndEnGUxWIVFLNsLJtQm khLh6Cdl49kYHJa0aMYoCkm7dpNOTtRrSuVnBwYZ52krWd0FNgCghFsS/woCoDYM0E9k 6C2lX+12V6AeehdzFbrKTnqZyjAdbe8hUiadObKaZS/LEkEM72kmLi/eJoIYQ4iQ4mu1 YoqPQ87xFnn0KtgByrMCZgoDN2XMGKztPcw2PJ5JRPi4BLfwtGKHAk5yeI7+c5aQixf8 1yvg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ju18si8632842ejc.455.2021.06.13.03.14.53; Sun, 13 Jun 2021 03:15:32 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231444AbhFMKQw (ORCPT + 99 others); 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