diff mbox series

[v7,09/13] crypto: ecdsa - Replace ndigits with nbits where precision is needed

Message ID 20240320114725.1644921-10-stefanb@linux.ibm.com (mailing list archive)
State New
Headers show
Series [v7,01/13] crypto: ecc - Use ECC_CURVE_NIST_P192/256/384_DIGITS where possible | expand

Commit Message

Stefan Berger March 20, 2024, 11:47 a.m. UTC
Replace the usage of ndigits with nbits where precise space calculations
are needed, such as in ecdsa_max_size where the length of a coordinate is
determined.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Tested-by: Lukas Wunner <lukas@wunner.de>
---
 crypto/ecdsa.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jarkko Sakkinen March 21, 2024, 5:19 p.m. UTC | #1
On Wed Mar 20, 2024 at 1:47 PM EET, Stefan Berger wrote:
> Replace the usage of ndigits with nbits where precise space calculations
> are needed, such as in ecdsa_max_size where the length of a coordinate is
> determined.
>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> Tested-by: Lukas Wunner <lukas@wunner.de>
> ---
>  crypto/ecdsa.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c
> index 1814f009f971..4daefb40c37a 100644
> --- a/crypto/ecdsa.c
> +++ b/crypto/ecdsa.c
> @@ -266,7 +266,7 @@ static unsigned int ecdsa_max_size(struct crypto_akcipher *tfm)
>  {
>  	struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm);
>  
> -	return ctx->pub_key.ndigits << ECC_DIGITS_TO_BYTES_SHIFT;
> +	return DIV_ROUND_UP(ctx->curve->nbits, 8);
>  }
>  
>  static int ecdsa_nist_p384_init_tfm(struct crypto_akcipher *tfm)

Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>

BR, Jarkko
diff mbox series

Patch

diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c
index 1814f009f971..4daefb40c37a 100644
--- a/crypto/ecdsa.c
+++ b/crypto/ecdsa.c
@@ -266,7 +266,7 @@  static unsigned int ecdsa_max_size(struct crypto_akcipher *tfm)
 {
 	struct ecc_ctx *ctx = akcipher_tfm_ctx(tfm);
 
-	return ctx->pub_key.ndigits << ECC_DIGITS_TO_BYTES_SHIFT;
+	return DIV_ROUND_UP(ctx->curve->nbits, 8);
 }
 
 static int ecdsa_nist_p384_init_tfm(struct crypto_akcipher *tfm)