mirror of
https://github.com/cuberite/polarssl.git
synced 2025-09-30 08:56:50 -04:00
Add key_destroyable parameter to check_key_attributes_sanity
This function is currently only used in the exercise_key smoke test. Signed-off-by: Ryan Everett <ryan.everett@arm.com>
This commit is contained in:
parent
0a271fde76
commit
f08a93fbe5
@ -38,7 +38,8 @@ static int lifetime_is_dynamic_secure_element(psa_key_lifetime_t lifetime)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int check_key_attributes_sanity(mbedtls_svc_key_id_t key)
|
static int check_key_attributes_sanity(mbedtls_svc_key_id_t key,
|
||||||
|
int key_destroyable)
|
||||||
{
|
{
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
|
||||||
@ -46,8 +47,13 @@ static int check_key_attributes_sanity(mbedtls_svc_key_id_t key)
|
|||||||
mbedtls_svc_key_id_t id;
|
mbedtls_svc_key_id_t id;
|
||||||
psa_key_type_t type;
|
psa_key_type_t type;
|
||||||
size_t bits;
|
size_t bits;
|
||||||
|
psa_status_t status = psa_get_key_attributes(key, &attributes);
|
||||||
PSA_ASSERT(psa_get_key_attributes(key, &attributes));
|
if (key_destroyable && status == PSA_ERROR_INVALID_HANDLE) {
|
||||||
|
/* The key has been destroyed. */
|
||||||
|
psa_reset_key_attributes(&attributes);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
PSA_ASSERT(status);
|
||||||
lifetime = psa_get_key_lifetime(&attributes);
|
lifetime = psa_get_key_lifetime(&attributes);
|
||||||
id = psa_get_key_id(&attributes);
|
id = psa_get_key_id(&attributes);
|
||||||
type = psa_get_key_type(&attributes);
|
type = psa_get_key_type(&attributes);
|
||||||
@ -66,17 +72,20 @@ static int check_key_attributes_sanity(mbedtls_svc_key_id_t key)
|
|||||||
(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(id) <= PSA_KEY_ID_USER_MAX));
|
(MBEDTLS_SVC_KEY_ID_GET_KEY_ID(id) <= PSA_KEY_ID_USER_MAX));
|
||||||
}
|
}
|
||||||
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
|
||||||
/* randomly-generated 64-bit constant, should never appear in test data */
|
/* MBEDTLS_PSA_CRYPTO_SE_C does not support thread safety. */
|
||||||
psa_key_slot_number_t slot_number = 0xec94d4a5058a1a21;
|
if (key_destroyable == 0) {
|
||||||
psa_status_t status = psa_get_key_slot_number(&attributes, &slot_number);
|
/* randomly-generated 64-bit constant, should never appear in test data */
|
||||||
if (lifetime_is_dynamic_secure_element(lifetime)) {
|
psa_key_slot_number_t slot_number = 0xec94d4a5058a1a21;
|
||||||
/* Mbed TLS currently always exposes the slot number to
|
status = psa_get_key_slot_number(&attributes, &slot_number);
|
||||||
* applications. This is not mandated by the PSA specification
|
if (lifetime_is_dynamic_secure_element(lifetime)) {
|
||||||
* and may change in future versions. */
|
/* Mbed TLS currently always exposes the slot number to
|
||||||
TEST_EQUAL(status, 0);
|
* applications. This is not mandated by the PSA specification
|
||||||
TEST_ASSERT(slot_number != 0xec94d4a5058a1a21);
|
* and may change in future versions. */
|
||||||
} else {
|
TEST_EQUAL(status, 0);
|
||||||
TEST_EQUAL(status, PSA_ERROR_INVALID_ARGUMENT);
|
TEST_ASSERT(slot_number != 0xec94d4a5058a1a21);
|
||||||
|
} else {
|
||||||
|
TEST_EQUAL(status, PSA_ERROR_INVALID_ARGUMENT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user