summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.ibm.com>2024-04-04 16:18:50 +0200
committerHerbert Xu <herbert@gondor.apana.org.au>2024-04-12 09:07:52 +0200
commit114e80437e0e48b967d0bd533a4c8ff1186ce12f (patch)
treea60b37a701fca4729a0c5af6f0ec34bbce7a835a /crypto
parentcrypto: ecc - Implement vli_mmod_fast_521 for NIST p521 (diff)
downloadlinux-114e80437e0e48b967d0bd533a4c8ff1186ce12f.tar.xz
linux-114e80437e0e48b967d0bd533a4c8ff1186ce12f.zip
crypto: ecc - Add special case for NIST P521 in ecc_point_mult
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. 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>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/ecc.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/crypto/ecc.c b/crypto/ecc.c
index 8914e437f94b..d15ef0747a76 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);