psa: slot mgmt: Simplify psa_validate_key_id

Special handling of volatile key identifiers is not
needed eventually, they can be handled just as
key identifier in the vendor range.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-11-11 14:57:44 +01:00
parent f473d8b44b
commit cbd7beab0d
3 changed files with 5 additions and 13 deletions

View file

@ -1870,7 +1870,7 @@ static psa_status_t psa_validate_key_attributes(
} }
else else
{ {
status = psa_validate_key_id( psa_get_key_id( attributes ), 0, 0 ); status = psa_validate_key_id( psa_get_key_id( attributes ), 0 );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
return( status ); return( status );
} }

View file

@ -52,7 +52,7 @@ typedef struct
static psa_global_data_t global_data; static psa_global_data_t global_data;
psa_status_t psa_validate_key_id( psa_status_t psa_validate_key_id(
mbedtls_svc_key_id_t key, int vendor_ok, int volatile_ok ) mbedtls_svc_key_id_t key, int vendor_ok )
{ {
psa_key_id_t key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key ); psa_key_id_t key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key );
@ -62,12 +62,7 @@ psa_status_t psa_validate_key_id(
if( vendor_ok && if( vendor_ok &&
( PSA_KEY_ID_VENDOR_MIN <= key_id ) && ( PSA_KEY_ID_VENDOR_MIN <= key_id ) &&
( key_id < PSA_KEY_ID_VOLATILE_MIN ) ) ( key_id <= PSA_KEY_ID_VENDOR_MAX ) )
return( PSA_SUCCESS );
if( volatile_ok &&
( PSA_KEY_ID_VOLATILE_MIN <= key_id ) &&
( key_id <= PSA_KEY_ID_VOLATILE_MAX ) )
return( PSA_SUCCESS ); return( PSA_SUCCESS );
return( PSA_ERROR_INVALID_HANDLE ); return( PSA_ERROR_INVALID_HANDLE );
@ -122,7 +117,7 @@ static psa_status_t psa_search_key_in_slots(
} }
else else
{ {
status = psa_validate_key_id( key, 1, 1 ); status = psa_validate_key_id( key, 1 );
if( status != PSA_SUCCESS ) if( status != PSA_SUCCESS )
return( status ); return( status );

View file

@ -212,13 +212,10 @@ psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime );
* \param[in] vendor_ok Non-zero to indicate that key identifiers in the * \param[in] vendor_ok Non-zero to indicate that key identifiers in the
* vendor range are allowed, volatile key identifiers * vendor range are allowed, volatile key identifiers
* excepted \c 0 otherwise. * excepted \c 0 otherwise.
* \param[in] volatile_ok Non-zero to indicate that volatile key identifiers
* are allowed \c 0 otherwise.
* *
* \retval #PSA_SUCCESS The identifier is valid. * \retval #PSA_SUCCESS The identifier is valid.
* \retval #PSA_ERROR_INVALID_ARGUMENT The key identifier is not valid. * \retval #PSA_ERROR_INVALID_ARGUMENT The key identifier is not valid.
*/ */
psa_status_t psa_validate_key_id( psa_status_t psa_validate_key_id( mbedtls_svc_key_id_t key, int vendor_ok );
mbedtls_svc_key_id_t key, int vendor_ok, int volatile_ok );
#endif /* PSA_CRYPTO_SLOT_MANAGEMENT_H */ #endif /* PSA_CRYPTO_SLOT_MANAGEMENT_H */