From: "Jarkko Sakkinen" <jarkko@kernel.org>
To: "Stefan Berger" <stefanb@linux.ibm.com>,
<keyrings@vger.kernel.org>, <linux-crypto@vger.kernel.org>,
<herbert@gondor.apana.org.au>, <davem@davemloft.net>
Cc: <linux-kernel@vger.kernel.org>, <lukas@wunner.de>
Subject: Re: [PATCH 2/2] crypto: ecdsa - Use ecc_digits_from_bytes to convert signature
Date: Thu, 30 May 2024 08:28:43 +0300 [thread overview]
Message-ID: <D1MQC3CFQVE0.W19B0918DT1I@kernel.org> (raw)
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 number
> 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 <stefanb@linux.ibm.com>
> ---
> 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 hdrlen, unsigned char tag,
> size_t bufsize = ndigits * sizeof(u64);
> ssize_t diff = vlen - bufsize;
> const char *d = value;
> - u8 rs[ECC_MAX_BYTES];
>
> if (!value || !vlen)
> return -EINVAL;
> @@ -46,7 +45,7 @@ static int ecdsa_get_signature_rs(u64 *dest, size_t hdrlen, unsigned char tag,
> /* diff = 0: 'value' has exacly the right size
> * diff > 0: 'value' has too many bytes; one leading zero is allowed that
> * 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 hdrlen, unsigned char tag,
> if (-diff >= bufsize)
> return -EINVAL;
>
> - 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);
>
> return 0;
> }
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
next prev parent reply other threads:[~2024-05-30 5:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-29 23:08 [PATCH 0/2] ecdsa: Use ecc_digits_from_bytes to simplify code Stefan Berger
2024-05-29 23:08 ` [PATCH 1/2] crypto: ecdsa - Use ecc_digits_from_bytes to create hash digits array Stefan Berger
2024-05-30 5:28 ` Jarkko Sakkinen
2024-05-30 12:24 ` Stefan Berger
2024-06-04 16:31 ` Jarkko Sakkinen
2024-05-29 23:08 ` [PATCH 2/2] crypto: ecdsa - Use ecc_digits_from_bytes to convert signature Stefan Berger
2024-05-30 5:28 ` Jarkko Sakkinen [this message]
2024-05-30 5:08 ` [PATCH 0/2] ecdsa: Use ecc_digits_from_bytes to simplify code Jarkko Sakkinen
2024-05-30 12:16 ` Stefan Berger
2024-06-04 16:30 ` Jarkko Sakkinen
2024-06-07 11:55 ` Herbert Xu
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=D1MQC3CFQVE0.W19B0918DT1I@kernel.org \
--to=jarkko@kernel.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=stefanb@linux.ibm.com \
/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