Skip to content

Commit db4b3ab

Browse files
Implement missing attributes setters and getters
1 parent 4747d19 commit db4b3ab

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

include/psa/crypto_struct.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,26 @@ static inline struct psa_key_attributes_s psa_key_attributes_init( void )
276276
return( v );
277277
}
278278

279+
static inline void psa_make_key_persistent(psa_key_attributes_t *attributes,
280+
psa_key_id_t id,
281+
psa_key_lifetime_t lifetime)
282+
{
283+
attributes->id = id;
284+
attributes->lifetime = lifetime;
285+
}
286+
287+
static inline psa_key_id_t psa_get_key_id(
288+
const psa_key_attributes_t *attributes)
289+
{
290+
return( attributes->id );
291+
}
292+
293+
static inline psa_key_lifetime_t psa_get_key_lifetime(
294+
const psa_key_attributes_t *attributes)
295+
{
296+
return( attributes->lifetime );
297+
}
298+
279299
static inline void psa_set_key_usage_flags(psa_key_attributes_t *attributes,
280300
psa_key_usage_t usage_flags)
281301
{
@@ -312,4 +332,10 @@ static inline psa_key_type_t psa_get_key_type(
312332
return( attributes->type );
313333
}
314334

335+
static inline size_t psa_get_key_bits(
336+
const psa_key_attributes_t *attributes)
337+
{
338+
return( attributes->bits );
339+
}
340+
315341
#endif /* PSA_CRYPTO_STRUCT_H */

library/psa_crypto.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ psa_status_t psa_destroy_key( psa_key_handle_t handle )
965965
}
966966

967967
/* Return the size of the key in the given slot, in bits. */
968-
static size_t psa_get_key_bits( const psa_key_slot_t *slot )
968+
static size_t psa_get_key_slot_bits( const psa_key_slot_t *slot )
969969
{
970970
if( key_type_is_raw_bytes( slot->type ) )
971971
return( slot->data.raw.bytes * 8 );
@@ -1001,7 +1001,7 @@ psa_status_t psa_get_key_information( psa_key_handle_t handle,
10011001
if( type != NULL )
10021002
*type = slot->type;
10031003
if( bits != NULL )
1004-
*bits = psa_get_key_bits( slot );
1004+
*bits = psa_get_key_slot_bits( slot );
10051005
return( PSA_SUCCESS );
10061006
}
10071007

@@ -1050,7 +1050,7 @@ static psa_status_t psa_internal_export_key( const psa_key_slot_t *slot,
10501050
{
10511051
psa_status_t status;
10521052

1053-
size_t bytes = PSA_BITS_TO_BYTES( psa_get_key_bits( slot ) );
1053+
size_t bytes = PSA_BITS_TO_BYTES( psa_get_key_slot_bits( slot ) );
10541054
if( bytes > data_size )
10551055
return( PSA_ERROR_BUFFER_TOO_SMALL );
10561056
status = mbedtls_to_psa_error(
@@ -1285,7 +1285,7 @@ static psa_status_t psa_finish_key_creation( psa_key_slot_t *slot )
12851285
size_t length;
12861286

12871287
buffer_size = PSA_KEY_EXPORT_MAX_SIZE( slot->type,
1288-
psa_get_key_bits( slot ) );
1288+
psa_get_key_slot_bits( slot ) );
12891289
buffer = mbedtls_calloc( 1, buffer_size );
12901290
if( buffer == NULL && buffer_size != 0 )
12911291
return( PSA_ERROR_INSUFFICIENT_MEMORY );
@@ -1355,7 +1355,7 @@ static psa_status_t psa_copy_key_material( const psa_key_slot_t *source,
13551355
size_t length;
13561356

13571357
buffer_size = PSA_KEY_EXPORT_MAX_SIZE( source->type,
1358-
psa_get_key_bits( source ) );
1358+
psa_get_key_slot_bits( source ) );
13591359
buffer = mbedtls_calloc( 1, buffer_size );
13601360
if( buffer == NULL && buffer_size != 0 )
13611361
return( PSA_ERROR_INSUFFICIENT_MEMORY );
@@ -2149,7 +2149,7 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
21492149
status = psa_get_key_from_slot( handle, &slot, usage, alg );
21502150
if( status != PSA_SUCCESS )
21512151
goto exit;
2152-
key_bits = psa_get_key_bits( slot );
2152+
key_bits = psa_get_key_slot_bits( slot );
21532153

21542154
#if defined(MBEDTLS_CMAC_C)
21552155
if( full_length_alg == PSA_ALG_CMAC )
@@ -3060,7 +3060,7 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
30603060
status = psa_get_key_from_slot( handle, &slot, usage, alg);
30613061
if( status != PSA_SUCCESS )
30623062
goto exit;
3063-
key_bits = psa_get_key_bits( slot );
3063+
key_bits = psa_get_key_slot_bits( slot );
30643064

30653065
cipher_info = mbedtls_cipher_info_from_psa( alg, slot->type, key_bits, NULL );
30663066
if( cipher_info == NULL )
@@ -3470,7 +3470,7 @@ static psa_status_t psa_aead_setup( aead_operation_t *operation,
34703470
if( status != PSA_SUCCESS )
34713471
return( status );
34723472

3473-
key_bits = psa_get_key_bits( operation->slot );
3473+
key_bits = psa_get_key_slot_bits( operation->slot );
34743474

34753475
operation->cipher_info =
34763476
mbedtls_cipher_info_from_psa( alg, operation->slot->type, key_bits,

0 commit comments

Comments
 (0)