Always declare restartable function variants
Otherwise code that uses these functions in other modules will have to do: #if defined(MBEDTLS_ECP_RESTARTABLE) ret = do_stuff( there, may, be, many, args ); #else ret = do_stuff( their, may, be, namy, args, rs_ctx ); #fi and there is a risk that the arg list will differ when code is updated, and this might not be caught immediately by tests because this depends on a config.h compile-time option which are harder to test. Always declaring the restartable variants of the API functions avoids this problem; the cost in ROM size should be negligible.
This commit is contained in:
parent
0ff17df081
commit
b5a50e754d
2 changed files with 7 additions and 13 deletions
|
@ -172,6 +172,7 @@ typedef struct
|
||||||
mbedtls_ecp_keypair;
|
mbedtls_ecp_keypair;
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Internal restart context for multiplication
|
* \brief Internal restart context for multiplication
|
||||||
*
|
*
|
||||||
|
@ -196,6 +197,12 @@ typedef struct
|
||||||
mbedtls_ecp_restart_mul_ctx *rsm; /*!< ecp_mul_comb() sub-context */
|
mbedtls_ecp_restart_mul_ctx *rsm; /*!< ecp_mul_comb() sub-context */
|
||||||
mbedtls_ecp_restart_muladd_ctx *ma; /*!< ecp_muladd() sub-context */
|
mbedtls_ecp_restart_muladd_ctx *ma; /*!< ecp_muladd() sub-context */
|
||||||
} mbedtls_ecp_restart_ctx;
|
} mbedtls_ecp_restart_ctx;
|
||||||
|
|
||||||
|
#else /* MBEDTLS_ECP_RESTARTABLE */
|
||||||
|
|
||||||
|
/* We want to declare restartable versions of existing functions anyway */
|
||||||
|
typedef void mbedtls_ecp_restart_ctx;
|
||||||
|
|
||||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -612,7 +619,6 @@ int mbedtls_ecp_mul( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng );
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
|
||||||
/**
|
/**
|
||||||
* \brief Restartable version of \c mbedtls_ecp_mul()
|
* \brief Restartable version of \c mbedtls_ecp_mul()
|
||||||
*
|
*
|
||||||
|
@ -636,7 +642,6 @@ int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
|
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
|
||||||
mbedtls_ecp_restart_ctx *rs_ctx );
|
mbedtls_ecp_restart_ctx *rs_ctx );
|
||||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Multiplication and addition of two points by integers:
|
* \brief Multiplication and addition of two points by integers:
|
||||||
|
@ -662,7 +667,6 @@ int mbedtls_ecp_muladd( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||||
const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
|
const mbedtls_mpi *n, const mbedtls_ecp_point *Q );
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_RESTARTABLE)
|
|
||||||
/**
|
/**
|
||||||
* \brief Restartable version of \c mbedtls_ecp_muladd()
|
* \brief Restartable version of \c mbedtls_ecp_muladd()
|
||||||
*
|
*
|
||||||
|
@ -687,7 +691,6 @@ int mbedtls_ecp_muladd_restartable(
|
||||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||||
const mbedtls_mpi *n, const mbedtls_ecp_point *Q,
|
const mbedtls_mpi *n, const mbedtls_ecp_point *Q,
|
||||||
mbedtls_ecp_restart_ctx *rs_ctx );
|
mbedtls_ecp_restart_ctx *rs_ctx );
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Check that a point is a valid public key on this curve
|
* \brief Check that a point is a valid public key on this curve
|
||||||
|
|
|
@ -250,9 +250,6 @@ static int ecp_check_budget( const mbedtls_ecp_group *grp,
|
||||||
#define ECP_BUDGET( ops ) MBEDTLS_MPI_CHK( ecp_check_budget( grp, rs_ctx, ops ) );
|
#define ECP_BUDGET( ops ) MBEDTLS_MPI_CHK( ecp_check_budget( grp, rs_ctx, ops ) );
|
||||||
#else
|
#else
|
||||||
#define ECP_BUDGET( ops ) /* no-op */
|
#define ECP_BUDGET( ops ) /* no-op */
|
||||||
|
|
||||||
/* We also need that type to make our life simpler for internal functions */
|
|
||||||
typedef void mbedtls_ecp_restart_ctx;
|
|
||||||
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
#endif /* MBEDTLS_ECP_RESTARTABLE */
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \
|
#if defined(MBEDTLS_ECP_DP_SECP192R1_ENABLED) || \
|
||||||
|
@ -2130,9 +2127,6 @@ cleanup:
|
||||||
/*
|
/*
|
||||||
* Restartable multiplication R = m * P
|
* Restartable multiplication R = m * P
|
||||||
*/
|
*/
|
||||||
#if !defined(MBEDTLS_ECP_RESTARTABLE)
|
|
||||||
static
|
|
||||||
#endif
|
|
||||||
int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
int mbedtls_ecp_mul_restartable( mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
|
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
|
||||||
|
@ -2295,9 +2289,6 @@ cleanup:
|
||||||
* Restartable linear combination
|
* Restartable linear combination
|
||||||
* NOT constant-time
|
* NOT constant-time
|
||||||
*/
|
*/
|
||||||
#if !defined(MBEDTLS_ECP_RESTARTABLE)
|
|
||||||
static
|
|
||||||
#endif
|
|
||||||
int mbedtls_ecp_muladd_restartable(
|
int mbedtls_ecp_muladd_restartable(
|
||||||
mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
mbedtls_ecp_group *grp, mbedtls_ecp_point *R,
|
||||||
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
const mbedtls_mpi *m, const mbedtls_ecp_point *P,
|
||||||
|
|
Loading…
Reference in a new issue