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

@ -1070,7 +1070,7 @@ static inline psa_key_handle_t mbedtls_ssl_get_opaque_psk(
if( ssl->conf->psk_opaque != 0 )
return( ssl->conf->psk_opaque );
return( 0 );
return( PSA_KEY_HANDLE_INIT );
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */

View file

@ -51,6 +51,7 @@
/* Integral type representing a key handle. */
typedef uint16_t psa_key_handle_t;
#define PSA_KEY_HANDLE_INIT ( (psa_key_handle_t)0 )
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)

View file

@ -543,7 +543,7 @@ static int ecdsa_verify_wrap( void *ctx_arg, mbedtls_md_type_t md_alg,
mbedtls_ecdsa_context *ctx = ctx_arg;
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
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;
psa_status_t status;
mbedtls_pk_context key;
int key_len;

View file

@ -2185,7 +2185,7 @@ exit:
if( status != PSA_SUCCESS )
{
psa_fail_key_creation( slot, driver );
*handle = 0;
*handle = PSA_KEY_HANDLE_INIT;
}
return( status );
}
@ -2197,7 +2197,7 @@ psa_status_t mbedtls_psa_register_se_key(
psa_status_t status;
psa_key_slot_t *slot = NULL;
psa_se_drv_table_entry_t *driver = NULL;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
/* Leaving attributes unspecified is not currently supported.
* It could make sense to query the key type and size from the
@ -2290,7 +2290,7 @@ exit:
if( status != PSA_SUCCESS )
{
psa_fail_key_creation( target_slot, driver );
*target_handle = 0;
*target_handle = PSA_KEY_HANDLE_INIT;
}
return( status );
}
@ -5390,7 +5390,7 @@ psa_status_t psa_key_derivation_output_key( const psa_key_attributes_t *attribut
if( status != PSA_SUCCESS )
{
psa_fail_key_creation( slot, driver );
*handle = 0;
*handle = PSA_KEY_HANDLE_INIT;
}
return( status );
}
@ -6232,7 +6232,7 @@ exit:
if( status != PSA_SUCCESS )
{
psa_fail_key_creation( slot, driver );
*handle = 0;
*handle = PSA_KEY_HANDLE_INIT;
}
return( status );
}

View file

@ -245,13 +245,13 @@ psa_status_t psa_open_key( mbedtls_svc_key_id_t key, psa_key_handle_t *handle )
if( status != PSA_SUCCESS )
{
psa_wipe_key_slot( slot );
*handle = 0;
*handle = PSA_KEY_HANDLE_INIT;
}
return( status );
#else /* defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
(void) key;
*handle = 0;
*handle = PSA_KEY_HANDLE_INIT;
return( PSA_ERROR_NOT_SUPPORTED );
#endif /* !defined(MBEDTLS_PSA_CRYPTO_STORAGE_C) */
}

View file

@ -3802,7 +3802,7 @@ static int ssl_write_client_key_exchange( mbedtls_ssl_context *ssl )
status = psa_destroy_key( handshake->ecdh_psa_privkey );
if( status != PSA_SUCCESS )
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
handshake->ecdh_psa_privkey = 0;
handshake->ecdh_psa_privkey = PSA_KEY_HANDLE_INIT;
}
else
#endif /* MBEDTLS_USE_PSA_CRYPTO &&

View file

@ -507,7 +507,7 @@ static int tls_prf_generic( mbedtls_md_type_t md_type,
{
psa_status_t status;
psa_algorithm_t alg;
psa_key_handle_t master_slot = 0;
psa_key_handle_t master_slot = PSA_KEY_HANDLE_INIT;
psa_key_derivation_operation_t derivation =
PSA_KEY_DERIVATION_OPERATION_INIT;
@ -4348,7 +4348,7 @@ static void ssl_conf_remove_psk( mbedtls_ssl_config *conf )
{
/* The maintenance of the PSK key slot is the
* user's responsibility. */
conf->psk_opaque = 0;
conf->psk_opaque = PSA_KEY_HANDLE_INIT;
}
/* This and the following branch should never
* be taken simultaenously as we maintain the
@ -4434,7 +4434,7 @@ static void ssl_remove_psk( mbedtls_ssl_context *ssl )
#if defined(MBEDTLS_USE_PSA_CRYPTO)
if( ssl->handshake->psk_opaque != 0 )
{
ssl->handshake->psk_opaque = 0;
ssl->handshake->psk_opaque = PSA_KEY_HANDLE_INIT;
}
else
#endif /* MBEDTLS_USE_PSA_CRYPTO */

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;

View file

@ -151,7 +151,7 @@ void pk_psa_utils( )
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, 0 ) ==
TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, PSA_KEY_HANDLE_INIT ) ==
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
mbedtls_pk_free( &pk );

View file

@ -298,7 +298,7 @@ int exercise_mac_setup( psa_key_type_t key_type,
psa_mac_operation_t *operation,
psa_status_t *status )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_SIGN_HASH );
@ -333,7 +333,7 @@ int exercise_cipher_setup( psa_key_type_t key_type,
psa_cipher_operation_t *operation,
psa_status_t *status )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_ENCRYPT );
@ -1452,7 +1452,7 @@ void import_with_policy( int type_arg,
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t type = type_arg;
psa_key_usage_t usage = usage_arg;
psa_algorithm_t alg = alg_arg;
@ -1496,7 +1496,7 @@ void import_with_data( data_t *data, int type_arg,
{
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t type = type_arg;
size_t attr_bits = attr_bits_arg;
psa_status_t expected_status = expected_status_arg;
@ -1536,7 +1536,7 @@ void import_large_key( int type_arg, int byte_size_arg,
size_t byte_size = byte_size_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t expected_status = expected_status_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status;
uint8_t *buffer = NULL;
size_t buffer_size = byte_size + 1;
@ -1580,7 +1580,7 @@ exit:
/* BEGIN_CASE */
void import_rsa_made_up( int bits_arg, int keypair, int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
size_t bits = bits_arg;
psa_status_t expected_status = expected_status_arg;
psa_status_t status;
@ -1624,7 +1624,7 @@ void import_export( data_t *data,
int expected_export_status_arg,
int canonical_input )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t type = type_arg;
psa_algorithm_t alg = alg_arg;
psa_status_t expected_export_status = expected_export_status_arg;
@ -1717,7 +1717,7 @@ void import_export_public_key( data_t *data,
int expected_export_status_arg,
data_t *expected_public_key )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t type = type_arg;
psa_algorithm_t alg = alg_arg;
psa_status_t expected_export_status = expected_export_status_arg;
@ -1768,7 +1768,7 @@ void import_and_exercise_key( data_t *data,
int bits_arg,
int alg_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t type = type_arg;
size_t bits = bits_arg;
psa_algorithm_t alg = alg_arg;
@ -1810,7 +1810,7 @@ void effective_key_attributes( int type_arg, int expected_type_arg,
int usage_arg, int expected_usage_arg,
int alg_arg, int expected_alg_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = type_arg;
psa_key_type_t expected_key_type = expected_type_arg;
size_t bits = bits_arg;
@ -1896,7 +1896,7 @@ void mac_key_policy( int policy_usage,
data_t *key_data,
int exercise_alg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
psa_status_t status;
@ -1941,7 +1941,7 @@ void cipher_key_policy( int policy_usage,
data_t *key_data,
int exercise_alg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_status_t status;
@ -1986,7 +1986,7 @@ void aead_key_policy( int policy_usage,
int tag_length_arg,
int exercise_alg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status;
unsigned char nonce[16] = {0};
@ -2045,7 +2045,7 @@ void asymmetric_encryption_key_policy( int policy_usage,
data_t *key_data,
int exercise_alg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status;
size_t key_bits;
@ -2108,7 +2108,7 @@ void asymmetric_signature_key_policy( int policy_usage,
int exercise_alg,
int payload_length_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t status;
unsigned char payload[PSA_HASH_MAX_SIZE] = {1};
@ -2161,7 +2161,7 @@ void derive_key_policy( int policy_usage,
data_t *key_data,
int exercise_alg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
psa_status_t status;
@ -2211,7 +2211,7 @@ void agreement_key_policy( int policy_usage,
int exercise_alg,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t key_type = key_type_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
@ -2243,7 +2243,7 @@ exit:
void key_policy_alg2( int key_type_arg, data_t *key_data,
int usage_arg, int alg_arg, int alg2_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t got_attributes = PSA_KEY_ATTRIBUTES_INIT;
@ -2284,7 +2284,7 @@ void raw_agreement_key_policy( int policy_usage,
int exercise_alg,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t key_type = key_type_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
@ -2326,8 +2326,8 @@ void copy_success( int source_usage_arg,
psa_key_usage_t expected_usage = expected_usage_arg;
psa_algorithm_t expected_alg = expected_alg_arg;
psa_algorithm_t expected_alg2 = expected_alg2_arg;
psa_key_handle_t source_handle = 0;
psa_key_handle_t target_handle = 0;
psa_key_handle_t source_handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t target_handle = PSA_KEY_HANDLE_INIT;
uint8_t *export_buffer = NULL;
PSA_ASSERT( psa_crypto_init( ) );
@ -2404,8 +2404,8 @@ void copy_fail( int source_usage_arg,
{
psa_key_attributes_t source_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t target_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t source_handle = 0;
psa_key_handle_t target_handle = 0;
psa_key_handle_t source_handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t target_handle = PSA_KEY_HANDLE_INIT;
PSA_ASSERT( psa_crypto_init( ) );
@ -2909,7 +2909,7 @@ exit:
/* BEGIN_CASE */
void mac_bad_order( )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = PSA_KEY_TYPE_HMAC;
psa_algorithm_t alg = PSA_ALG_HMAC(PSA_ALG_SHA_256);
const uint8_t key[] = {
@ -3036,7 +3036,7 @@ void mac_sign( int key_type_arg,
data_t *input,
data_t *expected_mac )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
@ -3110,7 +3110,7 @@ void mac_verify( int key_type_arg,
data_t *input,
data_t *expected_mac )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT;
@ -3264,7 +3264,7 @@ exit:
/* BEGIN_CASE */
void cipher_bad_order( )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = PSA_KEY_TYPE_AES;
psa_algorithm_t alg = PSA_ALG_CBC_PKCS7;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@ -3420,7 +3420,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
data_t *input, data_t *expected_output,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
@ -3487,7 +3487,7 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
int output1_length_arg, int output2_length_arg,
data_t *expected_output )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t first_part_size = first_part_size_arg;
@ -3560,8 +3560,7 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
int output1_length_arg, int output2_length_arg,
data_t *expected_output )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t first_part_size = first_part_size_arg;
@ -3633,7 +3632,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
data_t *input, data_t *expected_output,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
@ -3697,7 +3696,7 @@ void cipher_verify_output( int alg_arg, int key_type_arg,
data_t *key,
data_t *input )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char iv[16] = {0};
@ -3790,7 +3789,7 @@ void cipher_verify_output_multipart( int alg_arg,
data_t *input,
int first_part_size_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t first_part_size = first_part_size_arg;
@ -3903,7 +3902,7 @@ void aead_encrypt_decrypt( int key_type_arg, data_t *key_data,
data_t *input_data,
int expected_result_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *output_data = NULL;
@ -3979,7 +3978,7 @@ void aead_encrypt( int key_type_arg, data_t *key_data,
data_t *input_data,
data_t *expected_result )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *output_data = NULL;
@ -4030,7 +4029,7 @@ void aead_decrypt( int key_type_arg, data_t *key_data,
data_t *expected_data,
int expected_result_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *output_data = NULL;
@ -4103,7 +4102,7 @@ void sign_deterministic( int key_type_arg, data_t *key_data,
int alg_arg, data_t *input_data,
data_t *output_data )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t key_bits;
@ -4164,7 +4163,7 @@ void sign_fail( int key_type_arg, data_t *key_data,
int alg_arg, data_t *input_data,
int signature_size_arg, int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t signature_size = signature_size_arg;
@ -4218,7 +4217,7 @@ exit:
void sign_verify( int key_type_arg, data_t *key_data,
int alg_arg, data_t *input_data )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t key_bits;
@ -4285,7 +4284,7 @@ void asymmetric_verify( int key_type_arg, data_t *key_data,
int alg_arg, data_t *hash_data,
data_t *signature_data )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@ -4326,7 +4325,7 @@ void asymmetric_verify_fail( int key_type_arg, data_t *key_data,
data_t *signature_data,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
psa_status_t actual_status;
@ -4370,7 +4369,7 @@ void asymmetric_encrypt( int key_type_arg,
int expected_output_length_arg,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t expected_output_length = expected_output_length_arg;
@ -4437,7 +4436,7 @@ void asymmetric_encrypt_decrypt( int key_type_arg,
data_t *input_data,
data_t *label )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t key_bits;
@ -4503,7 +4502,7 @@ void asymmetric_decrypt( int key_type_arg,
data_t *label,
data_t *expected_data )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *output = NULL;
@ -4566,7 +4565,7 @@ void asymmetric_decrypt_fail( int key_type_arg,
int output_size_arg,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
unsigned char *output = NULL;
@ -4705,12 +4704,14 @@ void derive_input( int alg_arg,
expected_status_arg2,
expected_status_arg3};
data_t *inputs[] = {input1, input2, input3};
psa_key_handle_t handles[] = {0, 0, 0};
psa_key_handle_t handles[] = { PSA_KEY_HANDLE_INIT,
PSA_KEY_HANDLE_INIT,
PSA_KEY_HANDLE_INIT};
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
size_t i;
psa_key_type_t output_key_type = output_key_type_arg;
psa_key_handle_t output_handle = 0;
psa_key_handle_t output_handle = PSA_KEY_HANDLE_INIT;
psa_status_t expected_output_status = expected_output_status_arg;
psa_status_t actual_output_status;
@ -4784,7 +4785,7 @@ exit:
void test_derive_invalid_key_derivation_state( int alg_arg )
{
psa_algorithm_t alg = alg_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
size_t key_type = PSA_KEY_TYPE_DERIVE;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
unsigned char input1[] = "Input 1";
@ -4872,7 +4873,9 @@ void derive_output( int alg_arg,
psa_algorithm_t alg = alg_arg;
psa_key_derivation_step_t steps[] = {step1_arg, step2_arg, step3_arg};
data_t *inputs[] = {input1, input2, input3};
psa_key_handle_t handles[] = {0, 0, 0};
psa_key_handle_t handles[] = { PSA_KEY_HANDLE_INIT,
PSA_KEY_HANDLE_INIT,
PSA_KEY_HANDLE_INIT};
size_t requested_capacity = requested_capacity_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
uint8_t *expected_outputs[2] =
@ -4982,7 +4985,7 @@ void derive_full( int alg_arg,
data_t *input2,
int requested_capacity_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = alg_arg;
size_t requested_capacity = requested_capacity_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
@ -5048,8 +5051,8 @@ void derive_key_exercise( int alg_arg,
int derived_usage_arg,
int derived_alg_arg )
{
psa_key_handle_t base_handle = 0;
psa_key_handle_t derived_handle = 0;
psa_key_handle_t base_handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t derived_handle = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = alg_arg;
psa_key_type_t derived_type = derived_type_arg;
size_t derived_bits = derived_bits_arg;
@ -5107,8 +5110,8 @@ void derive_key_export( int alg_arg,
int bytes1_arg,
int bytes2_arg )
{
psa_key_handle_t base_handle = 0;
psa_key_handle_t derived_handle = 0;
psa_key_handle_t base_handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t derived_handle = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = alg_arg;
size_t bytes1 = bytes1_arg;
size_t bytes2 = bytes2_arg;
@ -5186,8 +5189,8 @@ void derive_key( int alg_arg,
int type_arg, int bits_arg,
int expected_status_arg )
{
psa_key_handle_t base_handle = 0;
psa_key_handle_t derived_handle = 0;
psa_key_handle_t base_handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t derived_handle = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = alg_arg;
psa_key_type_t type = type_arg;
size_t bits = bits_arg;
@ -5231,7 +5234,7 @@ void key_agreement_setup( int alg_arg,
data_t *our_key_data, data_t *peer_key_data,
int expected_status_arg )
{
psa_key_handle_t our_key = 0;
psa_key_handle_t our_key = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = alg_arg;
psa_algorithm_t our_key_alg = our_key_alg_arg;
psa_key_type_t our_key_type = our_key_type_arg;
@ -5280,7 +5283,7 @@ void raw_key_agreement( int alg_arg,
data_t *peer_key_data,
data_t *expected_output )
{
psa_key_handle_t our_key = 0;
psa_key_handle_t our_key = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = alg_arg;
psa_key_type_t our_key_type = our_key_type_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@ -5317,7 +5320,7 @@ void key_agreement_capacity( int alg_arg,
data_t *peer_key_data,
int expected_capacity_arg )
{
psa_key_handle_t our_key = 0;
psa_key_handle_t our_key = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = alg_arg;
psa_key_type_t our_key_type = our_key_type_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
@ -5377,7 +5380,7 @@ void key_agreement_output( int alg_arg,
data_t *peer_key_data,
data_t *expected_output1, data_t *expected_output2 )
{
psa_key_handle_t our_key = 0;
psa_key_handle_t our_key = PSA_KEY_HANDLE_INIT;
psa_algorithm_t alg = alg_arg;
psa_key_type_t our_key_type = our_key_type_arg;
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
@ -5491,7 +5494,7 @@ void generate_key( int type_arg,
int alg_arg,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t type = type_arg;
psa_key_usage_t usage = usage_arg;
size_t bits = bits_arg;
@ -5533,7 +5536,7 @@ void generate_key_rsa( int bits_arg,
data_t *e_arg,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t type = PSA_KEY_TYPE_RSA_KEY_PAIR;
size_t bits = bits_arg;
psa_key_usage_t usage = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT;
@ -5639,8 +5642,8 @@ void persistent_key_load_key_from_storage( data_t *data,
{
mbedtls_svc_key_id_t key_id = mbedtls_svc_key_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;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t base_key = PSA_KEY_HANDLE_INIT;
psa_key_type_t type = type_arg;
size_t bits = bits_arg;
psa_key_usage_t usage_flags = usage_flags_arg;
@ -5704,7 +5707,7 @@ void persistent_key_load_key_from_storage( data_t *data,
&handle ) );
PSA_ASSERT( psa_key_derivation_abort( &operation ) );
PSA_ASSERT( psa_destroy_key( base_key ) );
base_key = 0;
base_key = PSA_KEY_HANDLE_INIT;
}
break;
}

View file

@ -19,7 +19,7 @@ void ecdsa_sign( int force_status_arg,
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_algorithm_t alg = PSA_ALG_DETERMINISTIC_ECDSA( PSA_ALG_SHA_256 );
uint8_t signature[64];
@ -73,7 +73,7 @@ void ecdsa_verify( int force_status_arg,
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_algorithm_t alg = PSA_ALG_DETERMINISTIC_ECDSA( PSA_ALG_SHA_256 );
psa_status_t actual_status;
@ -124,7 +124,7 @@ void generate_key( int force_status_arg,
{
psa_status_t force_status = force_status_arg;
psa_status_t expected_status = expected_status_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_algorithm_t alg = PSA_ALG_ECDSA( PSA_ALG_SHA_256 );
const uint8_t *expected_output = NULL;
@ -226,7 +226,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
int force_status_arg,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
@ -319,7 +319,7 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
int output1_length_arg, int output2_length_arg,
data_t *expected_output )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t first_part_size = first_part_size_arg;
@ -404,8 +404,7 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
int output1_length_arg, int output2_length_arg,
data_t *expected_output )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
size_t first_part_size = first_part_size_arg;
@ -492,7 +491,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
int force_status_arg,
int expected_status_arg )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;
@ -581,7 +580,7 @@ void cipher_entry_points( int alg_arg, int key_type_arg,
data_t *key, data_t *iv,
data_t *input )
{
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status;
psa_key_type_t key_type = key_type_arg;
psa_algorithm_t alg = alg_arg;

View file

@ -117,7 +117,7 @@ exit:
void save_large_persistent_key( int data_length_arg, int expected_status )
{
mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 1, 42 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
uint8_t *data = NULL;
size_t data_length = data_length_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@ -149,7 +149,7 @@ void persistent_key_destroy( int owner_id_arg, int key_id_arg, int restart,
{
mbedtls_svc_key_id_t key_id =
mbedtls_svc_key_id_make( owner_id_arg, key_id_arg );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
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;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@ -204,7 +204,7 @@ void persistent_key_import( int owner_id_arg, int key_id_arg, int type_arg,
mbedtls_svc_key_id_t key_id =
mbedtls_svc_key_id_make( owner_id_arg, key_id_arg );
psa_key_type_t type = (psa_key_type_t) type_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
PSA_ASSERT( psa_crypto_init() );
@ -254,7 +254,7 @@ void import_export_persistent_key( data_t *data, int type_arg,
{
mbedtls_svc_key_id_t key_id = mbedtls_svc_key_id_make( 1, 42 );
psa_key_type_t type = (psa_key_type_t) type_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
unsigned char *exported = NULL;
size_t export_size = data->len;
size_t exported_length;

View file

@ -450,7 +450,7 @@ static psa_status_t ram_sign( psa_drv_se_context_t *context,
{
ram_slot_t *slot;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
(void) context;
@ -483,7 +483,7 @@ static psa_status_t ram_verify( psa_drv_se_context_t *context,
{
ram_slot_t *slot;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
(void) context;
@ -664,7 +664,7 @@ static int smoke_test_key( psa_key_handle_t handle )
PSA_KEY_DERIVATION_OPERATION_INIT;
uint8_t buffer[80]; /* large enough for a public key for ECDH */
size_t length;
psa_key_handle_t handle2 = 0;
psa_key_handle_t handle2 = PSA_KEY_HANDLE_INIT;
SMOKE_ASSERT( psa_get_key_attributes( handle, &attributes ) );
@ -880,7 +880,7 @@ void key_creation_import_export( int lifetime_arg, int min_slot, int restart )
psa_key_lifetime_t lifetime = (psa_key_lifetime_t) lifetime_arg;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
uint8_t exported[sizeof( key_material )];
@ -983,7 +983,7 @@ void key_creation_import_export( int lifetime_arg, int min_slot, int restart )
exported, exported_length );
PSA_ASSERT( psa_destroy_key( handle ) );
handle = 0;
handle = PSA_KEY_HANDLE_INIT;
if( ! check_persistent_data( location,
&ram_shadow_slot_usage,
sizeof( ram_shadow_slot_usage ) ) )
@ -1014,7 +1014,7 @@ void key_creation_in_chosen_slot( int slot_arg,
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
@ -1072,7 +1072,7 @@ void key_creation_in_chosen_slot( int slot_arg,
PSA_ASSERT( psa_get_key_attributes( handle, &attributes ) );
PSA_ASSERT( psa_destroy_key( handle ) );
handle = 0;
handle = PSA_KEY_HANDLE_INIT;
if( ! check_persistent_data( location,
&ram_shadow_slot_usage,
sizeof( ram_shadow_slot_usage ) ) )
@ -1098,7 +1098,7 @@ void import_key_smoke( int type_arg, int alg_arg,
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
TEST_USES_KEY_ID( id );
@ -1148,7 +1148,7 @@ void import_key_smoke( int type_arg, int alg_arg,
/* We're done. */
PSA_ASSERT( psa_destroy_key( handle ) );
handle = 0;
handle = PSA_KEY_HANDLE_INIT;
if( ! check_persistent_data( location,
&shadow_counter, sizeof( shadow_counter ) ) )
goto exit;
@ -1172,7 +1172,7 @@ void generate_key_not_supported( int type_arg, int bits_arg )
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
TEST_USES_KEY_ID( id );
@ -1213,7 +1213,7 @@ void generate_key_smoke( int type_arg, int bits_arg, int alg_arg )
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
TEST_USES_KEY_ID( id );
@ -1262,7 +1262,7 @@ void generate_key_smoke( int type_arg, int bits_arg, int alg_arg )
/* We're done. */
PSA_ASSERT( psa_destroy_key( handle ) );
handle = 0;
handle = PSA_KEY_HANDLE_INIT;
if( ! check_persistent_data( location,
&shadow_counter, sizeof( shadow_counter ) ) )
goto exit;
@ -1295,8 +1295,8 @@ 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 );
mbedtls_svc_key_id_t id = mbedtls_svc_key_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_handle_t drv_handle = PSA_KEY_HANDLE_INIT; /* key managed by the driver */
psa_key_handle_t sw_handle = PSA_KEY_HANDLE_INIT; /* transparent key */
psa_key_attributes_t sw_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t drv_attributes;
uint8_t signature[PSA_SIGNATURE_MAX_SIZE];
@ -1462,7 +1462,7 @@ void register_key_smoke_test( int lifetime_arg,
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( owner_id_arg, id_arg );
size_t bit_size = 48;
psa_key_slot_number_t wanted_slot = 0x123456789;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_status_t status;
TEST_USES_KEY_ID( id );
@ -1518,7 +1518,7 @@ void register_key_smoke_test( int lifetime_arg,
goto exit;
/* This time, destroy the key. */
PSA_ASSERT( psa_destroy_key( handle ) );
handle = 0;
handle = PSA_KEY_HANDLE_INIT;
TEST_EQUAL( psa_open_key( id, &handle ),
PSA_ERROR_DOES_NOT_EXIST );

View file

@ -333,7 +333,7 @@ void mock_import( int mock_alloc_return_value,
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
@ -402,7 +402,7 @@ void mock_export( int mock_export_return_value, int expected_result )
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
uint8_t exported[sizeof( key_material )];
@ -456,7 +456,7 @@ void mock_generate( int mock_alloc_return_value,
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
mock_allocate_data.return_value = mock_alloc_return_value;
@ -523,7 +523,7 @@ void mock_export_public( int mock_export_public_return_value,
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
uint8_t exported[sizeof( key_material )];
@ -573,7 +573,7 @@ void mock_sign( int mock_sign_return_value, int expected_result )
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
psa_algorithm_t algorithm = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
@ -634,7 +634,7 @@ void mock_verify( int mock_verify_return_value, int expected_result )
psa_key_lifetime_t lifetime = TEST_SE_PERSISTENT_LIFETIME;
psa_key_location_t location = PSA_KEY_LIFETIME_GET_LOCATION( lifetime );
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( 1, 1 );
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
const uint8_t key_material[3] = {0xfa, 0xca, 0xde};
psa_algorithm_t algorithm = PSA_ALG_ECDSA(PSA_ALG_SHA_256);

View file

@ -141,7 +141,7 @@ void transient_slot_lifecycle( int usage_arg, int alg_arg,
psa_key_usage_t usage_flags = usage_arg;
psa_key_type_t type = type_arg;
close_method_t close_method = close_method_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
PSA_ASSERT( psa_crypto_init( ) );
@ -185,7 +185,7 @@ void persistent_slot_lifecycle( int lifetime_arg, int owner_id_arg, int id_arg,
psa_key_usage_t usage_flags = usage_arg;
psa_key_type_t type = type_arg;
close_method_t close_method = close_method_arg;
psa_key_handle_t handle = 0;
psa_key_handle_t handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_attributes_t read_attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t *reexported = NULL;
@ -194,7 +194,7 @@ void persistent_slot_lifecycle( int lifetime_arg, int owner_id_arg, int id_arg,
#if defined(MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER)
mbedtls_svc_key_id_t wrong_owner_id =
mbedtls_svc_key_id_make( owner_id_arg + 1, id_arg );
psa_key_handle_t invalid_handle = 0;
psa_key_handle_t invalid_handle = PSA_KEY_HANDLE_INIT;
#endif
TEST_USES_KEY_ID( id );
@ -319,7 +319,8 @@ void create_existent( int lifetime_arg, int owner_id_arg, int id_arg,
{
psa_key_lifetime_t lifetime = lifetime_arg;
mbedtls_svc_key_id_t id = mbedtls_svc_key_id_make( owner_id_arg, id_arg );
psa_key_handle_t handle1 = 0, handle2 = 0;
psa_key_handle_t handle1 = PSA_KEY_HANDLE_INIT;
psa_key_handle_t handle2 = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_type_t type1 = PSA_KEY_TYPE_RAW_DATA;
const uint8_t material1[5] = "a key";
@ -447,7 +448,7 @@ void copy_across_lifetimes( int source_lifetime_arg, int source_owner_id_arg,
mbedtls_svc_key_id_make( source_owner_id_arg, 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_handle_t source_handle = PSA_KEY_HANDLE_INIT;
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;
@ -455,7 +456,7 @@ void copy_across_lifetimes( int source_lifetime_arg, int source_owner_id_arg,
mbedtls_svc_key_id_make( target_owner_id_arg, 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;
psa_key_handle_t target_handle = PSA_KEY_HANDLE_INIT;
psa_key_attributes_t target_attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_usage_t expected_usage = expected_usage_arg;
psa_algorithm_t expected_alg = expected_alg_arg;
@ -573,14 +574,14 @@ void copy_to_occupied( int source_lifetime_arg, int source_id_arg,
mbedtls_svc_key_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_handle_t source_handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t source_type = source_type_arg;
psa_key_lifetime_t target_lifetime = target_lifetime_arg;
mbedtls_svc_key_id_t target_id =
mbedtls_svc_key_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;
psa_key_handle_t target_handle = PSA_KEY_HANDLE_INIT;
psa_key_type_t target_type = target_type_arg;
psa_key_handle_t new_handle = 0xdead;
uint8_t *export_buffer = NULL;
@ -674,8 +675,8 @@ exit:
void invalid_handle( int handle_construction,
int close_status_arg, int usage_status_arg )
{
psa_key_handle_t valid_handle = 0;
psa_key_handle_t invalid_handle = 0;
psa_key_handle_t valid_handle = PSA_KEY_HANDLE_INIT;
psa_key_handle_t invalid_handle = PSA_KEY_HANDLE_INIT;
psa_status_t close_status = close_status_arg;
psa_status_t usage_status = usage_status_arg;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@ -696,7 +697,7 @@ void invalid_handle( int handle_construction,
switch( handle_construction )
{
case INVALID_HANDLE_0:
invalid_handle = 0;
invalid_handle = PSA_KEY_HANDLE_INIT;
break;
case INVALID_HANDLE_UNOPENED:
/* We can't easily construct a handle that's never been opened

View file

@ -161,7 +161,7 @@ void x509_csr_check_opaque( char *key_file, int md_type, int key_usage,
int cert_type )
{
mbedtls_pk_context key;
psa_key_handle_t slot = 0;
psa_key_handle_t slot = PSA_KEY_HANDLE_INIT;
psa_algorithm_t md_alg_psa;
mbedtls_x509write_csr req;
unsigned char buf[4096];