Skip to content

Commit 683c582

Browse files
committed
Clarify alternative ECP calling conventions
Function calls to alternative implementations have to follow certain rules in order to preserve correct functionality. To avoid accidentally breaking these rules we state them explicitly in the ECP module for ourselves and every contributor to see.
1 parent d2af46f commit 683c582

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

library/ecp.c

Lines changed: 29 additions & 0 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"

0 commit comments

Comments
 (0)