ECDH: not restartable unless explicitly enabled

This is mainly for the benefit of SSL modules, which only supports restart in
a limited number of cases. In the other cases (ECDHE_PSK) it would currently
return ERR_ECP_IN_PROGRESS and the user would thus call ssl_handshake() again,
but the SSL code wouldn't handle state properly and things would go wrong in
possibly unexpected ways.  This is undesirable, so it should be possible for
the SSL module to choose if ECDHE should behave the old or the new way.

Not that it also brings ECDHE more in line with the other modules which
already have that choice available (by passing a NULL or valid restart
context).
This commit is contained in:
Manuel Pégourié-Gonnard 2017-05-18 12:35:37 +02:00
parent 1f1f2a1ca6
commit 23e416261c
5 changed files with 68 additions and 12 deletions

View file

@ -53,6 +53,7 @@ typedef struct
mbedtls_ecp_point Vf; /*!< un-blinding value (for later) */
mbedtls_mpi _d; /*!< previous d (for later) */
#if defined(MBEDTLS_ECP_RESTARTABLE)
int restart_enabled; /*!< enable restartalbe EC computations? */
mbedtls_ecp_restart_ctx rs; /*!< restart context for EC computations */
#endif
}
@ -220,6 +221,22 @@ int mbedtls_ecdh_calc_secret( mbedtls_ecdh_context *ctx, size_t *olen,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
#if defined(MBEDTLS_ECP_RESTARTABLE)
/**
* \brief Enable restartable EC computations for this context.
* (Default: disabled.)
*
* \sa \c mbedtls_ecp_set_max_ops()
*
* \note It is not possible to safely disable restartable
* computations once enabled, except by free-ing the context,
* which cancels possible in-progress operations.
*
* \param ctx ECDH context
*/
void mbedtls_ecdh_enable_restart( mbedtls_ecdh_context *ctx );
#endif /* MBEDTLS_ECP_RESTARTABLE */
#ifdef __cplusplus
}
#endif