From 28d162829b2a136f9e57b9b260ea2f43315fb597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 23 Aug 2017 17:33:27 +0200 Subject: [PATCH] Avoid unnecessary xxx_copy() calls The call would anyway check for pointer equality and return early, but it doesn't hurt to save a function call, and also this follows more uniformly the pattern that those two lines go together: #if defined(MBEDTLS_ECP_RESTARTBLE) if( rs_ctx != NULL && ... --- library/ecdsa.c | 3 ++- library/ecp.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/ecdsa.c b/library/ecdsa.c index f3b3cf26d..835d3de88 100644 --- a/library/ecdsa.c +++ b/library/ecdsa.c @@ -353,7 +353,8 @@ modn: while( mbedtls_mpi_cmp_int( s, 0 ) == 0 ); #if defined(MBEDTLS_ECP_RESTARTABLE) - mbedtls_mpi_copy( r, pr ); + if( rs_ctx != NULL && rs_ctx->sig != NULL ) + mbedtls_mpi_copy( r, pr ); #endif cleanup: diff --git a/library/ecp.c b/library/ecp.c index 6675c475c..a8c367a3d 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -1804,7 +1804,8 @@ static int ecp_mul_comb_after_precomp( const mbedtls_ecp_group *grp, MBEDTLS_MPI_CHK( ecp_normalize_jac( grp, RR ) ); #if defined(MBEDTLS_ECP_RESTARTABLE) - MBEDTLS_MPI_CHK( mbedtls_ecp_copy( R, RR ) ); + if( rs_ctx != NULL && rs_ctx->rsm != NULL ) + MBEDTLS_MPI_CHK( mbedtls_ecp_copy( R, RR ) ); #endif cleanup: