2021-10-15 15:21:51 +02:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
|
|
|
|
#include "psa/crypto.h"
|
|
|
|
#include "test/psa_crypto_helpers.h"
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
#define INVALID_KEY_ID mbedtls_svc_key_id_make(0, 0xfedcba98)
|
2021-10-15 15:21:51 +02:00
|
|
|
|
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
|
|
|
* depends_on:MBEDTLS_PSA_CRYPTO_C
|
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void generate_key(int key_type_arg, int bits_arg, int expected_status_arg)
|
2021-10-15 15:21:51 +02:00
|
|
|
{
|
|
|
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
|
|
|
mbedtls_svc_key_id_t key_id = INVALID_KEY_ID;
|
|
|
|
|
2022-12-04 18:19:59 +01:00
|
|
|
// key lifetime, usage flags, algorithm are irrelevant for this test
|
2021-11-02 10:52:53 +01: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 15:21:51 +02:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
PSA_ASSERT(psa_crypto_init());
|
|
|
|
psa_set_key_type(&attributes, key_type);
|
|
|
|
psa_set_key_bits(&attributes, bits);
|
|
|
|
TEST_EQUAL(psa_generate_key(&attributes, &key_id),
|
|
|
|
expected_status);
|
2021-10-15 15:21:51 +02:00
|
|
|
|
|
|
|
// Verify attributes of the created key on success
|
2023-01-11 14:50:10 +01:00
|
|
|
if (expected_status == PSA_SUCCESS) {
|
2021-11-02 10:52:53 +01:00
|
|
|
psa_reset_key_attributes(&attributes);
|
2023-01-11 14:50:10 +01:00
|
|
|
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 15:21:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2021-11-02 10:52:53 +01:00
|
|
|
psa_reset_key_attributes(&attributes);
|
2023-01-11 14:50:10 +01:00
|
|
|
psa_destroy_key(key_id);
|
|
|
|
PSA_DONE();
|
2021-10-15 15:21:51 +02:00
|
|
|
}
|
|
|
|
/* END_CASE */
|