Optimize some case of mbedtls_ecp_muladd()

Those are used by EC-JPAKE
This commit is contained in:
Manuel Pégourié-Gonnard 2015-08-13 10:19:09 +02:00
parent cb7cd03412
commit 1a7c5ef42b

View file

@ -1697,8 +1697,17 @@ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
mbedtls_ecp_point_init( &mP );
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( grp, &mP, m, P, NULL, NULL ) );
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( grp, R, n, Q, NULL, NULL ) );
/* Optimize some simple special cases */
if( mbedtls_mpi_cmp_int( m, 1 ) == 0 )
MBEDTLS_MPI_CHK( mbedtls_ecp_copy( &mP, P ) );
else
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( grp, &mP, m, P, NULL, NULL ) );
if( mbedtls_mpi_cmp_int( n, 1 ) == 0 )
MBEDTLS_MPI_CHK( mbedtls_ecp_copy( R, Q ) );
else
MBEDTLS_MPI_CHK( mbedtls_ecp_mul( grp, R, n, Q, NULL, NULL ) );
MBEDTLS_MPI_CHK( ecp_add_mixed( grp, R, &mP, R ) );
MBEDTLS_MPI_CHK( ecp_normalize_jac( grp, R ) );