mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-24 10:35:12 +00:00
Make psa_calculate_key_bits return psa_key_bits_t
This is cleaner and solves a complaint from MSVC about truncation from size_t to psa_key_bits_t.
This commit is contained in:
parent
1b8594a218
commit
8908c5e81c
|
@ -714,20 +714,24 @@ static inline size_t psa_get_key_slot_bits( const psa_key_slot_t *slot )
|
||||||
*
|
*
|
||||||
* \return The key size in bits, calculated from the key data.
|
* \return The key size in bits, calculated from the key data.
|
||||||
*/
|
*/
|
||||||
static size_t psa_calculate_key_bits( const psa_key_slot_t *slot )
|
static psa_key_bits_t psa_calculate_key_bits( const psa_key_slot_t *slot )
|
||||||
{
|
{
|
||||||
|
size_t bits = 0; /* return 0 on an empty slot */
|
||||||
|
|
||||||
if( key_type_is_raw_bytes( slot->attr.type ) )
|
if( key_type_is_raw_bytes( slot->attr.type ) )
|
||||||
return( slot->data.raw.bytes * 8 );
|
bits = PSA_BYTES_TO_BITS( slot->data.raw.bytes );
|
||||||
#if defined(MBEDTLS_RSA_C)
|
#if defined(MBEDTLS_RSA_C)
|
||||||
if( PSA_KEY_TYPE_IS_RSA( slot->attr.type ) )
|
else if( PSA_KEY_TYPE_IS_RSA( slot->attr.type ) )
|
||||||
return( PSA_BYTES_TO_BITS( mbedtls_rsa_get_len( slot->data.rsa ) ) );
|
bits = PSA_BYTES_TO_BITS( mbedtls_rsa_get_len( slot->data.rsa ) );
|
||||||
#endif /* defined(MBEDTLS_RSA_C) */
|
#endif /* defined(MBEDTLS_RSA_C) */
|
||||||
#if defined(MBEDTLS_ECP_C)
|
#if defined(MBEDTLS_ECP_C)
|
||||||
if( PSA_KEY_TYPE_IS_ECC( slot->attr.type ) )
|
else if( PSA_KEY_TYPE_IS_ECC( slot->attr.type ) )
|
||||||
return( slot->data.ecp->grp.pbits );
|
bits = slot->data.ecp->grp.pbits;
|
||||||
#endif /* defined(MBEDTLS_ECP_C) */
|
#endif /* defined(MBEDTLS_ECP_C) */
|
||||||
/* Shouldn't happen except on an empty slot. */
|
|
||||||
return( 0 );
|
/* We know that the size fits in psa_key_bits_t thanks to checks
|
||||||
|
* when the key was created. */
|
||||||
|
return( (psa_key_bits_t) bits );
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Import key data into a slot. `slot->attr.type` must have been set
|
/** Import key data into a slot. `slot->attr.type` must have been set
|
||||||
|
|
Loading…
Reference in a new issue