mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 00:45:41 +01:00
Interface change in ECP info functions
ecp_named_curve_from_grp_id() -> ecp_curve_info_from_grp_id() ecp_grp_id_from_named_curve() -> ecp_curve_info_from_tls_id()
This commit is contained in:
parent
f71e587c5e
commit
f24b4a7316
@ -63,6 +63,11 @@ typedef enum
|
||||
POLARSSL_ECP_DP_SECP521R1, /*!< 521-bits NIST curve */
|
||||
} ecp_group_id;
|
||||
|
||||
/**
|
||||
* Number of supported curves (plus one for NONE)
|
||||
*/
|
||||
#define POLARSSL_ECP_DP_MAX 6
|
||||
|
||||
/**
|
||||
* Curve information for use by other modules
|
||||
*/
|
||||
@ -365,24 +370,22 @@ int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
|
||||
unsigned char *buf, size_t blen );
|
||||
|
||||
/**
|
||||
* \brief Get a TLS NamedCurve value from an internal group identifier
|
||||
* \brief Get curve information from an internal group identifier
|
||||
*
|
||||
* \param grp_id A POLARSSL_ECP_DP_XXX value
|
||||
*
|
||||
* \return The associated TLS NamedCurve value on success,
|
||||
* 0 on failure.
|
||||
* \return The associated curve information or NULL
|
||||
*/
|
||||
uint16_t ecp_named_curve_from_grp_id( ecp_group_id id );
|
||||
const ecp_curve_info *ecp_curve_info_from_grp_id( ecp_group_id grp_id );
|
||||
|
||||
/**
|
||||
* \brief Get an internal group identifier from a TLS NamedCurve value
|
||||
* \brief Get curve information from a TLS NamedCurve value
|
||||
*
|
||||
* \param curve A value from TLS's enum NamedCurve
|
||||
* \param grp_id A POLARSSL_ECP_DP_XXX value
|
||||
*
|
||||
* \return The associated POLARSSL_ECP_DP_XXX identifer on success,
|
||||
* POLARSSL_ECP_DP_NONE on failure.
|
||||
* \return The associated curve information or NULL
|
||||
*/
|
||||
ecp_group_id ecp_grp_id_from_named_curve( uint16_t curve );
|
||||
const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id );
|
||||
|
||||
/**
|
||||
* \brief Import a point from a TLS ECPoint record
|
||||
|
@ -703,7 +703,8 @@ int ecp_use_known_dp( ecp_group *grp, ecp_group_id id )
|
||||
*/
|
||||
int ecp_tls_read_group( ecp_group *grp, const unsigned char **buf, size_t len )
|
||||
{
|
||||
unsigned int named_curve;
|
||||
uint16_t tls_id;
|
||||
const ecp_curve_info *curve_info;
|
||||
|
||||
/*
|
||||
* We expect at least three bytes (see below)
|
||||
@ -720,10 +721,14 @@ int ecp_tls_read_group( ecp_group *grp, const unsigned char **buf, size_t len )
|
||||
/*
|
||||
* Next two bytes are the namedcurve value
|
||||
*/
|
||||
named_curve = *(*buf)++;
|
||||
named_curve <<= 8;
|
||||
named_curve |= *(*buf)++;
|
||||
return ecp_use_known_dp( grp, ecp_grp_id_from_named_curve( named_curve ) );
|
||||
tls_id = *(*buf)++;
|
||||
tls_id <<= 8;
|
||||
tls_id |= *(*buf)++;
|
||||
|
||||
if( ( curve_info = ecp_curve_info_from_tls_id( tls_id ) ) == NULL )
|
||||
return( POLARSSL_ERR_ECP_FEATURE_UNAVAILABLE );
|
||||
|
||||
return ecp_use_known_dp( grp, curve_info->grp_id );
|
||||
}
|
||||
|
||||
/*
|
||||
@ -732,7 +737,10 @@ int ecp_tls_read_group( ecp_group *grp, const unsigned char **buf, size_t len )
|
||||
int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
|
||||
unsigned char *buf, size_t blen )
|
||||
{
|
||||
unsigned int named_curve;
|
||||
const ecp_curve_info *curve_info;
|
||||
|
||||
if( ( curve_info = ecp_curve_info_from_grp_id( grp->id ) ) == NULL )
|
||||
return( POLARSSL_ERR_ECP_BAD_INPUT_DATA );
|
||||
|
||||
/*
|
||||
* We are going to write 3 bytes (see below)
|
||||
@ -749,17 +757,16 @@ int ecp_tls_write_group( const ecp_group *grp, size_t *olen,
|
||||
/*
|
||||
* Next two bytes are the namedcurve value
|
||||
*/
|
||||
named_curve = ecp_named_curve_from_grp_id( grp->id );
|
||||
buf[0] = named_curve >> 8;
|
||||
buf[1] = named_curve & 0xFF;
|
||||
buf[0] = curve_info->tls_id >> 8;
|
||||
buf[1] = curve_info->tls_id & 0xFF;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the internal identifer from the TLS name
|
||||
* Get the curve info from the TLS identifier
|
||||
*/
|
||||
ecp_group_id ecp_grp_id_from_named_curve( uint16_t tls_id )
|
||||
const ecp_curve_info *ecp_curve_info_from_tls_id( uint16_t tls_id )
|
||||
{
|
||||
const ecp_curve_info *curve_info;
|
||||
|
||||
@ -768,16 +775,16 @@ ecp_group_id ecp_grp_id_from_named_curve( uint16_t tls_id )
|
||||
curve_info++ )
|
||||
{
|
||||
if( curve_info->tls_id == tls_id )
|
||||
return( curve_info->grp_id );
|
||||
return( curve_info );
|
||||
}
|
||||
|
||||
return( POLARSSL_ECP_DP_NONE );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the TLS name for the internal identifer
|
||||
* Get the curve info for the internal identifer
|
||||
*/
|
||||
uint16_t ecp_named_curve_from_grp_id( ecp_group_id grp_id )
|
||||
const ecp_curve_info *ecp_curve_info_from_grp_id( ecp_group_id grp_id )
|
||||
{
|
||||
const ecp_curve_info *curve_info;
|
||||
|
||||
@ -786,10 +793,10 @@ uint16_t ecp_named_curve_from_grp_id( ecp_group_id grp_id )
|
||||
curve_info++ )
|
||||
{
|
||||
if( curve_info->grp_id == grp_id )
|
||||
return( curve_info->tls_id );
|
||||
return( curve_info );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
return( NULL );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -503,7 +503,7 @@ static int ssl_parse_supported_elliptic_curves( ssl_context *ssl,
|
||||
{
|
||||
size_t list_size;
|
||||
const unsigned char *p;
|
||||
ecp_group_id grp_id;
|
||||
const ecp_curve_info *curve_info;
|
||||
|
||||
list_size = ( ( buf[0] << 8 ) | ( buf[1] ) );
|
||||
if( list_size + 2 != len ||
|
||||
@ -516,11 +516,11 @@ static int ssl_parse_supported_elliptic_curves( ssl_context *ssl,
|
||||
p = buf + 2;
|
||||
while( list_size > 0 )
|
||||
{
|
||||
grp_id = ecp_grp_id_from_named_curve( ( p[0] << 8 ) | p[1] );
|
||||
curve_info = ecp_curve_info_from_tls_id( ( p[0] << 8 ) | p[1] );
|
||||
|
||||
if( grp_id != POLARSSL_ECP_DP_NONE )
|
||||
if( curve_info != NULL )
|
||||
{
|
||||
ssl->handshake->ec_curve = grp_id;
|
||||
ssl->handshake->ec_curve = curve_info->grp_id;
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user