Skip to content

Commit d19a7b7

Browse files
author
David Saada
committed
Replace ITS specific types with more generic PSA storage types
PSA spec now defines more generic PSA storage types instead of the ITS specific ones. This is necessary in order to integrate with the newer implementation of PSA ITS landing in Mbed OS soon. Changes include the following: - psa_status_t replaces psa_its_status_t - psa_storage_info_t replaces psa_its_info_t - psa_storage_uid_t replaces psa_its_uid_t
1 parent cbe31ee commit d19a7b7

File tree

2 files changed

+28
-104
lines changed

2 files changed

+28
-104
lines changed

library/psa_crypto.c

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4391,45 +4391,11 @@ psa_status_t psa_generate_random( uint8_t *output,
43914391

43924392
#if ( defined(MBEDTLS_ENTROPY_NV_SEED) && defined(MBEDTLS_PSA_HAS_ITS_IO) )
43934393

4394-
/* Support function for error conversion between psa_its error codes to psa crypto */
4395-
static psa_status_t its_to_psa_error( psa_its_status_t ret )
4396-
{
4397-
switch( ret )
4398-
{
4399-
case PSA_ITS_SUCCESS:
4400-
return( PSA_SUCCESS );
4401-
4402-
case PSA_ITS_ERROR_UID_NOT_FOUND:
4403-
return( PSA_ERROR_DOES_NOT_EXIST );
4404-
4405-
case PSA_ITS_ERROR_STORAGE_FAILURE:
4406-
return( PSA_ERROR_STORAGE_FAILURE );
4407-
4408-
case PSA_ITS_ERROR_INSUFFICIENT_SPACE:
4409-
return( PSA_ERROR_INSUFFICIENT_STORAGE );
4410-
4411-
case PSA_ITS_ERROR_OFFSET_INVALID:
4412-
case PSA_ITS_ERROR_INCORRECT_SIZE:
4413-
case PSA_ITS_ERROR_INVALID_ARGUMENTS:
4414-
return( PSA_ERROR_INVALID_ARGUMENT );
4415-
4416-
case PSA_ITS_ERROR_FLAGS_NOT_SUPPORTED:
4417-
return( PSA_ERROR_NOT_SUPPORTED );
4418-
4419-
case PSA_ITS_ERROR_WRITE_ONCE:
4420-
return( PSA_ERROR_ALREADY_EXISTS );
4421-
4422-
default:
4423-
return( PSA_ERROR_GENERIC_ERROR );
4424-
}
4425-
}
4426-
44274394
psa_status_t mbedtls_psa_inject_entropy( const unsigned char *seed,
44284395
size_t seed_size )
44294396
{
44304397
psa_status_t status;
4431-
psa_its_status_t its_status;
4432-
struct psa_its_info_t p_info;
4398+
struct psa_storage_info_t p_info;
44334399
if( global_data.initialized )
44344400
return( PSA_ERROR_NOT_PERMITTED );
44354401

@@ -4438,15 +4404,13 @@ psa_status_t mbedtls_psa_inject_entropy( const unsigned char *seed,
44384404
( seed_size > MBEDTLS_ENTROPY_MAX_SEED_SIZE ) )
44394405
return( PSA_ERROR_INVALID_ARGUMENT );
44404406

4441-
its_status = psa_its_get_info( PSA_CRYPTO_ITS_RANDOM_SEED_UID, &p_info );
4442-
status = its_to_psa_error( its_status );
4407+
status = psa_its_get_info( PSA_CRYPTO_ITS_RANDOM_SEED_UID, &p_info );
44434408

4444-
if( PSA_ITS_ERROR_UID_NOT_FOUND == its_status ) /* No seed exists */
4409+
if( PSA_ERROR_DOES_NOT_EXIST == status ) /* No seed exists */
44454410
{
4446-
its_status = psa_its_set( PSA_CRYPTO_ITS_RANDOM_SEED_UID, seed_size, seed, 0 );
4447-
status = its_to_psa_error( its_status );
4411+
status = psa_its_set( PSA_CRYPTO_ITS_RANDOM_SEED_UID, seed_size, seed, 0 );
44484412
}
4449-
else if( PSA_ITS_SUCCESS == its_status )
4413+
else if( PSA_SUCCESS == status )
44504414
{
44514415
/* You should not be here. Seed needs to be injected only once */
44524416
status = PSA_ERROR_NOT_PERMITTED;

library/psa_crypto_storage_its.c

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -36,71 +36,36 @@
3636
#include "mbedtls/platform.h"
3737
#endif
3838

39-
static psa_status_t its_to_psa_error( psa_its_status_t ret )
40-
{
41-
switch( ret )
42-
{
43-
case PSA_ITS_SUCCESS:
44-
return( PSA_SUCCESS );
45-
46-
case PSA_ITS_ERROR_UID_NOT_FOUND:
47-
return( PSA_ERROR_DOES_NOT_EXIST );
48-
49-
case PSA_ITS_ERROR_STORAGE_FAILURE:
50-
return( PSA_ERROR_STORAGE_FAILURE );
51-
52-
case PSA_ITS_ERROR_INSUFFICIENT_SPACE:
53-
return( PSA_ERROR_INSUFFICIENT_STORAGE );
54-
55-
case PSA_ITS_ERROR_OFFSET_INVALID:
56-
case PSA_ITS_ERROR_INCORRECT_SIZE:
57-
case PSA_ITS_ERROR_INVALID_ARGUMENTS:
58-
return( PSA_ERROR_INVALID_ARGUMENT );
59-
60-
case PSA_ITS_ERROR_FLAGS_NOT_SUPPORTED:
61-
return( PSA_ERROR_NOT_SUPPORTED );
62-
63-
case PSA_ITS_ERROR_WRITE_ONCE:
64-
return( PSA_ERROR_ALREADY_EXISTS );
65-
66-
default:
67-
return( PSA_ERROR_UNKNOWN_ERROR );
68-
}
69-
}
70-
71-
static psa_its_uid_t psa_its_identifier_of_slot( psa_key_id_t key )
39+
static psa_storage_uid_t psa_its_identifier_of_slot( psa_key_id_t key )
7240
{
7341
return( key );
7442
}
7543

7644
psa_status_t psa_crypto_storage_load( const psa_key_id_t key, uint8_t *data,
7745
size_t data_size )
7846
{
79-
psa_its_status_t ret;
8047
psa_status_t status;
81-
psa_its_uid_t data_identifier = psa_its_identifier_of_slot( key );
82-
struct psa_its_info_t data_identifier_info;
48+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
49+
struct psa_storage_info_t data_identifier_info;
8350

84-
ret = psa_its_get_info( data_identifier, &data_identifier_info );
85-
status = its_to_psa_error( ret );
86-
if( status != PSA_SUCCESS )
51+
status = psa_its_get_info( data_identifier, &data_identifier_info );
52+
if( status != PSA_SUCCESS )
8753
return( status );
8854

89-
ret = psa_its_get( data_identifier, 0, data_size, data );
90-
status = its_to_psa_error( ret );
55+
status = psa_its_get( data_identifier, 0, data_size, data );
9156

9257
return( status );
9358
}
9459

9560
int psa_is_key_present_in_storage( const psa_key_id_t key )
9661
{
97-
psa_its_status_t ret;
98-
psa_its_uid_t data_identifier = psa_its_identifier_of_slot( key );
99-
struct psa_its_info_t data_identifier_info;
62+
psa_status_t ret;
63+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
64+
struct psa_storage_info_t data_identifier_info;
10065

10166
ret = psa_its_get_info( data_identifier, &data_identifier_info );
10267

103-
if( ret == PSA_ITS_ERROR_UID_NOT_FOUND )
68+
if( ret == PSA_ERROR_DOES_NOT_EXIST )
10469
return( 0 );
10570
return( 1 );
10671
}
@@ -109,23 +74,20 @@ psa_status_t psa_crypto_storage_store( const psa_key_id_t key,
10974
const uint8_t *data,
11075
size_t data_length )
11176
{
112-
psa_its_status_t ret;
11377
psa_status_t status;
114-
psa_its_uid_t data_identifier = psa_its_identifier_of_slot( key );
115-
struct psa_its_info_t data_identifier_info;
78+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
79+
struct psa_storage_info_t data_identifier_info;
11680

11781
if( psa_is_key_present_in_storage( key ) == 1 )
11882
return( PSA_ERROR_ALREADY_EXISTS );
11983

120-
ret = psa_its_set( data_identifier, data_length, data, 0 );
121-
status = its_to_psa_error( ret );
84+
status = psa_its_set( data_identifier, data_length, data, 0 );
12285
if( status != PSA_SUCCESS )
12386
{
12487
return( PSA_ERROR_STORAGE_FAILURE );
12588
}
12689

127-
ret = psa_its_get_info( data_identifier, &data_identifier_info );
128-
status = its_to_psa_error( ret );
90+
status = psa_its_get_info( data_identifier, &data_identifier_info );
12991
if( status != PSA_SUCCESS )
13092
{
13193
goto exit;
@@ -145,19 +107,19 @@ psa_status_t psa_crypto_storage_store( const psa_key_id_t key,
145107

146108
psa_status_t psa_destroy_persistent_key( const psa_key_id_t key )
147109
{
148-
psa_its_status_t ret;
149-
psa_its_uid_t data_identifier = psa_its_identifier_of_slot( key );
150-
struct psa_its_info_t data_identifier_info;
110+
psa_status_t ret;
111+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
112+
struct psa_storage_info_t data_identifier_info;
151113

152114
ret = psa_its_get_info( data_identifier, &data_identifier_info );
153-
if( ret == PSA_ITS_ERROR_UID_NOT_FOUND )
115+
if( ret == PSA_ERROR_DOES_NOT_EXIST )
154116
return( PSA_SUCCESS );
155117

156-
if( psa_its_remove( data_identifier ) != PSA_ITS_SUCCESS )
118+
if( psa_its_remove( data_identifier ) != PSA_SUCCESS )
157119
return( PSA_ERROR_STORAGE_FAILURE );
158120

159121
ret = psa_its_get_info( data_identifier, &data_identifier_info );
160-
if( ret != PSA_ITS_ERROR_UID_NOT_FOUND )
122+
if( ret != PSA_ERROR_DOES_NOT_EXIST )
161123
return( PSA_ERROR_STORAGE_FAILURE );
162124

163125
return( PSA_SUCCESS );
@@ -166,13 +128,11 @@ psa_status_t psa_destroy_persistent_key( const psa_key_id_t key )
166128
psa_status_t psa_crypto_storage_get_data_length( const psa_key_id_t key,
167129
size_t *data_length )
168130
{
169-
psa_its_status_t ret;
170131
psa_status_t status;
171-
psa_its_uid_t data_identifier = psa_its_identifier_of_slot( key );
172-
struct psa_its_info_t data_identifier_info;
132+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
133+
struct psa_storage_info_t data_identifier_info;
173134

174-
ret = psa_its_get_info( data_identifier, &data_identifier_info );
175-
status = its_to_psa_error( ret );
135+
status = psa_its_get_info( data_identifier, &data_identifier_info );
176136
if( status != PSA_SUCCESS )
177137
return( status );
178138

0 commit comments

Comments
 (0)