2021-10-15 13:21:51 +00:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
|
|
|
|
#include "psa/crypto.h"
|
|
|
|
#include "test/psa_crypto_helpers.h"
|
|
|
|
|
|
|
|
#define INVALID_KEY_ID mbedtls_svc_key_id_make( 0, 0xfedcba98 )
|
|
|
|
|
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
* depends_on:MBEDTLS_PSA_CRYPTO_C
|
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2021-11-02 09:52:53 +00:00
|
|
|
void generate_key( int key_type_arg, int bits_arg, int expected_status_arg)
|
2021-10-15 13:21:51 +00:00
|
|
|
{
|
|
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
|
|
mbedtls_svc_key_id_t key_id = INVALID_KEY_ID;
|
|
|
|
|
|
|
|
// key lifetiem, usage flags, algorithm are irrelevant for this test
|
2021-11-02 09:52:53 +00:00
|
|
|
psa_key_type_t key_type = key_type_arg;
|
|
|
|
size_t bits = bits_arg;
|
|
|
|
psa_status_t expected_status = expected_status_arg;
|
2021-10-15 13:21:51 +00:00
|
|
|
|
|
|
|
PSA_ASSERT( psa_crypto_init( ) );
|
2021-11-02 09:52:53 +00:00
|
|
|
psa_set_key_type( &attributes, key_type );
|
|
|
|
psa_set_key_bits( &attributes, bits );
|
2021-10-15 13:21:51 +00:00
|
|
|
TEST_EQUAL( psa_generate_key( &attributes, &key_id ),
|
2021-11-02 09:52:53 +00:00
|
|
|
expected_status );
|
2021-10-15 13:21:51 +00:00
|
|
|
|
|
|
|
// Verify attributes of the created key on success
|
2021-11-02 09:52:53 +00:00
|
|
|
if ( expected_status == PSA_SUCCESS )
|
2021-10-15 13:21:51 +00:00
|
|
|
{
|
2021-11-02 09:52:53 +00:00
|
|
|
psa_reset_key_attributes(&attributes);
|
|
|
|
PSA_ASSERT( psa_get_key_attributes( key_id, &attributes ) );
|
|
|
|
TEST_EQUAL( psa_get_key_lifetime( &attributes ), PSA_KEY_LIFETIME_VOLATILE );
|
|
|
|
TEST_EQUAL( psa_get_key_usage_flags( &attributes ), 0 );
|
|
|
|
TEST_EQUAL( psa_get_key_algorithm( &attributes ), 0 );
|
|
|
|
TEST_EQUAL( psa_get_key_type( &attributes ), key_type );
|
|
|
|
TEST_EQUAL( psa_get_key_bits( &attributes ), bits );
|
2021-10-15 13:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2021-11-02 09:52:53 +00:00
|
|
|
psa_reset_key_attributes(&attributes);
|
2021-10-15 13:21:51 +00:00
|
|
|
psa_destroy_key( key_id );
|
|
|
|
PSA_DONE( );
|
|
|
|
}
|
|
|
|
/* END_CASE */
|