From: Stefan Berger <stefanb@linux.ibm.com>
To: herbert@gondor.apana.org.au, davem@davemloft.net,
linux-crypto@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] ecdsa: Fix incorrect usage of vli_cmp
Date: Tue, 26 Apr 2022 13:53:16 -0400 [thread overview]
Message-ID: <a22345e8-92a5-687e-4940-ac7b9dcc7c2f@linux.ibm.com> (raw)
In-Reply-To: <20220421185740.799271-1-stefanb@linux.ibm.com>
On 4/21/22 14:57, Stefan Berger wrote:
> Fix incorrect usage of vli_cmp when calculating the value of res.x. For
> signature verification to succeed, res.x must be the same as the r
> component of the signature which is in the range of [1..n-1] with 'n'
> being the order of the curve. Therefore, when res.x equals n calculate
> res.x = res.x - n as well. Signature verification could have previously
> unnecessarily failed in extremely rare cases.
Actually, I am withdrawing this patch. Before this patch res.x could
equal 'n' and then wouldn't match r due to the range of r being
[1..n-1]. Now if res.x equals 'n' then res.x - n will be 0 and again
will not match 'r' due to the range of r being [1..n-1]. So it makes no
difference whether vli_cmp() == 1 or vli_cmp() >= 1 and the concern
above about rare cases not verifying the signature is wrong.
Stefan
>
> Fixes: 4e6602916bc6 ("crypto: ecdsa - Add support for ECDSA signature verification")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> ---
> crypto/ecdsa.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c
> index b3a8a6b572ba..674ab9275366 100644
> --- a/crypto/ecdsa.c
> +++ b/crypto/ecdsa.c
> @@ -120,8 +120,8 @@ static int _ecdsa_verify(struct ecc_ctx *ctx, const u64 *hash, const u64 *r, con
> /* res = u1*G + u2 * pub_key */
> ecc_point_mult_shamir(&res, u1, &curve->g, u2, &ctx->pub_key, curve);
>
> - /* res.x = res.x mod n (if res.x > order) */
> - if (unlikely(vli_cmp(res.x, curve->n, ndigits) == 1))
> + /* res.x = res.x mod n (if res.x >= order) */
> + if (unlikely(vli_cmp(res.x, curve->n, ndigits) >= 0))
> /* faster alternative for NIST p384, p256 & p192 */
> vli_sub(res.x, res.x, curve->n, ndigits);
>
prev parent reply other threads:[~2022-04-26 17:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-21 18:57 Stefan Berger
2022-04-26 17:53 ` Stefan Berger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a22345e8-92a5-687e-4940-ac7b9dcc7c2f@linux.ibm.com \
--to=stefanb@linux.ibm.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®