diff --git a/include/mbedtls/ecp_internal.h b/include/mbedtls/ecp_internal.h index 46e595a65..eda07badd 100644 --- a/include/mbedtls/ecp_internal.h +++ b/include/mbedtls/ecp_internal.h @@ -26,56 +26,54 @@ #if defined(MBEDTLS_ECP_FUNCTION_ALT) -unsigned char mbedtls_ecp_alt_grp_capable( const mbedtls_ecp_group *grp ); +unsigned char mbedtls_int_ecp_grp_capable( const mbedtls_ecp_group *grp ); -#if defined(MBEDTLS_ECP_INIT_ALT) -int mbedtls_ecp_alt_init( const mbedtls_ecp_group *grp ); -#endif +int mbedtls_int_ecp_init( const mbedtls_ecp_group *grp ); -#if defined(MBEDTLS_ECP_DEINIT_ALT) -void mbedtls_ecp_alt_deinit( const mbedtls_ecp_group *grp ); -#endif +void mbedtls_int_ecp_deinit( const mbedtls_ecp_group *grp ); #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) -int mbedtls_ecp_randomize_jac_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ); +int mbedtls_int_ecp_randomize_jac( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *pt, int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); #endif #if defined(MBEDTLS_ECP_ADD_MIXED_ALT) -int mbedtls_ecp_add_mixed_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, - const mbedtls_ecp_point *P, const mbedtls_ecp_point *Q ); +int mbedtls_int_ecp_add_mixed( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *R, const mbedtls_ecp_point *P, + const mbedtls_ecp_point *Q ); #endif #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) -int mbedtls_ecp_double_jac_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, - const mbedtls_ecp_point *P ); +int mbedtls_int_ecp_double_jac( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *R, const mbedtls_ecp_point *P ); #endif #if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) -int mbedtls_ecp_normalize_jac_many_alt( const mbedtls_ecp_group *grp, - mbedtls_ecp_point *T[], size_t t_len ); +int mbedtls_int_ecp_normalize_jac_many( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *T[], size_t t_len ); #endif #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) -int mbedtls_ecp_normalize_jac_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *pt ); +int mbedtls_int_ecp_normalize_jac( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *pt ); #endif #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) -int mbedtls_ecp_double_add_mxz_alt( const mbedtls_ecp_group *grp, - mbedtls_ecp_point *R, mbedtls_ecp_point *S, - const mbedtls_ecp_point *P, - const mbedtls_ecp_point *Q, const mbedtls_mpi *d ); +int mbedtls_int_ecp_double_add_mxz( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *R, mbedtls_ecp_point *S, const mbedtls_ecp_point *P, + const mbedtls_ecp_point *Q, const mbedtls_mpi *d ); #endif #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) -int mbedtls_ecp_randomize_mxz_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P, - int (*f_rng)(void *, unsigned char *, size_t), - void *p_rng ); +int mbedtls_int_ecp_randomize_mxz( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *P, int (*f_rng)(void *, unsigned char *, size_t), + void *p_rng ); #endif #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) -int mbedtls_ecp_normalize_mxz_alt( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P ); +int mbedtls_int_ecp_normalize_mxz( const mbedtls_ecp_group *grp, + mbedtls_ecp_point *P ); #endif #endif /* MBEDTLS_ECP_FUNCTION_ALT */ diff --git a/library/ecp.c b/library/ecp.c index 6d8c89777..cf57a6be5 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -754,9 +754,9 @@ static int ecp_normalize_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *p return( 0 ); #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - return mbedtls_ecp_normalize_jac_alt( grp, pt ); + return mbedtls_int_ecp_normalize_jac( grp, pt ); } #endif /* MBEDTLS_ECP_NORMALIZE_JAC_ALT */ mbedtls_mpi_init( &Zi ); mbedtls_mpi_init( &ZZi ); @@ -808,9 +808,9 @@ static int ecp_normalize_jac_many( const mbedtls_ecp_group *grp, return( ecp_normalize_jac( grp, *T ) ); #if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - return mbedtls_ecp_normalize_jac_many_alt(grp, T, t_len); + return mbedtls_int_ecp_normalize_jac_many(grp, T, t_len); } #endif @@ -931,9 +931,9 @@ static int ecp_double_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, #endif #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - return mbedtls_ecp_double_jac_alt( grp, R, P ); + return mbedtls_int_ecp_double_jac( grp, R, P ); } #endif /* MBEDTLS_ECP_DOUBLE_JAC_ALT */ @@ -1029,9 +1029,9 @@ static int ecp_add_mixed( const mbedtls_ecp_group *grp, mbedtls_ecp_point *R, #endif #if defined(MBEDTLS_ECP_ADD_MIXED_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - return mbedtls_ecp_add_mixed_alt( grp, R, P, Q ); + return mbedtls_int_ecp_add_mixed( grp, R, P, Q ); } #endif /* MBEDTLS_ECP_ADD_MIXED_ALT */ @@ -1116,9 +1116,9 @@ static int ecp_randomize_jac( const mbedtls_ecp_group *grp, mbedtls_ecp_point *p int count = 0; #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - return mbedtls_ecp_randomize_jac_alt( grp, pt, f_rng, p_rng ); + return mbedtls_int_ecp_randomize_jac( grp, pt, f_rng, p_rng ); } #endif /* MBEDTLS_ECP_RANDOMIZE_JAC_ALT */ @@ -1484,9 +1484,9 @@ static int ecp_normalize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P int ret; #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - return mbedtls_ecp_normalize_mxz_alt( grp, P ); + return mbedtls_int_ecp_normalize_mxz( grp, P ); } #endif /* MBEDTLS_ECP_NORMALIZE_MXZ_ALT */ @@ -1515,9 +1515,9 @@ static int ecp_randomize_mxz( const mbedtls_ecp_group *grp, mbedtls_ecp_point *P int count = 0; #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - return mbedtls_ecp_randomize_mxz_alt( grp, P, f_rng, p_rng ); + return mbedtls_int_ecp_randomize_mxz( grp, P, f_rng, p_rng ); } #endif /* MBEDTLS_ECP_RANDOMIZE_MXZ_ALT */ @@ -1570,9 +1570,9 @@ static int ecp_double_add_mxz( const mbedtls_ecp_group *grp, mbedtls_mpi A, AA, B, BB, E, C, D, DA, CB; #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - return mbedtls_ecp_double_add_mxz_alt( grp, R, S, P, Q, d ); + return mbedtls_int_ecp_double_add_mxz( grp, R, S, P, Q, d ); } #endif /* MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT */ @@ -1686,18 +1686,18 @@ int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, ( ret = mbedtls_ecp_check_pubkey( grp, P ) ) != 0 ) return( ret ); -#if defined(MBEDTLS_ECP_FUNCTION_ALT) && defined(MBEDTLS_THREADING_C) +#if defined(MBEDTLS_ECP_FUNCTION_ALT) +#if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_lock( &mbedtls_threading_cryptohw_asym_mutex ) != 0 ) return ( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); #endif -#if defined(MBEDTLS_ECP_INIT_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - MBEDTLS_MPI_CHK( mbedtls_ecp_alt_init( grp ) ); + MBEDTLS_MPI_CHK( mbedtls_int_ecp_init( grp ) ); } -#endif +#endif /* MBEDTLS_ECP_FUNCTION_ALT */ #if defined(ECP_MONTGOMERY) if( ecp_get_type( grp ) == ECP_TYPE_MONTGOMERY ) ret = ecp_mul_mxz( grp, R, m, P, f_rng, p_rng ); @@ -1708,22 +1708,20 @@ int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, ret = ecp_mul_comb( grp, R, m, P, f_rng, p_rng ); #endif -#if defined(MBEDTLS_ECP_INIT_ALT) +#if defined(MBEDTLS_ECP_FUNCTION_ALT) cleanup: -#endif -#if defined(MBEDTLS_ECP_DEINIT_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - mbedtls_ecp_alt_deinit( grp ); + mbedtls_int_ecp_deinit( grp ); } -#endif -#if defined(MBEDTLS_ECP_FUNCTION_ALT) && defined(MBEDTLS_THREADING_C) +#if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &mbedtls_threading_cryptohw_asym_mutex ) != 0 ) return ( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); #endif +#endif /* MBEDTLS_ECP_FUNCTION_ALT */ return( ret ); } @@ -1826,35 +1824,35 @@ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R, MBEDTLS_MPI_CHK( mbedtls_ecp_mul_shortcuts( grp, &mP, m, P ) ); MBEDTLS_MPI_CHK( mbedtls_ecp_mul_shortcuts( grp, R, n, Q ) ); -#if defined(MBEDTLS_ECP_FUNCTION_ALT) && defined(MBEDTLS_THREADING_C) +#if defined(MBEDTLS_ECP_FUNCTION_ALT) +#if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_lock( &mbedtls_threading_cryptohw_asym_mutex ) != 0 ) return ( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); #endif -#if defined(MBEDTLS_ECP_INIT_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - MBEDTLS_MPI_CHK( mbedtls_ecp_alt_init( grp ) ); + MBEDTLS_MPI_CHK( mbedtls_int_ecp_init( grp ) ); } -#endif +#endif /* MBEDTLS_ECP_FUNCTION_ALT */ MBEDTLS_MPI_CHK( ecp_add_mixed( grp, R, &mP, R ) ); MBEDTLS_MPI_CHK( ecp_normalize_jac( grp, R ) ); cleanup: -#if defined(MBEDTLS_ECP_DEINIT_ALT) - if ( mbedtls_ecp_alt_grp_capable( grp ) ) +#if defined(MBEDTLS_ECP_FUNCTION_ALT) + if ( mbedtls_int_ecp_grp_capable( grp ) ) { - mbedtls_ecp_alt_deinit( grp ); + mbedtls_int_ecp_deinit( grp ); } -#endif -#if defined(MBEDTLS_ECP_FUNCTION_ALT) && defined(MBEDTLS_THREADING_C) +#if defined(MBEDTLS_THREADING_C) if( mbedtls_mutex_unlock( &mbedtls_threading_cryptohw_asym_mutex ) != 0 ) return ( MBEDTLS_ERR_THREADING_MUTEX_ERROR ); #endif +#endif /* MBEDTLS_ECP_FUNCTION_ALT */ mbedtls_ecp_point_free( &mP ); return( ret );