All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Wunner <lukas@wunner.de>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: "David S. Miller" <davem@davemloft.net>,
	Stefan Berger <stefanb@linux.ibm.com>,
	Vitaly Chikunov <vt@altlinux.org>,
	David Howells <dhowells@redhat.com>,
	Ignat Korchagin <ignat@cloudflare.com>,
	linux-crypto@vger.kernel.org, keyrings@vger.kernel.org,
	Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [PATCH 3/3] crypto: ecdsa - Fix NIST P521 key size reported by KEYCTL_PKEY_QUERY
Date: Sat, 4 Jan 2025 12:31:19 +0100	[thread overview]
Message-ID: <Z3kcB6ouES8RzOwf@wunner.de> (raw)
In-Reply-To: <Z3iElsILmoSu6FuC@gondor.apana.org.au>

On Sat, Jan 04, 2025 at 08:45:10AM +0800, Herbert Xu wrote:
> On Thu, Dec 26, 2024 at 07:08:03PM +0100, Lukas Wunner wrote:
> >
> > diff --git a/crypto/ecdsa-p1363.c b/crypto/ecdsa-p1363.c
> > index eaae7214d69b..c4f458df18ed 100644
> > --- a/crypto/ecdsa-p1363.c
> > +++ b/crypto/ecdsa-p1363.c
> > @@ -21,7 +21,7 @@ static int ecdsa_p1363_verify(struct crypto_sig *tfm,
> >  			      const void *digest, unsigned int dlen)
> >  {
> >  	struct ecdsa_p1363_ctx *ctx = crypto_sig_ctx(tfm);
> > -	unsigned int keylen = crypto_sig_keysize(ctx->child);
> > +	unsigned int keylen = DIV_ROUND_UP(crypto_sig_keysize(ctx->child), 8);
> 
> This may overflow unnecessarily, please rewrite these as:
> 
> 	X / 8 + !!(X & 7)

Interesting.  Wouldn't it make sense to have a DIV_ROUND_UP_SAFE() macro
for cases like this?

I'd expect this version to actually be faster than DIV_ROUND_UP():
There's the extra logical AND, as well as the negation.
But the "n / d" and "!!(n & (d - 1))" can be computed in parallel.

Thanks,

Lukas

      reply	other threads:[~2025-01-04 11:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-26 18:08 [PATCH 0/3] ecdsa KEYCTL_PKEY_QUERY fixes Lukas Wunner
2024-12-26 18:08 ` [PATCH 1/3] crypto: sig - Prepare for algorithms with variable signature size Lukas Wunner
2025-01-02 15:06   ` Stefan Berger
2024-12-26 18:08 ` [PATCH 2/3] crypto: ecdsa - Fix enc/dec size reported by KEYCTL_PKEY_QUERY Lukas Wunner
2025-01-02 14:09   ` Stefan Berger
2024-12-26 18:08 ` [PATCH 3/3] crypto: ecdsa - Fix NIST P521 key " Lukas Wunner
2025-01-02 17:45   ` Stefan Berger
2025-01-03 17:38     ` Lukas Wunner
2025-01-03 18:06       ` Stefan Berger
2025-01-04  0:45   ` Herbert Xu
2025-01-04 11:31     ` Lukas Wunner [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=Z3kcB6ouES8RzOwf@wunner.de \
    --to=lukas@wunner.de \
    --cc=dan.carpenter@linaro.org \
    --cc=davem@davemloft.net \
    --cc=dhowells@redhat.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=ignat@cloudflare.com \
    --cc=keyrings@vger.kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=stefanb@linux.ibm.com \
    --cc=vt@altlinux.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.