Skip to content

Commit 01b34fb

Browse files
committed
Merge remote-tracking branch 'upstream-public/pr/2267' into development
2 parents faafcd8 + 172ba63 commit 01b34fb

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Bugfix
4949
* Add explicit integer to enumeration type casts to example program
5050
programs/pkey/gen_key which previously led to compilation failure
5151
on some toolchains. Reported by phoenixmcallister. Fixes #2170.
52+
* Fix double initialization of ECC hardware that made some accelerators
53+
hang.
5254

5355
= mbed TLS 2.14.0 branch released 2018-11-19
5456

include/mbedtls/check_config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
defined(MBEDTLS_ECDSA_SIGN_ALT) || \
115115
defined(MBEDTLS_ECDSA_VERIFY_ALT) || \
116116
defined(MBEDTLS_ECDSA_GENKEY_ALT) || \
117+
defined(MBEDTLS_ECP_INTERNAL_ALT) || \
117118
defined(MBEDTLS_ECP_ALT) )
118119
#error "MBEDTLS_ECP_RESTARTABLE defined, but it cannot coexist with an alternative ECP implementation"
119120
#endif

include/mbedtls/config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,11 @@
414414
* unsigned char mbedtls_internal_ecp_grp_capable(
415415
* const mbedtls_ecp_group *grp )
416416
* int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp )
417-
* void mbedtls_internal_ecp_deinit( const mbedtls_ecp_group *grp )
417+
* void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp )
418418
* The mbedtls_internal_ecp_grp_capable function should return 1 if the
419419
* replacement functions implement arithmetic for the given group and 0
420420
* otherwise.
421-
* The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_deinit are
421+
* The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_free are
422422
* called before and after each point operation and provide an opportunity to
423423
* implement optimized set up and tear down instructions.
424424
*

library/ecp.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,35 @@
4747
#include MBEDTLS_CONFIG_FILE
4848
#endif
4949

50+
/**
51+
* \brief Function level alternative implementation.
52+
*
53+
* The MBEDTLS_ECP_INTERNAL_ALT macro enables alternative implementations to
54+
* replace certain functions in this module. The alternative implementations are
55+
* typically hardware accelerators and need to activate the hardware before the
56+
* computation starts and deactivate it after it finishes. The
57+
* mbedtls_internal_ecp_init() and mbedtls_internal_ecp_free() functions serve
58+
* this purpose.
59+
*
60+
* To preserve the correct functionality the following conditions must hold:
61+
*
62+
* - The alternative implementation must be activated by
63+
* mbedtls_internal_ecp_init() before any of the replaceable functions is
64+
* called.
65+
* - mbedtls_internal_ecp_free() must \b only be called when the alternative
66+
* implementation is activated.
67+
* - mbedtls_internal_ecp_init() must \b not be called when the alternative
68+
* implementation is activated.
69+
* - Public functions must not return while the alternative implementation is
70+
* activated.
71+
* - Replaceable functions are guarded by \c MBEDTLS_ECP_XXX_ALT macros and
72+
* before calling them an \code if( mbedtls_internal_ecp_grp_capable( grp ) )
73+
* \endcode ensures that the alternative implementation supports the current
74+
* group.
75+
*/
76+
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
77+
#endif
78+
5079
#if defined(MBEDTLS_ECP_C)
5180

5281
#include "mbedtls/ecp.h"
@@ -2412,11 +2441,6 @@ int mbedtls_ecp_muladd_restartable(
24122441

24132442
mbedtls_ecp_point_init( &mP );
24142443

2415-
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
2416-
if( ( is_grp_capable = mbedtls_internal_ecp_grp_capable( grp ) ) )
2417-
MBEDTLS_MPI_CHK( mbedtls_internal_ecp_init( grp ) );
2418-
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
2419-
24202444
ECP_RS_ENTER( ma );
24212445

24222446
#if defined(MBEDTLS_ECP_RESTARTABLE)
@@ -2444,6 +2468,12 @@ int mbedtls_ecp_muladd_restartable(
24442468
mul2:
24452469
#endif
24462470
MBEDTLS_MPI_CHK( mbedtls_ecp_mul_shortcuts( grp, pR, n, Q, rs_ctx ) );
2471+
2472+
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
2473+
if( ( is_grp_capable = mbedtls_internal_ecp_grp_capable( grp ) ) )
2474+
MBEDTLS_MPI_CHK( mbedtls_internal_ecp_init( grp ) );
2475+
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
2476+
24472477
#if defined(MBEDTLS_ECP_RESTARTABLE)
24482478
if( rs_ctx != NULL && rs_ctx->ma != NULL )
24492479
rs_ctx->ma->state = ecp_rsma_add;

0 commit comments

Comments
 (0)