mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-09-13 14:22:19 +08:00
library: replace mbedtls_ssl_get_ecp_group_id_from_tls_id
All the usages of 'mbedtls_ssl_get_ecp_group_id_from_tls_id' basically reduce to checking if a specific TLS ID is supported or not. Therefore the function is replaced with 'mbedtls_ssl_is_tls_id_supported'. Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
parent
9e9eb069d6
commit
cac52a43c9
@ -255,8 +255,7 @@ static int ssl_write_supported_groups_ext(mbedtls_ssl_context *ssl,
|
|||||||
if (flags & SSL_WRITE_SUPPORTED_GROUPS_EXT_TLS1_3_FLAG) {
|
if (flags & SSL_WRITE_SUPPORTED_GROUPS_EXT_TLS1_3_FLAG) {
|
||||||
#if defined(PSA_WANT_ALG_ECDH)
|
#if defined(PSA_WANT_ALG_ECDH)
|
||||||
if (mbedtls_ssl_tls13_named_group_is_ecdhe(*group_list) &&
|
if (mbedtls_ssl_tls13_named_group_is_ecdhe(*group_list) &&
|
||||||
mbedtls_ssl_get_psa_curve_info_from_tls_id(
|
(mbedtls_ssl_is_tls_id_supported(*group_list))) {
|
||||||
*group_list, NULL, NULL) == PSA_SUCCESS) {
|
|
||||||
propose_group = 1;
|
propose_group = 1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -271,8 +270,7 @@ static int ssl_write_supported_groups_ext(mbedtls_ssl_context *ssl,
|
|||||||
#if defined(MBEDTLS_SSL_TLS1_2_SOME_ECC)
|
#if defined(MBEDTLS_SSL_TLS1_2_SOME_ECC)
|
||||||
if ((flags & SSL_WRITE_SUPPORTED_GROUPS_EXT_TLS1_2_FLAG) &&
|
if ((flags & SSL_WRITE_SUPPORTED_GROUPS_EXT_TLS1_2_FLAG) &&
|
||||||
mbedtls_ssl_tls12_named_group_is_ecdhe(*group_list) &&
|
mbedtls_ssl_tls12_named_group_is_ecdhe(*group_list) &&
|
||||||
(mbedtls_ssl_get_ecp_group_id_from_tls_id(*group_list) !=
|
(mbedtls_ssl_is_tls_id_supported(*group_list))) {
|
||||||
MBEDTLS_ECP_DP_NONE)) {
|
|
||||||
propose_group = 1;
|
propose_group = 1;
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_SSL_TLS1_2_SOME_ECC */
|
#endif /* MBEDTLS_SSL_TLS1_2_SOME_ECC */
|
||||||
|
|||||||
@ -1528,13 +1528,12 @@ int mbedtls_ssl_get_psa_curve_info_from_tls_id(uint16_t tls_id,
|
|||||||
size_t *bits);
|
size_t *bits);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return \c mbedtls_ecp_group_id for the specified TLS ID.
|
* \brief Tell if a TLS group ID is supported or not.
|
||||||
*
|
*
|
||||||
* \param tls_id The TLS ID to look for
|
* \param tls_id The TLS ID to look for.
|
||||||
* \return Proper \c mbedtls_ecp_group_id if the TLS ID is supported,
|
* \return 1 if specified TLS ID is supported, 0 otherwise.
|
||||||
* or MBEDTLS_ECP_DP_NONE otherwise
|
|
||||||
*/
|
*/
|
||||||
mbedtls_ecp_group_id mbedtls_ssl_get_ecp_group_id_from_tls_id(uint16_t tls_id);
|
int mbedtls_ssl_is_tls_id_supported(uint16_t tls_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Return TLS ID for the specified \c mbedtls_ecp_group_id.
|
* \brief Return TLS ID for the specified \c mbedtls_ecp_group_id.
|
||||||
@ -2249,8 +2248,7 @@ static inline int mbedtls_ssl_named_group_is_supported(uint16_t named_group)
|
|||||||
{
|
{
|
||||||
#if defined(PSA_WANT_ALG_ECDH)
|
#if defined(PSA_WANT_ALG_ECDH)
|
||||||
if (mbedtls_ssl_tls13_named_group_is_ecdhe(named_group)) {
|
if (mbedtls_ssl_tls13_named_group_is_ecdhe(named_group)) {
|
||||||
if (mbedtls_ssl_get_ecp_group_id_from_tls_id(named_group) !=
|
if (mbedtls_ssl_is_tls_id_supported(named_group)) {
|
||||||
MBEDTLS_ECP_DP_NONE) {
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5865,15 +5865,15 @@ int mbedtls_ssl_get_psa_curve_info_from_tls_id(uint16_t tls_id,
|
|||||||
return PSA_ERROR_NOT_SUPPORTED;
|
return PSA_ERROR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_ecp_group_id mbedtls_ssl_get_ecp_group_id_from_tls_id(uint16_t tls_id)
|
int mbedtls_ssl_is_tls_id_supported(uint16_t tls_id)
|
||||||
{
|
{
|
||||||
for (int i = 0; tls_id_match_table[i].tls_id != 0; i++) {
|
for (int i = 0; tls_id_match_table[i].tls_id != 0; i++) {
|
||||||
if (tls_id_match_table[i].tls_id == tls_id) {
|
if (tls_id_match_table[i].tls_id == tls_id) {
|
||||||
return tls_id_match_table[i].ecp_group_id;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return MBEDTLS_ECP_DP_NONE;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t mbedtls_ssl_get_tls_id_from_ecp_group_id(mbedtls_ecp_group_id grp_id)
|
uint16_t mbedtls_ssl_get_tls_id_from_ecp_group_id(mbedtls_ecp_group_id grp_id)
|
||||||
|
|||||||
@ -219,8 +219,7 @@ static int ssl_parse_supported_groups_ext(mbedtls_ssl_context *ssl,
|
|||||||
while (list_size > 0 && our_size > 1) {
|
while (list_size > 0 && our_size > 1) {
|
||||||
uint16_t curr_tls_id = MBEDTLS_GET_UINT16_BE(p, 0);
|
uint16_t curr_tls_id = MBEDTLS_GET_UINT16_BE(p, 0);
|
||||||
|
|
||||||
if (mbedtls_ssl_get_ecp_group_id_from_tls_id(curr_tls_id) !=
|
if (mbedtls_ssl_is_tls_id_supported(curr_tls_id)) {
|
||||||
MBEDTLS_ECP_DP_NONE) {
|
|
||||||
*curves_tls_id++ = curr_tls_id;
|
*curves_tls_id++ = curr_tls_id;
|
||||||
our_size--;
|
our_size--;
|
||||||
}
|
}
|
||||||
@ -630,12 +629,24 @@ static int ssl_check_key_curve(mbedtls_pk_context *pk,
|
|||||||
uint16_t *curves_tls_id)
|
uint16_t *curves_tls_id)
|
||||||
{
|
{
|
||||||
uint16_t *curr_tls_id = curves_tls_id;
|
uint16_t *curr_tls_id = curves_tls_id;
|
||||||
mbedtls_ecp_group_id grp_id = mbedtls_pk_get_ec_group_id(pk);
|
psa_key_type_t key_type = mbedtls_pk_get_type(pk);
|
||||||
mbedtls_ecp_group_id curr_grp_id;
|
size_t key_bits = mbedtls_pk_get_bitlen(pk);
|
||||||
|
psa_key_type_t curr_key_type;
|
||||||
|
size_t curr_key_bits;
|
||||||
|
psa_status_t status;
|
||||||
|
|
||||||
while (*curr_tls_id != 0) {
|
while (*curr_tls_id != 0) {
|
||||||
curr_grp_id = mbedtls_ssl_get_ecp_group_id_from_tls_id(*curr_tls_id);
|
status = mbedtls_ssl_get_psa_curve_info_from_tls_id(*curr_tls_id,
|
||||||
if (curr_grp_id == grp_id) {
|
&curr_key_type, &curr_key_bits);
|
||||||
|
if (status != PSA_SUCCESS) {
|
||||||
|
/* This TLS group ID is not supported. Move to the next one. */
|
||||||
|
curr_tls_id++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
/* Check if EC family type and key bits for the current TLS group ID are the
|
||||||
|
* same as the ones in the provided PK context. */
|
||||||
|
if ((PSA_KEY_TYPE_ECC_GET_FAMILY(key_type) == PSA_KEY_TYPE_ECC_GET_FAMILY(curr_key_type)) &&
|
||||||
|
(key_bits == curr_key_bits)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
curr_tls_id++;
|
curr_tls_id++;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user