lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <CZZLJ4ND05DX.27IUNFT505Z9R@kernel.org>
Date: Thu, 21 Mar 2024 19:15:32 +0200
From: "Jarkko Sakkinen" <jarkko@...nel.org>
To: "Stefan Berger" <stefanb@...ux.ibm.com>, <keyrings@...r.kernel.org>,
 <linux-crypto@...r.kernel.org>, <herbert@...dor.apana.org.au>,
 <davem@...emloft.net>
Cc: <linux-kernel@...r.kernel.org>, <saulo.alessandre@....jus.br>,
 <lukas@...ner.de>, <bbhushan2@...vell.com>
Subject: Re: [PATCH v7 04/13] crypto: ecdsa - Extend res.x mod n calculation
 for NIST P521

On Wed Mar 20, 2024 at 1:47 PM EET, Stefan Berger wrote:
> res.x has been calculated by ecc_point_mult_shamir, which uses
> 'mod curve_prime' on res.x and therefore p > res.x with 'p' being the
> curve_prime. Further, it is true that for the NIST curves p > n with 'n'
> being the 'curve_order' and therefore the following may be true as well:
> p > res.x >= n.
>
> If res.x >= n then res.x mod n can be calculated by iteratively sub-
> tracting n from res.x until res.x < n. For NIST P192/256/384 this can be
> done in a single subtraction. This can also be done in a single
> subtraction for NIST P521.
>
> The mathematical reason why a single subtraction is sufficient is due to
> the values of 'p' and 'n' of the NIST curves where the following holds
> true:
>
>    note: max(res.x) = p - 1
>
>    max(res.x) - n < n
>        p - 1  - n < n
>        p - 1      < 2n  => holds true for the NIST curves
>
> Signed-off-by: Stefan Berger <stefanb@...ux.ibm.com>
> Tested-by: Lukas Wunner <lukas@...ner.de>
> ---
>  crypto/ecdsa.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/crypto/ecdsa.c b/crypto/ecdsa.c
> index 64e1e69d53ba..1814f009f971 100644
> --- a/crypto/ecdsa.c
> +++ b/crypto/ecdsa.c
> @@ -122,7 +122,7 @@ static int _ecdsa_verify(struct ecc_ctx *ctx, const u64 *hash, const u64 *r, con
>  
>  	/* res.x = res.x mod n (if res.x > order) */
>  	if (unlikely(vli_cmp(res.x, curve->n, ndigits) == 1))
> -		/* faster alternative for NIST p384, p256 & p192 */
> +		/* faster alternative for NIST p521, p384, p256 & p192 */
>  		vli_sub(res.x, res.x, curve->n, ndigits);
>  
>  	if (!vli_cmp(res.x, r, ndigits))


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

BR, Jarkko

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ