|
47 | 47 | #include MBEDTLS_CONFIG_FILE
|
48 | 48 | #endif
|
49 | 49 |
|
| 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 | + |
50 | 79 | #if defined(MBEDTLS_ECP_C)
|
51 | 80 |
|
52 | 81 | #include "mbedtls/ecp.h"
|
@@ -2412,11 +2441,6 @@ int mbedtls_ecp_muladd_restartable(
|
2412 | 2441 |
|
2413 | 2442 | mbedtls_ecp_point_init( &mP );
|
2414 | 2443 |
|
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 |
| - |
2420 | 2444 | ECP_RS_ENTER( ma );
|
2421 | 2445 |
|
2422 | 2446 | #if defined(MBEDTLS_ECP_RESTARTABLE)
|
@@ -2444,6 +2468,12 @@ int mbedtls_ecp_muladd_restartable(
|
2444 | 2468 | mul2:
|
2445 | 2469 | #endif
|
2446 | 2470 | 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 | + |
2447 | 2477 | #if defined(MBEDTLS_ECP_RESTARTABLE)
|
2448 | 2478 | if( rs_ctx != NULL && rs_ctx->ma != NULL )
|
2449 | 2479 | rs_ctx->ma->state = ecp_rsma_add;
|
|
0 commit comments