diff mbox series

[v6,07/13] crypto: ecc - Add special case for NIST P521 in ecc_point_mult

Message ID 20240312183618.1211745-8-stefanb@linux.vnet.ibm.com (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show
Series Add support for NIST P521 to ecdsa | expand

Commit Message

Stefan Berger March 12, 2024, 6:36 p.m. UTC
From: Stefan Berger <stefanb@linux.ibm.com>

In ecc_point_mult use the number of bits of the NIST P521 curve + 2. The
change is required specifically for NIST P521 to pass mathematical tests
on the public key.

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

Comments

Jarkko Sakkinen March 18, 2024, 8:50 p.m. UTC | #1
On Tue Mar 12, 2024 at 8:36 PM EET, Stefan Berger wrote:
> From: Stefan Berger <stefanb@linux.ibm.com>
>
> In ecc_point_mult use the number of bits of the NIST P521 curve + 2. The
> change is required specifically for NIST P521 to pass mathematical tests
> on the public key.
>
> Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
> Tested-by: Lukas Wunner <lukas@wunner.de>
> ---
>  crypto/ecc.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/crypto/ecc.c b/crypto/ecc.c
> index 99d41887c005..ead40b5ebb46 100644
> --- a/crypto/ecc.c
> +++ b/crypto/ecc.c
> @@ -1320,7 +1320,10 @@ static void ecc_point_mult(struct ecc_point *result,
>  	carry = vli_add(sk[0], scalar, curve->n, ndigits);
>  	vli_add(sk[1], sk[0], curve->n, ndigits);
>  	scalar = sk[!carry];
> -	num_bits = sizeof(u64) * ndigits * 8 + 1;
> +	if (curve->nbits == 521)	/* NIST P521 */
> +		num_bits = curve->nbits + 2;
> +	else
> +		num_bits = sizeof(u64) * ndigits * 8 + 1;
>  
>  	vli_set(rx[1], point->x, ndigits);
>  	vli_set(ry[1], point->y, ndigits);


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

BR, Jarkko
diff mbox series

Patch

diff --git a/crypto/ecc.c b/crypto/ecc.c
index 99d41887c005..ead40b5ebb46 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -1320,7 +1320,10 @@  static void ecc_point_mult(struct ecc_point *result,
 	carry = vli_add(sk[0], scalar, curve->n, ndigits);
 	vli_add(sk[1], sk[0], curve->n, ndigits);
 	scalar = sk[!carry];
-	num_bits = sizeof(u64) * ndigits * 8 + 1;
+	if (curve->nbits == 521)	/* NIST P521 */
+		num_bits = curve->nbits + 2;
+	else
+		num_bits = sizeof(u64) * ndigits * 8 + 1;
 
 	vli_set(rx[1], point->x, ndigits);
 	vli_set(ry[1], point->y, ndigits);