From 31f0b452c7b76531ff1d6cf1851ae159f76d1b3c Mon Sep 17 00:00:00 2001 From: Minos Galanakis Date: Thu, 18 May 2023 11:08:50 +0100 Subject: [PATCH] ecp_curves: Reintroduced input checking for Signed-off-by: Minos Galanakis --- library/ecp_curves.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/library/ecp_curves.c b/library/ecp_curves.c index 16800aadc8..1808152920 100644 --- a/library/ecp_curves.c +++ b/library/ecp_curves.c @@ -5431,6 +5431,13 @@ cleanup: MBEDTLS_STATIC_TESTABLE int mbedtls_ecp_mod_p255_raw(mbedtls_mpi_uint *X, size_t X_Limbs) { + + if (X_Limbs > 2*P255_WIDTH) { + X_Limbs = 2*P255_WIDTH; + } else if (X_Limbs < P255_WIDTH) { + return 0; + } + mbedtls_mpi_uint *carry = mbedtls_calloc(P255_WIDTH, ciL); if (carry == NULL) { return MBEDTLS_ERR_ECP_ALLOC_FAILED;