1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Use PSA_ERROR_DATA_INVALID error code

If the file is read correctly, but it contains data that isn't valid,
the crypto storage code returns PSA_ERROR_DATA_INVALID.
The PSA_ERROR_DATA_CORRUPT and PSA_ERROR_STORAGE_FAILURE error codes are
replaced with PSA_ERROR_DATA_INVALID, except in the ITS subsystem.

Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
gabor-mezei-arm
2020-11-09 17:39:56 +01:00
parent 3d8b4f54d3
commit fe30924c45
5 changed files with 29 additions and 12 deletions

View File

@ -6593,7 +6593,7 @@ static psa_status_t psa_crypto_recover_transaction(
default:
/* We found an unsupported transaction in the storage.
* We don't know what state the storage is in. Give up. */
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
}
}
#endif /* PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS */

View File

@ -253,7 +253,7 @@ static psa_status_t psa_load_persistent_key_into_slot( psa_key_slot_t *slot )
psa_se_key_data_storage_t *data;
if( key_data_length != sizeof( *data ) )
{
status = PSA_ERROR_STORAGE_FAILURE;
status = PSA_ERROR_DATA_INVALID;
goto exit;
}
data = (psa_se_key_data_storage_t *) key_data;

View File

@ -108,7 +108,7 @@ static psa_status_t psa_crypto_storage_load(
status = psa_its_get( data_identifier, 0, (uint32_t) data_size, data, &data_length );
if( data_size != data_length )
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
return( status );
}
@ -156,7 +156,7 @@ static psa_status_t psa_crypto_storage_store( const mbedtls_svc_key_id_t key,
status = psa_its_set( data_identifier, (uint32_t) data_length, data, 0 );
if( status != PSA_SUCCESS )
{
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
}
status = psa_its_get_info( data_identifier, &data_identifier_info );
@ -167,7 +167,7 @@ static psa_status_t psa_crypto_storage_store( const mbedtls_svc_key_id_t key,
if( data_identifier_info.size != data_length )
{
status = PSA_ERROR_STORAGE_FAILURE;
status = PSA_ERROR_DATA_INVALID;
goto exit;
}
@ -194,11 +194,11 @@ psa_status_t psa_destroy_persistent_key( const mbedtls_svc_key_id_t key )
return( PSA_SUCCESS );
if( psa_its_remove( data_identifier ) != PSA_SUCCESS )
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
ret = psa_its_get_info( data_identifier, &data_identifier_info );
if( ret != PSA_ERROR_DOES_NOT_EXIST )
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
return( PSA_SUCCESS );
}
@ -313,7 +313,7 @@ static psa_status_t check_magic_header( const uint8_t *data )
{
if( memcmp( data, PSA_KEY_STORAGE_MAGIC_HEADER,
PSA_KEY_STORAGE_MAGIC_HEADER_LENGTH ) != 0 )
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
return( PSA_SUCCESS );
}
@ -329,7 +329,7 @@ psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data,
uint32_t version;
if( storage_data_length < sizeof(*storage_format) )
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
status = check_magic_header( storage_data );
if( status != PSA_SUCCESS )
@ -337,12 +337,12 @@ psa_status_t psa_parse_key_data_from_storage( const uint8_t *storage_data,
GET_UINT32_LE( version, storage_format->version, 0 );
if( version != 0 )
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
GET_UINT32_LE( *key_data_length, storage_format->data_len, 0 );
if( *key_data_length > ( storage_data_length - sizeof(*storage_format) ) ||
*key_data_length > PSA_CRYPTO_MAX_STORAGE_SIZE )
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
if( *key_data_length == 0 )
{
@ -470,7 +470,7 @@ psa_status_t psa_crypto_load_transaction( void )
if( status != PSA_SUCCESS )
return( status );
if( length != sizeof( psa_crypto_transaction ) )
return( PSA_ERROR_STORAGE_FAILURE );
return( PSA_ERROR_DATA_INVALID );
return( PSA_SUCCESS );
}