Skip to content

Commit 424f894

Browse files
SE keys: store the bit size internally (partial implementation)
This commit blindingly copies the size from the attributes. This is not correct for copy and import.
1 parent adb1c52 commit 424f894

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

library/psa_crypto.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,11 @@ psa_status_t psa_destroy_key( psa_key_handle_t handle )
10351035
/* Return the size of the key in the given slot, in bits. */
10361036
static size_t psa_get_key_slot_bits( const psa_key_slot_t *slot )
10371037
{
1038+
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
1039+
if( psa_get_se_driver( slot->lifetime, NULL, NULL ) )
1040+
return( slot->data.se.bits );
1041+
#endif /* defined(MBEDTLS_PSA_CRYPTO_SE_C) */
1042+
10381043
if( key_type_is_raw_bytes( slot->type ) )
10391044
return( slot->data.raw.bytes * 8 );
10401045
#if defined(MBEDTLS_RSA_C)
@@ -1489,6 +1494,10 @@ static psa_status_t psa_start_key_creation(
14891494
(void) psa_crypto_stop_transaction( );
14901495
return( status );
14911496
}
1497+
1498+
/* TOnogrepDO: validate bits. How to do this depends on the key
1499+
* creation method, so setting bits might not belong here. */
1500+
slot->data.se.bits = psa_get_key_bits( attributes );
14921501
}
14931502
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
14941503

library/psa_crypto_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef struct
6464
struct se
6565
{
6666
psa_key_slot_number_t slot_number;
67+
size_t bits;
6768
} se;
6869
} data;
6970
} psa_key_slot_t;

0 commit comments

Comments
 (0)