Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1080156lqb; Wed, 29 May 2024 22:28:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVIBRStPkyPTlLhFcpW/p+UVXYgLmP5VQzDlmkOYMQYVQCrvZzWViVmn+g1XaWZbO78to7pV9IQnDrLuW6Gwg2zpYoO4+s6gig/oXZMPg== X-Google-Smtp-Source: AGHT+IGbNefebjdNOxR5zmCvTgKO1H1g02bN/LVUchwl8MF/Z6vfMZKP0pzz9E8dBbQAKrxgWT7M X-Received: by 2002:a05:6358:5119:b0:192:5cbd:ad35 with SMTP id e5c5f4694b2df-199b9861ad2mr73044155d.31.1717046939305; Wed, 29 May 2024 22:28:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717046939; cv=pass; d=google.com; s=arc-20160816; b=YbHDMmNvRw5Spgphfi6f3awDzADT9LgrNmL0yoP861MRE1C2zQFxKudIMNeFMyxLcr xCK+QiymvhCpD0n68CLI28gf8XPNNbKkB8+mMHzdKdE5ZL2yRAqtQ8ChsFMUfvu3L5k+ aF5uVOw1cfwpoNMMDNPcVgfcflwBiF77u02qR6DHRjKPL/evkXQHukwa/Y5kdwFJa2Nc FXgggw8IOJyx4R8OW5md7O0i2mY1r0T2H5JMizpkfijaNBcUV/cPvIOB8zOdmSkKzWpH V1K7ySpY8wLk0MZjpEwxZU/awVmKf0RHGIHjgRG2EiKwcLcau0kXbAUBQjLb+vm9mDEI 18vA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=g4Tg672VTvYgov0c/7rPfD1U7/xMJKSF8xsdRGIJzpc=; fh=WWjADH6PQAccBbhAzysZ23DVRdk4u8LQanecdgGdGwE=; b=SMg4Mlo6VvoqOeYXA8iuqoxuJHch4GsOhMkwkMEoq3bb+dO951VK1pqIR32WYHHVFD xyJLrjb/LfGcSpPytS1It6kfwTv6Hzd2uRW/ASJLqmrDS3tU3jzvpacdEiMmtXq+9SBL ebvC745FWZRgx/z9MM9vcsDOMerEb0a/ppkBn1N4kzQcNDrN8+lpnd6tMYK81BXruD7u JbhZzeZ7AsaCTJ0QERMQnLiunAOWMrT3OWy8bQl5Iethkn+N5Wa5ebl0+rlThGZq4fsD eOAn96tMUSek0aN0umxQhOeek/BSFM+3MwaJCL7w69vOxbNBstE0tJHzll66kzOro/qV ykLw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Id/Betoz"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4517-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4517-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6bee3c18b1fsi1129240a12.151.2024.05.29.22.28.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 22:28:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto+bounces-4517-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Id/Betoz"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-4517-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-crypto+bounces-4517-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id F1898B23250 for ; Thu, 30 May 2024 05:28:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45A4D143C4E; Thu, 30 May 2024 05:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Id/Betoz" 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 EDEA9143C49; Thu, 30 May 2024 05:28:49 +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=1717046930; cv=none; b=KrQMS95/sAkD5o0k1Lhb0wHA5oaXYkfldcnVkx3h/KUkS8xAwZGUR5ZQoWYbdKnraMileemV/l9u1yn9riD2zm6Owj9QZMSvovZURZZmdapMdMSGdUusqaEgpmC3TdQQPMeUC5wu4u4Mu8gRnFFQzLjcNhijBpyjkPU+DsS64T4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717046930; c=relaxed/simple; bh=cb4PAq0uFIPeKLQhiizJcOzIgfExkFZm+Cc9F71CdHQ=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=dxDXzEvt4nt+ht/NKLAyDDd/6EpTsOHJTiazMeFSFeDmllbwTWVH0le1/D1iEa7XYfAOeUXXOVshwOHvCVsVEgMEnmfWFw8leXxZGDzB+JdnLdiZimVUJbcHX/thff4goDaFFCgL5SD8PRfob5eoq0nXfUi2ei8kQvwIf8sHty8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Id/Betoz; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0ED7AC2BBFC; Thu, 30 May 2024 05:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717046929; bh=cb4PAq0uFIPeKLQhiizJcOzIgfExkFZm+Cc9F71CdHQ=; h=Date:Cc:Subject:From:To:References:In-Reply-To:From; b=Id/BetozTUhF1QSpRC9R0j5WmBAY8A9R1D5sunH7eU41t00laI+bTq3O8F256aHBh LKh+OSGprNc4tHRC6t2PU9W17wxiF+qbBNvSEtJcdV0qvt1MqrBwsWQDoB1mshOQn1 S9Uem30ggJKFBprURXhDRDasmaB5pfsh/QoVHGKFVo5YvWj2ROyVhEFsbyYrI45HOm rd+IGZgW8H4P18X8O9W0N/NMI2HJOFhf3YRiMQLMrJU+7JgSeZQSaKdaWSEF8kEvfJ HWhkbo8GCktmZx26PQhd52t58Tn8uTOfPprpiQ6oUb8snQTuIBvBRLYWfwEgq8X3yZ FMWlh1CmV7KIw== 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, 30 May 2024 08:28:43 +0300 Message-Id: Cc: , Subject: Re: [PATCH 2/2] crypto: ecdsa - Use ecc_digits_from_bytes to convert signature From: "Jarkko Sakkinen" To: "Stefan Berger" , , , , X-Mailer: aerc 0.17.0 References: <20240529230827.379111-1-stefanb@linux.ibm.com> <20240529230827.379111-3-stefanb@linux.ibm.com> In-Reply-To: <20240529230827.379111-3-stefanb@linux.ibm.com> On Thu May 30, 2024 at 2:08 AM EEST, Stefan Berger wrote: > Since ecc_digits_from_bytes will provide zeros when an insufficient numbe= r > of bytes are passed in the input byte array, use it to convert the r and = s > components of the signature to digits directly from the input byte > array. This avoids going through an intermediate byte array that has the > first few bytes filled with zeros. > > Signed-off-by: Stefan Berger > --- > crypto/ecdsa.c | 12 ++---------- > 1 file changed, 2 insertions(+), 10 deletions(-) > > diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c > index fa029f36110b..941cdc2b889b 100644 > --- a/crypto/ecdsa.c > +++ b/crypto/ecdsa.c > @@ -38,7 +38,6 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdr= len, unsigned char tag, > size_t bufsize =3D ndigits * sizeof(u64); > ssize_t diff =3D vlen - bufsize; > const char *d =3D value; > - u8 rs[ECC_MAX_BYTES]; > =20 > if (!value || !vlen) > return -EINVAL; > @@ -46,7 +45,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdr= len, unsigned char tag, > /* diff =3D 0: 'value' has exacly the right size > * diff > 0: 'value' has too many bytes; one leading zero is allowed th= at > * makes the value a positive integer; error on more > - * diff < 0: 'value' is missing leading zeros, which we add > + * diff < 0: 'value' is missing leading zeros > */ > if (diff > 0) { > /* skip over leading zeros that make 'value' a positive int */ > @@ -61,14 +60,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hd= rlen, unsigned char tag, > if (-diff >=3D bufsize) > return -EINVAL; > =20 > - if (diff) { > - /* leading zeros not given in 'value' */ > - memset(rs, 0, -diff); > - } > - > - memcpy(&rs[-diff], d, vlen); > - > - ecc_swap_digits((u64 *)rs, dest, ndigits); > + ecc_digits_from_bytes(d, vlen, dest, ndigits); > =20 > return 0; > } Reviewed-by: Jarkko Sakkinen BR, Jarkko