Skip to content

Commit 4d79d88

Browse files
author
David Saada
committed
Change ITS specific types to the more generic ones (defined in PSA spec)
1 parent 414fe31 commit 4d79d88

File tree

2 files changed

+28
-103
lines changed

2 files changed

+28
-103
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_EMPTY_SLOT );
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_OCCUPIED_SLOT );
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 & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -36,71 +36,37 @@
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_EMPTY_SLOT );
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_OCCUPIED_SLOT );
6539

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 )
40+
static psa_storage_uid_t psa_its_identifier_of_slot( psa_key_id_t key )
7241
{
7342
return( key );
7443
}
7544

7645
psa_status_t psa_crypto_storage_load( const psa_key_id_t key, uint8_t *data,
7746
size_t data_size )
7847
{
79-
psa_its_status_t ret;
8048
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;
49+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
50+
struct psa_storage_info_t data_identifier_info;
8351

84-
ret = psa_its_get_info( data_identifier, &data_identifier_info );
85-
status = its_to_psa_error( ret );
86-
if( status != PSA_SUCCESS )
52+
status = psa_its_get_info( data_identifier, &data_identifier_info );
53+
if( status != PSA_SUCCESS )
8754
return( status );
8855

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

9258
return( status );
9359
}
9460

9561
int psa_is_key_present_in_storage( const psa_key_id_t key )
9662
{
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;
63+
psa_status_t ret;
64+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
65+
struct psa_storage_info_t data_identifier_info;
10066

10167
ret = psa_its_get_info( data_identifier, &data_identifier_info );
10268

103-
if( ret == PSA_ITS_ERROR_UID_NOT_FOUND )
69+
if( ret == PSA_ERROR_DOES_NOT_EXIST )
10470
return( 0 );
10571
return( 1 );
10672
}
@@ -109,23 +75,20 @@ psa_status_t psa_crypto_storage_store( const psa_key_id_t key,
10975
const uint8_t *data,
11076
size_t data_length )
11177
{
112-
psa_its_status_t ret;
11378
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;
79+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
80+
struct psa_storage_info_t data_identifier_info;
11681

11782
if( psa_is_key_present_in_storage( key ) == 1 )
11883
return( PSA_ERROR_OCCUPIED_SLOT );
11984

120-
ret = psa_its_set( data_identifier, data_length, data, 0 );
121-
status = its_to_psa_error( ret );
85+
status = psa_its_set( data_identifier, data_length, data, 0 );
12286
if( status != PSA_SUCCESS )
12387
{
12488
return( PSA_ERROR_STORAGE_FAILURE );
12589
}
12690

127-
ret = psa_its_get_info( data_identifier, &data_identifier_info );
128-
status = its_to_psa_error( ret );
91+
status = psa_its_get_info( data_identifier, &data_identifier_info );
12992
if( status != PSA_SUCCESS )
13093
{
13194
goto exit;
@@ -145,19 +108,19 @@ psa_status_t psa_crypto_storage_store( const psa_key_id_t key,
145108

146109
psa_status_t psa_destroy_persistent_key( const psa_key_id_t key )
147110
{
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;
111+
psa_status_t ret;
112+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
113+
struct psa_storage_info_t data_identifier_info;
151114

152115
ret = psa_its_get_info( data_identifier, &data_identifier_info );
153-
if( ret == PSA_ITS_ERROR_UID_NOT_FOUND )
116+
if( ret == PSA_ERROR_DOES_NOT_EXIST )
154117
return( PSA_SUCCESS );
155118

156-
if( psa_its_remove( data_identifier ) != PSA_ITS_SUCCESS )
119+
if( psa_its_remove( data_identifier ) != PSA_SUCCESS )
157120
return( PSA_ERROR_STORAGE_FAILURE );
158121

159122
ret = psa_its_get_info( data_identifier, &data_identifier_info );
160-
if( ret != PSA_ITS_ERROR_UID_NOT_FOUND )
123+
if( ret != PSA_ERROR_DOES_NOT_EXIST )
161124
return( PSA_ERROR_STORAGE_FAILURE );
162125

163126
return( PSA_SUCCESS );
@@ -166,13 +129,11 @@ psa_status_t psa_destroy_persistent_key( const psa_key_id_t key )
166129
psa_status_t psa_crypto_storage_get_data_length( const psa_key_id_t key,
167130
size_t *data_length )
168131
{
169-
psa_its_status_t ret;
170132
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;
133+
psa_storage_uid_t data_identifier = psa_its_identifier_of_slot( key );
134+
struct psa_storage_info_t data_identifier_info;
173135

174-
ret = psa_its_get_info( data_identifier, &data_identifier_info );
175-
status = its_to_psa_error( ret );
136+
status = psa_its_get_info( data_identifier, &data_identifier_info );
176137
if( status != PSA_SUCCESS )
177138
return( status );
178139

0 commit comments

Comments
 (0)