mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 09:05:39 +01:00
psa: Use psa_key_file_id_t as the key id type
The purpose of this commit and the following is for psa_key_id_t to always be as defined by the PSA Cryptography API specification. Currently psa_key_id_t departs from its specification definition when MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER configuration flag is set. In that configuration, it is set to be equal to psa_key_file_id_t which in that configuration encodes an owner identifier along the key identifier. Type psa_key_file_id_t was meant to be the key identifier type used throughout the library code. If MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER is set it includes both a key and owner identifier, otherwise it is equal to psa_key_id_t. It has not been the key identifier type throughout the library so far because when the PSA Cryptography specification was developped the library Doxygen documentation was used to generate the PSA Cryptography API specification thus the need to use psa_key_id_t and not psa_key_file_id_t. As this constraint does not hold anymore, move to psa_key_file_id_t as the key identifier type throughout the library code. By the way, this commit updates the key identifier initialization in the tests to be compatible with a composit key identifier. A psa_key_id_make() inline function is introduced to initialize key identifiers (composit ot not) at runtime. Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
80b95101a9
commit
27238fcbd8
@ -146,11 +146,11 @@ static psa_key_attributes_t psa_key_attributes_init(void);
|
||||
* linkage). This function may be provided as a function-like macro,
|
||||
* but in this case it must evaluate each of its arguments exactly once.
|
||||
*
|
||||
* \param[out] attributes The attribute structure to write to.
|
||||
* \param id The persistent identifier for the key.
|
||||
* \param[out] attributes The attribute structure to write to.
|
||||
* \param key The persistent identifier for the key.
|
||||
*/
|
||||
static void psa_set_key_id(psa_key_attributes_t *attributes,
|
||||
psa_key_id_t id);
|
||||
psa_key_file_id_t key);
|
||||
|
||||
/** Set the location of a persistent key.
|
||||
*
|
||||
@ -192,7 +192,7 @@ static void psa_set_key_lifetime(psa_key_attributes_t *attributes,
|
||||
* This value is unspecified if the attribute structure declares
|
||||
* the key as volatile.
|
||||
*/
|
||||
static psa_key_id_t psa_get_key_id(const psa_key_attributes_t *attributes);
|
||||
static psa_key_file_id_t psa_get_key_id(const psa_key_attributes_t *attributes);
|
||||
|
||||
/** Retrieve the lifetime from key attributes.
|
||||
*
|
||||
@ -392,8 +392,9 @@ void psa_reset_key_attributes(psa_key_attributes_t *attributes);
|
||||
* with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key
|
||||
* always has a nonzero key identifier, set with psa_set_key_id() when
|
||||
* creating the key. Implementations may provide additional pre-provisioned
|
||||
* keys that can be opened with psa_open_key(). Such keys have a key identifier
|
||||
* in the vendor range, as documented in the description of #psa_key_id_t.
|
||||
* keys that can be opened with psa_open_key(). Such keys have an application
|
||||
* key identifier in the vendor range, as documented in the description of
|
||||
* #psa_key_id_t.
|
||||
*
|
||||
* The application must eventually close the handle with psa_close_key() or
|
||||
* psa_destroy_key() to release associated resources. If the application dies
|
||||
@ -408,7 +409,7 @@ void psa_reset_key_attributes(psa_key_attributes_t *attributes);
|
||||
* portable to implementations that only permit a single key handle to be
|
||||
* opened. See also :ref:\`key-handles\`.
|
||||
*
|
||||
* \param id The persistent identifier of the key.
|
||||
* \param key The persistent identifier of the key.
|
||||
* \param[out] handle On success, a handle to the key.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
@ -436,8 +437,7 @@ void psa_reset_key_attributes(psa_key_attributes_t *attributes);
|
||||
* It is implementation-dependent whether a failure to initialize
|
||||
* results in this error code.
|
||||
*/
|
||||
psa_status_t psa_open_key(psa_key_id_t id,
|
||||
psa_key_handle_t *handle);
|
||||
psa_status_t psa_open_key(psa_key_file_id_t key, psa_key_handle_t *handle);
|
||||
|
||||
|
||||
/** Close a key handle.
|
||||
|
@ -330,7 +330,7 @@ typedef struct
|
||||
psa_key_type_t type;
|
||||
psa_key_bits_t bits;
|
||||
psa_key_lifetime_t lifetime;
|
||||
psa_key_id_t id;
|
||||
psa_key_file_id_t id;
|
||||
psa_key_policy_t policy;
|
||||
psa_key_attributes_flag_t flags;
|
||||
} psa_core_key_attributes_t;
|
||||
@ -360,14 +360,14 @@ static inline struct psa_key_attributes_s psa_key_attributes_init( void )
|
||||
}
|
||||
|
||||
static inline void psa_set_key_id(psa_key_attributes_t *attributes,
|
||||
psa_key_id_t id)
|
||||
psa_key_file_id_t key)
|
||||
{
|
||||
attributes->core.id = id;
|
||||
attributes->core.id = key;
|
||||
if( attributes->core.lifetime == PSA_KEY_LIFETIME_VOLATILE )
|
||||
attributes->core.lifetime = PSA_KEY_LIFETIME_PERSISTENT;
|
||||
}
|
||||
|
||||
static inline psa_key_id_t psa_get_key_id(
|
||||
static inline psa_key_file_id_t psa_get_key_id(
|
||||
const psa_key_attributes_t *attributes)
|
||||
{
|
||||
return( attributes->core.id );
|
||||
|
@ -37,6 +37,11 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
|
||||
!defined(inline) && !defined(__cplusplus)
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/** \defgroup error Error codes
|
||||
* @{
|
||||
*/
|
||||
@ -125,7 +130,7 @@ typedef uint32_t psa_algorithm_t;
|
||||
* implementation-specific device management event occurs (for example,
|
||||
* a factory reset).
|
||||
*
|
||||
* Persistent keys have a key identifier of type #psa_key_id_t.
|
||||
* Persistent keys have a key identifier of type #psa_key_file_id_t.
|
||||
* This identifier remains valid throughout the lifetime of the key,
|
||||
* even if the application instance that created the key terminates.
|
||||
* The application can call psa_open_key() to open a persistent key that
|
||||
@ -239,6 +244,19 @@ typedef psa_key_id_t psa_key_file_id_t;
|
||||
#define PSA_KEY_ID_INIT 0
|
||||
#define PSA_KEY_FILE_GET_KEY_ID( id ) ( id )
|
||||
|
||||
/** Utility to initialize a key file identifier at runtime.
|
||||
*
|
||||
* \param unused Unused parameter.
|
||||
* \param key_id Identifier of the key.
|
||||
*/
|
||||
static inline psa_key_file_id_t psa_key_file_id_make(
|
||||
unsigned int unused, psa_key_id_t key_id )
|
||||
{
|
||||
(void)unused;
|
||||
|
||||
return( key_id );
|
||||
}
|
||||
|
||||
#else /* MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
|
||||
typedef struct
|
||||
{
|
||||
@ -246,16 +264,21 @@ typedef struct
|
||||
psa_key_owner_id_t owner;
|
||||
} psa_key_file_id_t;
|
||||
|
||||
/* Since crypto.h is used as part of the PSA Cryptography API specification,
|
||||
* it must use standard types for things like the argument of psa_open_key().
|
||||
* If it wasn't for that constraint, psa_open_key() would take a
|
||||
* `psa_key_file_id_t` argument. As a workaround, make `psa_key_id_t` an
|
||||
* alias for `psa_key_file_id_t` when building for a multi-client service. */
|
||||
typedef psa_key_file_id_t psa_key_id_t;
|
||||
|
||||
#define PSA_KEY_ID_INIT {0, 0}
|
||||
#define PSA_KEY_FILE_GET_KEY_ID( file_id ) ( ( file_id ).key_id )
|
||||
|
||||
/** Utility to initialize a key file identifier at runtime.
|
||||
*
|
||||
* \param owner_id Identifier of the key owner.
|
||||
* \param key_id Identifier of the key.
|
||||
*/
|
||||
static inline psa_key_file_id_t psa_key_file_id_make(
|
||||
psa_key_owner_id_t owner_id, uint32_t key_id )
|
||||
{
|
||||
return( (psa_key_file_id_t){ .key_id = key_id,
|
||||
.owner = owner_id } );
|
||||
}
|
||||
|
||||
#endif /* !MBEDTLS_PSA_CRYPTO_KEY_FILE_ID_ENCODES_OWNER */
|
||||
|
||||
/**@}*/
|
||||
|
@ -45,13 +45,13 @@
|
||||
/** The base of the range of ITS file identifiers for secure element
|
||||
* driver persistent data.
|
||||
*
|
||||
* We use a slice of the implemenation reserved range 0xffff0000..0xffffffff,
|
||||
* We use a slice of the implementation reserved range 0xffff0000..0xffffffff,
|
||||
* specifically the range 0xfffffe00..0xfffffeff. The length of this range
|
||||
* drives the value of #PSA_MAX_SE_LOCATION. The identifier 0xfffffe00 is
|
||||
* actually not used since it corresponds to #PSA_KEY_LOCATION_LOCAL_STORAGE
|
||||
* which doesn't have a driver.
|
||||
*/
|
||||
#define PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE ( (psa_key_id_t) 0xfffffe00 )
|
||||
#define PSA_CRYPTO_SE_DRIVER_ITS_UID_BASE ( (psa_app_key_id_t) 0xfffffe00 )
|
||||
|
||||
/** The maximum number of registered secure element driver locations. */
|
||||
#define PSA_MAX_SE_DRIVERS 4
|
||||
|
@ -204,7 +204,7 @@ psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime,
|
||||
}
|
||||
|
||||
psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime,
|
||||
psa_key_id_t key_id )
|
||||
psa_key_file_id_t key )
|
||||
{
|
||||
if ( PSA_KEY_LIFETIME_IS_VOLATILE( lifetime ) )
|
||||
{
|
||||
@ -215,19 +215,19 @@ psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime,
|
||||
{
|
||||
/* Persistent keys require storage support */
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
|
||||
if( psa_is_key_id_valid( key_id,
|
||||
if( psa_is_key_id_valid( key,
|
||||
psa_key_lifetime_is_external( lifetime ) ) )
|
||||
return( PSA_SUCCESS );
|
||||
else
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
#else /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
|
||||
(void) key_id;
|
||||
(void) key;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
#endif /* !MBEDTLS_PSA_CRYPTO_STORAGE_C */
|
||||
}
|
||||
}
|
||||
|
||||
psa_status_t psa_open_key( psa_key_file_id_t id, psa_key_handle_t *handle )
|
||||
psa_status_t psa_open_key( psa_key_file_id_t key, psa_key_handle_t *handle )
|
||||
{
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
|
||||
psa_status_t status;
|
||||
@ -235,7 +235,7 @@ psa_status_t psa_open_key( psa_key_file_id_t id, psa_key_handle_t *handle )
|
||||
|
||||
*handle = 0;
|
||||
|
||||
if( ! psa_is_key_id_valid( id, 1 ) )
|
||||
if( ! psa_is_key_id_valid( key, 1 ) )
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
|
||||
status = psa_get_empty_key_slot( handle, &slot );
|
||||
@ -243,7 +243,7 @@ psa_status_t psa_open_key( psa_key_file_id_t id, psa_key_handle_t *handle )
|
||||
return( status );
|
||||
|
||||
slot->attr.lifetime = PSA_KEY_LIFETIME_PERSISTENT;
|
||||
slot->attr.id = id;
|
||||
slot->attr.id = key;
|
||||
|
||||
status = psa_load_persistent_key_into_slot( slot );
|
||||
if( status != PSA_SUCCESS )
|
||||
@ -254,7 +254,7 @@ psa_status_t psa_open_key( psa_key_file_id_t id, psa_key_handle_t *handle )
|
||||
return( status );
|
||||
|
||||
#else /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
|
||||
(void) id;
|
||||
(void) key;
|
||||
*handle = 0;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
#endif /* !defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
|
||||
|
@ -113,14 +113,14 @@ psa_status_t psa_validate_key_location( psa_key_lifetime_t lifetime,
|
||||
* This function checks whether a key's declared persistence level and key ID
|
||||
* attributes are valid and known to the PSA Core in its actual configuration.
|
||||
*
|
||||
* \param[in] lifetime The key lifetime attribute.
|
||||
* \param[in] key_id The key ID attribute
|
||||
* \param[in] lifetime The key lifetime attribute.
|
||||
* \param[in] key The key identifier.
|
||||
*
|
||||
* \retval #PSA_SUCCESS
|
||||
* \retval #PSA_ERROR_INVALID_ARGUMENT
|
||||
*/
|
||||
psa_status_t psa_validate_key_persistence( psa_key_lifetime_t lifetime,
|
||||
psa_key_id_t key_id );
|
||||
psa_key_file_id_t key );
|
||||
|
||||
|
||||
#endif /* PSA_CRYPTO_SLOT_MANAGEMENT_H */
|
||||
|
@ -394,7 +394,7 @@ psa_status_t psa_load_persistent_key( psa_core_key_attributes_t *attr,
|
||||
psa_status_t status = PSA_SUCCESS;
|
||||
uint8_t *loaded_data;
|
||||
size_t storage_data_length = 0;
|
||||
psa_key_id_t key = attr->id;
|
||||
psa_key_file_id_t key = attr->id;
|
||||
|
||||
status = psa_crypto_storage_get_data_length( key, &storage_data_length );
|
||||
if( status != PSA_SUCCESS )
|
||||
|
@ -292,7 +292,7 @@ typedef union
|
||||
uint16_t unused1;
|
||||
psa_key_lifetime_t lifetime;
|
||||
psa_key_slot_number_t slot;
|
||||
psa_key_id_t id;
|
||||
psa_key_file_id_t id;
|
||||
} key;
|
||||
} psa_crypto_transaction_t;
|
||||
|
||||
@ -361,7 +361,7 @@ psa_status_t psa_crypto_stop_transaction( void );
|
||||
*
|
||||
* 0xffffffNN = special file; 0x74 = 't' for transaction.
|
||||
*/
|
||||
#define PSA_CRYPTO_ITS_TRANSACTION_UID ( (psa_key_id_t) 0xffffff74 )
|
||||
#define PSA_CRYPTO_ITS_TRANSACTION_UID ( (psa_app_key_id_t) 0xffffff74 )
|
||||
|
||||
#endif /* PSA_CRYPTO_STORAGE_HAS_TRANSACTIONS */
|
||||
|
||||
|
@ -233,7 +233,7 @@ int check_key_attributes_sanity( psa_key_handle_t key )
|
||||
int ok = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_lifetime_t lifetime;
|
||||
psa_key_id_t id;
|
||||
psa_key_file_id_t id;
|
||||
psa_key_type_t type;
|
||||
psa_key_type_t bits;
|
||||
|
||||
@ -1326,7 +1326,7 @@ void attributes_set_get( int id_arg, int lifetime_arg,
|
||||
int type_arg, int bits_arg )
|
||||
{
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_id_t id = id_arg;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, id_arg );
|
||||
psa_key_lifetime_t lifetime = lifetime_arg;
|
||||
psa_key_usage_t usage_flags = usage_flags_arg;
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
@ -1370,10 +1370,10 @@ void persistence_attributes( int id1_arg, int lifetime_arg, int id2_arg,
|
||||
int expected_id_arg, int expected_lifetime_arg )
|
||||
{
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_id_t id1 = id1_arg;
|
||||
psa_key_file_id_t id1 = psa_key_file_id_make( 1, id1_arg );
|
||||
psa_key_lifetime_t lifetime = lifetime_arg;
|
||||
psa_key_id_t id2 = id2_arg;
|
||||
psa_key_id_t expected_id = expected_id_arg;
|
||||
psa_key_file_id_t id2 = psa_key_file_id_make( 1, id2_arg );
|
||||
psa_key_file_id_t expected_id = psa_key_file_id_make( 1, expected_id_arg );
|
||||
psa_key_lifetime_t expected_lifetime = expected_lifetime_arg;
|
||||
|
||||
if( id1_arg != -1 )
|
||||
@ -5584,7 +5584,7 @@ void persistent_key_load_key_from_storage( data_t *data,
|
||||
int usage_flags_arg, int alg_arg,
|
||||
int generation_method )
|
||||
{
|
||||
psa_key_id_t key_id = 1;
|
||||
psa_key_file_id_t key_id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_handle_t base_key = 0;
|
||||
|
@ -112,7 +112,7 @@ exit:
|
||||
/* BEGIN_CASE */
|
||||
void save_large_persistent_key( int data_length_arg, int expected_status )
|
||||
{
|
||||
psa_key_id_t key_id = 42;
|
||||
psa_key_file_id_t key_id = psa_key_file_id_make( 1, 42 );
|
||||
psa_key_handle_t handle = 0;
|
||||
uint8_t *data = NULL;
|
||||
size_t data_length = data_length_arg;
|
||||
@ -143,7 +143,7 @@ void persistent_key_destroy( int key_id_arg, int restart,
|
||||
int first_type_arg, data_t *first_data,
|
||||
int second_type_arg, data_t *second_data )
|
||||
{
|
||||
psa_key_id_t key_id = key_id_arg;
|
||||
psa_key_file_id_t key_id = psa_key_file_id_make( 1, key_id_arg );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_type_t first_type = (psa_key_type_t) first_type_arg;
|
||||
psa_key_type_t second_type = (psa_key_type_t) second_type_arg;
|
||||
@ -196,7 +196,7 @@ exit:
|
||||
void persistent_key_import( int key_id_arg, int type_arg, data_t *data,
|
||||
int restart, int expected_status )
|
||||
{
|
||||
psa_key_id_t key_id = (psa_key_id_t) key_id_arg;
|
||||
psa_key_file_id_t key_id = psa_key_file_id_make( 1, key_id_arg );
|
||||
psa_key_type_t type = (psa_key_type_t) type_arg;
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
@ -245,7 +245,7 @@ void import_export_persistent_key( data_t *data, int type_arg,
|
||||
int expected_bits,
|
||||
int restart, int key_not_exist )
|
||||
{
|
||||
psa_key_id_t key_id = 42;
|
||||
psa_key_file_id_t key_id = psa_key_file_id_make( 1, 42 );
|
||||
psa_key_type_t type = (psa_key_type_t) type_arg;
|
||||
psa_key_handle_t handle = 0;
|
||||
unsigned char *exported = NULL;
|
||||
|
@ -760,13 +760,13 @@ exit:
|
||||
#define MAX_KEY_ID_FOR_TEST 10
|
||||
static void psa_purge_storage( void )
|
||||
{
|
||||
psa_key_id_t id;
|
||||
psa_app_key_id_t id;
|
||||
psa_key_location_t location;
|
||||
/* The tests may have potentially created key ids from 1 to
|
||||
* MAX_KEY_ID_FOR_TEST. In addition, run the destroy function on key id
|
||||
* 0, which file-based storage uses as a temporary file. */
|
||||
for( id = 0; id <= MAX_KEY_ID_FOR_TEST; id++ )
|
||||
psa_destroy_persistent_key( id );
|
||||
psa_destroy_persistent_key( psa_key_file_id_make( 1, id ) );
|
||||
/* Purge the transaction file. */
|
||||
psa_crypto_stop_transaction( );
|
||||
/* Purge driver persistent data. */
|
||||
@ -853,7 +853,7 @@ void key_creation_import_export( int lifetime_arg, int min_slot, int restart )
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = (psa_key_lifetime_t) lifetime_arg;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
@ -985,7 +985,7 @@ void key_creation_in_chosen_slot( int slot_arg,
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
@ -1067,7 +1067,7 @@ void import_key_smoke( int type_arg, int alg_arg,
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
@ -1139,7 +1139,7 @@ void generate_key_not_supported( int type_arg, int bits_arg )
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
@ -1178,7 +1178,7 @@ void generate_key_smoke( int type_arg, int bits_arg, int alg_arg )
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
@ -1258,7 +1258,7 @@ void sign_verify( int flow,
|
||||
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t drv_handle = 0; /* key managed by the driver */
|
||||
psa_key_handle_t sw_handle = 0; /* transparent key */
|
||||
psa_key_attributes_t sw_attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
@ -1420,7 +1420,7 @@ void register_key_smoke_test( int lifetime_arg,
|
||||
psa_drv_se_t driver;
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_id_t id = id_arg;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, id_arg );
|
||||
size_t bit_size = 48;
|
||||
psa_key_slot_number_t wanted_slot = 0x123456789;
|
||||
psa_key_handle_t handle = 0;
|
||||
|
@ -89,13 +89,13 @@ static struct
|
||||
#define MAX_KEY_ID_FOR_TEST 10
|
||||
static void psa_purge_storage( void )
|
||||
{
|
||||
psa_key_id_t id;
|
||||
psa_app_key_id_t id;
|
||||
psa_key_location_t location;
|
||||
/* The tests may have potentially created key ids from 1 to
|
||||
* MAX_KEY_ID_FOR_TEST. In addition, run the destroy function on key id
|
||||
* 0, which file-based storage uses as a temporary file. */
|
||||
for( id = 0; id <= MAX_KEY_ID_FOR_TEST; id++ )
|
||||
psa_destroy_persistent_key( id );
|
||||
psa_destroy_persistent_key( psa_key_file_id_make( 1, id ) );
|
||||
/* Purge the transaction file. */
|
||||
psa_crypto_stop_transaction( );
|
||||
/* Purge driver persistent data. */
|
||||
@ -330,7 +330,7 @@ void mock_import( int mock_alloc_return_value,
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
@ -387,7 +387,7 @@ void mock_export( int mock_export_return_value, int expected_result )
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
@ -441,7 +441,7 @@ void mock_generate( int mock_alloc_return_value,
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
|
||||
@ -496,7 +496,7 @@ void mock_export_public( int mock_export_public_return_value,
|
||||
psa_drv_se_key_management_t key_management;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
@ -546,7 +546,7 @@ void mock_sign( int mock_sign_return_value, int expected_result )
|
||||
psa_drv_se_asymmetric_t asymmetric;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
@ -607,7 +607,7 @@ void mock_verify( int mock_verify_return_value, int expected_result )
|
||||
psa_drv_se_asymmetric_t asymmetric;
|
||||
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
|
||||
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
|
||||
psa_key_id_t id = 1;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, 1 );
|
||||
psa_key_handle_t handle = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
|
||||
|
@ -34,11 +34,11 @@ typedef enum
|
||||
* code. */
|
||||
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_STORAGE_C)
|
||||
static psa_key_id_t key_ids_used_in_test[9];
|
||||
static psa_key_file_id_t key_ids_used_in_test[9];
|
||||
static size_t num_key_ids_used;
|
||||
|
||||
/* Record a key id as potentially used in a test case. */
|
||||
static int test_uses_key_id( psa_key_id_t key_id )
|
||||
static int test_uses_key_id( psa_key_file_id_t key_id )
|
||||
{
|
||||
size_t i;
|
||||
if( key_id > PSA_MAX_PERSISTENT_KEY_IDENTIFIER )
|
||||
@ -178,7 +178,7 @@ void persistent_slot_lifecycle( int lifetime_arg, int id_arg,
|
||||
int close_method_arg )
|
||||
{
|
||||
psa_key_lifetime_t lifetime = lifetime_arg;
|
||||
psa_key_id_t id = id_arg;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, id_arg );
|
||||
psa_algorithm_t alg = alg_arg;
|
||||
psa_algorithm_t alg2 = alg2_arg;
|
||||
psa_key_usage_t usage_flags = usage_arg;
|
||||
@ -296,7 +296,7 @@ void create_existent( int lifetime_arg, int id_arg,
|
||||
int reopen_policy_arg )
|
||||
{
|
||||
psa_key_lifetime_t lifetime = lifetime_arg;
|
||||
psa_key_id_t id = id_arg;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, id_arg );
|
||||
psa_key_handle_t handle1 = 0, handle2 = 0;
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_type_t type1 = PSA_KEY_TYPE_RAW_DATA;
|
||||
@ -363,7 +363,7 @@ exit:
|
||||
void open_fail( int id_arg,
|
||||
int expected_status_arg )
|
||||
{
|
||||
psa_key_id_t id = id_arg;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, id_arg );
|
||||
psa_status_t expected_status = expected_status_arg;
|
||||
psa_key_handle_t handle = 0xdead;
|
||||
|
||||
@ -382,7 +382,7 @@ void create_fail( int lifetime_arg, int id_arg,
|
||||
int expected_status_arg )
|
||||
{
|
||||
psa_key_lifetime_t lifetime = lifetime_arg;
|
||||
psa_key_id_t id = id_arg;
|
||||
psa_key_file_id_t id = psa_key_file_id_make( 1, id_arg );
|
||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_status_t expected_status = expected_status_arg;
|
||||
psa_key_handle_t handle = 0xdead;
|
||||
@ -420,14 +420,14 @@ void copy_across_lifetimes( int source_lifetime_arg, int source_id_arg,
|
||||
int expected_alg_arg, int expected_alg2_arg )
|
||||
{
|
||||
psa_key_lifetime_t source_lifetime = source_lifetime_arg;
|
||||
psa_key_id_t source_id = source_id_arg;
|
||||
psa_key_file_id_t source_id = psa_key_file_id_make( 1, source_id_arg );
|
||||
psa_key_usage_t source_usage = source_usage_arg;
|
||||
psa_algorithm_t source_alg = source_alg_arg;
|
||||
psa_key_handle_t source_handle = 0;
|
||||
psa_key_attributes_t source_attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||
psa_key_type_t source_type = type_arg;
|
||||
psa_key_lifetime_t target_lifetime = target_lifetime_arg;
|
||||
psa_key_id_t target_id = target_id_arg;
|
||||
psa_key_file_id_t target_id = psa_key_file_id_make( 1, target_id_arg );
|
||||
psa_key_usage_t target_usage = target_usage_arg;
|
||||
psa_algorithm_t target_alg = target_alg_arg;
|
||||
psa_key_handle_t target_handle = 0;
|
||||
@ -534,13 +534,13 @@ void copy_to_occupied( int source_lifetime_arg, int source_id_arg,
|
||||
int target_type_arg, data_t *target_material )
|
||||
{
|
||||
psa_key_lifetime_t source_lifetime = source_lifetime_arg;
|
||||
psa_key_id_t source_id = source_id_arg;
|
||||
psa_key_file_id_t source_id = psa_key_file_id_make( 1, source_id_arg );
|
||||
psa_key_usage_t source_usage = source_usage_arg;
|
||||
psa_algorithm_t source_alg = source_alg_arg;
|
||||
psa_key_handle_t source_handle = 0;
|
||||
psa_key_type_t source_type = source_type_arg;
|
||||
psa_key_lifetime_t target_lifetime = target_lifetime_arg;
|
||||
psa_key_id_t target_id = target_id_arg;
|
||||
psa_key_file_id_t target_id = psa_key_file_id_make( 1, target_id_arg );
|
||||
psa_key_usage_t target_usage = target_usage_arg;
|
||||
psa_algorithm_t target_alg = target_alg_arg;
|
||||
psa_key_handle_t target_handle = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user