Renamings and other fixes

This commit is contained in:
Manuel Pégourié-Gonnard 2014-02-04 14:48:50 +01:00
parent e40c469ad3
commit ac7194133e
3 changed files with 50 additions and 41 deletions

View File

@ -222,12 +222,22 @@ ecp_keypair;
#define POLARSSL_ECP_TLS_NAMED_CURVE 3 /**< ECCurveType's named_curve */
/**
* \brief Return the list of supported curves with associated info
* \brief Get the list of supported curves in order of preferrence
* (full information)
*
* \return A statically allocated array, the last entry is 0.
*/
const ecp_curve_info *ecp_curve_list( void );
/**
* \brief Get the list of supported curves in order of preferrence
* (grp_id only)
*
* \return A statically allocated array,
* terminated with POLARSSL_ECP_DP_NONE.
*/
const ecp_group_id *ecp_grp_id_list( void );
/**
* \brief Get curve information from an internal group identifier
*
@ -255,13 +265,6 @@ const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id );
*/
const ecp_curve_info *ecp_curve_info_from_name( const char *name );
/**
* \brief Get the default ECDH curve list
*
* \return The default ECDH curve list
*/
ecp_group_id *ecp_get_default_echd_curve_list( void );
/**
* \brief Initialize a point (as zero)
*/

View File

@ -115,13 +115,10 @@ typedef enum
* - size in bits
* - readable name
*
* The sequence of elements in this list also determines the default preference
* of the curves used by an ECHDE handshake.
* We start with the most secure curves. From the same sized curves, we prefer
* the SECP ones because they are much faster.
*
* Curves are listed in order: largest curves first, and for a given size,
* fastest curves first. This provides the default order for the SSL module.
*/
static const ecp_curve_info ecp_supported_curves[] =
static const ecp_curve_info ecp_supported_curves[POLARSSL_ECP_DP_MAX] =
{
#if defined(POLARSSL_ECP_DP_SECP521R1_ENABLED)
{ POLARSSL_ECP_DP_SECP521R1, 25, 521, "secp521r1" },
@ -138,28 +135,28 @@ static const ecp_curve_info ecp_supported_curves[] =
#if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
{ POLARSSL_ECP_DP_SECP256R1, 23, 256, "secp256r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP256K1_ENABLED)
{ POLARSSL_ECP_DP_SECP256K1, 22, 256, "secp256k1" },
#endif
#if defined(POLARSSL_ECP_DP_BP256R1_ENABLED)
{ POLARSSL_ECP_DP_BP256R1, 26, 256, "brainpoolP256r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP224R1_ENABLED)
{ POLARSSL_ECP_DP_SECP224R1, 21, 224, "secp224r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
{ POLARSSL_ECP_DP_SECP192R1, 19, 192, "secp192r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP256K1_ENABLED)
{ POLARSSL_ECP_DP_SECP256K1, 22, 256, "secp256k1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP224K1_ENABLED)
{ POLARSSL_ECP_DP_SECP224K1, 20, 224, "secp224k1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
{ POLARSSL_ECP_DP_SECP192R1, 19, 192, "secp192r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP192K1_ENABLED)
{ POLARSSL_ECP_DP_SECP192K1, 18, 192, "secp192k1" },
#endif
{ POLARSSL_ECP_DP_NONE, 0, 0, NULL },
};
#define ECP_NUM_SUPPORTED_CURVES ( sizeof( ecp_supported_curves ) / \
sizeof( ecp_curve_info ) )
static ecp_group_id ecp_supported_grp_id[POLARSSL_ECP_DP_MAX];
/*
* List of supported curves and associated info
@ -170,7 +167,33 @@ const ecp_curve_info *ecp_curve_list( void )
}
/*
* Get the curve info for the internal identifer
* List of supported curves, group ID only
*/
const ecp_group_id *ecp_grp_id_list( void )
{
static int init_done = 0;
if( ! init_done )
{
size_t i = 0;
const ecp_curve_info *curve_info;
for( curve_info = ecp_curve_list();
curve_info->grp_id != POLARSSL_ECP_DP_NONE;
curve_info++ )
{
ecp_supported_grp_id[i++] = curve_info->grp_id;
}
ecp_supported_grp_id[i] = POLARSSL_ECP_DP_NONE;
init_done = 1;
}
return ecp_supported_grp_id;
}
/*
* Get the curve info for the internal identifier
*/
const ecp_curve_info *ecp_curve_info_from_grp_id( ecp_group_id grp_id )
{
@ -223,23 +246,6 @@ const ecp_curve_info *ecp_curve_info_from_name( const char *name )
return( NULL );
}
/*
* Get the default ECDH curve list
*/
ecp_group_id *ecp_get_default_echd_curve_list( void )
{
static ecp_group_id ecdh_default_curve_list[ECP_NUM_SUPPORTED_CURVES];
int i;
/* Build the list of default curves based on ecp_supported_curves[] */
for( i = 0; i < ECP_NUM_SUPPORTED_CURVES; i++)
{
ecdh_default_curve_list[i] = ecp_supported_curves[i].grp_id;
}
return ecdh_default_curve_list;
}
/*
* Get the type of a curve
*/

View File

@ -3386,7 +3386,7 @@ int ssl_init( ssl_context *ssl )
#if defined(POLARSSL_KEY_EXCHANGE__SOME__ECDHE_ENABLED) && \
defined(POLARSSL_SSL_SET_CURVES)
ssl->curve_list = ecp_get_default_echd_curve_list( );
ssl->curve_list = ecp_grp_id_list( );
#endif
if( ( ret = ssl_handshake_init( ssl ) ) != 0 )