Skip to content

Commit 1ec0fee

Browse files
committed
pk: wrap curve_id before passing it to PSA
Add a helper function in PSA utils
1 parent 08dfcea commit 1ec0fee

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

include/mbedtls/psa_util.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,19 @@ static inline int mbedtls_psa_err_translate_pk( psa_status_t status )
244244
}
245245
}
246246

247+
/* Translations for ECC */
248+
249+
/* This function transforms an ECC group identifier from
250+
* https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
251+
* into a PSA ECC group identifier. */
252+
static inline psa_ecc_curve_t mbedtls_psa_parse_tls_ecc_group(
253+
uint16_t tls_ecc_grp_reg_id )
254+
{
255+
/* The PSA identifiers are currently aligned with those from
256+
* the TLS Supported Groups registry, so no conversion is necessary. */
257+
return( (psa_ecc_curve_t) tls_ecc_grp_reg_id );
258+
}
259+
247260
#endif /* MBEDTLS_USE_PSA_CRYPTO */
248261

249262
#endif /* MBEDTLS_PSA_UTIL_H */

library/pk.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,8 @@ int mbedtls_pk_wrap_as_opaque( mbedtls_pk_context *pk,
572572
return( ret );
573573

574574
curve_id = mbedtls_ecp_curve_info_from_grp_id( ec->grp.id )->tls_id;
575-
key_type = PSA_KEY_TYPE_ECC_KEYPAIR(curve_id);
575+
key_type = PSA_KEY_TYPE_ECC_KEYPAIR(
576+
mbedtls_psa_parse_tls_ecc_group ( curve_id ) );
576577

577578
/* allocate a key slot */
578579
if( PSA_SUCCESS != psa_allocate_key( key_type, d_len * 8, &key ) )

0 commit comments

Comments
 (0)