mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-10 06:40:16 +00:00
Convert TLS1.3 functions to get_supported_groups
Signed-off-by: Brett Warren <brett.warren@arm.com>
This commit is contained in:
parent
25386b7652
commit
14efd33a6c
@ -117,36 +117,35 @@ static int ssl_tls13_write_supported_versions_ext( mbedtls_ssl_context *ssl,
|
|||||||
* 'elliptic_curves' and only contained elliptic curve groups.
|
* 'elliptic_curves' and only contained elliptic curve groups.
|
||||||
*/
|
*/
|
||||||
static int ssl_tls13_write_named_group_list_ecdhe( mbedtls_ssl_context *ssl,
|
static int ssl_tls13_write_named_group_list_ecdhe( mbedtls_ssl_context *ssl,
|
||||||
unsigned char *buf,
|
unsigned char *buf,
|
||||||
unsigned char *end,
|
unsigned char *end,
|
||||||
size_t *olen )
|
size_t *olen )
|
||||||
{
|
{
|
||||||
unsigned char *p = buf;
|
unsigned char *p = buf;
|
||||||
|
|
||||||
*olen = 0;
|
*olen = 0;
|
||||||
|
|
||||||
if( ssl->conf->curve_list == NULL )
|
const uint16_t *group_list = mbedtls_ssl_get_groups( ssl );
|
||||||
|
|
||||||
|
if( group_list == NULL )
|
||||||
return( MBEDTLS_ERR_SSL_BAD_CONFIG );
|
return( MBEDTLS_ERR_SSL_BAD_CONFIG );
|
||||||
|
|
||||||
for ( const mbedtls_ecp_group_id *grp_id = ssl->conf->curve_list;
|
for ( ; *group_list != 0; group_list++ )
|
||||||
*grp_id != MBEDTLS_ECP_DP_NONE;
|
|
||||||
grp_id++ )
|
|
||||||
{
|
{
|
||||||
const mbedtls_ecp_curve_info *info;
|
const mbedtls_ecp_curve_info *info;
|
||||||
info = mbedtls_ecp_curve_info_from_grp_id( *grp_id );
|
info = mbedtls_ecp_curve_info_from_tls_id( *group_list );
|
||||||
if( info == NULL )
|
if( info == NULL )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( !mbedtls_ssl_tls13_named_group_is_ecdhe( info->tls_id ) )
|
if( !mbedtls_ssl_tls13_named_group_is_ecdhe( *group_list ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2);
|
MBEDTLS_SSL_CHK_BUF_PTR( p, end, 2);
|
||||||
MBEDTLS_PUT_UINT16_BE( info->tls_id, p, 0 );
|
MBEDTLS_PUT_UINT16_BE( *group_list, p, 0 );
|
||||||
p += 2;
|
p += 2;
|
||||||
|
|
||||||
MBEDTLS_SSL_DEBUG_MSG( 3, ( "NamedGroup: %s ( %x )",
|
MBEDTLS_SSL_DEBUG_MSG( 3, ( "NamedGroup: %s ( %x )",
|
||||||
mbedtls_ecp_curve_info_from_tls_id( info->tls_id )->name,
|
info->name, *group_list ) );
|
||||||
info->tls_id ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*olen = p - buf;
|
*olen = p - buf;
|
||||||
@ -301,20 +300,19 @@ static int ssl_tls13_get_default_group_id( mbedtls_ssl_context *ssl,
|
|||||||
|
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECDH_C)
|
#if defined(MBEDTLS_ECDH_C)
|
||||||
|
const uint16_t *group_list = mbedtls_ssl_get_groups( ssl );
|
||||||
/* Pick first available ECDHE group compatible with TLS 1.3 */
|
/* Pick first available ECDHE group compatible with TLS 1.3 */
|
||||||
if( ssl->conf->curve_list == NULL )
|
if( group_list == NULL )
|
||||||
return( MBEDTLS_ERR_SSL_BAD_CONFIG );
|
return( MBEDTLS_ERR_SSL_BAD_CONFIG );
|
||||||
|
|
||||||
for ( const mbedtls_ecp_group_id *grp_id = ssl->conf->curve_list;
|
for ( ; *group_list != 0; group_list++ )
|
||||||
*grp_id != MBEDTLS_ECP_DP_NONE;
|
|
||||||
grp_id++ )
|
|
||||||
{
|
{
|
||||||
const mbedtls_ecp_curve_info *info;
|
const mbedtls_ecp_curve_info *info;
|
||||||
info = mbedtls_ecp_curve_info_from_grp_id( *grp_id );
|
info = mbedtls_ecp_curve_info_from_tls_id( *group_list );
|
||||||
if( info != NULL &&
|
if( info != NULL &&
|
||||||
mbedtls_ssl_tls13_named_group_is_ecdhe( info->tls_id ) )
|
mbedtls_ssl_tls13_named_group_is_ecdhe( *group_list ) )
|
||||||
{
|
{
|
||||||
*group_id = info->tls_id;
|
*group_id = *group_list;
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user