Skip to content

Commit c8eb51d

Browse files
author
itayzafrir
committed
Add crypto acl test - key derivation
1 parent 964f5ad commit c8eb51d

File tree

1 file changed

+44
-0
lines changed
  • TESTS/psa/crypto_access_control/COMPONENT_NSPE

1 file changed

+44
-0
lines changed

TESTS/psa/crypto_access_control/COMPONENT_NSPE/main.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,48 @@ void test_use_other_partition_key_asymmetric_encrypt_decrypt(void)
442442
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
443443
}
444444

445+
void test_use_other_partition_key_derivation_setup(void)
446+
{
447+
static const psa_key_id_t key_id = 999;
448+
static const psa_algorithm_t key_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256);
449+
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_DERIVE;
450+
static const psa_key_type_t key_type = PSA_KEY_TYPE_DERIVE;
451+
static const unsigned char key_data[] = {
452+
0x30, 0x82, 0x01, 0x3b, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xee, 0x2b,
453+
0x13, 0x1d, 0x6b, 0x18, 0x18, 0xa9, 0x4c, 0xa8, 0xe9, 0x1c, 0x42, 0x38
454+
};
455+
static const unsigned char salt[] = {
456+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
457+
0x0c
458+
};
459+
static const unsigned char label[] = {
460+
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9
461+
};
462+
463+
psa_key_handle_t key_handle = 0;
464+
psa_crypto_generator_t generator = psa_crypto_generator_init();
465+
size_t bits = 128;
466+
467+
/* via test partition - create a key without generating any key material */
468+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, &key_handle));
469+
TEST_ASSERT_NOT_EQUAL(0, key_handle);
470+
471+
/* via test partition - set key policy */
472+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(key_handle, key_usage, key_alg));
473+
474+
/* via test partition - import key data for the key created by the test partition */
475+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_import_key(key_handle, key_type, key_data, sizeof(key_data)));
476+
477+
/* try to setup key derivation using the key that was created by the test partition */
478+
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_key_derivation(&generator, key_handle, key_alg,
479+
(unsigned char *)salt, sizeof(salt),
480+
(unsigned char *)label, sizeof(label),
481+
PSA_BITS_TO_BYTES(bits)));
482+
483+
/* via test partition - destroy the key created by the test partition */
484+
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_destroy_key(key_handle));
485+
}
486+
445487
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
446488
{
447489
psa_status_t status = mbed_psa_reboot_and_request_new_security_state(PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
@@ -489,6 +531,8 @@ Case cases[] = {
489531
case_setup_handler, test_use_other_partition_key_asymmetric_sign_verify, case_teardown_handler),
490532
Case("use other partitions' key - asymmetric encrypt decrypt",
491533
case_setup_handler, test_use_other_partition_key_asymmetric_encrypt_decrypt, case_teardown_handler),
534+
Case("use other partitions' key - key derivation setup",
535+
case_setup_handler, test_use_other_partition_key_derivation_setup, case_teardown_handler),
492536
};
493537

494538
Specification specification(test_setup, cases);

0 commit comments

Comments
 (0)