Allocate the right amount of memory

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
Gabor Mezei 2023-04-26 15:22:11 +02:00
parent fead53311b
commit 19c6f47dbc
No known key found for this signature in database
GPG key ID: FEE76C0CF8C6267D

View file

@ -5538,19 +5538,19 @@ static inline int ecp_mod_koblitz(mbedtls_mpi_uint *X,
{
int ret = 0;
size_t R_limbs = P_KOBLITZ_R;
size_t M_limbs = X_limbs + R_limbs + adjust;
mbedtls_mpi_uint *M = mbedtls_calloc(M_limbs, ciL);
if (M == NULL) {
return MBEDTLS_ERR_ECP_ALLOC_FAILED;
}
size_t A1_limbs = X_limbs - (P_limbs - adjust);
if (A1_limbs > P_limbs + adjust) {
A1_limbs = P_limbs + adjust;
}
mbedtls_mpi_uint *A1 = mbedtls_calloc(A1_limbs, ciL);
if (A1 == NULL) {
return MBEDTLS_ERR_ECP_ALLOC_FAILED;
}
size_t R_limbs = P_KOBLITZ_R;
size_t M_limbs = A1_limbs + R_limbs;
mbedtls_mpi_uint *M = mbedtls_calloc(M_limbs, ciL);
if (M == NULL) {
ret = MBEDTLS_ERR_ECP_ALLOC_FAILED;
goto cleanup;
}