Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: ecdsa - Extend res.x mod n calculation for NIST P521

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

Tested-by: Lukas Wunner <lukas@wunner.de>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Stefan Berger and committed by
Herbert Xu
48e8d3a5 dcee6068

+1 -1
+1 -1
crypto/ecdsa.c
··· 122 122 123 123 /* res.x = res.x mod n (if res.x > order) */ 124 124 if (unlikely(vli_cmp(res.x, curve->n, ndigits) == 1)) 125 - /* faster alternative for NIST p384, p256 & p192 */ 125 + /* faster alternative for NIST p521, p384, p256 & p192 */ 126 126 vli_sub(res.x, res.x, curve->n, ndigits); 127 127 128 128 if (!vli_cmp(res.x, r, ndigits))