Introduce PSA_KEY_HANDLE_INIT macro

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
Ronald Cron 2020-07-30 17:48:03 +02:00
parent 98a54ddbd6
commit 91e9515424
19 changed files with 145 additions and 141 deletions

View file

@ -165,7 +165,7 @@ cipher_example_encrypt_decrypt_aes_cbc_nopad_1_block( void )
psa_status_t status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle = 0;
psa_key_handle_t key_handle = PSA_KEY_HANDLE_INIT;
size_t output_len = 0;
uint8_t iv[block_size];
uint8_t input[block_size];
@ -215,7 +215,7 @@ static psa_status_t cipher_example_encrypt_decrypt_aes_cbc_pkcs7_multi( void )
psa_status_t status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle = 0;
psa_key_handle_t key_handle = PSA_KEY_HANDLE_INIT;
size_t output_len = 0;
uint8_t iv[block_size], input[input_size],
encrypt[input_size + block_size], decrypt[input_size + block_size];
@ -262,7 +262,7 @@ static psa_status_t cipher_example_encrypt_decrypt_aes_ctr_multi( void )
psa_status_t status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t key_handle = 0;
psa_key_handle_t key_handle = PSA_KEY_HANDLE_INIT;
size_t output_len = 0;
uint8_t iv[block_size], input[input_size], encrypt[input_size],
decrypt[input_size];

View file

@ -197,7 +197,7 @@ exit:
static psa_status_t generate( const char *key_file_name )
{
psa_status_t status = PSA_SUCCESS;
psa_key_handle_t key_handle = 0;
psa_key_handle_t key_handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_set_key_usage_flags( &attributes,
@ -232,7 +232,7 @@ static psa_status_t import_key_from_file( psa_key_usage_t usage,
FILE *key_file = NULL;
unsigned char extra_byte;
*master_key_handle = 0;
*master_key_handle = PSA_KEY_HANDLE_INIT;
SYS_CHECK( ( key_file = fopen( key_file_name, "rb" ) ) != NULL );
SYS_CHECK( ( key_size = fread( key_data, 1, sizeof( key_data ),
@ -262,7 +262,7 @@ exit:
* *master_key_handle is 0. psa_destroy_key(0) is guaranteed to do
* nothing and return PSA_ERROR_INVALID_HANDLE. */
(void) psa_destroy_key( *master_key_handle );
*master_key_handle = 0;
*master_key_handle = PSA_KEY_HANDLE_INIT;
}
return( status );
}
@ -304,7 +304,7 @@ static psa_status_t derive_key_ladder( const char *ladder[],
/* When the parent key is not the master key, destroy it,
* since it is no longer needed. */
PSA_CHECK( psa_close_key( *key_handle ) );
*key_handle = 0;
*key_handle = PSA_KEY_HANDLE_INIT;
/* Derive the next intermediate key from the parent key. */
PSA_CHECK( psa_key_derivation_output_key( &attributes, &operation,
key_handle ) );
@ -316,7 +316,7 @@ exit:
if( status != PSA_SUCCESS )
{
psa_close_key( *key_handle );
*key_handle = 0;
*key_handle = PSA_KEY_HANDLE_INIT;
}
return( status );
}
@ -330,7 +330,7 @@ static psa_status_t derive_wrapping_key( psa_key_usage_t usage,
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
*wrapping_key_handle = 0;
*wrapping_key_handle = PSA_KEY_HANDLE_INIT;
/* Set up a key derivation operation from the key derived from
* the master key. */
@ -527,8 +527,8 @@ static psa_status_t run( enum program_mode mode,
const char *output_file_name )
{
psa_status_t status = PSA_SUCCESS;
psa_key_handle_t derivation_key_handle = 0;
psa_key_handle_t wrapping_key_handle = 0;
psa_key_handle_t derivation_key_handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t wrapping_key_handle = PSA_KEY_HANDLE_INIT;
/* Initialize the PSA crypto library. */
PSA_CHECK( psa_crypto_init( ) );

View file

@ -1207,7 +1207,7 @@ int main( int argc, char *argv[] )
const char *pers = "ssl_client2";
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_key_handle_t slot = 0;
psa_key_handle_t slot = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = 0;
psa_key_attributes_t key_attributes;
psa_status_t status;
@ -1232,7 +1232,7 @@ int main( int argc, char *argv[] )
mbedtls_x509_crt clicert;
mbedtls_pk_context pkey;
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_key_handle_t key_slot = 0; /* invalid key slot */
psa_key_handle_t key_slot = PSA_KEY_HANDLE_INIT; /* invalid key slot */
#endif
#endif
char *p, *q;

View file

@ -1795,7 +1795,7 @@ int main( int argc, char *argv[] )
#if defined(MBEDTLS_KEY_EXCHANGE_SOME_PSK_ENABLED)
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_algorithm_t alg = 0;
psa_key_handle_t psk_slot = 0;
psa_key_handle_t psk_slot = PSA_KEY_HANDLE_INIT;
#endif /* MBEDTLS_USE_PSA_CRYPTO */
unsigned char psk[MBEDTLS_PSK_MAX_LEN];
size_t psk_len = 0;