Commit 56cd319f authored by Manuel Pégourié-Gonnard's avatar Manuel Pégourié-Gonnard Committed by Paul Bakker
Browse files

Add human-friendly name in ecp_curve_info

parent 803bb312
......@@ -68,9 +68,10 @@ typedef enum
*/
typedef struct
{
ecp_group_id grp_id; /*!< Internal identifier */
uint16_t name; /*!< TLS NamedCurve value */
uint16_t size; /*!< Curve size in bits */
ecp_group_id grp_id; /*!< Internal identifier */
uint16_t tls_id; /*!< TLS NamedCurve identifier */
uint16_t size; /*!< Curve size in bits */
const char *name; /*!< Human-friendly name */
} ecp_curve_info;
/**
......
......@@ -70,27 +70,28 @@ unsigned long add_count, dbl_count;
/*
* List of supported curves:
* - internal ID
* - TLS NamedCurve number (RFC 4492 section 5.1.1)
* - TLS NamedCurve ID (RFC 4492 section 5.1.1)
* - size in bits
* - readeble name
*/
const ecp_curve_info ecp_supported_curves[] =
{
#if defined(POLARSSL_ECP_DP_SECP521R1_ENABLED)
{ POLARSSL_ECP_DP_SECP521R1, 25, 521, },
{ POLARSSL_ECP_DP_SECP521R1, 25, 521, "secp521r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP384R1_ENABLED)
{ POLARSSL_ECP_DP_SECP384R1, 24, 384, },
{ POLARSSL_ECP_DP_SECP384R1, 24, 384, "secp384r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP256R1_ENABLED)
{ POLARSSL_ECP_DP_SECP256R1, 23, 256, },
{ POLARSSL_ECP_DP_SECP256R1, 23, 256, "secp256r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP224R1_ENABLED)
{ POLARSSL_ECP_DP_SECP224R1, 21, 224, },
{ POLARSSL_ECP_DP_SECP224R1, 21, 224, "secp224r1" },
#endif
#if defined(POLARSSL_ECP_DP_SECP192R1_ENABLED)
{ POLARSSL_ECP_DP_SECP192R1, 19, 192, },
{ POLARSSL_ECP_DP_SECP192R1, 19, 192, "secp192r1" },
#endif
{ POLARSSL_ECP_DP_NONE, 0, 0 },
{ POLARSSL_ECP_DP_NONE, 0, 0, NULL },
};
/*
......@@ -741,7 +742,7 @@ int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
/*
* Get the internal identifer from the TLS name
*/
ecp_group_id ecp_grp_id_from_named_curve( uint16_t name )
ecp_group_id ecp_grp_id_from_named_curve( uint16_t tls_id )
{
const ecp_curve_info *curve_info;
......@@ -749,7 +750,7 @@ ecp_group_id ecp_grp_id_from_named_curve( uint16_t name )
curve_info->grp_id != POLARSSL_ECP_DP_NONE;
curve_info++ )
{
if( curve_info->name == name )
if( curve_info->tls_id == tls_id )
return( curve_info->grp_id );
}
......@@ -759,7 +760,7 @@ ecp_group_id ecp_grp_id_from_named_curve( uint16_t name )
/*
* Get the TLS name for the internal identifer
*/
uint16_t ecp_named_curve_from_grp_id( ecp_group_id id )
uint16_t ecp_named_curve_from_grp_id( ecp_group_id grp_id )
{
const ecp_curve_info *curve_info;
......@@ -767,8 +768,8 @@ uint16_t ecp_named_curve_from_grp_id( ecp_group_id id )
curve_info->grp_id != POLARSSL_ECP_DP_NONE;
curve_info++ )
{
if( curve_info->grp_id == id )
return( curve_info->name );
if( curve_info->grp_id == grp_id )
return( curve_info->tls_id );
}
return( 0 );
......
......@@ -244,8 +244,8 @@ static void ssl_write_supported_elliptic_curves_ext( ssl_context *ssl,
curve->grp_id != POLARSSL_ECP_DP_NONE;
curve++ )
{
elliptic_curve_list[elliptic_curve_len++] = curve->name >> 8;
elliptic_curve_list[elliptic_curve_len++] = curve->name & 0xFF;
elliptic_curve_list[elliptic_curve_len++] = curve->tls_id >> 8;
elliptic_curve_list[elliptic_curve_len++] = curve->tls_id & 0xFF;
}
if( elliptic_curve_len == 0 )
......
......@@ -456,11 +456,15 @@ int main( int argc, char *argv[] )
if( ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 )
exit( 1 );
snprintf( title, sizeof( title ), "ECDSA-%d",
(int) curve_info->size );
snprintf( title, sizeof( title ), "ECDSA-%s",
curve_info->name );
TIME_PUBLIC( title, "sign",
ret = ecdsa_write_signature( &ecdsa, buf, curve_info->size,
tmp, &sig_len, myrand, NULL ) );
tmp, &sig_len, myrand, NULL ) );
TIME_PUBLIC( title, "verify",
ret = ecdsa_read_signature( &ecdsa, buf, curve_info->size,
tmp, sig_len ) );
ecdsa_free( &ecdsa );
}
......@@ -488,16 +492,16 @@ int main( int argc, char *argv[] )
exit( 1 );
}
snprintf( title, sizeof( title ), "ECDHE-%d",
(int) curve_info->size );
snprintf( title, sizeof( title ), "ECDHE-%s",
curve_info->name );
TIME_PUBLIC( title, "handshake",
ret |= ecdh_make_public( &ecdh, &olen, buf, sizeof( buf),
myrand, NULL );
ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
myrand, NULL ) );
snprintf( title, sizeof( title ), "ECDH-%d",
(int) curve_info->size );
snprintf( title, sizeof( title ), "ECDH-%s",
curve_info->name );
TIME_PUBLIC( title, "handshake",
ret |= ecdh_calc_secret( &ecdh, &olen, buf, sizeof( buf ),
myrand, NULL ) );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment