crypto: ecc - Prevent ecc_digits_from_bytes from reading too many bytes
authorStefan Berger <stefanb@linux.ibm.com>
Fri, 10 May 2024 01:59:21 +0000 (21:59 -0400)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 17 May 2024 10:55:07 +0000 (18:55 +0800)
commitc6ab5c915da460c0397960af3c308386c3f3247b
treec717a821b8783d5f6f7371fc4c65ea0a5a6d74d5
parentd3b17c6d9dddc2db3670bc9be628b122416a3d26
crypto: ecc - Prevent ecc_digits_from_bytes from reading too many bytes

Prevent ecc_digits_from_bytes from reading too many bytes from the input
byte array in case an insufficient number of bytes is provided to fill the
output digit array of ndigits. Therefore, initialize the most significant
digits with 0 to avoid trying to read too many bytes later on. Convert the
function into a regular function since it is getting too big for an inline
function.

If too many bytes are provided on the input byte array the extra bytes
are ignored since the input variable 'ndigits' limits the number of digits
that will be filled.

Fixes: d67c96fb97b5 ("crypto: ecdsa - Convert byte arrays with key coordinates to digits")
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>
crypto/ecc.c
include/crypto/internal/ecc.h