Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp618657lqp; Thu, 21 Mar 2024 10:20:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU5wMHg+iROQLGakrIACSsiZ9iLTkGa8KPD0rYWM6eccS1PmPRgj3s2sdAh19BMe+NiYIhD7+Ya3GQhD6A6gJMnAej0IxCAfnpU1IRA7w== X-Google-Smtp-Source: AGHT+IGWLJz5SybAhrVn9VsrEhVOVF9N+Xh7v51k0Klz0xW3bl6eOSDCyy9DoVQfZO4hFBl9QDrT X-Received: by 2002:a05:620a:31a0:b0:788:3f49:1ca4 with SMTP id bi32-20020a05620a31a000b007883f491ca4mr3351319qkb.43.1711041641355; Thu, 21 Mar 2024 10:20:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711041641; cv=pass; d=google.com; s=arc-20160816; b=ml4o/ZQLpLlWxB951nNd6ub8JwSftmCXNO54cCuEWBvRwVDdmmutqQW/OBm8n16HBi y/NZfDGVVFygMJa87yknec8NhsdKC9SGz95+0MMBf4llBKh6vnSMJX0izHBM0VXVRRW+ UuUfrxtJV8PG/4usUEb4E3ONtRE1AZXf4sSX95b5kyx0HFoOKQCXaD/g2THWwFoOwr1U 3XDC8kJKSPNyYjHm8SgvFVF9HZn45SDDoOswmnp5XMGZumdKcsC/q/pogGkt3D9/46OD FqEmgrfd7QjwVpafCS8VzepHKOpP7nswpJEviCa8y/A7P+uUM6WE6wSNw5vPRLjfcyJx LpPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:from:subject:cc:to:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=x95L+CmP9qctaoANyQ7vRF2IhFprjIQI5TEKSaD+eMY=; fh=2mr4W+BfuAP6ovGgAw17bsPtLE4g35z+gXY/IZoF0jM=; b=rTwKQjcMCKbVkEQ8R4OKE9bqZF+4blHiVsGwnulvShoeHh8wpD80kzmiCcSZC1sxKD ++dJv7qmT1zu78s/JBXp2RilPq9u/zere+rawqm65FXPZB9AxP/YqqC35n4UVQpoHBvk 1u9zDfpIjV0qx8KphDwviDHiBJnhFDUhCEBSHwE+t+ZceG0d9zUZmyVIemFvb8xt6P+S oQWR4pv5XZpYA7ohwF75N4lp8SY9+uFDMQ6yPU9HeJ/EAxn2pcTEo2r3/JlaWB8/E5YJ QrFM+82jb1cAy5evwcrU0EvA/Xg7rTiL2E7YntKAPzaxHk0QF9ipQt4Q0dwVBmRA5zyB dLdA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="NNUPr/Li"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2812-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2812-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id z9-20020a05620a08c900b00789e1c4bbcasi145872qkz.544.2024.03.21.10.20.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:20:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2812-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="NNUPr/Li"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2812-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2812-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 191A61C23830 for ; Thu, 21 Mar 2024 17:20:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB75D132C37; Thu, 21 Mar 2024 17:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NNUPr/Li" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71E40133413; Thu, 21 Mar 2024 17:19:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711041587; cv=none; b=mLjO/xm7CBDsBZSwUOUzpISAkk2iHKMORHdkSNMykzabstFuTvkHxP5SgiOZlfaJ01O6p3M6ZtJmDNvn2vjvWoNLAnEdVMhtAFPdyM8DNlt+BpvkWNmCYyR4y9urBoWjEgEAfvrTrldgubGbgDukXeRaJ3xr6jnQoeKlKhcPLnQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711041587; c=relaxed/simple; bh=q5Ux1I1rh/WfHaHpnSuErVTSeCb6Au9flA++b+omwdA=; h=Mime-Version:Content-Type:Date:Message-Id:To:Cc:Subject:From: References:In-Reply-To; b=iwc94ECD1SmgxXj+nfcbunrR1fYMw/6HwLcf3VVn/K8OGe037exkqqGF2FSWRrnwKTmIkWQWRDuI/p08hSyPQ75zaJM8VxpqCbFvhHpqZn+BeSGUjafEEm0iOAElyopbAA1R/ERDHxB/hup9ge1hF/eBgiOJjjHkZHoTJ/szbMY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NNUPr/Li; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E985C433C7; Thu, 21 Mar 2024 17:19:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711041587; bh=q5Ux1I1rh/WfHaHpnSuErVTSeCb6Au9flA++b+omwdA=; h=Date:To:Cc:Subject:From:References:In-Reply-To:From; b=NNUPr/LiWrA6Ry3kVWBnVqEzBXSm+kP20MHO20hbPF1whkfJb47I04sNczYUTezxc uuu0O+Kw3BtAke6EG2gzp1OhBGuzsDAd86XliztJVE0E5YqqjPYJRws13HvicYcray cvPyz+n06iwnEZ8kkwDuxAfwGlnRs+csp4B1lqZNrjxkd0csJehD0l8gj3H4hkz4dj rsVifdBtwnObaWKihuRApL+io1FIea25abQbevHYi4BDW91yQMuySHeUzAUBd5Q/bZ 1kbcYMo6CmB9Zzbj6f8r7bSN3ZbVDOKCp6jehQABEqOkdZIHUtmN/+fa0Nq1oJ0FJA /QJQ/EkitE39g== Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 21 Mar 2024 19:19:43 +0200 Message-Id: To: "Stefan Berger" , , , , Cc: , , , Subject: Re: [PATCH v7 10/13] crypto: ecdsa - Rename keylen to bufsize where necessary From: "Jarkko Sakkinen" X-Mailer: aerc 0.17.0 References: <20240320114725.1644921-1-stefanb@linux.ibm.com> <20240320114725.1644921-11-stefanb@linux.ibm.com> In-Reply-To: <20240320114725.1644921-11-stefanb@linux.ibm.com> On Wed Mar 20, 2024 at 1:47 PM EET, Stefan Berger wrote: > In cases where 'keylen' was referring to the size of the buffer used by > a curve's digits, it does not reflect the purpose of the variable anymore > once NIST P521 is used. What it refers to then is the size of the buffer, > which may be a few bytes larger than the size a coordinate of a key. > Therefore, rename keylen to bufsize where appropriate. > > Signed-off-by: Stefan Berger > Tested-by: Lukas Wunner > --- > crypto/ecdsa.c | 12 ++++++------ > 1 file changed, 6 insertions(+), 6 deletions(-) > > diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c > index 4daefb40c37a..4e847b59622a 100644 > --- a/crypto/ecdsa.c > +++ b/crypto/ecdsa.c > @@ -35,8 +35,8 @@ struct ecdsa_signature_ctx { > static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned cha= r tag, > const void *value, size_t vlen, unsigned int ndigits) > { > - size_t keylen =3D ndigits * sizeof(u64); > - ssize_t diff =3D vlen - keylen; > + size_t bufsize =3D ndigits * sizeof(u64); > + ssize_t diff =3D vlen - bufsize; > const char *d =3D value; > u8 rs[ECC_MAX_BYTES]; > =20 > @@ -58,7 +58,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdr= len, unsigned char tag, > if (diff) > return -EINVAL; > } > - if (-diff >=3D keylen) > + if (-diff >=3D bufsize) > return -EINVAL; > =20 > if (diff) { > @@ -138,7 +138,7 @@ static int ecdsa_verify(struct akcipher_request *req) > { > struct crypto_akcipher *tfm =3D crypto_akcipher_reqtfm(req); > struct ecc_ctx *ctx =3D akcipher_tfm_ctx(tfm); > - size_t keylen =3D ctx->curve->g.ndigits * sizeof(u64); > + size_t bufsize =3D ctx->curve->g.ndigits * sizeof(u64); > struct ecdsa_signature_ctx sig_ctx =3D { > .curve =3D ctx->curve, > }; > @@ -165,14 +165,14 @@ static int ecdsa_verify(struct akcipher_request *re= q) > goto error; > =20 > /* if the hash is shorter then we will add leading zeros to fit to ndig= its */ > - diff =3D keylen - req->dst_len; > + diff =3D bufsize - req->dst_len; > if (diff >=3D 0) { > if (diff) > memset(rawhash, 0, diff); > memcpy(&rawhash[diff], buffer + req->src_len, req->dst_len); > } else if (diff < 0) { > /* given hash is longer, we take the left-most bytes */ > - memcpy(&rawhash, buffer + req->src_len, keylen); > + memcpy(&rawhash, buffer + req->src_len, bufsize); > } > =20 > ecc_swap_digits((u64 *)rawhash, hash, ctx->curve->g.ndigits); Reviewed-by: Jarkko Sakkinen BR, Jarkko