From 235c1947fb668a58646f13ddd3e0efdecb35a527 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 16 May 2023 15:51:23 +0100 Subject: [PATCH] Group memory allocations earlier Signed-off-by: Paul Elliott --- library/ecp_curves.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/ecp_curves.c b/library/ecp_curves.c index 6c588f713..2bbec41e2 100644 --- a/library/ecp_curves.c +++ b/library/ecp_curves.c @@ -5508,6 +5508,13 @@ int mbedtls_ecp_mod_p448(mbedtls_mpi_uint *X, size_t X_limbs) return MBEDTLS_ERR_ECP_ALLOC_FAILED; } + mbedtls_mpi_uint *Q = mbedtls_calloc(Q_limbs, ciL); + + if (Q == NULL) { + ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; + goto cleanup; + } + /* M = A1 */ memset(M, 0, (M_limbs * ciL)); @@ -5524,13 +5531,6 @@ int mbedtls_ecp_mod_p448(mbedtls_mpi_uint *X, size_t X_limbs) (void) mbedtls_mpi_core_add(X, X, M, M_limbs); /* Q = B1, N += B1 */ - mbedtls_mpi_uint *Q = mbedtls_calloc(Q_limbs, ciL); - - if (Q == NULL) { - ret = MBEDTLS_ERR_ECP_ALLOC_FAILED; - goto cleanup; - } - memcpy(Q, M, (Q_limbs * ciL)); mbedtls_mpi_core_shift_r(Q, Q_limbs, 224);