From 83ed69871355f2eca80d6fc5d3db9cb6b03c2e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Fri, 10 Apr 2026 10:01:11 +0200 Subject: [PATCH] ecp: align mbedtls_ecp_mod_p448_raw() with others MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The size checks were wrong, and the removed comment was misleading: this is not about tests, it's just the normal way to wrap a "new bignum" (aka "raw") function, that expects a fixed number of limbs, to a "legacy bignum" function, that accepts any size (and allocates). Also, this aligns ecp_mod_p448() and mbedtls_ecp_mod_p448_raw() with all other ecp_mod_pXXX() and mbedtls_ecp_mod_pXXX_raw() functions. Signed-off-by: Manuel Pégourié-Gonnard --- library/ecp_curves.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/library/ecp_curves.c b/library/ecp_curves.c index e2cd7c648e..7f5622db88 100644 --- a/library/ecp_curves.c +++ b/library/ecp_curves.c @@ -5476,14 +5476,8 @@ static int ecp_mod_p448(mbedtls_mpi *N) { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; size_t expected_width = BITS_TO_LIMBS(448) * 2; - - /* This is required as some tests and use cases do not pass in a Bignum of - * the correct size, and expect the growth to be done automatically, which - * will no longer happen. */ MBEDTLS_MPI_CHK(mbedtls_mpi_grow(N, expected_width)); - - ret = mbedtls_ecp_mod_p448_raw(N->p, N->n); - + ret = mbedtls_ecp_mod_p448_raw(N->p, expected_width); cleanup: return ret; } @@ -5506,18 +5500,11 @@ int mbedtls_ecp_mod_p448_raw(mbedtls_mpi_uint *X, size_t X_limbs) int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; if (X_limbs != BITS_TO_LIMBS(448) * 2) { - return 0; - } - - size_t M_limbs = X_limbs - (P448_WIDTH); - - if (M_limbs > P448_WIDTH) { - /* Shouldn't be called with X larger than 2^896! */ return MBEDTLS_ERR_ECP_BAD_INPUT_DATA; } /* Both M and Q require an extra limb to catch carries. */ - M_limbs++; + size_t M_limbs = BITS_TO_LIMBS(448) + 1; const size_t Q_limbs = M_limbs; mbedtls_mpi_uint *M = NULL;