Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp438342ybh; Sun, 12 Jul 2020 11:05:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzj1IkX0pIFEKLVlY1U0HEbVVlyaEMq9Uj1BheKp4daGeh+SkpyD4Iz/MACYMU9+Z596zWm X-Received: by 2002:aa7:df08:: with SMTP id c8mr86045603edy.372.1594577113480; Sun, 12 Jul 2020 11:05:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594577113; cv=none; d=google.com; s=arc-20160816; b=kGj037mVUd2V5KAcOCm6zxNShVEn4Rd1oVEgR7qk6TqSVuV7sXjsW774bIK4l/NWR6 GA3RGoI0vlr1p5Q97HjoVL3d4kIlytuXaw+BGvj6rFVL2XvHEHzJ1T462+o5jwkfRTs4 nzvYqEmm5TbTqO98WC33SD8PJH5VcKHT7W6r0qKhkwgL9i9fseix1+QNUlVr2PpPXWqg FtNKM40Y91gV117BmmqiMR97GBGrDjjlODkR8WOx1jMZfvAWX59Qc8x9tROG1syD5CGq x4SRKnyNdeaAtualGTuR3dqgTMjjj5f+C7XoO/OnQsJYbQaZO/WgelHNcoNaAQWW6BMt pDlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date; bh=Lyu3sjCU55KCtblyD2BKmK0qgo066v/uOkf/E45rfI4=; b=El48686LDSRAZ2Mso1a3VFk/Dxv+ooBXorGToGdsAOiNUBz1c4kz8BO7OJ6JQVPZWD iUcxgYldLOikAi2c3lzV7XYOuUx8LRtMLOioLT4WhHyU8w5rFYQxZRjT9ZKcBJj8GmIs Wq7fbkK6Ppv9xrLV0FM6yy+tq3KKs8AL50n2pn9VE/q8j52JaqQV/n6MlOq/YEWUaDZ6 GEe/o8bOEVYYjROL1vpi4zmZvbguAMlOcBqS3Hznw+ioL4liuHRPpPLJNMAzs5jO/nmu Ye+3VDz5Cv2H4SOl+jYidhjKz4zfRwaric+nIukLRxF3WeLXNu60+ZK73TGhG4z798vW rBNg== 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 d10si6878709ejt.515.2020.07.12.11.04.39; Sun, 12 Jul 2020 11:05:13 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729103AbgGLSCf (ORCPT + 99 others); Sun, 12 Jul 2020 14:02:35 -0400 Received: from vmicros1.altlinux.org ([194.107.17.57]:55302 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728859AbgGLSCf (ORCPT ); Sun, 12 Jul 2020 14:02:35 -0400 Received: from imap.altlinux.org (imap.altlinux.org [194.107.17.38]) by vmicros1.altlinux.org (Postfix) with ESMTP id 05D1E72CCF5; Sun, 12 Jul 2020 21:02:33 +0300 (MSK) Received: from altlinux.org (sole.flsd.net [185.75.180.6]) by imap.altlinux.org (Postfix) with ESMTPSA id E3E4B4A4AEE; Sun, 12 Jul 2020 21:02:32 +0300 (MSK) Date: Sun, 12 Jul 2020 21:02:32 +0300 From: Vitaly Chikunov To: Stephan =?utf-8?Q?M=C3=BCller?= Cc: herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, Marcelo Cerri , Tianjia Zhang , ard.biesheuvel@linaro.org, nhorman@redhat.com, simo@redhat.com Subject: Re: [PATCH v2 1/5] crypto: ECDH - check validity of Z before export Message-ID: <20200712180232.jnvkz6xtx63hisvg@altlinux.org> Mail-Followup-To: Stephan =?utf-8?Q?M=C3=BCller?= , herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, Marcelo Cerri , Tianjia Zhang , ard.biesheuvel@linaro.org, nhorman@redhat.com, simo@redhat.com References: <2543601.mvXUDI8C0e@positron.chronox.de> <5722559.lOV4Wx5bFT@positron.chronox.de> <4348752.LvFx2qVVIh@positron.chronox.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4348752.LvFx2qVVIh@positron.chronox.de> User-Agent: NeoMutt/20171215-106-ac61c7 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org On Sun, Jul 12, 2020 at 06:39:26PM +0200, Stephan Müller wrote: > SP800-56A rev3 section 5.7.1.2 step 2 mandates that the validity of the > calculated shared secret is verified before the data is returned to the > caller. Thus, the export function and the validity check functions are > reversed. In addition, the sensitive variables of priv and rand_z are Reviewed-by: Vitaly Chikunov > zeroized. > > Signed-off-by: Stephan Mueller > --- > crypto/ecc.c | 11 ++++++++--- > 1 file changed, 8 insertions(+), 3 deletions(-) > > diff --git a/crypto/ecc.c b/crypto/ecc.c > index 02d35be7702b..52e2d49262f2 100644 > --- a/crypto/ecc.c > +++ b/crypto/ecc.c > @@ -1495,11 +1495,16 @@ int crypto_ecdh_shared_secret(unsigned int curve_id, unsigned int ndigits, > > ecc_point_mult(product, pk, priv, rand_z, curve, ndigits); > > - ecc_swap_digits(product->x, secret, ndigits); > - > - if (ecc_point_is_zero(product)) > + if (ecc_point_is_zero(product)) { > ret = -EFAULT; > + goto err_validity; > + } > + > + ecc_swap_digits(product->x, secret, ndigits); > > +err_validity: > + memzero_explicit(priv, sizeof(priv)); > + memzero_explicit(rand_z, sizeof(rand_z)); > ecc_free_point(product); > err_alloc_product: > ecc_free_point(pk); > -- > 2.26.2 > > >