From 71387e33f1d34e15aefb0e2a296867b2ea2cdb16 Mon Sep 17 00:00:00 2001 From: Janos Follath Date: Fri, 7 Dec 2018 11:18:40 +0000 Subject: [PATCH] Mbed TLS: Fix ECC hardware double initialization We initialized the ECC hardware before calling mbedtls_ecp_mul_shortcuts(). This in turn calls mbedtls_ecp_mul_restartable(), which initializes and frees the hardware too. This issue has been introduced by recent changes and caused some accelerators to hang. We move the initialization after the mbedtle_ecp_mul_shortcuts() calls to avoid double initialization. --- features/mbedtls/src/ecp.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/features/mbedtls/src/ecp.c b/features/mbedtls/src/ecp.c index de5725c700..e3b9106dbc 100644 --- a/features/mbedtls/src/ecp.c +++ b/features/mbedtls/src/ecp.c @@ -2393,11 +2393,6 @@ int mbedtls_ecp_muladd_restartable( mbedtls_ecp_point_init( &mP ); -#if defined(MBEDTLS_ECP_INTERNAL_ALT) - if( ( is_grp_capable = mbedtls_internal_ecp_grp_capable( grp ) ) ) - MBEDTLS_MPI_CHK( mbedtls_internal_ecp_init( grp ) ); -#endif /* MBEDTLS_ECP_INTERNAL_ALT */ - ECP_RS_ENTER( ma ); #if defined(MBEDTLS_ECP_RESTARTABLE) @@ -2425,6 +2420,12 @@ int mbedtls_ecp_muladd_restartable( mul2: #endif MBEDTLS_MPI_CHK( mbedtls_ecp_mul_shortcuts( grp, pR, n, Q, rs_ctx ) ); + +#if defined(MBEDTLS_ECP_INTERNAL_ALT) + if( ( is_grp_capable = mbedtls_internal_ecp_grp_capable( grp ) ) ) + MBEDTLS_MPI_CHK( mbedtls_internal_ecp_init( grp ) ); +#endif /* MBEDTLS_ECP_INTERNAL_ALT */ + #if defined(MBEDTLS_ECP_RESTARTABLE) if( rs_ctx != NULL && rs_ctx->ma != NULL ) rs_ctx->ma->state = ecp_rsma_add;