@@ -183,39 +183,54 @@ static int psa_is_key_id_valid( psa_key_file_id_t file_id,
183183}
184184#endif /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
185185
186- psa_status_t psa_validate_persistent_key_parameters (
187- psa_key_lifetime_t lifetime ,
188- psa_key_file_id_t id ,
189- psa_se_drv_table_entry_t * * p_drv ,
190- int creating )
186+ psa_status_t psa_validate_key_location ( const psa_key_attributes_t * attributes ,
187+ psa_se_drv_table_entry_t * * p_drv )
191188{
192- if ( p_drv != NULL )
193- * p_drv = NULL ;
194- #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
195- if ( psa_key_lifetime_is_external ( lifetime ) )
189+ psa_key_lifetime_t lifetime = psa_get_key_lifetime ( attributes );
190+ if ( psa_key_lifetime_is_external ( lifetime ) )
196191 {
197- * p_drv = psa_get_se_driver_entry ( lifetime );
198- if ( * p_drv == NULL )
192+ #if defined(MBEDTLS_PSA_CRYPTO_SE_C )
193+ psa_se_drv_table_entry_t * p_drv_e = psa_get_se_driver_entry ( lifetime );
194+ if ( p_drv_e == NULL )
199195 return ( PSA_ERROR_INVALID_ARGUMENT );
196+ else
197+ {
198+ if (p_drv != NULL )
199+ * p_drv = p_drv_e ;
200+ return ( PSA_SUCCESS );
201+ }
202+ #else
203+ (void ) p_drv ;
204+ return ( PSA_ERROR_INVALID_ARGUMENT );
205+ #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
200206 }
201207 else
202- #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
203- if ( ( PSA_KEY_LIFETIME_GET_LOCATION ( lifetime )
204- != PSA_KEY_LOCATION_LOCAL_STORAGE ) ||
205- ( PSA_KEY_LIFETIME_GET_PERSISTENCE ( lifetime )
206- != PSA_KEY_PERSISTENCE_DEFAULT ) )
207- return ( PSA_ERROR_INVALID_ARGUMENT );
208+ /* Local/internal keys are always valid */
209+ return ( PSA_SUCCESS );
210+ }
208211
209- #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C )
210- if ( ! psa_is_key_id_valid ( id , ! creating ) )
211- return ( PSA_ERROR_INVALID_ARGUMENT );
212- return ( PSA_SUCCESS );
212+ psa_status_t psa_validate_key_persistence ( const psa_key_attributes_t * attributes )
213+ {
214+ psa_key_lifetime_t lifetime = psa_get_key_lifetime ( attributes );
213215
216+ if ( PSA_KEY_LIFETIME_IS_VOLATILE ( lifetime ) )
217+ {
218+ /* Volatile keys are always supported */
219+ return ( PSA_SUCCESS );
220+ }
221+ else
222+ {
223+ /* Persistent keys require storage support */
224+ #if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C )
225+ if ( psa_is_key_id_valid ( psa_get_key_id ( attributes ),
226+ psa_key_lifetime_is_external ( lifetime ) ) )
227+ return ( PSA_SUCCESS );
228+ else
229+ return ( PSA_ERROR_INVALID_ARGUMENT );
214230#else /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
215- (void ) id ;
216- (void ) creating ;
217- return ( PSA_ERROR_NOT_SUPPORTED );
231+ return ( PSA_ERROR_NOT_SUPPORTED );
218232#endif /* !MBEDTLS_PSA_CRYPTO_STORAGE_C */
233+ }
219234}
220235
221236psa_status_t psa_open_key ( psa_key_file_id_t id , psa_key_handle_t * handle )
@@ -226,10 +241,8 @@ psa_status_t psa_open_key( psa_key_file_id_t id, psa_key_handle_t *handle )
226241
227242 * handle = 0 ;
228243
229- status = psa_validate_persistent_key_parameters (
230- PSA_KEY_LIFETIME_PERSISTENT , id , NULL , 0 );
231- if ( status != PSA_SUCCESS )
232- return ( status );
244+ if ( ! psa_is_key_id_valid ( id , 1 ) )
245+ return ( PSA_ERROR_INVALID_ARGUMENT );
233246
234247 status = psa_get_empty_key_slot ( handle , & slot );
235248 if ( status != PSA_SUCCESS )
0 commit comments