Group related code together
This will be split to a new function next.
diff --git a/library/ecp.c b/library/ecp.c
index 987739f..c85b8ae 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -1389,7 +1389,7 @@
unsigned char w, m_is_odd, p_eq_g, pre_len, i;
size_t d;
unsigned char k[COMB_MAX_D + 1];
- mbedtls_ecp_point *T;
+ mbedtls_ecp_point *T = NULL;
mbedtls_mpi M, mm;
#if defined(MBEDTLS_ECP_EARLY_RETURN)
@@ -1405,6 +1405,15 @@
return( MBEDTLS_ERR_ECP_BAD_INPUT_DATA );
/*
+ * Make sure M is odd (M = m or M = N - m, since N is odd)
+ * using the fact that m * P = - (N - m) * P
+ */
+ m_is_odd = ( mbedtls_mpi_get_bit( m, 0 ) == 1 );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &M, m ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &mm, &grp->N, m ) );
+ MBEDTLS_MPI_CHK( mbedtls_mpi_safe_cond_assign( &M, &mm, ! m_is_odd ) );
+
+ /*
* Minimize the number of multiplications, that is minimize
* 10 * d * w + 18 * 2^(w-1) + 11 * d + 7 * w, with d = ceil( nbits / w )
* (see costs of the various parts, with 1S = 1M)
@@ -1463,15 +1472,6 @@
}
/*
- * Make sure M is odd (M = m or M = N - m, since N is odd)
- * using the fact that m * P = - (N - m) * P
- */
- m_is_odd = ( mbedtls_mpi_get_bit( m, 0 ) == 1 );
- MBEDTLS_MPI_CHK( mbedtls_mpi_copy( &M, m ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_sub_mpi( &mm, &grp->N, m ) );
- MBEDTLS_MPI_CHK( mbedtls_mpi_safe_cond_assign( &M, &mm, ! m_is_odd ) );
-
- /*
* Go for comb multiplication, R = M * P
*/
ecp_comb_fixed( k, d, w, &M );