mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-08 10:09:54 +00:00
Group related code together
This will be split to a new function next.
This commit is contained in:
parent
510d5caece
commit
7306dff01f
|
@ -1389,7 +1389,7 @@ static int ecp_mul_comb( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
|||
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)
|
||||
|
@ -1404,6 +1404,15 @@ static int ecp_mul_comb( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
|||
if( mbedtls_mpi_get_bit( &grp->N, 0 ) != 1 )
|
||||
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 )
|
||||
|
@ -1462,15 +1471,6 @@ static int ecp_mul_comb( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue