Apply review feedback on ECP interface

Naming conventions are revised, style issues corrected and minor
optimisation added.
This commit is contained in:
Janos Follath 2016-11-18 16:38:23 +00:00 committed by Simon Butcher
parent b8a90fb51c
commit c44ab97cc9
7 changed files with 105 additions and 98 deletions

View file

@ -150,43 +150,43 @@
#error "MBEDTLS_GCM_C defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_INIT_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_INIT_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_INIT_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_DEINIT_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_DEINIT_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_DEINIT_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_RANDOMIZE_JAC_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_ADD_MIXED_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_DOUBLE_JAC_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_NORMALIZE_JAC_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_RANDOMIZE_MXZ_ALT defined, but not all prerequisites"
#endif
#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
#error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites"
#endif

View file

@ -296,7 +296,9 @@
//#define MBEDTLS_AES_DECRYPT_ALT
/**
* \def MBEDTLS_ECP_FUNCTION_ALT
* \def MBEDTLS_ECP_INTERNAL_ALT
*
* Expose a part of the internal interface of the Elliptic Curve Point module.
*
* MBEDTLS_ECP__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use your
* alternative core implementation of elliptic curve arithmetic. Keep in mind
@ -307,37 +309,34 @@
* is still present and it is used for group structures not supported by the
* alternative.
*
* Any of these options become available by defining MBEDTLS_ECP_FUNCTION_ALT
* and implementing the following function:
* unsigned char mbedtls_ecp_alt_grp_capable( const mbedtls_ecp_group *grp )
* This should return 1 if the replacement functions implement arithmetic for
* the given group and 0 otherwise.
* Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT
* and implementing the following functions:
* unsigned char mbedtls_internal_ecp_grp_capable(
* const mbedtls_ecp_group *grp )
* int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp )
* void mbedtls_internal_ecp_deinit( const mbedtls_ecp_group *grp )
* The mbedtls_internal_ecp_grp_capable function should return 1 if the
* replacement functions implement arithmetic for the given group and 0
* otherwise.
* The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_deinit are
* called before and after each point operation and provide an opportunity to
* implement optimized set up and tear down instructions.
*
* The functions:
* int mbedtls_ecp_alt_init( const mbedtls_ecp_group *grp )
* void mbedtls_ecp_alt_deinit( const mbedtls_ecp_group *grp )
* can be enabled by MBEDTLS_ECP_INIT_ALT and MBEDTLS_ECP_DEINIT_ALT.
* They are called before and after each point operation and provide an
* opportunity to implement optimized set up and tear down instructions.
*
* Example: In case you uncomment MBEDTLS_ECP_FUNCTION_ALT and
* Example: In case you uncomment MBEDTLS_ECP_INTERNAL_ALT and
* MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac
* function, but will use your mbedtls_ecp_double_jac_alt if the group is
* supported (your mbedtls_ecp_alt_grp_capable function returns 1 when receives
* it as an argument). If the group is not supported then the original
* function, but will use your mbedtls_internal_ecp_double_jac if the group is
* supported (your mbedtls_internal_ecp_grp_capable function returns 1 when
* receives it as an argument). If the group is not supported then the original
* implementation is used. The other functions and the definition of
* mbedtls_ecp_group and mbedtls_ecp_point will not change, so your
* implementation of mbedtls_ecp_double_jac_alt and mbedtls_ecp_alt_grp_capable
* must be compatible with this definition.
* implementation of mbedtls_internal_ecp_double_jac and
* mbedtls_internal_ecp_grp_capable must be compatible with this definition.
*
* Uncomment a macro to enable alternate implementation of the corresponding
* function.
*/
/* Required for all the functions in this section */
//#define MBEDTLS_ECP_FUNCTION_ALT
/* Utility functions for setup and cleanup */
//#define MBEDTLS_ECP_INIT_ALT
//#define MBEDTLS_ECP_DEINIT_ALT
//#define MBEDTLS_ECP_INTERNAL_ALT
/* Support for Weierstrass curves with Jacobi representation */
//#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT
//#define MBEDTLS_ECP_ADD_MIXED_ALT

View file

@ -38,11 +38,13 @@
#define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH -0x4C00 /**< Signature is valid but shorter than the user-supplied length. */
#if !defined(MBEDTLS_ECP_ALT)
// default mbed TLS elliptic curve arithmetic implementation
//
// (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
// alternative implementation for the whole module and it will replace this
// one.)
/*
* default mbed TLS elliptic curve arithmetic implementation
*
* (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
* alternative implementation for the whole module and it will replace this
* one.)
*/
#ifdef __cplusplus
extern "C" {

View file

@ -21,62 +21,62 @@
*
* This file is part of mbed TLS (https://tls.mbed.org)
*/
#ifndef MBEDTLS_ECP_FUNCTION_ALT_H
#define MBEDTLS_ECP_FUNCTION_ALT_H
#ifndef MBEDTLS_ECP_INTERNAL_H
#define MBEDTLS_ECP_INTERNAL_H
#if defined(MBEDTLS_ECP_FUNCTION_ALT)
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
unsigned char mbedtls_int_ecp_grp_capable( const mbedtls_ecp_group *grp );
unsigned char mbedtls_internal_ecp_grp_capable( const mbedtls_ecp_group *grp );
int mbedtls_int_ecp_init( const mbedtls_ecp_group *grp );
int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp );
void mbedtls_int_ecp_deinit( const mbedtls_ecp_group *grp );
void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp );
#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
int mbedtls_int_ecp_randomize_jac( const mbedtls_ecp_group *grp,
int mbedtls_internal_ecp_randomize_jac( const mbedtls_ecp_group *grp,
mbedtls_ecp_point *pt, int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
#endif
#if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
int mbedtls_int_ecp_add_mixed( const mbedtls_ecp_group *grp,
int mbedtls_internal_ecp_add_mixed( const mbedtls_ecp_group *grp,
mbedtls_ecp_point *R, const mbedtls_ecp_point *P,
const mbedtls_ecp_point *Q );
#endif
#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
int mbedtls_int_ecp_double_jac( const mbedtls_ecp_group *grp,
int mbedtls_internal_ecp_double_jac( const mbedtls_ecp_group *grp,
mbedtls_ecp_point *R, const mbedtls_ecp_point *P );
#endif
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
int mbedtls_int_ecp_normalize_jac_many( const mbedtls_ecp_group *grp,
int mbedtls_internal_ecp_normalize_jac_many( const mbedtls_ecp_group *grp,
mbedtls_ecp_point *T[], size_t t_len );
#endif
#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
int mbedtls_int_ecp_normalize_jac( const mbedtls_ecp_group *grp,
int mbedtls_internal_ecp_normalize_jac( const mbedtls_ecp_group *grp,
mbedtls_ecp_point *pt );
#endif
#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
int mbedtls_int_ecp_double_add_mxz( const mbedtls_ecp_group *grp,
int mbedtls_internal_ecp_double_add_mxz( const mbedtls_ecp_group *grp,
mbedtls_ecp_point *R, mbedtls_ecp_point *S, const mbedtls_ecp_point *P,
const mbedtls_ecp_point *Q, const mbedtls_mpi *d );
#endif
#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
int mbedtls_int_ecp_randomize_mxz( const mbedtls_ecp_group *grp,
int mbedtls_internal_ecp_randomize_mxz( const mbedtls_ecp_group *grp,
mbedtls_ecp_point *P, int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng );
#endif
#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
int mbedtls_int_ecp_normalize_mxz( const mbedtls_ecp_group *grp,
int mbedtls_internal_ecp_normalize_mxz( const mbedtls_ecp_group *grp,
mbedtls_ecp_point *P );
#endif
#endif /* MBEDTLS_ECP_FUNCTION_ALT */
#endif /* MBEDTLS_ECP_INTERNAL_ALT */
#endif /* ecp_function_alt.h */
#endif /* ecp_internal.h */

View file

@ -97,8 +97,8 @@ extern int (*mbedtls_mutex_unlock)( mbedtls_threading_mutex_t *mutex );
*/
extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex;
extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex;
#if defined(MBEDTLS_ECP_FUNCTION_ALT)
extern mbedtls_threading_mutex_t mbedtls_threading_cryptohw_asym_mutex;
#if defined(MBEDTLS_ECP_INTERNAL_ALT)
extern mbedtls_threading_mutex_t mbedtls_threading_ecp_mutex;
#endif
#endif /* MBEDTLS_THREADING_C */