Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp746031pxb; Sat, 6 Mar 2021 16:04:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxb1IIjGrGWl+E59YfGw3psDEW+wFZh0tzv9gFcXFFiT9Lbo5bpW3ogJnrjzwckAL+QBnBB X-Received: by 2002:a17:906:4c85:: with SMTP id q5mr8590584eju.375.1615075474913; Sat, 06 Mar 2021 16:04:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615075474; cv=none; d=google.com; s=arc-20160816; b=tCxyHppAov7bjYoqlw1G+xMgPSZY9YXgYrjyMXmXg029X8adwKlsPpjI07fnwKRf+b gygnFQyk1LJi2uBYeI3XZ/JRblBrnlukvciUp4sePMeoRSXVxt8ndXTNfQxHd9+xgwQM 9FC2N/Xpgn+3bUvkVHcF+OSaYZYoDR1/GFpR8Gvrfna4E/eKuSfpcpz1P4eGC5WzAzJL LsH6+9saD/f/9kjkFp8vtjvdGrc6Gq4oceI5ZYeBHdpqnhLMUPYITYt0z3K2v8+BKqQ3 ooy1p4fgAlRxtwRCBfnD0XAynlh/D/UuLJVyioRwUjbog30xK/nbVrFoQOCyRrffZFDV lKvQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=KVGPCiPUXBNxdG8t/BVbTwryhHfLmjxu9vHpIM5XArk=; b=Mg89wj2c/QK+Gww7s3IDa5LtQC0+ZomaIBhjwPWBvQRtl8G071QDV03mvZMdCerWFl iiCbJ34GSl1SFqUBS2dqdw3CcL/fbYzk46qeqcPnW8JqwTcOQKLVXSp49mRyPnmjNf1K 8YAF0uMVR+Esglsn9BtwDwyaxzcvUm+VxV9C4GySnjmKq/rV4V9BI/Riyn7G2fzE1Npd 6sVok50BvQIS56VPWExd9IhjevXH5TA45t0OGdfij9S3rkGGrUaB+ybzyaFEio81aycs O3h05KYJppmzK36OsUHDhV0So71KwllufcVTsYwVH8Bj5rIcVmRzpMmkO9m3hJheJHEp u6xw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ar21si4076129ejc.618.2021.03.06.16.04.03; Sat, 06 Mar 2021 16:04:34 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229816AbhCGAD3 (ORCPT + 99 others); Sat, 6 Mar 2021 19:03:29 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:35862 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbhCGADN (ORCPT ); Sat, 6 Mar 2021 19:03:13 -0500 Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id C418D72C8B8; Sun, 7 Mar 2021 03:03:10 +0300 (MSK) Received: from altlinux.org (sole.flsd.net [185.75.180.6]) by imap.altlinux.org (Postfix) with ESMTPSA id A896C4A4736; Sun, 7 Mar 2021 03:03:10 +0300 (MSK) Date: Sun, 7 Mar 2021 03:03:10 +0300 From: Vitaly Chikunov To: Stefan Berger Cc: Stefan Berger , keyrings@vger.kernel.org, linux-crypto@vger.kernel.org, davem@davemloft.net, herbert@gondor.apana.org.au, dhowells@redhat.com, zohar@linux.ibm.com, linux-kernel@vger.kernel.org, patrick@puiterwijk.org, linux-integrity@vger.kernel.org, Saulo Alessandre Subject: Re: [PATCH v10 3/9] crypto: Add math to support fast NIST P384 Message-ID: <20210307000310.ytes6la73x5bkori@altlinux.org> References: <20210305005203.3547587-1-stefanb@linux.vnet.ibm.com> <20210305005203.3547587-4-stefanb@linux.vnet.ibm.com> <20210306192553.lxy5w262g2vs2hvv@altlinux.org> <9ac456d7-a5e1-9e42-5d34-7dc1c70082e0@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9ac456d7-a5e1-9e42-5d34-7dc1c70082e0@linux.ibm.com> Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Stefan, On Sat, Mar 06, 2021 at 06:29:18PM -0500, Stefan Berger wrote: > On 3/6/21 2:25 PM, Vitaly Chikunov wrote: > > > > On Thu, Mar 04, 2021 at 07:51:57PM -0500, Stefan Berger wrote: > > > From: Saulo Alessandre > > > > > > * crypto/ecc.c > > > - add vli_mmod_fast_384 > > > - change some routines to pass ecc_curve forward until vli_mmod_fast > > > > > > * crypto/ecc.h > > > - add ECC_CURVE_NIST_P384_DIGITS > > > - change ECC_MAX_DIGITS to P384 size > > > > > > Signed-off-by: Saulo Alessandre > > > Tested-by: Stefan Berger > > > --- > > > crypto/ecc.c | 266 +++++++++++++++++++++++++++++++++++++-------------- > > > crypto/ecc.h | 3 +- > > > 2 files changed, 194 insertions(+), 75 deletions(-) > > > > > > diff --git a/crypto/ecc.c b/crypto/ecc.c > > > index f6cef5a7942d..c125576cda6b 100644 > > > --- a/crypto/ecc.c > > > +++ b/crypto/ecc.c > > > @@ -778,18 +778,133 @@ static void vli_mmod_fast_256(u64 *result, const u64 *product, > > > ... > > > /* Computes result = product % curve_prime for different curve_primes. > > > * > > > * Note that curve_primes are distinguished just by heuristic check and > > > * not by complete conformance check. > > > */ > > > static bool vli_mmod_fast(u64 *result, u64 *product, > > > - const u64 *curve_prime, unsigned int ndigits) > > > + const struct ecc_curve *curve) > > > { > > > u64 tmp[2 * ECC_MAX_DIGITS]; > > > + const u64 *curve_prime = curve->p; > > > + const unsigned int ndigits = curve->g.ndigits; > > > - /* Currently, both NIST primes have -1 in lowest qword. */ > > > - if (curve_prime[0] != -1ull) { > > > + /* Currently, all NIST have name nist_.* */ > > > + if (strncmp(curve->name, "nist_", 5) != 0) { > > I am not sure, but maybe this strncmp should not be optimized somehow, > > since vli_mmod_fast could be called quite frequently. Perhaps by integer > > algo id or even callback? > > Should be optimized or should not be? You seem to say both. Excuse me for the typo. I meant "should be optimized". I think, maybe it's time to add algo selector id (for the case statement, for example instead of `switch (ndigits)') or just callback for a low level mmod function. If you think this would not impact performance then nevermind. Thanks, > > The code code here is shared with ecrdsa. The comparison won't go beyond a > single letter considering the naming of the curves define here: > > "cp256a": > https://elixir.bootlin.com/linux/v5.11.3/source/crypto/ecrdsa_defs.h#L49 > > "cp256b": > https://elixir.bootlin.com/linux/v5.11.3/source/crypto/ecrdsa_defs.h#L82 > > "cp256c": > https://elixir.bootlin.com/linux/v5.11.3/source/crypto/ecrdsa_defs.h#L119 > > "tc512a": > https://elixir.bootlin.com/linux/v5.11.3/source/crypto/ecrdsa_defs.h#L168 > > and here: > > "nist_192": > https://elixir.bootlin.com/linux/v5.11.3/source/crypto/ecc_curve_defs.h#L18 > > "nist_256": > https://elixir.bootlin.com/linux/v5.11.3/source/crypto/ecc_curve_defs.h#L45 > > > All the ecrdsa curves were previously evaluating 'curve_prime[0] != -1ull', > so it doesn't change anything. > > ? Stefan >