From 91e20a0580b811cbb398b7a9e8d2a9fc26145858 Mon Sep 17 00:00:00 2001 From: David Horstmann Date: Thu, 6 Oct 2022 19:11:28 +0100 Subject: [PATCH] Refactor macro-spanning ifs in ecdh.c Signed-off-by: David Horstmann --- library/ecdh.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/ecdh.c b/library/ecdh.c index 35ab1b7044..c9c2e06bd1 100644 --- a/library/ecdh.c +++ b/library/ecdh.c @@ -71,10 +71,12 @@ static int ecdh_gen_public_restartable( mbedtls_ecp_group *grp, { int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - /* If multiplication is in progress, we already generated a privkey */ + int restarting = 0; #if defined(MBEDTLS_ECP_RESTARTABLE) - if( rs_ctx == NULL || rs_ctx->rsm == NULL ) + restarting = ( rs_ctx != NULL && rs_ctx->rsm != NULL ); #endif + /* If multiplication is in progress, we already generated a privkey */ + if( !restarting ) MBEDTLS_MPI_CHK( mbedtls_ecp_gen_privkey( grp, d, f_rng, p_rng ) ); MBEDTLS_MPI_CHK( mbedtls_ecp_mul_restartable( grp, Q, d, &grp->G,