Merge pull request #11315 from Patater/psa-crypto-api-1.0b3

Update Mbed OS for PSA Crypto API 1.0b3
pull/11419/head
Martin Kojtal 2019-09-03 09:20:15 +02:00 committed by GitHub
commit e001216b55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
379 changed files with 14690 additions and 26017 deletions

View File

@ -4,6 +4,7 @@
^components/TARGET_PSA/services/attestation/attestation.h
^components/TARGET_PSA/services/attestation/COMPONENT_PSA_SRV_IMPL/tfm_impl
^components/TARGET_PSA/services/attestation/qcbor
^components/TARGET_PSA/services/crypto/COMPONENT_PSA_SRV_IPC/crypto_struct_ipc.h
^components/TARGET_PSA/TARGET_TFM
^components/TARGET_PSA/TESTS
^features/cryptocell

View File

@ -86,26 +86,24 @@ void test_crypto_random(void)
void test_crypto_asymmetric_encrypt_decrypt(void)
{
psa_status_t status = PSA_SUCCESS;
psa_key_handle_t key_handle = 0;
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEYPAIR;
psa_key_handle_t key_handle;
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEY_PAIR;
psa_algorithm_t alg = PSA_ALG_RSA_PKCS1V15_CRYPT;
size_t key_bits = 512, got_bits = 0, output_length;
psa_key_policy_t policy;
size_t key_bits = 512, output_length;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
static const unsigned char input[] = "encrypt me!";
unsigned char encrypted[64];
unsigned char decrypted[sizeof(input)];
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
policy = psa_key_policy_init();
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
status = psa_generate_key(key_handle, key_type, key_bits, NULL, 0);
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_ENCRYPT);
psa_set_key_algorithm(&attributes, alg);
psa_set_key_type(&attributes, key_type);
psa_set_key_bits(&attributes, key_bits);
status = psa_generate_key(&attributes, &key_handle);
TEST_SKIP_UNLESS_MESSAGE(status != PSA_ERROR_NOT_SUPPORTED, "RSA key generation is not supported");
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_information(key_handle, NULL, &got_bits));
TEST_ASSERT_EQUAL(key_bits, got_bits);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_attributes(key_handle, &attributes));
TEST_ASSERT_EQUAL(key_bits, psa_get_key_bits(&attributes));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_encrypt(key_handle, alg, input, sizeof(input), NULL, 0,
encrypted, sizeof(encrypted), &output_length));
TEST_ASSERT_EQUAL(sizeof(encrypted), output_length);
@ -135,11 +133,11 @@ void test_crypto_hash_verify(void)
void test_crypto_symmetric_cipher_encrypt_decrypt(void)
{
psa_key_handle_t key_handle = 0;
psa_key_handle_t key_handle;
psa_key_type_t key_type = PSA_KEY_TYPE_AES;
psa_algorithm_t alg = PSA_ALG_CBC_NO_PADDING;
psa_cipher_operation_t operation;
psa_key_policy_t policy;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
size_t output_len;
static const unsigned char key[] = {
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
@ -155,13 +153,12 @@ void test_crypto_symmetric_cipher_encrypt_decrypt(void)
};
unsigned char encrypted[sizeof(input)], decrypted[sizeof(input)], iv[16];
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
memset(iv, 0x2a, sizeof(iv));
policy = psa_key_policy_init();
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(key_handle, key_type, key, sizeof(key)));
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT);
psa_set_key_algorithm(&attributes, alg);
psa_set_key_type(&attributes, key_type);
psa_set_key_bits(&attributes, 128);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(&attributes, key, sizeof(key), &key_handle));
operation = psa_cipher_operation_init();
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_cipher_encrypt_setup(&operation, key_handle, alg));
@ -187,10 +184,10 @@ void test_crypto_symmetric_cipher_encrypt_decrypt(void)
void test_crypto_asymmetric_sign_verify(void)
{
psa_key_handle_t key_handle = 0;
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEYPAIR;
psa_key_handle_t key_handle;
psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEY_PAIR;
psa_algorithm_t alg = PSA_ALG_RSA_PKCS1V15_SIGN_RAW;
psa_key_policy_t policy;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
static const unsigned char key[] = {
0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xaf,
0x05, 0x7d, 0x39, 0x6e, 0xe8, 0x4f, 0xb7, 0x5f, 0xdb, 0xb5, 0xc2, 0xb1,
@ -261,12 +258,10 @@ void test_crypto_asymmetric_sign_verify(void)
unsigned char signature[sizeof(expected_signature)];
size_t signature_len;
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
policy = psa_key_policy_init();
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(key_handle, key_type, key, sizeof(key)));
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY);
psa_set_key_algorithm(&attributes, alg);
psa_set_key_type(&attributes, key_type);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_import_key(&attributes, key, sizeof(key), &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_asymmetric_sign(key_handle, alg, input, sizeof(input),
signature, sizeof(signature), &signature_len));
TEST_ASSERT_EQUAL(sizeof(signature), signature_len);
@ -279,31 +274,43 @@ void test_crypto_asymmetric_sign_verify(void)
void test_crypto_key_derivation(void)
{
psa_key_handle_t key_handle = 0, derived_key_handle = 0;
psa_key_handle_t key_handle, derived_key_handle;
psa_algorithm_t alg = PSA_ALG_HKDF(PSA_ALG_SHA_256), derived_alg = PSA_ALG_CTR;
psa_key_type_t key_type = PSA_KEY_TYPE_DERIVE, derived_key_type = PSA_KEY_TYPE_AES, got_type;
psa_key_policy_t policy;
psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT;
size_t key_bits = 512, derived_key_bits = 256, got_bits;
psa_key_type_t key_type = PSA_KEY_TYPE_DERIVE, derived_key_type = PSA_KEY_TYPE_AES;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_derivation_operation_t operation =
PSA_KEY_DERIVATION_OPERATION_INIT;
size_t key_bits = 512, derived_key_bits = 256;
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
policy = psa_key_policy_init();
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_DERIVE, alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle, key_type, key_bits, NULL, 0));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_key_derivation(&generator, key_handle, alg, NULL, 0, NULL, 0,
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
psa_set_key_algorithm(&attributes, alg);
psa_set_key_type(&attributes, key_type);
psa_set_key_bits(&attributes, key_bits);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(&attributes, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_key_derivation_setup(&operation, alg));
TEST_ASSERT_EQUAL(PSA_SUCCESS,
psa_key_derivation_set_capacity(&operation,
PSA_BITS_TO_BYTES(derived_key_bits)));
TEST_ASSERT_EQUAL(PSA_SUCCESS,
psa_key_derivation_input_bytes(&operation,
PSA_KEY_DERIVATION_INPUT_SALT, NULL, 0));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_key_derivation_input_key(&operation,
PSA_KEY_DERIVATION_INPUT_SECRET,
key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS,
psa_key_derivation_input_bytes(&operation,
PSA_KEY_DERIVATION_INPUT_INFO, NULL, 0));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&derived_key_handle));
psa_key_policy_set_usage(&policy, PSA_KEY_USAGE_ENCRYPT, derived_alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(derived_key_handle, &policy));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generator_import_key(derived_key_handle, derived_key_type,
derived_key_bits, &generator));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_information(derived_key_handle, &got_type, &got_bits));
TEST_ASSERT_EQUAL(derived_key_type, got_type);
TEST_ASSERT_EQUAL(derived_key_bits, got_bits);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generator_abort(&generator));
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_ENCRYPT);
psa_set_key_algorithm(&attributes, derived_alg);
psa_set_key_type(&attributes, derived_key_type);
psa_set_key_bits(&attributes, derived_key_bits);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
psa_key_derivation_output_key(&attributes, &operation, &derived_key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_attributes(derived_key_handle, &attributes));
TEST_ASSERT_EQUAL(derived_key_type, psa_get_key_type(&attributes));
TEST_ASSERT_EQUAL(derived_key_bits, psa_get_key_bits(&attributes));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_key_derivation_abort(&operation));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(derived_key_handle));
}
@ -316,42 +323,45 @@ void test_crypto_key_handles(void)
psa_key_usage_t usage = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT;
psa_algorithm_t alg = PSA_ALG_CBC_NO_PADDING;
psa_key_handle_t key_handle;
psa_key_policy_t policy;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
policy = psa_key_policy_init();
psa_key_policy_set_usage(&policy, usage, alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle, type, bits, NULL, 0));
psa_set_key_usage_flags(&attributes, usage);
psa_set_key_algorithm(&attributes, alg);
psa_set_key_type(&attributes, type);
psa_set_key_bits(&attributes, bits);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(&attributes, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_close_key(key_handle));
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_allocate_key(&key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
policy = psa_key_policy_init();
psa_key_policy_set_usage(&policy, usage, alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle, type, bits, NULL, 0));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_create_key(PSA_KEY_LIFETIME_PERSISTENT, id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
policy = psa_key_policy_init();
psa_key_policy_set_usage(&policy, usage, alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle, &policy));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle, type, bits, NULL, 0));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_close_key(key_handle));
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, id, &key_handle));
attributes = psa_key_attributes_init();
psa_set_key_usage_flags(&attributes, usage);
psa_set_key_algorithm(&attributes, alg);
psa_set_key_type(&attributes, type);
psa_set_key_bits(&attributes, bits);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(&attributes, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_ERROR_DOES_NOT_EXIST, psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, id, &key_handle));
attributes = psa_key_attributes_init();
psa_set_key_usage_flags(&attributes, usage);
psa_set_key_algorithm(&attributes, alg);
psa_set_key_type(&attributes, type);
psa_set_key_bits(&attributes, bits);
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_PERSISTENT);
psa_set_key_id(&attributes, id);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(&attributes, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_close_key(key_handle));
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_open_key(id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_destroy_key(key_handle));
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_ERROR_DOES_NOT_EXIST, psa_open_key(id, &key_handle));
}
void test_crypto_hash_clone(void)

View File

@ -94,7 +94,7 @@ static void check_initial_attestation_get_token()
TEST_ASSERT_EQUAL(status, PSA_SUCCESS);
status = psa_attestation_inject_key(private_key_data,
sizeof(private_key_data),
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP256R1),
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1),
exported,
sizeof(exported),
&exported_length);
@ -119,9 +119,8 @@ static void check_initial_attestation_get_token()
utest::v1::status_t case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
{
const psa_key_id_t key_id = PSA_ATTESTATION_PRIVATE_KEY_ID;
psa_key_handle_t handle = 0;
psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, key_id, &handle);
psa_key_handle_t handle;
psa_open_key(PSA_ATTESTATION_PRIVATE_KEY_ID, &handle);
psa_destroy_key(handle);
mbedtls_psa_crypto_free();
return greentea_case_teardown_handler(source, passed, failed, reason);

View File

@ -52,15 +52,15 @@ void inject_entropy()
}
#endif // defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
static psa_status_t create_and_generate_key_via_test_partition(psa_key_id_t key_id, psa_key_type_t key_type,
psa_algorithm_t key_alg, psa_key_usage_t key_usage,
size_t key_bits, psa_key_handle_t *key_handle,
unsigned char close_key)
static psa_status_t create_and_generate_key_via_test_partition(
const psa_key_attributes_t *attributes,
psa_key_handle_t *key_handle,
uint8_t close_key)
{
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS,
test_partition_crypto_generate_key(attributes,
key_handle));
TEST_ASSERT_NOT_EQUAL(0, *key_handle);
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(*key_handle, key_usage, key_alg));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_generate_key(*key_handle, key_type, key_bits));
if (close_key) {
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(*key_handle));
}
@ -75,25 +75,31 @@ void test_open_other_partition_key(void)
static const psa_algorithm_t key_alg = PSA_ALG_CBC_NO_PADDING;
static const size_t key_bits = 128;
psa_key_handle_t key_handle = 0;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* via test partition - create a key, set key policy, generate key material and close */
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg, key_usage,
key_bits, &key_handle, 1));
/* via test partition - create a key, generate key material and close */
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
create_and_generate_key_via_test_partition(&attributes, &key_handle, 1));
/* via test partition - reopen the key created by the test partition */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* via test partition - close the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
/* try to open the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_ERROR_DOES_NOT_EXIST, psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_ERROR_DOES_NOT_EXIST, psa_open_key(key_id, &key_handle));
/* via test partition - reopen the key created by the test partition and keep it open */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* via test partition - destroy the key created by the test partition */
@ -111,61 +117,54 @@ void test_create_key_same_id_different_partitions(void)
key_bits_local = 256;
psa_key_handle_t key_handle_remote = 0,
key_handle_local = 0;
psa_key_type_t got_key_type_remote = 0,
got_key_type_local = 0;
size_t got_key_bits_remote = 0,
got_key_bits_local = 0;
psa_key_usage_t got_key_usage_remote = 0;
psa_algorithm_t got_key_alg_remote = 0;
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* via test partition - create a key, set key policy, generate key material and close */
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg,
key_usage_remote, key_bits_remote,
&key_handle_remote, 1));
/* via test partition - create a key, generate key material and close */
psa_set_key_usage_flags(&attributes, key_usage_remote);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits_remote);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
create_and_generate_key_via_test_partition(&attributes, &key_handle_remote, 1));
psa_reset_key_attributes(&attributes);
/* create a key, set key policy, generate key material and close from current partition (i.e. NSPE) */
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_create_key(PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle_local));
/* create a key, generate key material and close from current partition (i.e. NSPE) */
psa_set_key_usage_flags(&attributes, key_usage_local);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits_local);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(&attributes, &key_handle_local));
TEST_ASSERT_NOT_EQUAL(0, key_handle_local);
psa_key_policy_set_usage(&policy, key_usage_local, key_alg);
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_set_key_policy(key_handle_local, &policy));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_generate_key(key_handle_local, key_type, key_bits_local, NULL, 0));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_close_key(key_handle_local));
/* via test partition - reopen the key created by the test partition */
key_handle_remote = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle_remote));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle_remote));
TEST_ASSERT_NOT_EQUAL(0, key_handle_remote);
/* reopen the key created from the current partition (NSPE) */
key_handle_local = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle_local));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_open_key(key_id, &key_handle_local));
TEST_ASSERT_NOT_EQUAL(0, key_handle_local);
/* via test partition - get key info for the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_get_key_information(key_handle_remote,
&got_key_type_remote,
&got_key_bits_remote));
TEST_ASSERT_EQUAL(key_type, got_key_type_remote);
TEST_ASSERT_EQUAL(key_bits_remote, got_key_bits_remote);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
test_partition_crypto_get_key_attributes(key_handle_remote,
&attributes));
TEST_ASSERT_EQUAL(key_type, psa_get_key_type(&attributes));
TEST_ASSERT_EQUAL(key_bits_remote, psa_get_key_bits(&attributes));
TEST_ASSERT_EQUAL(key_usage_remote, psa_get_key_usage_flags(&attributes));
TEST_ASSERT_EQUAL(key_alg, psa_get_key_algorithm(&attributes));
/* via test partition - get key policy for key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_get_key_policy(key_handle_remote,
&got_key_usage_remote,
&got_key_alg_remote));
TEST_ASSERT_EQUAL(key_usage_remote, got_key_usage_remote);
TEST_ASSERT_EQUAL(key_alg, got_key_alg_remote);
/* get key info for key created by the current partition (NSPE) */
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_information(key_handle_local, &got_key_type_local, &got_key_bits_local));
TEST_ASSERT_EQUAL(key_type, got_key_type_local);
TEST_ASSERT_EQUAL(key_bits_local, got_key_bits_local);
/* get key policy for key created by the current partition (NSPE) */
policy = psa_key_policy_init();
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_policy(key_handle_local, &policy));
TEST_ASSERT_EQUAL(key_usage_local, policy.usage);
TEST_ASSERT_EQUAL(key_alg, policy.alg);
/* get key attributes for key created by the current partition (NSPE) */
attributes = psa_key_attributes_init();
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_get_key_attributes(key_handle_local, &attributes));
TEST_ASSERT_EQUAL(key_type, psa_get_key_type(&attributes));
TEST_ASSERT_EQUAL(key_bits_local, psa_get_key_bits(&attributes));
TEST_ASSERT_EQUAL(key_usage_local, psa_get_key_usage_flags(&attributes));
TEST_ASSERT_EQUAL(key_alg, psa_get_key_algorithm(&attributes));
/* via test partition - destroy the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_destroy_key(key_handle_remote));
@ -181,68 +180,50 @@ void test_use_other_partition_key_manage_key(void)
static const psa_algorithm_t key_alg = PSA_ALG_CBC_NO_PADDING;
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_EXPORT;
static const size_t key_bits = 128;
static const unsigned char key_data[] = {
static const uint8_t key_data[] = {
0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c
};
psa_key_handle_t key_handle = 0;
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
unsigned char output[sizeof(key_data)] = { 0 };
size_t len, got_key_bits;
psa_key_type_t got_key_type;
psa_key_lifetime_t got_lifetime;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
uint8_t output[sizeof(key_data)] = { 0 };
size_t len;
/* via test partition - create a key without generating any key material */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* try to set the key policy for the key that was created by the test partition */
psa_key_policy_set_usage(&policy, key_usage, key_alg);
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_set_key_policy(key_handle, &policy));
/* via test partition - set key policy */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(key_handle, key_usage, key_alg));
/* try to generate key data for the key that was created by the test partition */
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_generate_key(key_handle, key_type, key_bits, NULL, 0));
/* via test partition - generate key material and close the key */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_generate_key(key_handle, key_type, key_bits));
/* via test partition - generate a persistent key and close the key */
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_generate_key(&attributes, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
/* via test partition - reopen the key created by the test partition and keep it open */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* try to work with the handle created for a key created by the test partition */
got_key_type = 0;
got_key_bits = 0;
got_lifetime = 0;
policy = psa_key_policy_init();
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_get_key_policy(key_handle, &policy));
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_get_key_lifetime(key_handle, &got_lifetime));
attributes = psa_key_attributes_init();
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_get_key_attributes(key_handle, &attributes));
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_close_key(key_handle));
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_destroy_key(key_handle));
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_get_key_information(key_handle, &got_key_type, &got_key_bits));
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_export_key(key_handle, output, sizeof(output), &len));
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_export_public_key(key_handle, output, sizeof(output), &len));
/* via test partition - destroy the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_destroy_key(key_handle));
/* via test partition - create a key, set key policy but no key material */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(key_handle, key_usage, key_alg));
/* try to import key data into the key that was created by the test partition */
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_import_key(key_handle, key_type,
key_data, sizeof(key_data)));
/* via test partition - import key data for the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_import_key(key_handle, key_type, key_data, sizeof(key_data)));
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
test_partition_crypto_import_key(
&attributes, key_data, sizeof(key_data), &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* via test partition - destroy the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_destroy_key(key_handle));
@ -257,14 +238,20 @@ void test_use_other_partition_key_mac(void)
static const size_t key_bits = 128;
psa_key_handle_t key_handle = 0;
psa_mac_operation_t operation;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* via test partition - create a key, set key policy, generate key material and close */
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg, key_usage,
key_bits, &key_handle, 1));
/* via test partition - create a key, generate key material and close */
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
create_and_generate_key_via_test_partition(&attributes, &key_handle, 1));
/* via test partition - reopen the key created by the test partition */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* try to setup mac sign operation using the key that was created by the test partition */
@ -288,17 +275,23 @@ void test_use_other_partition_key_cipher(void)
static const size_t key_bits = 128;
psa_key_handle_t key_handle = 0;
psa_cipher_operation_t operation;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* via test partition - create a key, set key policy, generate key material and close */
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg, key_usage,
key_bits, &key_handle, 1));
/* via test partition - create a key, generate key material and close */
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
create_and_generate_key_via_test_partition(&attributes, &key_handle, 1));
/* via test partition - reopen the key created by the test partition */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* try to setup cipher encrypt sign operation using the key that was created by the test partition */
/* try to setup cipher encrypt operation using the key that was created by the test partition */
operation = psa_cipher_operation_init();
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_cipher_encrypt_setup(&operation, key_handle, key_alg));
@ -317,19 +310,25 @@ void test_use_other_partition_key_aead(void)
static const psa_algorithm_t key_alg = PSA_ALG_GCM;
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT;
static const size_t key_bits = 128;
static const unsigned char nonce[16] = { 0 };
unsigned char plain_text[] = "encrypt me!";
unsigned char cipher_text[PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_alg, sizeof(plain_text))] = { 0 };
static const uint8_t nonce[16] = { 0 };
uint8_t plain_text[] = "encrypt me!";
uint8_t cipher_text[PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_alg, sizeof(plain_text))] = { 0 };
psa_key_handle_t key_handle = 0;
size_t len;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* via test partition - create a key, set key policy, generate key material and close */
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg, key_usage,
key_bits, &key_handle, 1));
/* via test partition - create a key, generate key material and close */
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
create_and_generate_key_via_test_partition(&attributes, &key_handle, 1));
/* via test partition - reopen the key created by the test partition */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* try to aead encrypt using the key that was created by the test partition */
@ -349,22 +348,28 @@ void test_use_other_partition_key_aead(void)
void test_use_other_partition_key_asymmetric_sign_verify(void)
{
static const psa_key_id_t key_id = 999;
static const psa_key_type_t key_type = PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP256R1);
static const psa_key_type_t key_type = PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_CURVE_SECP256R1);
static const psa_algorithm_t key_alg = PSA_ALG_ECDSA(PSA_ALG_SHA_256);
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY;
static const size_t key_bits = 256;
static const unsigned char input[] = "hello world!";
unsigned char signature[PSA_ECDSA_SIGNATURE_SIZE(key_bits)] = { 0 };
static const uint8_t input[] = "hello world!";
uint8_t signature[PSA_ECDSA_SIGNATURE_SIZE(key_bits)] = { 0 };
psa_key_handle_t key_handle = 0;
size_t len;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* via test partition - create a key, set key policy, generate key material and close */
TEST_ASSERT_EQUAL(PSA_SUCCESS, create_and_generate_key_via_test_partition(key_id, key_type, key_alg, key_usage,
key_bits, &key_handle, 1));
/* via test partition - create a key, generate key material and close */
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, key_bits);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
create_and_generate_key_via_test_partition(&attributes, &key_handle, 1));
/* via test partition - reopen the key created by the test partition */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* try to asymmetric sign using the key that was created by the test partition */
@ -382,11 +387,11 @@ void test_use_other_partition_key_asymmetric_sign_verify(void)
void test_use_other_partition_key_asymmetric_encrypt_decrypt(void)
{
static const psa_key_id_t key_id = 999;
static const psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEYPAIR;
static const psa_key_type_t key_type = PSA_KEY_TYPE_RSA_KEY_PAIR;
static const psa_algorithm_t key_alg = PSA_ALG_RSA_PKCS1V15_CRYPT;
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT;
static const unsigned char input[] = "encrypt me!";
static const unsigned char key_data[] = {
static const uint8_t input[] = "encrypt me!";
static const uint8_t key_data[] = {
0x30, 0x82, 0x01, 0x3b, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xee, 0x2b,
0x13, 0x1d, 0x6b, 0x18, 0x18, 0xa9, 0x4c, 0xa8, 0xe9, 0x1c, 0x42, 0x38,
0x7e, 0xb1, 0x5a, 0x7c, 0x27, 0x1f, 0x57, 0xb8, 0x9e, 0x73, 0x36, 0xb1,
@ -415,27 +420,29 @@ void test_use_other_partition_key_asymmetric_encrypt_decrypt(void)
0xd8, 0xfb, 0x93, 0x0a, 0xfc, 0xf4, 0x6f, 0x36, 0x60, 0x6e, 0x3a, 0xa0,
0xeb, 0x7a, 0x93, 0xad, 0x88, 0xc1, 0x0c
};
unsigned char encrypted[64] = { 0 };
unsigned char decrypted[sizeof(input)] = { 0 };
uint8_t encrypted[64] = { 0 };
uint8_t decrypted[sizeof(input)] = { 0 };
psa_key_handle_t key_handle = 0;
size_t len;
/* via test partition - create a key without generating any key material */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* via test partition - set key policy */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(key_handle, key_usage, key_alg));
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* via test partition - import key data for the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_import_key(key_handle, key_type, key_data, sizeof(key_data)));
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, 512);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
test_partition_crypto_import_key(
&attributes, key_data, sizeof(key_data), &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* via test partition - close the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_close_key(key_handle));
/* via test partition - reopen the key created by the test partition and keep it open */
key_handle = 0;
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_persistent_key(key_id, &key_handle));
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_open_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* try to asymmetric encrypt using the key that was created by the test partition */
@ -457,79 +464,32 @@ void test_use_other_partition_key_derivation_setup(void)
static const psa_algorithm_t key_alg = PSA_ALG_HKDF(PSA_ALG_SHA_256);
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_DERIVE;
static const psa_key_type_t key_type = PSA_KEY_TYPE_DERIVE;
static const unsigned char key_data[] = {
static const uint8_t key_data[] = {
0x30, 0x82, 0x01, 0x3b, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, 0xee, 0x2b,
0x13, 0x1d, 0x6b, 0x18, 0x18, 0xa9, 0x4c, 0xa8, 0xe9, 0x1c, 0x42, 0x38
};
static const unsigned char salt[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
0x0c
};
static const unsigned char label[] = {
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9
};
psa_key_handle_t key_handle = 0;
psa_crypto_generator_t generator = psa_crypto_generator_init();
size_t bits = 128;
/* via test partition - create a key without generating any key material */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* via test partition - set key policy */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(key_handle, key_usage, key_alg));
psa_key_derivation_operation_t operation = PSA_KEY_DERIVATION_OPERATION_INIT;
size_t bits = 192;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
/* via test partition - import key data for the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_import_key(key_handle, key_type, key_data, sizeof(key_data)));
psa_set_key_usage_flags(&attributes, key_usage);
psa_set_key_algorithm(&attributes, key_alg);
psa_set_key_bits(&attributes, bits);
psa_set_key_type(&attributes, key_type);
psa_set_key_id(&attributes, key_id);
TEST_ASSERT_EQUAL(PSA_SUCCESS,
test_partition_crypto_import_key(
&attributes, key_data, sizeof(key_data), &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* try to setup key derivation using the key that was created by the test partition */
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_key_derivation(&generator, key_handle, key_alg,
(unsigned char *)salt, sizeof(salt),
(unsigned char *)label, sizeof(label),
PSA_BITS_TO_BYTES(bits)));
/* via test partition - destroy the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_destroy_key(key_handle));
}
void test_use_other_partition_key_agreement_setup(void)
{
static const psa_key_id_t key_id = 999;
static const psa_algorithm_t key_alg = PSA_ALG_ECDH(PSA_ALG_SELECT_RAW);
static const psa_key_usage_t key_usage = PSA_KEY_USAGE_DERIVE;
static const psa_key_type_t key_type = PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP256R1);
static const unsigned char key_data[] = {
0xc8, 0x8f, 0x01, 0xf5, 0x10, 0xd9, 0xac, 0x3f, 0x70, 0xa2, 0x92, 0xda,
0xa2, 0x31, 0x6d, 0xe5, 0x44, 0xe9, 0xaa, 0xb8, 0xaf, 0xe8, 0x40, 0x49,
0xc6, 0x2a, 0x9c, 0x57, 0x86, 0x2d, 0x14, 0x33
};
static const unsigned char peer_key_data[] = {
0x04, 0xd1, 0x2d, 0xfb, 0x52, 0x89, 0xc8, 0xd4, 0xf8, 0x12, 0x08, 0xb7,
0x02, 0x70, 0x39, 0x8c, 0x34, 0x22, 0x96, 0x97, 0x0a, 0x0b, 0xcc, 0xb7,
0x4c, 0x73, 0x6f, 0xc7, 0x55, 0x44, 0x94, 0xbf, 0x63, 0x56, 0xfb, 0xf3,
0xca, 0x36, 0x6c, 0xc2, 0x3e, 0x81, 0x57, 0x85, 0x4c, 0x13, 0xc5, 0x8d,
0x6a, 0xac, 0x23, 0xf0, 0x46, 0xad, 0xa3, 0x0f, 0x83, 0x53, 0xe7, 0x4f,
0x33, 0x03, 0x98, 0x72, 0xab
};
psa_key_handle_t key_handle = 0;
psa_crypto_generator_t generator = psa_crypto_generator_init();
/* via test partition - create a key without generating any key material */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_create_persistent_key(key_id, &key_handle));
TEST_ASSERT_NOT_EQUAL(0, key_handle);
/* via test partition - set key policy */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_set_key_policy(key_handle, key_usage, key_alg));
/* via test partition - import key data for the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_import_key(key_handle, key_type, key_data, sizeof(key_data)));
/* try to setup key agreement using the key that was created by the test partition */
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE, psa_key_agreement(&generator, key_handle,
(unsigned char *)peer_key_data, sizeof(peer_key_data),
key_alg));
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_key_derivation_setup(&operation, key_alg));
TEST_ASSERT_EQUAL(PSA_ERROR_INVALID_HANDLE,
psa_key_derivation_input_key(
&operation, PSA_KEY_DERIVATION_INPUT_SECRET, key_handle));
/* via test partition - destroy the key created by the test partition */
TEST_ASSERT_EQUAL(PSA_SUCCESS, test_partition_crypto_destroy_key(key_handle));
@ -584,8 +544,6 @@ Case cases[] = {
case_setup_handler, test_use_other_partition_key_asymmetric_encrypt_decrypt, case_teardown_handler),
Case("use other partition's key - key derivation setup",
case_setup_handler, test_use_other_partition_key_derivation_setup, case_teardown_handler),
Case("use other partition's key - key agreement setup",
case_setup_handler, test_use_other_partition_key_agreement_setup, case_teardown_handler),
};
Specification specification(test_setup, cases);

View File

@ -37,66 +37,35 @@ static psa_status_t invoke_ipc_call(uint32_t sid, psa_invec *in_vec, size_t in_v
return (status);
}
psa_status_t test_partition_crypto_create_persistent_key(psa_key_id_t key_id, psa_key_handle_t *key_handle)
psa_status_t test_partition_crypto_get_key_attributes(
psa_key_handle_t key_handle, psa_key_attributes_t *attributes)
{
psa_invec in_vec = { &key_handle, sizeof(key_handle) };
psa_outvec out_vec[1] = {
{ attributes, sizeof(*attributes) }
};
psa_status_t status = invoke_ipc_call(CRYPTO_GET_KEY_ATTRIBUTES, &in_vec, 1, out_vec, 1);
return (status);
}
psa_status_t test_partition_crypto_generate_key(
const psa_key_attributes_t *attributes, psa_key_handle_t *key_handle)
{
psa_invec in_vec[] = {
{ attributes, sizeof(*attributes) },
};
psa_outvec out_vec[] = {
{ key_handle, sizeof(*key_handle) },
};
psa_status_t status = invoke_ipc_call(CRYPTO_GENERATE_KEY, in_vec, 1, out_vec, 1);
return (status);
}
psa_status_t test_partition_crypto_open_key(psa_key_id_t key_id, psa_key_handle_t *key_handle)
{
psa_invec in_vec = { &key_id, sizeof(key_id) };
psa_outvec out_vec = { key_handle, sizeof(*key_handle) };
psa_status_t status = invoke_ipc_call(CRYPTO_CREATE_PERSISTENT_KEY, &in_vec, 1, &out_vec, 1);
return (status);
}
psa_status_t test_partition_crypto_set_key_policy(psa_key_handle_t key_handle, psa_key_usage_t key_usage,
psa_algorithm_t key_alg)
{
psa_invec in_vec[3] = {
{ &key_handle, sizeof(key_handle) },
{ &key_usage, sizeof(key_usage) },
{ &key_alg, sizeof(key_alg) }
};
psa_status_t status = invoke_ipc_call(CRYPTO_SET_KEY_POLICY, in_vec, 3, NULL, 0);
return (status);
}
psa_status_t test_partition_crypto_get_key_policy(psa_key_handle_t key_handle, psa_key_usage_t *key_usage,
psa_algorithm_t *key_alg)
{
psa_invec in_vec = { &key_handle, sizeof(key_handle) };
psa_outvec out_vec[2] = {
{ key_usage, sizeof(*key_usage) },
{ key_alg, sizeof(*key_alg) }
};
psa_status_t status = invoke_ipc_call(CRYPTO_GET_KEY_POLICY, &in_vec, 1, out_vec, 2);
return (status);
}
psa_status_t test_partition_crypto_get_key_information(psa_key_handle_t key_handle, psa_key_type_t *key_type,
size_t *key_bits)
{
psa_invec in_vec = { &key_handle, sizeof(key_handle) };
psa_outvec out_vec[2] = {
{ key_type, sizeof(*key_type) },
{ key_bits, sizeof(*key_bits) }
};
psa_status_t status = invoke_ipc_call(CRYPTO_GET_KEY_INFO, &in_vec, 1, out_vec, 2);
return (status);
}
psa_status_t test_partition_crypto_generate_key(psa_key_handle_t key_handle, psa_key_type_t key_type, size_t key_bits)
{
psa_invec in_vec[3] = {
{ &key_handle, sizeof(key_handle) },
{ &key_type, sizeof(key_type) },
{ &key_bits, sizeof(key_bits) }
};
psa_status_t status = invoke_ipc_call(CRYPTO_GENERATE_KEY, in_vec, 3, NULL, 0);
return (status);
}
psa_status_t test_partition_crypto_open_persistent_key(psa_key_id_t key_id, psa_key_handle_t *key_handle)
{
psa_invec in_vec = { &key_id, sizeof(key_id) };
psa_outvec out_vec = { key_handle, sizeof(*key_handle) };
psa_status_t status = invoke_ipc_call(CRYPTO_OPEN_PERSISTENT_KEY, &in_vec, 1, &out_vec, 1);
psa_status_t status = invoke_ipc_call(CRYPTO_OPEN_KEY, &in_vec, 1, &out_vec, 1);
return (status);
}
@ -114,15 +83,19 @@ psa_status_t test_partition_crypto_destroy_key(psa_key_handle_t key_handle)
return (status);
}
psa_status_t test_partition_crypto_import_key(psa_key_handle_t key_handle, psa_key_type_t key_type,
const unsigned char *key_data, size_t key_data_size)
psa_status_t test_partition_crypto_import_key(
const psa_key_attributes_t *attributes,
const uint8_t *key_data,
size_t key_data_size,
psa_key_handle_t *key_handle)
{
psa_invec in_vec[4] = {
{ &key_handle, sizeof(key_handle) },
{ &key_type, sizeof(key_type) },
{ &key_data_size, sizeof(key_data_size) },
{ key_data, key_data_size }
psa_invec in_vec[] = {
{ attributes, sizeof(*attributes) },
{ key_data, key_data_size },
};
psa_status_t status = invoke_ipc_call(CRYPTO_IMPORT_KEY, in_vec, 4, NULL, 0);
psa_outvec out_vec[] = {
{ key_handle, sizeof(*key_handle) },
};
psa_status_t status = invoke_ipc_call(CRYPTO_IMPORT_KEY, in_vec, 2, out_vec, 1);
return (status);
}

View File

@ -24,27 +24,24 @@
extern "C" {
#endif
psa_status_t test_partition_crypto_create_persistent_key(psa_key_id_t key_id, psa_key_handle_t *key_handle);
psa_status_t test_partition_crypto_get_key_attributes(
psa_key_handle_t key_handle, psa_key_attributes_t *attributes);
psa_status_t test_partition_crypto_set_key_policy(psa_key_handle_t key_handle, psa_key_usage_t key_usage,
psa_algorithm_t key_alg);
psa_status_t test_partition_crypto_generate_key(
const psa_key_attributes_t *attributes, psa_key_handle_t *key_handle);
psa_status_t test_partition_crypto_get_key_policy(psa_key_handle_t key_handle, psa_key_usage_t *key_usage,
psa_algorithm_t *key_alg);
psa_status_t test_partition_crypto_get_key_information(psa_key_handle_t key_handle, psa_key_type_t *key_type,
size_t *key_bits);
psa_status_t test_partition_crypto_generate_key(psa_key_handle_t key_handle, psa_key_type_t key_type, size_t key_bits);
psa_status_t test_partition_crypto_open_persistent_key(psa_key_id_t key_id, psa_key_handle_t *key_handle);
psa_status_t test_partition_crypto_open_key(
psa_key_id_t key_id, psa_key_handle_t *key_handle);
psa_status_t test_partition_crypto_close_key(psa_key_handle_t key_handle);
psa_status_t test_partition_crypto_destroy_key(psa_key_handle_t key_handle);
psa_status_t test_partition_crypto_import_key(psa_key_handle_t key_handle, psa_key_type_t key_type,
const unsigned char *key_data, size_t key_data_size);
psa_status_t test_partition_crypto_import_key(
const psa_key_attributes_t *attributes,
const uint8_t *key_data,
size_t key_data_size,
psa_key_handle_t *key_handle);
#ifdef __cplusplus
}

View File

@ -31,37 +31,24 @@ static void read_input_param_from_message(psa_msg_t *msg, uint8_t param_index, v
}
}
static psa_status_t crypto_create_persistent_key(psa_msg_t *msg)
{
psa_status_t status;
psa_key_id_t key_id = 0;
psa_key_handle_t key_handle = 0;
read_input_param_from_message(msg, 0, &key_id);
status = psa_create_key(PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle);
if (status == PSA_SUCCESS) {
psa_write(msg->handle, 0, &key_handle, sizeof(key_handle));
}
return (status);
}
static psa_status_t crypto_generate_key(psa_msg_t *msg)
{
psa_status_t status;
psa_key_handle_t key_handle = 0;
psa_key_type_t key_type = 0;
size_t key_bits = 0;
psa_key_attributes_t attributes;
read_input_param_from_message(msg, 0, &key_handle);
read_input_param_from_message(msg, 1, &key_type);
read_input_param_from_message(msg, 2, &key_bits);
read_input_param_from_message(msg, 0, &attributes);
status = psa_generate_key(key_handle, key_type, key_bits, NULL, 0);
status = psa_generate_key(&attributes, &key_handle);
if (status == PSA_SUCCESS) {
psa_write(msg->handle, 0, &key_handle, sizeof(key_handle));
}
return (status);
}
static psa_status_t crypto_open_persistent_key(psa_msg_t *msg)
static psa_status_t crypto_open_key(psa_msg_t *msg)
{
psa_status_t status;
psa_key_id_t key_id;
@ -69,7 +56,7 @@ static psa_status_t crypto_open_persistent_key(psa_msg_t *msg)
read_input_param_from_message(msg, 0, &key_id);
status = psa_open_key(PSA_KEY_LIFETIME_PERSISTENT, key_id, &key_handle);
status = psa_open_key(key_id, &key_handle);
if (status == PSA_SUCCESS) {
psa_write(msg->handle, 0, &key_handle, sizeof(key_handle));
}
@ -87,23 +74,6 @@ static psa_status_t crypto_close_key(psa_msg_t *msg)
return (status);
}
static psa_status_t crypto_set_key_policy(psa_msg_t *msg)
{
psa_status_t status;
psa_key_handle_t key_handle;
psa_key_usage_t key_usage;
psa_algorithm_t key_alg;
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
read_input_param_from_message(msg, 0, &key_handle);
read_input_param_from_message(msg, 1, &key_usage);
read_input_param_from_message(msg, 2, &key_alg);
psa_key_policy_set_usage(&policy, key_usage, key_alg);
status = psa_set_key_policy(key_handle, &policy);
return (status);
}
static psa_status_t crypto_destroy_key(psa_msg_t *msg)
{
psa_status_t status;
@ -115,35 +85,17 @@ static psa_status_t crypto_destroy_key(psa_msg_t *msg)
return (status);
}
static psa_status_t crypto_get_key_info(psa_msg_t *msg)
static psa_status_t crypto_get_key_attributes(psa_msg_t *msg)
{
psa_status_t status;
psa_key_handle_t key_handle;
psa_key_type_t key_type = 0;
size_t key_bits = 0;
psa_key_attributes_t attributes;
read_input_param_from_message(msg, 0, &key_handle);
status = psa_get_key_information(key_handle, &key_type, &key_bits);
status = psa_get_key_attributes(key_handle, &attributes);
if (status == PSA_SUCCESS) {
psa_write(msg->handle, 0, &key_type, sizeof(key_type));
psa_write(msg->handle, 1, &key_bits, sizeof(key_bits));
}
return (status);
}
static psa_status_t crypto_get_key_policy(psa_msg_t *msg)
{
psa_status_t status;
psa_key_handle_t key_handle;
psa_key_policy_t policy = PSA_KEY_POLICY_INIT;
read_input_param_from_message(msg, 0, &key_handle);
status = psa_get_key_policy(key_handle, &policy);
if (status == PSA_SUCCESS) {
psa_write(msg->handle, 0, &(policy.usage), sizeof(policy.usage));
psa_write(msg->handle, 1, &(policy.alg), sizeof(policy.alg));
psa_write(msg->handle, 0, &attributes, sizeof(attributes));
}
return (status);
}
@ -152,22 +104,22 @@ static psa_status_t crypto_import_key(psa_msg_t *msg)
{
psa_status_t status;
psa_key_handle_t key_handle;
psa_key_type_t key_type;
size_t key_data_size;
unsigned char *key_data = NULL;
psa_key_attributes_t attributes;
uint8_t *key_data;
size_t key_data_size = msg->in_size[1];
read_input_param_from_message(msg, 0, &key_handle);
read_input_param_from_message(msg, 1, &key_type);
read_input_param_from_message(msg, 2, &key_data_size);
read_input_param_from_message(msg, 0, &attributes);
key_data = calloc(1, key_data_size);
if (key_data == NULL) {
return (PSA_ERROR_INSUFFICIENT_MEMORY);
}
read_input_param_from_message(msg, 1, key_data);
read_input_param_from_message(msg, 3, key_data);
status = psa_import_key(key_handle, key_type, key_data, key_data_size);
status = psa_import_key(&attributes, key_data, key_data_size, &key_handle);
if (status == PSA_SUCCESS) {
psa_write(msg->handle, 0, &key_handle, sizeof(key_handle));
}
free(key_data);
return (status);
@ -201,23 +153,17 @@ void test_partition_main(void)
psa_msg_t msg = {0};
while (1) {
signal = psa_wait(CRYPTO_ACL_TEST_WAIT_ANY_SID_MSK, PSA_BLOCK);
if (signal & CRYPTO_CREATE_PERSISTENT_KEY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_CREATE_PERSISTENT_KEY_MSK, &msg)) {
continue;
}
message_handler(&msg, crypto_create_persistent_key);
}
if (signal & CRYPTO_GENERATE_KEY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_GENERATE_KEY_MSK, &msg)) {
continue;
}
message_handler(&msg, crypto_generate_key);
}
if (signal & CRYPTO_OPEN_PERSISTENT_KEY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_OPEN_PERSISTENT_KEY_MSK, &msg)) {
if (signal & CRYPTO_OPEN_KEY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_OPEN_KEY_MSK, &msg)) {
continue;
}
message_handler(&msg, crypto_open_persistent_key);
message_handler(&msg, crypto_open_key);
}
if (signal & CRYPTO_CLOSE_KEY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_CLOSE_KEY_MSK, &msg)) {
@ -225,29 +171,17 @@ void test_partition_main(void)
}
message_handler(&msg, crypto_close_key);
}
if (signal & CRYPTO_SET_KEY_POLICY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_SET_KEY_POLICY_MSK, &msg)) {
continue;
}
message_handler(&msg, crypto_set_key_policy);
}
if (signal & CRYPTO_DESTROY_KEY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_DESTROY_KEY_MSK, &msg)) {
continue;
}
message_handler(&msg, crypto_destroy_key);
}
if (signal & CRYPTO_GET_KEY_INFO_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_GET_KEY_INFO_MSK, &msg)) {
if (signal & CRYPTO_GET_KEY_ATTRIBUTES_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_GET_KEY_ATTRIBUTES_MSK, &msg)) {
continue;
}
message_handler(&msg, crypto_get_key_info);
}
if (signal & CRYPTO_GET_KEY_POLICY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_GET_KEY_POLICY_MSK, &msg)) {
continue;
}
message_handler(&msg, crypto_get_key_policy);
message_handler(&msg, crypto_get_key_attributes);
}
if (signal & CRYPTO_IMPORT_KEY_MSK) {
if (PSA_SUCCESS != psa_get(CRYPTO_IMPORT_KEY_MSK, &msg)) {

View File

@ -7,14 +7,6 @@
"stack_size": "0x200",
"heap_size": "0x400",
"services": [
{
"name": "CRYPTO_CREATE_PERSISTENT_KEY",
"identifier": "0x00000200",
"signal": "CRYPTO_CREATE_PERSISTENT_KEY_MSK",
"non_secure_clients": true,
"minor_version": 1,
"minor_policy": "RELAXED"
},
{
"name": "CRYPTO_GENERATE_KEY",
"identifier": "0x00000201",
@ -24,9 +16,9 @@
"minor_policy": "RELAXED"
},
{
"name": "CRYPTO_OPEN_PERSISTENT_KEY",
"name": "CRYPTO_OPEN_KEY",
"identifier": "0x00000202",
"signal": "CRYPTO_OPEN_PERSISTENT_KEY_MSK",
"signal": "CRYPTO_OPEN_KEY_MSK",
"non_secure_clients": true,
"minor_version": 1,
"minor_policy": "RELAXED"
@ -39,14 +31,6 @@
"minor_version": 1,
"minor_policy": "RELAXED"
},
{
"name": "CRYPTO_SET_KEY_POLICY",
"identifier": "0x00000204",
"signal": "CRYPTO_SET_KEY_POLICY_MSK",
"non_secure_clients": true,
"minor_version": 1,
"minor_policy": "RELAXED"
},
{
"name": "CRYPTO_DESTROY_KEY",
"identifier": "0x00000205",
@ -56,17 +40,9 @@
"minor_policy": "RELAXED"
},
{
"name": "CRYPTO_GET_KEY_INFO",
"name": "CRYPTO_GET_KEY_ATTRIBUTES",
"identifier": "0x00000206",
"signal": "CRYPTO_GET_KEY_INFO_MSK",
"non_secure_clients": true,
"minor_version": 1,
"minor_policy": "RELAXED"
},
{
"name": "CRYPTO_GET_KEY_POLICY",
"identifier": "0x00000207",
"signal": "CRYPTO_GET_KEY_POLICY_MSK",
"signal": "CRYPTO_GET_KEY_ATTRIBUTES_MSK",
"non_secure_clients": true,
"minor_version": 1,
"minor_policy": "RELAXED"

View File

@ -133,6 +133,7 @@ set(unittest-includes-base
"${PROJECT_SOURCE_DIR}/../features/lorawan/system"
"${PROJECT_SOURCE_DIR}/../features/mbedtls"
"${PROJECT_SOURCE_DIR}/../features/mbedtls/inc"
"${PROJECT_SOURCE_DIR}/../features/mbedtls/mbed-crypto/inc"
)
# Create a list for test suites.

View File

@ -1,574 +0,0 @@
# PSA Crypto Testcase checklist
| Group | Test | Function | Scenario | Return Value | Steps | Test Case |
|------------------------------|-----------|----------------------------|-----------------------------------------------------------------------------------------------------------------------|---------------------------------|------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------|
| Basic | test_c001 | psa_crypto_init | Library initialization | PSA_SUCCESS | Calling this function should return SUCCESS | |
| | | | Applications must call this function before calling any other function in this module. | PSA_SUCCESS | Try calling crypto operations doing a crypto_init should be successful(can be covered as part of other testcase) | |
| | | | Applications may call this function more than once. Once a call succeeds, subsequent calls are guaranteed to succeed. | PSA_SUCCESS | Try calling multiple crypto init and should return SUCCESS | |
| | | | Applications must call this function before calling any other function in this module. | PSA_ERROR_BAD_STATE | Try calling crypto operations without doing a crypto_init should return FAILURE | |
| | | | | | | |
| Key Management | test_c002 | psa_import_key | Import a key in binary format. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. 2048 RSA public key |
| | | | | | 5. Import the key data into the key slot | 5. 2048 RSA keypair |
| | | | | | 6. Get basic metadata about a key | 6. DES 64 bit key |
| | | | | | 7. Export a key in binary format | 7. Triple DES 2-Key |
| | | | | | 8. Check if original key data matches with the exported data | 8. Triple DES 3-Key |
| | | | | | | 9. EC Public key |
| | | | | | | 10. EC keypair |
| | | | | PSA_ERROR_NOT_SUPPORTED | Calling this function with incorrect key type | Incorrect key type |
| | | | | PSA_ERROR_INVALID_ARGUMENT | Calling this function with invalid parameter should return this error | 1. Key data greater than the algorithm size |
| | | | | | | 2. Incorrect key data size |
| | | | | | | |
| | | | | | | |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid key handle should return this error | 1. Invalid key slot </br> 2. Zero key slot |
| | | | | PSA_ERROR_OCCUPIED_SLOT | Pass the key slot to store data which is already occupied | Already occupied key slot |
| | test_c003 | psa_export_key | Export a key in binary format | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | 2. 24 Byte AES |
| | | | | | | |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. 2048 RSA public key |
| | | | | | 5. Import the key data into the key slot | 5. 2048 RSA keypair |
| | | | | | 6. Get basic metadata about a key | 6. DES 64 bit key |
| | | | | | 7. Export a key in binary format | 7. Triple DES 2-Key |
| | | | | | 8. Check if original key data matches with the exported data | 8. Triple DES 3-Key |
| | | | | | | 9. EC Public key |
| | | | | | | 10. EC keypair |
| | | | | PSA_ERROR_BUFFER_TOO_SMALL | Calling this function with buffer size less than required | Less buffer size |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid parameter should return this error | 1. Zero key slot |
| | | | | | | 2. Invalid key slot |
| | | | | PSA_ERROR_BAD_STATE | Calling this function with key policy that cannot be exported | Invalid key policy usage |
| | | | | PSA_ERROR_EMPTY_SLOT | Calling this function with empty key slot | Empty key slot |
| | test_c004 | psa_export_public_key | Export a public key or the public part of a key pair in binary format. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 2048 RSA public key |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | 2. 2048 RSA keypair |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. EC Public key |
| | | | | | 4. Set the usage policy on a key slot | 4. EC keypair |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Get basic metadata about a key | |
| | | | | | 7. Export a key in binary format | |
| | | | | | 8. Check if original key data matches with the exported data | |
| | | | | PSA_ERROR_INVALID_ARGUMENT | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. DES 64 bit key |
| | | | | | 5. Import the key data into the key slot | 5. Triple DES 2-Key |
| | | | | | 6. Get basic metadata about a key | 6. Triple DES 3-Key |
| | | | | | 7. Export a key in binary format | |
| | | | | | 8. Check if original key data matches with the exported data | |
| | | | | PSA_ERROR_BUFFER_TOO_SMALL | Calling this function with buffer size less than required | Less buffer size |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid parameter should return this error | 1. Zero key slot |
| | | | | | | 2. Invalid key slot |
| | | | | PSA_ERROR_BAD_STATE | Calling this function with key policy that cannot be exported | Invalid key policy usage |
| | test_c005 | psa_destroy_key | Destroy a key and restore the slot to its default state. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. 2048 RSA public key |
| | | | | | 5. Import the key data into the key slot | 5. 2048 RSA keypair |
| | | | | | 6. Get basic metadata about a key | 6. DES 64 bit key |
| | | | | | 7. Destroy a key and restore the slot to its default state | 7. Triple DES 2-Key |
| | | | | | 8. Check that if the key metadata are destroyed | 8. Triple DES 3-Key |
| | | | | | | 9. EC Public key |
| | | | | | | 10. EC keypair |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid parameter should return this error | 1. Invalid key slot |
| | | | | | | 2. Zero key slot |
| | | | | | | 3. Empty key slot |
| | test_c006 | psa_get_key_information | Get basic metadata about a key. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. 2048 RSA public key |
| | | | | | 5. Import the key data into the key slot | 5. 2048 RSA keypair |
| | | | | | 6. Get basic metadata about a key | 6. DES 64 bit key |
| | | | | | | 7. Triple DES 2-Key |
| | | | | | | 8. Triple DES 3-Key |
| | | | | | | 9. EC Public key |
| | | | | | | 10. EC keypair |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid parameter should return this error | 1. Zero key slot |
| | | | | | | 2. Invalid key slot |
| | | | | PSA_ERROR_EMPTY_SLOT | Pass the key slot number which has the key type as none | Empty key slot |
| | NO TEST | psa_key_policy_set_usage | Set the standard fields of a policy structure. | void | Void function. Covered as part of other cases | |
| | | | | | | |
| Key Policies | test_c007 | psa_set_key_policy | Set the usage policy on a key slot. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. 2048 RSA public key |
| | | | | | 5. Import the key data into the key slot | 5. 2048 RSA keypair |
| | | | | | 6. Get the usage policy for a key slot | 6. DES 64 bit key |
| | | | | | 7. Check if the policy matches the original input | 7. Triple DES 2-Key |
| | | | | | | 8. Triple DES 3-Key |
| | | | | | | 9. EC Public key |
| | | | | | | 10. EC keypair |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid parameter should return this error | 1. Invalid key policy |
| | | | | | | 2. Zero key slot |
| | | | | | | 3. Invalid key slot |
| | | | | PSA_ERROR_OCCUPIED_SLOT | Pass the key slot to store data which is already occupied | Already occupied key slot |
| | test_c008 | psa_get_key_policy | Get the usage policy for a key slot | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. 2048 RSA public key |
| | | | | | 5. Change the lifetime of a key slot | 5. 2048 RSA keypair |
| | | | | | 6. Import the key data into the key slot | 6. DES 64 bit key |
| | | | | | 7. Get the usage policy for a key slot | 7. Triple DES 2-Key |
| | | | | | 8. Retrieve the usage field of a policy structure | 8. Triple DES 3-Key |
| | | | | | 9. Retrieve the algorithm field of a policy structure | 9. EC Public key |
| | | | | | 10. Make sure they match the original value | 10. EC keypair |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid parameter should return this error | 1. Zero key slot |
| | | | | | | 2. Invalid key slot |
| | test_c009 | psa_allocate_key | Allocate a key slot for a transient key | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. Volatile keys |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | |
| | | | | | 3. Allocate a key slot for a transient key | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | | | |
| | | | | PSA_ERROR_INSUFFICIENT_MEMORY | Calling this function with multiple time | |
| | | | | | | |
| | | | | | | |
| | test_c010 | psa_get_key_lifetime | Retrieve the lifetime of a key slot. | PSA_SUCCESS | 1. Initialize the PSA crypto library | Testing only volatile keys as other key types are currently not supported |
| | | | | | 2. Initialize a key policy structure to a default that forbids all usage of the key | |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Change the lifetime of a key slot | |
| | | | | | 6. Import the key data into the key slot | |
| | | | | | 7. Get the lifetime of a key slot | |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Zero key slot |
| | | | | | | 2. Invalid key slot |
| | | | | | | 3. Empty key slot |
| | | | | PSA_ERROR_INVALID_ARGUMENT | | 1. Invalid key policy |
| Message Authentication Codes | test_c011 | psa_hash_start | Start a multipart hash operation. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. MD2 |
| | | | | | 2. Start a multipart hash operation | 2. MD4 |
| | | | | | | 3. MD5 |
| | | | | | | 4. RIPEMD160 |
| | | | | | | 5. SHA1 |
| | | | | | | 6. SHA224 |
| | | | | | | 7. SHA256 |
| | | | | | | 8. SHA512 |
| | | | | | | 9. SHA512_224 |
| | | | | | | 10. SHA512_256 |
| | | | | | | 11. SHA3_224 1 |
| | | | | | | 2. SHA3_256 1 |
| | | | | | | 3. SHA3_384 1 |
| | | | | | | 4. SHA3_512 |
| | | | | PSA_ERROR_NOT_SUPPORTED | Calling this function with unsupported algorithm should return error | Invalid hash algorithm |
| | test_c012 | psa_hash_update | Add a message fragment to a multipart hash operation. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. MD2 |
| | | | | | 2. Start a multipart hash operation | 2. MD4 |
| | | | | | 3. Add a message fragment to a multipart hash operation | 3. MD5 |
| | | | | | | 4. RIPEMD160 |
| | | | | | | 5. SHA1 |
| | | | | | | 6. SHA224 |
| | | | | | | 7. SHA256 |
| | | | | | | 8. SHA384 |
| | | | | | | 9. SHA512 |
| | | | | PSA_ERROR_INVALID_ARGUMENT | Calling this function without calling the psa_hash_start() should return error | Inactive operation handle |
| | | | | PSA_ERROR_INVALID_ARGUMENT | Calling this function with completed operation handle should return error | Completed operation handle |
| | test_c013 | psa_hash_verify | Finish the calculation of the hash of a message and compare it with an expected value. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. MD2 |
| | | | | | 2. Start a multipart hash operation | 2. MD4 |
| | | | | | 3. Add a message fragment to a multipart hash operation | 3. MD5 |
| | | | | | 4. Finish the calculation of the hash of a message and compare it with an expected value | 4. RIPEMD160 |
| | | | | | | 5. SHA1 |
| | | | | | | 6. SHA224 |
| | | | | | | 7. SHA256 |
| | | | | | | 8. SHA384 |
| | | | | | | 9. SHA512 |
| | | | | PSA_ERROR_INVALID_ARGUMENT | Calling this function with inactive operation handle should return error | Inactive operation handle |
| | | | | PSA_ERROR_INVALID_SIGNATURE | Calling this function with incorrect expected value should return error | 1. Incorrect expected hash value |
| | | | | | | 2. Incorrect expected hash length |
| | test_c014 | psa_hash_finish | Finish the calculation of the hash of a message. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. MD2 |
| | | | | | 2. Start a multipart hash operation | 2. MD4 |
| | | | | | 3. Add a message fragment to a multipart hash operation | 3. MD5 |
| | | | | | 4. Finish the calculation of the hash of a message | 4. RIPEMD160 |
| | | | | | 5. Compare it with the expected value | 5. SHA1 |
| | | | | | | 6. SHA224 |
| | | | | | | 7. SHA256 |
| | | | | | | 8. SHA384 |
| | | | | | | 9. SHA512 |
| | | | | PSA_ERROR_INVALID_ARGUMENT | Calling this function with an inactive operation handle should return error | Inactive operation handle |
| | | | | PSA_ERROR_BUFFER_TOO_SMALL | Calling this function with a hash buffer whose size is less than the algorithm output should return error | Buffer size less than required |
| | test_c015 | psa_hash_abort | Abort a hash operation. | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. MD2 |
| | | | | | 2. Start a multipart hash operation | 2. MD4 |
| | | | | | 3. Abort a hash operation | 3. MD5 |
| | | | | | | 4. RIPEMD160 |
| | | | | | | 5. SHA1 |
| | | | | | | 6. SHA224 |
| | | | | | | 7. SHA256 |
| | | | | | | 8. SHA384 |
| | | | | | | 9. SHA512 |
| | | | | PSA_ERROR_INVALID_ARGUMENT | Calling psa_hash_finish after calling psa_hash_abort should return error | |
| Generator | test_c016 | psa_generate_key | Generate a key or key pair | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. AES |
| | | | | | 2. Initialize a key policy structure | 2. DES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. ECC |
| | | | | | 4. Set the usage policy on a key slot | 4. RSA |
| | | | | | 5. Generate a key or key pair | |
| | | | | | 6. Get basic metadata about a key | |
| | | | | | 7. Check if key type and key length matches | |
| | | | | | 8. Export a key in binary format | |
| | | | | | 9. Check if the metadata matches | |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid key slot should return this error | Invalid key slot |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with zero as key slot should return this error | Zero as key slot |
| | | | | PSA_ERROR_INVALID_ARGUMENT | Calling this function with Null extra and Non-Zero extra size should return this error | Null extra and Non-Zero extra size |
| | | | | PSA_ERROR_OCCUPIED_SLOT | Calling this function with pre-occupied key slot should return this error | Pre-occupied key slot |
| | | | | PSA_ERROR_NOT_SUPPORTED | Calling this function to generate only public key should return this error | Key type as public key |
| | test_c017 | psa_generate_random | Generate random bytes | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte data |
| | | | | | 2. Generate random bytes | 2. 24 Byte data |
| | | | | | 3. Check that if generated data are Non-Zero | 3. 32 Byte data |
| | | | | | | 4. 64 Byte data |
| | | | | | | 5. 128 Byte data |
| | | | | | | 6. 256 Byte data |
| | | | | | | 7. 512 Byte data |
| | | | | | | 8. 1000 Byte data |
| | | | | | | 9. 1024 Byte data |
| | test_c018 | psa_generator_read | Read some data from a generator | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte key |
| | | | | | 2. Initialize a key policy structure | 2. 32 Byte key |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 8 Byte Key |
| | | | | | 4. Set the usage policy on a key slot | 4. SHA 256 |
| | | | | | 5. Import the key data into the key slot | 5. SHA 512 |
| | | | | | 6. Set up a key derivation operation | 6. SHA 1 |
| | | | | | 7. Generate random bytes | 7. Output size less than generator capacity |
| | | | | | 8. Check that if generated data are non-zero | 8. Output size equal to generator capacity |
| | | | | | 9. Generate random bytes for remaining capacity | 9. Request maximum capacity |
| | | | | | 10. Check that if generated data are non-zero | |
| | | | | | 11. Generate random bytes and check that it fails | |
| | | | | PSA_ERROR_INSUFFICIENT_CAPACITY | Calling this function with output size greater than the current capacity should return this error | output size greater than the current capacity |
| | | | | PSA_ERROR_INSUFFICIENT_CAPACITY | Calling this function with capacity greater than the allowed capacity should return this error | request maximum capacity +1 |
| | test_c019 | psa_generator_get_capacity | Retrieve the current capacity of a generator | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. Output size less than generator capacity |
| | | | | | 2. Initialize a key policy structure | 2. Output size equal to generator capacity |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Set up a key derivation operation | |
| | | | | | 7. Retrieve the current capacity of a generator | |
| | | | | | 8. Check that it is equal to the input capacity | |
| | | | | | 9. Generate random bytes | |
| | | | | | 10. Retrieve the current capacity of a generator | |
| | | | | | 11. Check that it is equal to the remaining capacity | |
| | test_c020 | psa_generator_import_key | Create a symmetric key from data read from a generator | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure | 2. 32 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Set up a key derivation operation | |
| | | | | | 7. Initialize a key policy structure for new slot | |
| | | | | | 8. Set the standard fields of a policy structure | |
| | | | | | 9. Set the usage policy on a new key slot | |
| | | | | | 10. Create a symmetric key from data read from a generator | |
| | | | | | 11. Export a key in binary format | |
| | | | | | 12. Check that length of the key matches | |
| | | | | | 13. Check that the key is non-zero | |
| | | | | | 14. Initialize a key policy structure for new slot | |
| | | | | | 15. Set the standard fields of a policy structure | |
| | | | | | 16. Set the usage policy on a new key slot | |
| | | | | | 17. Create a symmetric key from data read from a generator for the remaining size | |
| | | | | | 18. Export a key in binary format | |
| | | | | | 19. Check that length of the key matches | |
| | | | | | 20. Check that the key is non-zero | |
| | | | | | 21. Initialize a key policy structure for new slot | |
| | | | | | 22. Set the standard fields of a policy structure | |
| | | | | | 23. Set the usage policy on a new key slot | |
| | | | | | 24. Create a symmetric key from data read from a generator for the some size | |
| | | | | | Check that it fails | |
| | | | | PSA_ERROR_INSUFFICIENT_CAPACITY | Calling this function with output greater than capacity should return this error | Output greater than capacity |
| | | | | PSA_ERROR_INVALID_ARGUMENT | Calling this function with public key algorithm should return this error | 1. RSA public key </br>2.Invalid key size |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this function with invalid arguments should return this error | 1. Invalid key slot |
| | | | | | | 2. Zero as key slot |
| | | | | | | |
| | | | | PSA_ERROR_OCCUPIED_SLOT | Calling this function with already occupied key slot should return this error | Pre-occupied key slot |
| | test_c021 | psa_generator_abort | Abort a generator | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. Abort |
| | | | | | 2. Initialize a key policy structure | 2. Multiple |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. Calling generator functions after abort should fail |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Set the key for a multipart symmetric encryption/decryption operation | |
| | | | | | 7. Abort a cipher operation | |
| | | | | | 8. Multiple abort cipher operation should return success | |
| Key derivation | test_c022 | psa_key_derivation | Set up a key derivation operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte data with SHA-256 |
| | | | | | 2. Initialize a key policy structure | 2. 32 byte data with SHA-512 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte data with MD-5 |
| | | | | | 4. Import the key data into the key slot | 4. Salt and label provided as input |
| | | | | | 5. Set up a key derivation operation | |
| | | | | | 6. Retrieve the current capacity of a generator | |
| | | | | | 7. Make sure that the capacity is same as input capacity | |
| | | | | PSA_INVALID_ARGUMENT | Calling this function with invalid argument should return this error | 1. Invalid algorithm 2. Unsupported generator capacity |
| | | | | | | 3. Unsupported key type |
| | | | | PSA_ERROR_INVALID_HANDLE | Calling this functoin wih incorrect key handle | 1. Invalid key handle </br>2. Zero as key slot |
| | | | | PSA_ERROR_EMPTY_SLOT | Calling this function with empty key slot should return this error | Empty key slot |
| Key policies | test_c023 | psa_key_policy_get_usage | Retrieve the usage field of a policy structure | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. Encrypt |
| | | | | | 2. Initialize a key policy structure | 2. Decrypt |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. Export |
| | | | | | 4. Retrieve the usage field of a policy structure | 4. Sign |
| | | | | | 5. Check that usage is same as input | 5. Verify |
| | | | | | | 6. Derive |
| AEAD | test_c024 | psa_aead_encrypt | Process an authenticated encryption operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. CCM - 16B AES - Nounce and additional data |
| | | | | | 2. Initialize a key policy structure | 2. GCM - 16B AES - NULL Nounce & addi data |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. GCM -16B AES - 12B Nounce & 12B addi data |
| | | | | | 4. Set the usage policy on a key slot | 4. CCM - 16B AES - 13B Nounce & 8B addi data |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Call aead encrypt | |
| | | | | | 7. Check if the status is expected | |
| | | | | | 8. Check if the cipher text is expected length | |
| | | | | PSA_ERROR_NOT_SUPPORTED | | 1. DES key |
| | | | | | | 2. Unsupported algorithm |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Zero as key slot |
| | | | | | | 2. Invalid key slot |
| | | | | PSA_ERROR_NOT_PERMITTED | | 1. Small output buffer size |
| | | | | | | 2. Invalid key usage |
| | test_c025 | psa_aead_decrypt | Process an authenticated decryption operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. CCM - 16B AES - Nounce and additional data |
| | | | | | 2. Initialize a key policy structure | 2. GCM - 16B AES - NULL Nounce & addi data |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. GCM -16B AES - 12B Nounce & 12B addi data |
| | | | | | 4. Set the usage policy on a key slot | 4. CCM - 16B AES - 13B Nounce & 8B addi data |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Call aead decrypt | |
| | | | | | 7. Check if the status is expected | |
| | | | | | 8. Check if the plain text is expected length | |
| | | | | PSA_ERROR_NOT_SUPPORTED | | 1. DES key |
| | | | | | | 2. Unsupported algorithm |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Zero as key slot |
| | | | | | | 2. Invalid key slot |
| | | | | PSA_ERROR_NOT_PERMITTED | | 1. Small output buffer size |
| | | | | | | 2. Invalid key usage |
| Message Authentication Codes | test_c026 | psa_mac_sign_setup | Start a multipart MAC calculation operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 64 Byte HMAC |
| | | | | | 2. Initialize a key policy structure | 2. 16 Byte AES - CMAC |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Start a multipart MAC calculation operation | |
| | | | | PSA_ERROR_NOT_SUPPORTED | | 1. 16 Byte AES - GMAC |
| | | | | | | 2. Incompatible HMAC for CMAC |
| | | | | | | 3. Bad algorithm (unknown MAC algorithm)<br /< |
| | | | | PSA_ERROR_NOT_PERMITTED | | Invalid usage |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Invalid key type |
| | | | | | | 2. Truncated MAC too large |
| | | | | | | 3 |
| | test_c027 | psa_mac_update | Add a message fragment to a multipart MAC operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1.64 Byte HMAC SHA256 |
| | | | | | 2. Initialize a key policy structure | 2. 16 Byte AES - CMAC |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte HMAC SHA512 |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Start a multipart MAC calculation operation | |
| | | | | | 7. Add a message fragment to a multipart MAC operation | |
| | | | | | 8. Check for the expected status | |
| | | | | | 9. If success, Finish the calculation of the MAC of a message | |
| | | | | | 10. Add a message fragment to the same multipart MAC operation should fail | |
| | | | | PSA_ERROR_BAD_STATE | | 1. Completed operation as input |
| | | | | | | 2. Uninitialized operation as input |
| | test_c028 | psa_mac_sign_finish | Finish the calculation of the MAC of a message | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. HMAC SHA 224 |
| | | | | | 2. Initialize a key policy structure | 2. HMAC SHA 256 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. HMAC SHA 512 |
| | | | | | 4. Set the usage policy on a key slot | 4. HMAC SHA 224 (truncated to 8 Byte) |
| | | | | | 5. Import the key data into the key slot | 5. CMAC AES 128 |
| | | | | | 6. Start a multipart MAC calculation operation | |
| | | | | | 7. Add a message fragment to a multipart MAC operation | |
| | | | | | 8. Finish the calculation of the MAC of a message | |
| | | | | | 9. Check for the expected status | |
| | | | | | 10. If success, Check if the MAC length matches with the expected length | |
| | | | | | 11. Check if the MAC data matches with the expected data | |
| | | | | | 12. Finish the calculation of the MAC of a message using same operation should return error | |
| | | | | PSA_ERROR_BUFFER_TOO_SMALL | | Small size buffer |
| | | | | PSA_ERROR_BAD_STATE | | Invalid operation as input |
| | test_c029 | psa_mac_verify_setup | | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 64 Byte HMAC |
| | | | | | 2. Initialize a key policy structure | 2. 16 Byte AES - CMAC |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Start a multipart MAC verification operation | |
| | | | | | 7. Check for the expected status | |
| | | | | PSA_ERROR_NOT_SUPPORTED | | 1. 16 Byte AES - GMAC |
| | | | | | | 2. Incompatible HMAC for CMAC |
| | | | | | | 3. Bad algorithm (unknown MAC algorithm)<br /< |
| | | | | PSA_ERROR_NOT_PERMITTED | | Invalid usage |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty slot as input |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Invalid key type |
| | | | | | | 2. Truncated MAC too large |
| | test_c030 | psa_mac_verify_finish | Finish the calculation of the MAC of a message and compare it with an expected value | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. HMAC SHA 224 |
| | | | | | 2. Initialize a key policy structure | 2. HMAC SHA 256 |
| | | | | | 3.Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. HMAC SHA 512 |
| | | | | | 4. Set the usage policy on a key slot | 4. HMAC SHA 224 (truncated to 8 Byte) |
| | | | | | 5. Import the key data into the key slot | 5. CMAC AES 128 |
| | | | | | 6. Start a multipart MAC calculation operation | |
| | | | | | 7. Add a message fragment to a multipart MAC operation | |
| | | | | | 8. Finish the calculation of the MAC of a message | |
| | | | | | 9. Check for the expected status | |
| | | | | | 10. Finish the calculation of the MAC of a message using same operation should return error | |
| | | | | PSA_ERROR_INVALID_SIGNATURE | | 1. Small size buffer |
| | | | | | | 2. Incorrect expected hash |
| | | | | PSA_ERROR_BAD_STATE | | Invalid operation as input |
| | test_c031 | psa_mac_abort | Abort a MAC operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. HMAC SHA 224 |
| | | | | | 2. Initialize a key policy structure | 2. HMAC SHA 256 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. HMAC SHA 512 |
| | | | | | 4. Set the usage policy on a key slot | 4. CMAC AES 128 |
| | | | | | 5. Import the key data into the key slot | 5. HMAC truncated |
| | | | | | 6. Start a multipart MAC calculation operation | 6. Multiple abort |
| | | | | | 7. Abort the MAC operation | 7. psa_mac_finish after psa_mac_abort should return failure |
| Symmetric Ciphers | test_c032 | psa_cipher_encrypt_setup | Set the key for a multipart symmetric encryption operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. DES 64 bit key |
| | | | | | 5. Import the key data into the key slot | 5. Triple DES 2-Key |
| | | | | | 6. Set the key for a multipart symmetric encryption operation | 6. Triple DES 3-Key |
| | | | | PSA_ERROR_NOT_SUPPORTED | | 1. 16 Byte raw data |
| | | | | | | 2. Unknown cipher algorithm |
| | | | | | | 3. Incompatible key ARC4 |
| | | | | PSA_ERROR_INVALID_ARGUMENT | | 1. Not a cipher algorithm |
| | | | | | | 2. Invalid key slot |
| | | | | | | 3. Zero as key slot |
| | | | | | | 4. RSA public key |
| | | | | | | 5. RSA keypair |
| | | | | | | 6. EC Public key |
| | | | | | | 7. EC keypair |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | | | | PSA_ERROR_NOT_PERMITTED | | Incorrect usage |
| | test_c033 | psa_cipher_decrypt_setup | Set the key for a multipart symmetric decryption operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. HMAC SHA 224 |
| | | | | | 2. Initialize a key policy structure | 2. HMAC SHA 256 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. HMAC SHA 512 |
| | | | | | 4. Set the usage policy on a key slot | 4. CMAC AES 128 |
| | | | | | 5. Import the key data into the key slot | 5. HMAC truncated |
| | | | | | 6. Set the key for a multipart symmetric decryption operation | 6. Multiple abort |
| | | | | | | 7. psa_mac_finish after psa_mac_abort should return failure |
| | | | | PSA_ERROR_NOT_SUPPORTED | | 1. 16 Byte raw data |
| | | | | | | 2. Unknown cipher algorithm |
| | | | | | | 3. Incompatible key ARC4 |
| | | | | PSA_ERROR_INVALID_ARGUMENT | | 1. Not a cipher algorithm |
| | | | | | | 2. Invalid key slot |
| | | | | | | 3. Zero as key slot |
| | | | | | | 4. RSA public key |
| | | | | | | 5. RSA keypair |
| | | | | | | 6. EC Public key |
| | | | | | | 7. EC keypair |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | | | | PSA_ERROR_NOT_PERMITTED | | Invalid usage |
| | test_c034 | psa_cipher_generate_iv | Generate an IV for a symmetric encryption operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. DES 64 bit key |
| | | | | | 5. Import the key data into the key slot | 5. Triple DES 2-Key |
| | | | | | 6. Set the key for a multipart symmetric encryption operation | 6. Triple DES 3-Key |
| | | | | | 7. Generate an IV for a symmetric encryption operation | 7. AES - large iv buffer |
| | | | | | 8. Check that if generated iv length match the expected length | 8. DES - large iv buffer |
| | | | | | 9. Check that if generated iv are zero | |
| | | | | | 10. Generating an IV for a symmetric encryption operation using the same operator should fail | |
| | | | | PSA_ERROR_BUFFER_TOO_SMALL | | 1. AES - small iv buffer |
| | | | | | | 2. DES - small iv buffer |
| | test_c035 | psa_cipher_set_iv | Set the IV for a symmetric encryption or decryption operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. 16 Byte AES |
| | | | | | 2. Initialize a key policy structure | 2. 24 Byte AES |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. 32 Byte AES |
| | | | | | 4. Set the usage policy on a key slot | 4. DES 64 bit key |
| | | | | | 5. Import the key data into the key slot | 5. Triple DES 2-Key |
| | | | | | 6. Set the key for a multipart symmetric encryption/decryption operation | 6. Triple DES 3-Key |
| | | | | | 7. Set an IV for a symmetric encryption/decryption operation | |
| | | | | | 8. Check that if generated iv length match the expected length | |
| | | | | | 9. Check that if generated iv are zero | |
| | | | | | 10. Setting an IV for a symmetric encryption/decryption operation using the same operator should fail | |
| | | | | PSA_ERROR_INVALID_ARGUMENT | | 1. AES - small iv buffer 2. DES - small iv buffer 3. AES - large iv buffer 4. DES - large iv buffer |
| | test_c036 | psa_cipher_update | Encrypt or decrypt a message fragment in an active cipher operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. AES CBC_NO_PADDING |
| | | | | | 2. Initialize a key policy structure | 2. AES CBC_NO_PADDING (Short input) |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. AES CBC_PKCS7 |
| | | | | | 4. Set the usage policy on a key slot | 4. AES CBC_PKCS7 (Short input) |
| | | | | | 5. Import the key data into the key slot | 5. AES CTR |
| | | | | | 6. Set the key for a multipart symmetric encryption operation | 6. DES CBC (nopad) |
| | | | | | 7. Set an IV for a symmetric encryption operation | 7. 2-key 3DE -CBC (nopad) |
| | | | | | 8. Encrypt or decrypt a message fragment in an active cipher operation | 8. 3-key 3DE -CBC (nopad) |
| | | | | | 9. Check if the output length matches the expected length | |
| | | | | | 10. Check if the output data matches the expected data | |
| | | | | | 11. Encrypt or decrypt a message fragment in an invalid cipher operation should fail | |
| | | | | PSA_ERROR_BAD_STATE | Encrypt or decrypt a message fragment in an invalid cipher operation should fail | Invalid operation as input |
| | test_c037 | psa_cipher_finish | Finish encrypting or decrypting a message in a cipher operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. AES CBC_NO_PADDING |
| | | | | | 2. Initialize a key policy structure | 2. AES CBC_NO_PADDING (Short input) |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. AES CBC_PKCS7 |
| | | | | | 4. Set the usage policy on a key slot | 4. AES CBC_PKCS7 (Short input) |
| | | | | | 5. Import the key data into the key slot | 5. AES CTR |
| | | | | | 6. Set the key for a multipart symmetric encryption operation | 6. DES CBC (nopad) |
| | | | | | 7. Set an IV for a symmetric encryption operation | 7. 2-key 3DE -CBC (nopad) |
| | | | | | 8. Encrypt or decrypt a message fragment in an active cipher operation | 8. 3-key 3DE -CBC (nopad) |
| | | | | | 9. Finish encrypting or decrypting a message in a cipher operation | |
| | | | | | 10. Check if the output length matches the expected length | |
| | | | | | 11. Check if the output data matches the expected data | |
| | | | | | 12. Finish encrypting or decrypting a message using an invalid operation should fail | |
| | | | | PSA_ERROR_BAD_STATE | Encrypt or decrypt a message fragment in an invalid cipher operation should fail | Invalid operation as input |
| | test_c038 | psa_cipher_abort | Abort a cipher operation | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. Encrypt - AES CBC_NO_PADDING |
| | | | | | 2. Initialize a key policy structure | 2. Encrypt - AES CBC_PKCS7 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. Encrypt - AES CTR |
| | | | | | 4. Set the usage policy on a key slot | 4. Encrypt - DES CBC (nopad) |
| | | | | | 5. Import the key data into the key slot | 5. Encrypt - 2-key 3DE -CBC (nopad) |
| | | | | | 6. Set the key for a multipart symmetric encryption/decryption operation | 6. Encrypt - 3-key 3DE -CBC (nopad) |
| | | | | | 7. Abort a cipher operation | 7. Decrypt - AES CBC_NO_PADDING |
| | | | | | 8. Multiple abort cipher operation should return success | 8. Decrypt - AES CBC_PKCS7 |
| | | | | | | 9. Decrypt - AES CTR |
| | | | | | | 10. Decrypt - DES CBC (nopad) |
| | | | | | | 11. Decrypt - 2-key 3DE -CBC (nopad) |
| | | | | | | 12. Decrypt - 3-key 3DE -CBC (nopad) |
| | | | | | | 13. psa_cipher_update after psa_cipher_abort should fail |
| Asymmetric Cryptography | test_c039 | psa_asymmetric_encrypt | Encrypt a short message with a public key | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. RSA PKCS1V15 |
| | | | | | 2. Initialize a key policy structure | 2. RSA OAEP SHA256 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. RSA OAEP SHA256 with label |
| | | | | | 4. Set the usage policy on a key slot | 4. RSA KEYPAIR PKCS1V15 |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Encrypt a short message with a public key | |
| | | | | | 7. Check if the output length matches with the expected output length | |
| | | | | | 8. Decrypt the cipher text | |
| | | | | | 9. Check if the output length matches with the input length | |
| | | | | | 10. Check if the output matches with the given input data | |
| | | | | PSA_ERROR_INVALID_ARGUMENT | | 1. Small output buffer |
| | | | | | | 2. Invalid algorithm |
| | | | | | | 3. Invalid key type |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Invalid key slot </br>2. Zero key slot |
| | | | | PSA_ERROR_NOT_PERMITTED | | Invalid usage |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | test_c040 | psa_asymmetric_decrypt | Decrypt a short message with a private key | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. RSA KEYPAIR PKCS1V15 |
| | | | | | 2. Initialize a key policy structure | 2. RSA KEYPAIR OAEP SHA256 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. RSA KEYPAIR OAEP SHA256 with label |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Decrypt a short message with a private key | |
| | | | | | 7. Check if the output length matches with the expected length | |
| | | | | | 8. Check if the output matches with the expected data | |
| | | | | PSA_ERROR_INVALID_ARGUMENT | | 1. Invalid key type (RSA public key) |
| | | | | | | 2. Invalid algorithm |
| | | | | | | 3. Invalid key type (AES Key) |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | | | | PSA_ERROR_NOT_PERMITTED | | Invalid usage |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Invalid key slot </br>2. Zero key slot |
| | | | | PSA_ERROR_BUFFER_TOO_SMALL | | Small output buffer |
| | test_c041 | psa_asymmetric_sign | Sign a hash or short message with a private key | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. RSA KEYPAIR PKCS1V15 RAW |
| | | | | | 2. Initialize a key policy structure | 2. RSA KEYPAIR PKCS1V15 SHA-256 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. ECDSA KEYPAIR SECP256R1 SHA-256 |
| | | | | | 4. Set the usage policy on a key slot | |
| | | | | | 5. Import the key data into the key slot | |
| | | | | | 6. Sign a hash or short message with a private key | |
| | | | | | 7. Check if the output length matches with the expected length | |
| | | | | | 8. Check if the output matches with the expected data | |
| | | | | PSA_ERROR_INVALID_ARGUMENT | | 1. Invalid key type (RSA public key) |
| | | | | | | 2. Invalid algorithm |
| | | | | | | 3. Invalid key type (AES Key) |
| | | | | | | 4. Wrong hash size |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Invalid key slot </br>2. Zero key slot |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | | | | PSA_ERROR_NOT_PERMITTED | | Invalid usage |
| | | | | PSA_ERROR_BUFFER_TOO_SMALL | | Small output buffer |
| | test_c042 | psa_asymmetric_verify | Verify the signature a hash or short message using a public key | PSA_SUCCESS | 1. Initialize the PSA crypto library | 1. RSA KEYPAIR PKCS1V15 RAW |
| | | | | | 2. Initialize a key policy structure | 2. RSA KEYPAIR PKCS1V15 SHA-256 |
| | | | | | 3. Allocate a key slot for a transient key and set the standard fields of a policy structure | 3. ECDSA KEYPAIR SECP256R1 SHA-256 |
| | | | | | 4. Set the key data based on key type | 4. RSA public key |
| | | | | | 5. Set the usage policy on a key slot | 5. EC public key |
| | | | | | 6. Import the key data into the key slot | |
| | | | | | 7. Verify the signature a hash or short message using a public key | |
| | | | | PSA_ERROR_INVALID_ARGUMENT | | 1. Invalid algorithm |
| | | | | | | 2. Wrong hash size |
| | | | | PSA_ERROR_INVALID_HANDLE | | 1. Invalid key slot </br>2. Zero key slot |
| | | | | PSA_ERROR_INVALID_SIGNATURE | | Wrong signature size |
| | | | | | | Wrong signature |
| | | | | PSA_ERROR_EMPTY_SLOT | | Empty key slot |
| | | | | PSA_ERROR_NOT_PERMITTED | | Invalid usage |
| | | | | PSA_ERROR_NOT_SUPPORTED | | Invalid key type (AES Key) |
| | | | | PSA_ERROR_BUFFER_TOO_SMALL | | Small output buffer |
## License
Arm PSA test suite is distributed under Apache v2.0 License.
--------------
*Copyright (c) 2018-2019, Arm Limited and Contributors. All rights reserved.*

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c001(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c001, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,73 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c001.h"
client_test_t test_c001_crypto_list[] = {
NULL,
psa_generate_random_without_init_test,
psa_crypto_init_test,
multiple_psa_crypto_init_test,
NULL,
};
int32_t psa_generate_random_without_init_test(security_t caller)
{
uint8_t output[GENERATE_SIZE];
int32_t status;
val->print(PRINT_TEST, "[Check 1] Test calling crypto functions before psa_crypto_init\n", 0);
/* Generate random bytes */
status = val->crypto_function(VAL_CRYPTO_GENERATE_RANDOM, output, GENERATE_SIZE);
if (status == PSA_SUCCESS)
return RESULT_SKIP(VAL_STATUS_INIT_ALREADY_DONE);
else
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(1));
return VAL_STATUS_SUCCESS;
}
int32_t psa_crypto_init_test(security_t caller)
{
int32_t status;
val->print(PRINT_TEST, "[Check 2] Test psa_crypto_init\n", 0);
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
return VAL_STATUS_SUCCESS;
}
int32_t multiple_psa_crypto_init_test(security_t caller)
{
int32_t i, status;
val->print(PRINT_TEST, "[Check 3] Test multiple psa_crypto_init \n", 0);
for (i = 0; i < 5; i++)
{
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,34 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C001_CLIENT_TESTS_H_
#define _TEST_C001_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c001)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
#define GENERATE_SIZE 32
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c001_crypto_list[];
int32_t psa_crypto_init_test(security_t caller);
int32_t multiple_psa_crypto_init_test(security_t caller);
int32_t psa_generate_random_without_init_test(security_t caller);
#endif /* _TEST_C001_CLIENT_TESTS_H_ */

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c001.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 1)
#define TEST_DESC "Testing psa_crypto_init API: Basic\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_LOW_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_client_tests_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c001_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c002(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c002, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,217 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c002.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c002_crypto_list[] = {
NULL,
psa_import_key_test,
psa_import_key_negative_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_import_key_test(security_t caller)
{
uint32_t length, i;
uint8_t data[BUFFER_SIZE];
const uint8_t *key_data;
psa_key_policy_t policy;
psa_key_type_t key_type;
size_t bits;
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check1[i].key_data;
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check1[i].key_handle,
&key_type, &bits);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
TEST_ASSERT_EQUAL(key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(7));
TEST_ASSERT_EQUAL(bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(8));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, check1[i].key_handle, data,
BUFFER_SIZE, &length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(10));
if (PSA_KEY_TYPE_IS_UNSTRUCTURED(check1[i].key_type))
{
TEST_ASSERT_MEMCMP(data, check1[i].key_data, length, TEST_CHECKPOINT_NUM(11));
}
else if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type) || PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
TEST_ASSERT_MEMCMP(key_data, data, length, TEST_CHECKPOINT_NUM(12));
}
else
{
return VAL_STATUS_INVALID;
}
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_import_key_negative_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
int32_t i, status;
psa_key_policy_t policy;
psa_key_handle_t invalid_key_handle;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] Test psa_import_key with already occupied key slot\n",
g_test_count++);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
memset(&invalid_key_handle, 0xDEADDEAD, sizeof(invalid_key_handle));
/* Set the usage policy on a key slot */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check2[i].usage,
check2[i].key_alg);
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].key_data, check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the occupied key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].key_data, check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_OCCUPIED_SLOT, TEST_CHECKPOINT_NUM(5));
val->print(PRINT_TEST, "[Check %d] Test psa_import_key with zero as key handle\n",
g_test_count++);
/* Import the key data with zero as key handle */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, 0, check2[i].key_type,
check2[i].key_data, check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(6));
val->print(PRINT_TEST, "[Check %d] Test psa_import_key with destroyed handle\n",
g_test_count++);
/* Destroy the handle */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
/* Import the key data with destroyed handle */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].key_data, check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(8));
val->print(PRINT_TEST, "[Check %d] Test psa_import_key with unallocated key handle\n",
g_test_count++);
/* Import the key data with unallocated key handle */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, invalid_key_handle, check2[i].key_type,
check2[i].key_data, check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(6));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C002_CLIENT_TESTS_H_
#define _TEST_C002_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c002)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c002_crypto_list[];
int32_t psa_import_key_test(security_t caller);
int32_t psa_import_key_negative_test(security_t caller);
#endif /* _TEST_C002_CLIENT_TESTS_H_ */

View File

@ -1,299 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[34];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
static const uint8_t rsa_384_keypair[1];
static const uint8_t rsa_384_keydata[1];
static const uint8_t rsa_256_keypair[] = {
0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
0xBA, 0xE0, 0x21, 0xE5, 0x72, 0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA,
0xAC, 0x1B, 0x53, 0xB9, 0x5F, 0x3F, 0xD7, 0x19, 0x0D, 0x25, 0x4F, 0xE1, 0x63,
0x63, 0x51, 0x8B, 0x0B, 0x64, 0x3F, 0xAD, 0x43, 0xB8, 0xA5, 0x1C, 0x5C, 0x34,
0xB3, 0xAE, 0x00, 0xA0, 0x63, 0xC5, 0xF6, 0x7F, 0x0B, 0x59, 0x68, 0x78, 0x73,
0xA6, 0x8C, 0x18, 0xA9, 0x02, 0x6D, 0xAF, 0xC3, 0x19, 0x01, 0x2E, 0xB8, 0x10,
0xE3, 0xC6, 0xCC, 0x40, 0xB4, 0x69, 0xA3, 0x46, 0x33, 0x69, 0x87, 0x6E, 0xC4,
0xBB, 0x17, 0xA6, 0xF3, 0xE8, 0xDD, 0xAD, 0x73, 0xBC, 0x7B, 0x2F, 0x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10, 0x1B, 0xAD, 0x44, 0x41, 0xE0, 0xFE, 0x79, 0xA0,
0x63, 0x93, 0x8A, 0xB1, 0x5D, 0xE9, 0xB0, 0xEE, 0x6F, 0x02, 0x03, 0x01, 0x00, 0x01};
static const uint8_t ec_keydata[] = {
0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
static const uint8_t ec_keypair[] = {
0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_import_key 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_import_key 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_import_key 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_import_key 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 270, PSA_SUCCESS
},
{"Test psa_import_key with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
{0},
1193, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 1193, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_import_key with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_import_key with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
DES3_2KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_import_key with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
DES3_3KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
{"Test psa_import_key with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0},
65, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
256, 65, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
{"Test psa_import_key with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
{0},
28, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
224, 28, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES
{"Test psa_import_key with key data greater than the algorithm size\n", 11, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_34B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_34B_KEY_SIZE), AES_34B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
{"Test psa_import_key with incorrect key data size\n", 12, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90},
AES_18B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_18B_KEY_SIZE), AES_18B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
{"Test psa_import_key with incorrect key type\n", 13, PSA_KEY_TYPE_VENDOR_FLAG,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_ERROR_NOT_SUPPORTED,
},
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_import_key negative cases\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_OCCUPIED_SLOT
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c002.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 2)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c002_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c003(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c003, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,220 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c003.h"
#include "test_data.h"
client_test_t test_c003_crypto_list[] = {
NULL,
psa_export_key_test,
psa_export_key_negative_test,
NULL,
};
static int g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t psa_export_key_test(security_t caller)
{
uint32_t length, i;
const uint8_t *key_data;
psa_key_policy_t policy;
psa_key_type_t key_type;
size_t bits;
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check1[i].key_data;
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check1[i].key_handle,
&key_type, &bits);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
TEST_ASSERT_EQUAL(key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(7));
TEST_ASSERT_EQUAL(bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(8));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, check1[i].key_handle, data,
check1[i].buffer_size, &length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(9));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(10));
/* Check if original key data matches with the exported data */
if (PSA_KEY_TYPE_IS_UNSTRUCTURED(check1[i].key_type))
{
TEST_ASSERT_MEMCMP(check1[i].key_data, data, length, TEST_CHECKPOINT_NUM(11));
}
else if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type) || PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
TEST_ASSERT_MEMCMP(key_data, data, length, TEST_CHECKPOINT_NUM(12));
}
else
{
return VAL_STATUS_INVALID;
}
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_export_key_negative_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
uint32_t i, length;
int32_t status;
psa_key_policy_t policy;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
val->print(PRINT_TEST, "[Check %d] Test psa_export_key with unallocated key handle\n",
g_test_count++);
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, check2[i].key_handle, data,
check2[i].key_length, &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
val->print(PRINT_TEST, "[Check %d] Test psa_export_key with empty key handle\n",
g_test_count++);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, check2[i].key_handle, data,
check2[i].key_length, &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_EMPTY_SLOT, TEST_CHECKPOINT_NUM(5));
val->print(PRINT_TEST, "[Check %d] Test psa_export_key with zero as key handle\n",
g_test_count++);
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, 0, data,
check2[i].key_length, &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(6));
val->print(PRINT_TEST, "[Check %d] Test psa_export_key with destroyed key handle\n",
g_test_count++);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check2[i].usage,
check2[i].key_alg);
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].key_data, check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
/* Destroy the key handle */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, check2[i].key_handle, data,
check2[i].key_length, &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(10));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C003_CLIENT_TESTS_H_
#define _TEST_C003_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c003)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c003_crypto_list[];
int32_t psa_export_key_test(security_t caller);
int32_t psa_export_key_negative_test(security_t caller);
#endif /* _TEST_C003_CLIENT_TESTS_H_ */

View File

@ -1,289 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[34];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
size_t buffer_size;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
static const uint8_t rsa_384_keypair[1];
static const uint8_t rsa_384_keydata[1];
static const uint8_t rsa_256_keypair[] = {
0x30, 0x82, 0x04,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0x02, 0x03, 0x01, 0x00, 0x01};
static const uint8_t ec_keydata[] = {
0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
static const uint8_t ec_keypair[] = {
0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_export_key 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_export_key 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_export_key 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_export_key 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
2048, 270, PSA_SUCCESS
},
{"Test psa_export_key with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
{0},
1193, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
2048, 1193, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_export_key with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_export_key with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
DES3_2KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_export_key with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
DES3_3KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
{"Test psa_export_key with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0},
65, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, BUFFER_SIZE,
256, 65, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
{"Test psa_export_key with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
{0},
28, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, BUFFER_SIZE,
224, 28, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_export_key with key policy verify\n", 11, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_VERIFY, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_NOT_PERMITTED
},
{"Test psa_export_key with less buffer size\n", 12, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, 14,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_BUFFER_TOO_SMALL
},
#endif
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_export_key negative case\n", 13, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c003.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 3)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c003_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c004(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c004, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,258 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c004.h"
#include "test_data.h"
client_test_t test_c004_crypto_list[] = {
NULL,
test_psa_export_public_key,
test_psa_export_public_key_handle,
NULL,
};
static int g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t test_psa_export_public_key(security_t caller)
{
uint32_t length, i;
const uint8_t *key_data;
psa_key_policy_t policy;
psa_key_type_t key_type;
size_t bits;
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check1[i].key_data;
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check1[i].key_handle,
&key_type, &bits);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
TEST_ASSERT_EQUAL(key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(7));
TEST_ASSERT_EQUAL(bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(8));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, check1[i].key_handle, data,
check1[i].buffer_size, &length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(9));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(10));
/* Check if original key data matches with the exported data */
if (PSA_KEY_TYPE_IS_UNSTRUCTURED(check1[i].key_type))
{
TEST_ASSERT_MEMCMP(check1[i].key_data, data, length, TEST_CHECKPOINT_NUM(11));
}
else if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type) || PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
key_data = expected_rsa_256_pubprv;
else if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = expected_ec_pubprv;
TEST_ASSERT_MEMCMP(key_data, data, length, TEST_CHECKPOINT_NUM(12));
}
else
{
return VAL_STATUS_INVALID;
}
}
return VAL_STATUS_SUCCESS;
}
int32_t test_psa_export_public_key_handle(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
uint32_t i, length;
int32_t status;
const uint8_t *key_data;
psa_key_policy_t policy;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] Test psa_export_key with unallocated key handle\n",
g_test_count++);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, check2[i].key_handle, data,
check2[i].key_length, &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
val->print(PRINT_TEST, "[Check %d] Test psa_export_key with empty key handle\n",
g_test_count++);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, check2[i].key_handle, data,
check2[i].key_length, &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_EMPTY_SLOT, TEST_CHECKPOINT_NUM(5));
val->print(PRINT_TEST, "[Check %d] Test psa_export_key with zero as key handle\n",
g_test_count++);
status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, 0, data,
check2[i].key_length, &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(6));
val->print(PRINT_TEST, "[Check %d] Test psa_export_key with destroyed key handle\n",
g_test_count++);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check2[i].usage,
check2[i].key_alg);
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
if (PSA_KEY_TYPE_IS_RSA(check2[i].key_type))
{
if (check2[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check2[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check2[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check2[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check2[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check2[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check2[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check2[i].key_data;
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check2[i].key_handle,
check2[i].key_type, key_data, check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
/* Destroy the key handle */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_PUBLIC_KEY, check2[i].key_handle, data,
check2[i].key_length, &length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(10));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C004_CLIENT_TESTS_H_
#define _TEST_C004_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c004)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c004_crypto_list[];
int32_t test_psa_export_public_key(security_t caller);
int32_t test_psa_export_public_key_handle(security_t caller);
#endif /* _TEST_C004_CLIENT_TESTS_H_ */

View File

@ -1,312 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[34];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
size_t buffer_size;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
static const uint8_t rsa_384_keypair[1];
static const uint8_t rsa_384_keydata[1];
static const uint8_t expected_rsa_256_pubprv[] = {
0x30, 0x82,
0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0, 0x95, 0x08, 0xE1, 0x57, 0x41,
0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27, 0x01, 0x65, 0xC6, 0x45, 0xAE,
0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F, 0x4E, 0xD6, 0xF6, 0x1C, 0x88,
0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE, 0x5C, 0x9C, 0x51, 0x75, 0xF7,
0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1, 0xBD, 0x7B, 0xC0, 0x2F, 0x7C,
0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B, 0xBA, 0xE0, 0x21, 0xE5, 0x72,
0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA, 0xAC, 0x1B, 0x53, 0xB9, 0x5F,
0x3F, 0xD7, 0x19, 0x0D, 0x25, 0x4F, 0xE1, 0x63, 0x63, 0x51, 0x8B, 0x0B, 0x64,
0x3F, 0xAD, 0x43, 0xB8, 0xA5, 0x1C, 0x5C, 0x34, 0xB3, 0xAE, 0x00, 0xA0, 0x63,
0xC5, 0xF6, 0x7F, 0x0B, 0x59, 0x68, 0x78, 0x73, 0xA6, 0x8C, 0x18, 0xA9, 0x02,
0x6D, 0xAF, 0xC3, 0x19, 0x01, 0x2E, 0xB8, 0x10, 0xE3, 0xC6, 0xCC, 0x40, 0xB4,
0x69, 0xA3, 0x46, 0x33, 0x69, 0x87, 0x6E, 0xC4, 0xBB, 0x17, 0xA6, 0xF3, 0xE8,
0xDD, 0xAD, 0x73, 0xBC, 0x7B, 0x2F, 0x21, 0xB5, 0xFD, 0x66, 0x51, 0x0C, 0xBD,
0x54, 0xB3, 0xE1, 0x6D, 0x5F, 0x1C, 0xBC, 0x23, 0x73, 0xD1, 0x09, 0x03, 0x89,
0x14, 0xD2, 0x10, 0xB9, 0x64, 0xC3, 0x2A, 0xD0, 0xA1, 0x96, 0x4A, 0xBC, 0xE1,
0xD4, 0x1A, 0x5B, 0xC7, 0xA0, 0xC0, 0xC1, 0x63, 0x78, 0x0F, 0x44, 0x37, 0x30,
0x32, 0x96, 0x80, 0x32, 0x23, 0x95, 0xA1, 0x77, 0xBA, 0x13, 0xD2, 0x97, 0x73,
0xE2, 0x5D, 0x25, 0xC9, 0x6A, 0x0D, 0xC3, 0x39, 0x60, 0xA4, 0xB4, 0xB0, 0x69,
0x42, 0x42, 0x09, 0xE9, 0xD8, 0x08, 0xBC, 0x33, 0x20, 0xB3, 0x58, 0x22, 0xA7,
0xAA, 0xEB, 0xC4, 0xE1, 0xE6, 0x61, 0x83, 0xC5, 0xD2, 0x96, 0xDF, 0xD9, 0xD0,
0x4F, 0xAD, 0xD7, 0x02, 0x03, 0x01, 0x00, 0x01};
static const uint8_t expected_ec_pubprv[] = {
0x04, 0x16, 0x93, 0xa2, 0x90, 0xf7, 0xf0, 0xb5, 0x71, 0xfe, 0x2b, 0x41, 0xd5,
0xd8, 0x4b, 0x01, 0x32, 0x76, 0x31, 0xf4, 0xa8, 0x60, 0xf9, 0x95, 0xfa, 0x33,
0x2c, 0x09, 0x7f, 0x54, 0x19, 0x2b, 0xb1, 0x0f, 0x00, 0x11, 0x3f, 0x2a, 0xff,
0xb1, 0x3c, 0x1a, 0x24, 0xce, 0x44, 0x91, 0x45, 0x71, 0xa9, 0x54, 0x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, 0xFE, 0x79, 0xA0,
0x63, 0x93, 0x8A, 0xB1, 0x5D, 0xE9, 0xB0, 0xEE, 0x6F, 0x02, 0x03, 0x01, 0x00, 0x01};
static const uint8_t ec_keydata[] = {
0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
static const uint8_t ec_keypair[] = {
0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_export_public_key 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_export_public_key 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_export_public_key 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_export_public_key 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
2048, 270, PSA_SUCCESS
},
{"Test psa_export_public_key with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
{0},
1193, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
2048, 270, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_export_public_key with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_export_public_key with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
DES3_2KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_export_public_key with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
DES3_3KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, BUFFER_SIZE,
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
{"Test psa_export_public_key with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0},
65, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, BUFFER_SIZE,
256, 65, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
{"Test psa_export_public_key with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
{0},
28, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION, BUFFER_SIZE,
224, 57, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA
{"Test psa_export_public_key with less buffer size\n", 12, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, 200,
2048, 270, PSA_ERROR_BUFFER_TOO_SMALL
},
#endif
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA
{"Test psa_export_public_key negative case\n", 13, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW, BUFFER_SIZE,
2048, 270, PSA_SUCCESS
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c004.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 4)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c004_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c005(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c005, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,182 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c005.h"
#include "test_data.h"
client_test_t test_c005_crypto_list[] = {
NULL,
psa_destroy_key_test,
psa_destroy_invalid_key_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_destroy_key_test(security_t caller)
{
uint32_t i;
const uint8_t *key_data;
psa_key_policy_t policy;
psa_key_type_t key_type;
size_t bits;
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
key_type = 0;
bits = 0;
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check1[i].key_data;
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get basic metadata about a key */
TEST_ASSERT_EQUAL(val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check1[i].key_handle,
&key_type, &bits),
PSA_SUCCESS,
TEST_CHECKPOINT_NUM(6));
TEST_ASSERT_EQUAL(key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(7));
TEST_ASSERT_EQUAL(bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(8));
/* Destroy a key and restore the slot to its default state */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check1[i].key_handle);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(9));
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check1[i].key_handle,
&key_type, &bits);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(10));
/* Check that if the key metadata are destroyed */
TEST_ASSERT_NOT_EQUAL(key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(11));
TEST_ASSERT_NOT_EQUAL(bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(12));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_destroy_invalid_key_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
int32_t i, status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] Test psa_destroy_key with unallocated key handle\n",
g_test_count++);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Destroy a key and restore the slot to its default state */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
val->print(PRINT_TEST, "[Check %d] Test psa_destroy_key with zero as key handle\n",
g_test_count++);
/* Destroy a key and restore the slot to its default state */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, 0);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
val->print(PRINT_TEST, "[Check %d] Test psa_destroy_key with empty key handle\n",
g_test_count++);
/* Destroy a key and restore the slot to its default state */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Destroy a key and restore the slot to its default state */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(7));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C005_CLIENT_TESTS_H_
#define _TEST_C005_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c005)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c005_crypto_list[];
int32_t psa_destroy_key_test(security_t caller);
int32_t psa_destroy_invalid_key_test(security_t caller);
#endif /* _TEST_C005_CLIENT_TESTS_H_ */

View File

@ -1,274 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[34];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
static const uint8_t rsa_384_keypair[1];
static const uint8_t rsa_384_keydata[1];
static const uint8_t rsa_256_keypair[] = {
0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0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 0xfc, 0x58, 0x3f, 0xed, 0x8b,
0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
static const uint8_t ec_keypair[] = {
0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_destroy_key 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_destroy_key 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_destroy_key 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_destroy_key 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 270, PSA_SUCCESS
},
{"Test psa_destroy_key with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
{0},
1193, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 1193, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_destroy_key with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_destroy_key with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
DES3_2KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_destroy_key with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
DES3_3KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
{"Test psa_destroy_key with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0},
65, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
256, 65, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
{"Test psa_destroy_key with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
{0},
28, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
224, 28, PSA_SUCCESS
},
#endif
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_destroy_key negative case\n", 11, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c005.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 5)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c005_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c006(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c006, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,178 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c006.h"
#include "test_data.h"
client_test_t test_c006_crypto_list[] = {
NULL,
psa_get_key_information_test,
psa_get_key_information_invalid_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_get_key_information_test(security_t caller)
{
int32_t i, status;
const uint8_t *key_data;
psa_key_policy_t policy;
psa_key_type_t key_type;
size_t bits;
int num_checks = sizeof(check1)/sizeof(check1[0]);
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check1[i].key_data;
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check1[i].key_handle,
&key_type, &bits);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(6));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
TEST_ASSERT_EQUAL(key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(7));
TEST_ASSERT_EQUAL(bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(8));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_get_key_information_invalid_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
int32_t i, status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_information with unallocated"
" key handle\n", g_test_count++);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check2[i].key_handle,
&check2[i].key_type, &check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_information with zero as"
" key handle\n", g_test_count++);
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, 0,
&check2[i].key_type, &check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_information with empty key handle\n",
g_test_count++);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check2[i].key_handle,
&check2[i].key_type, &check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_EMPTY_SLOT, TEST_CHECKPOINT_NUM(6));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_information with destroyed"
" key handle\n", g_test_count++);
/* Destroy a key and restore the slot to its default state */
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check2[i].key_handle,
&check2[i].key_type, &check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(8));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C006_CLIENT_TESTS_H_
#define _TEST_C006_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c006)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c006_crypto_list[];
int32_t psa_get_key_information_test(security_t caller);
int32_t psa_get_key_information_invalid_test(security_t caller);
#endif /* _TEST_C006_CLIENT_TESTS_H_ */

View File

@ -1,273 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[34];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
static const uint8_t rsa_384_keypair[1];
static const uint8_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, 0x93, 0x8A, 0xB1, 0x5D, 0xE9, 0xB0, 0xEE, 0x6F, 0x02, 0x03, 0x01, 0x00, 0x01};
static const uint8_t ec_keydata[] = {
0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
static const uint8_t ec_keypair[] = {
0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_get_key_information 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_get_key_information 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_get_key_information 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_get_key_information 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 270, PSA_SUCCESS
},
{"Test psa_get_key_information with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
{0},
1193, PSA_KEY_USAGE_EXPORT, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 1193, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_get_key_information with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_get_key_information with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
DES3_2KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_get_key_information with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
DES3_3KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
{"Test psa_get_key_information with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0},
65, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
256, 65, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
{"Test psa_get_key_information with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
{0},
28, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
224, 28, PSA_SUCCESS
},
#endif
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_get_key_information negative cases\n", 11, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c006.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 6)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c006_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c007(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c007, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,188 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c007.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c007_crypto_list[] = {
NULL,
psa_set_key_policy_test,
psa_set_key_policy_negative_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_set_key_policy_test(security_t caller)
{
const uint8_t *key_data;
psa_key_policy_t policy, expected_policy;
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check1[i].key_data;
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get the usage policy for a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_POLICY, check1[i].key_handle,
&expected_policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Check if the usage is same as programmed */
TEST_ASSERT_EQUAL(expected_policy.usage, check1[i].usage, TEST_CHECKPOINT_NUM(7));
/* Check if the algorithm is same as programmed */
TEST_ASSERT_EQUAL(expected_policy.alg, check1[i].key_alg, TEST_CHECKPOINT_NUM(8));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_set_key_policy_negative_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
int32_t i, status;
psa_key_policy_t policy;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] Test psa_set_key_policy with unallocated key handle\n",
g_test_count++);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Set the usage policy on a key slot */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check2[i].usage,
check2[i].key_alg);
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
val->print(PRINT_TEST, "[Check %d] Test psa_set_key_policy with zero as key handle\n",
g_test_count++);
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, 0, &policy);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Set the usage policy on a key slot */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check2[i].usage,
check2[i].key_alg);
val->print(PRINT_TEST, "[Check %d] Test psa_set_key_policy with already occupied handle\n",
g_test_count++);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].key_data, check2[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_ERROR_OCCUPIED_SLOT, TEST_CHECKPOINT_NUM(8));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,32 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C007_CLIENT_TESTS_H_
#define _TEST_C007_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c007)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c007_crypto_list[];
int32_t psa_set_key_policy_test(security_t caller);
int32_t psa_set_key_policy_negative_test(security_t caller);
#endif /* _TEST_C007_CLIENT_TESTS_H_ */

View File

@ -1,285 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[34];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
static const uint8_t rsa_384_keypair[1];
static const uint8_t rsa_384_keydata[1];
static const uint8_t rsa_256_keypair[] = {
0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
0xBA, 0xE0, 0x21, 0xE5, 0x72, 0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA,
0xAC, 0x1B, 0x53,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x38, 0xA3, 0xBD, 0xE2, 0xD1, 0xE0, 0x66, 0x6B, 0xE2, 0x9C, 0x47, 0x99,
0xE9, 0x28, 0xE6, 0xB6, 0xFC, 0x2E, 0xCA, 0x67, 0x43, 0x84, 0xE8, 0xD5, 0x83, 0xD6,
0x9D, 0x98, 0x6B, 0x01, 0x3E, 0x81, 0xDC, 0x3C, 0x7A, 0xCA, 0xF9, 0xF3, 0x9C, 0xF7,
0xD6, 0x28, 0x1B, 0x27, 0x78, 0x7C, 0xC3, 0xD0, 0xD5, 0x63, 0xA7, 0x81, 0x34, 0x89,
0xAD, 0x25, 0x6A, 0xBD, 0xF2, 0xEA, 0xED, 0xFA, 0x57, 0xFC, 0xE5, 0x34, 0xC6, 0xC1,
0x0F, 0x71, 0x2D, 0xD2, 0x08, 0x10, 0x1B, 0xAD, 0x44, 0x41, 0xE0, 0xFE, 0x79, 0xA0,
0x63, 0x93, 0x8A, 0xB1, 0x5D, 0xE9, 0xB0, 0xEE, 0x6F, 0x02, 0x03, 0x01, 0x00, 0x01};
static const uint8_t ec_keydata[] = {
0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
static const uint8_t ec_keypair[] = {
0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_set_key_policy 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_set_key_policy 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_set_key_policy 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_set_key_policy 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 270, PSA_SUCCESS
},
{"Test psa_set_key_policy with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
{0},
1193, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 1193, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_set_key_policy with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_set_key_policy with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
DES3_2KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_set_key_policy with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
DES3_3KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
{"Test psa_set_key_policy with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0},
65, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
256, 65, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
{"Test psa_set_key_policy with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
{0},
28, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
224, 28, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_set_key_policy with invalid usage\n", 13, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_INVALID, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_set_key_policy negative case\n", 11, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_OCCUPIED_SLOT
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c007.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 7)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c007_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c008(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c008, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,181 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c008.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c008_crypto_list[] = {
NULL,
psa_get_key_policy_test,
psa_get_key_policy_negative_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_get_key_policy_test(security_t caller)
{
const uint8_t *key_data;
psa_key_policy_t policy, expected_policy;
psa_key_usage_t expected_usage;
psa_algorithm_t expected_alg;
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check1[i].key_data;
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get the usage policy for a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_POLICY, check1[i].key_handle,
&expected_policy);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(6));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
TEST_ASSERT_EQUAL(expected_policy.usage, check1[i].usage, TEST_CHECKPOINT_NUM(7));
TEST_ASSERT_EQUAL(expected_policy.alg, check1[i].key_alg, TEST_CHECKPOINT_NUM(8));
/* Retrieve the usage field of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_GET_USAGE, &policy, &expected_usage);
/* Retrieve the algorithm field of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_GET_ALGORITHM, &policy, &expected_alg);
TEST_ASSERT_EQUAL(expected_usage, check1[i].usage, TEST_CHECKPOINT_NUM(9));
TEST_ASSERT_EQUAL(expected_alg, check1[i].key_alg, TEST_CHECKPOINT_NUM(10));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_get_key_policy_negative_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
int32_t i, status;
psa_key_policy_t policy;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check2[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_policy with unallocated key handle\n",
g_test_count++);
/* Get the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_policy with zero as key handle\n",
g_test_count++);
/* Get the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_POLICY, 0, &policy);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_policy with empty key handle\n",
g_test_count++);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C008_CLIENT_TESTS_H_
#define _TEST_C008_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c008)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c008_crypto_list[];
int32_t psa_get_key_policy_test(security_t caller);
int32_t psa_get_key_policy_negative_test(security_t caller);
#endif /* _TEST_C008_CLIENT_TESTS_H_ */

View File

@ -1,272 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[34];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
static const uint8_t rsa_384_keypair[1];
static const uint8_t rsa_384_keydata[1];
static const uint8_t rsa_256_keypair[] = {
0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
0xBA, 0xE0, 0x21, 0xE5, 0x72, 0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA,
0xAC, 0x1B, 0x53, 0xB9, 0x5F, 0x3F, 0xD7, 0x19, 0x0D, 0x25, 0x4F, 0xE1, 0x63,
0x63, 0x51, 0x8B, 0x0B, 0x64, 0x3F, 0xAD, 0x43, 0xB8, 0xA5, 0x1C, 0x5C, 0x34,
0xB3, 0xAE, 0x00, 0xA0, 0x63, 0xC5, 0xF6, 0x7F, 0x0B, 0x59, 0x68, 0x78, 0x73,
0xA6, 0x8C, 0x18, 0xA9, 0x02, 0x6D, 0xAF, 0xC3, 0x19, 0x01, 0x2E, 0xB8, 0x10,
0xE3, 0xC6, 0xCC, 0x40, 0xB4, 0x69, 0xA3, 0x46, 0x33, 0x69, 0x87, 0x6E, 0xC4,
0xBB, 0x17, 0xA6, 0xF3, 0xE8, 0xDD, 0xAD, 0x73, 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 0x2D, 0xD2, 0x08, 0x10, 0x1B, 0xAD, 0x44, 0x41, 0xE0, 0xFE, 0x79, 0xA0,
0x63, 0x93, 0x8A, 0xB1, 0x5D, 0xE9, 0xB0, 0xEE, 0x6F, 0x02, 0x03, 0x01, 0x00, 0x01};
static const uint8_t ec_keydata[] = {
0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
static const uint8_t ec_keypair[] = {
0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_get_key_policy 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_get_key_policy 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_get_key_policy 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_get_key_policy 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 270, PSA_SUCCESS
},
{"Test psa_get_key_policy with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
{0},
1193, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, 1193, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_get_key_policy with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_get_key_policy with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
DES3_2KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_get_key_policy with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
DES3_3KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef ARCH_TEST_ECDSA
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
{"Test psa_get_key_policy with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0},
65, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
256, 65, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
{"Test psa_get_key_policy with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
{0},
28, PSA_KEY_USAGE_EXPORT, PSA_ALG_ECDSA_ANY,
224, 28, PSA_SUCCESS
},
#endif
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_get_key_policy negative cases\n", 11, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c008.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 8)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c008_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c009(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c009, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,85 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c009.h"
#include "test_data.h"
#include "val_crypto.h"
#define MAX_KEYS 100
client_test_t test_c009_crypto_list[] = {
NULL,
psa_allocate_key_test,
psa_allocate_key_negative_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_allocate_key_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(3));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_allocate_key_negative_test(security_t caller)
{
int32_t i, status;
psa_key_handle_t key_handle[MAX_KEYS];
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] Testing the insufficient memory\n", g_test_count++);
for (i = 0; i < MAX_KEYS; i++)
{
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &key_handle[i]);
if (status != PSA_SUCCESS)
break;
}
TEST_ASSERT_EQUAL(status, PSA_ERROR_INSUFFICIENT_MEMORY, TEST_CHECKPOINT_NUM(2));
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C009_CLIENT_TESTS_H_
#define _TEST_C009_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c009)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c009_crypto_list[];
int32_t psa_allocate_key_test(security_t caller);
int32_t psa_allocate_key_negative_test(security_t caller);
#endif /* _TEST_C009_CLIENT_TESTS_H_ */

View File

@ -1,86 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
size_t key_length;
psa_status_t expected_status;
} test_data;
static test_data check1[] = {
#ifdef ARCH_TEST_AES_128
{"Test psa_allocate_key 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_allocate_key 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
AES_24B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_allocate_key 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_RSA_2048
{"Test psa_allocate_key 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
294, PSA_SUCCESS
},
{"Test psa_allocate_key with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
1193, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_allocate_key with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_allocate_key with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_allocate_key with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP192R1
{"Test psa_allocate_key with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | PSA_ECC_CURVE_SECP192R1,
75, PSA_SUCCESS
},
{"Test psa_allocate_key with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR_BASE | PSA_ECC_CURVE_SECP192R1,
97, PSA_SUCCESS
},
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c009.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 9)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c009_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c010(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c010, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,168 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c010.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c010_crypto_list[] = {
NULL,
psa_get_key_lifetime_test,
psa_get_key_lifetime_negative_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_get_key_lifetime_test(security_t caller)
{
const uint8_t *key_data;
psa_key_policy_t policy;
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_key_lifetime_t lifetime;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
/* Set the key data buffer to the input base on algorithm */
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (PSA_KEY_TYPE_IS_RSA(check1[i].key_type))
{
if (check1[i].key_type == PSA_KEY_TYPE_RSA_KEYPAIR)
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keypair;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keypair;
else
return VAL_STATUS_INVALID;
}
else
{
if (check1[i].expected_bit_length == BYTES_TO_BITS(384))
key_data = rsa_384_keydata;
else if (check1[i].expected_bit_length == BYTES_TO_BITS(256))
key_data = rsa_256_keydata;
else
return VAL_STATUS_INVALID;
}
}
else if (PSA_KEY_TYPE_IS_ECC(check1[i].key_type))
{
if (PSA_KEY_TYPE_IS_ECC_KEYPAIR(check1[i].key_type))
key_data = ec_keypair;
else
key_data = ec_keydata;
}
else
key_data = check1[i].key_data;
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Get the lifetime of a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, check1[i].key_handle, &lifetime);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
TEST_ASSERT_EQUAL(lifetime, check1[i].lifetime, TEST_CHECKPOINT_NUM(7));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_get_key_lifetime_negative_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
int32_t i, status;
psa_key_lifetime_t lifetime;
psa_key_policy_t policy;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_lifetime with invalid key handle\n",
g_test_count++);
/* Get the lifetime of a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, check2[i].key_handle, &lifetime);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_lifetime with zero as key handle\n",
g_test_count++);
/* Get the lifetime of a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, 0, &lifetime);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
val->print(PRINT_TEST, "[Check %d] Test psa_get_key_lifetime with empty key handle\n",
g_test_count++);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Get the lifetime of a key slot */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_LIFETIME, check2[i].key_handle, &lifetime);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C010_CLIENT_TESTS_H_
#define _TEST_C010_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c010)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c010_crypto_list[];
int32_t psa_get_key_lifetime_test(security_t caller);
int32_t psa_get_key_lifetime_negative_test(security_t caller);
#endif /* _TEST_C010_CLIENT_TESTS_H_ */

View File

@ -1,275 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[34];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
psa_key_lifetime_t lifetime;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
static const uint8_t rsa_384_keypair[1];
static const uint8_t rsa_384_keydata[1];
static const uint8_t rsa_256_keypair[] = {
0x30, 0x82, 0x04, 0xA5, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, 0xC0,
0x95, 0x08, 0xE1, 0x57, 0x41, 0xF2, 0x71, 0x6D, 0xB7, 0xD2, 0x45, 0x41, 0x27,
0x01, 0x65, 0xC6, 0x45, 0xAE, 0xF2, 0xBC, 0x24, 0x30, 0xB8, 0x95, 0xCE, 0x2F,
0x4E, 0xD6, 0xF6, 0x1C, 0x88, 0xBC, 0x7C, 0x9F, 0xFB, 0xA8, 0x67, 0x7F, 0xFE,
0x5C, 0x9C, 0x51, 0x75, 0xF7, 0x8A, 0xCA, 0x07, 0xE7, 0x35, 0x2F, 0x8F, 0xE1,
0xBD, 0x7B, 0xC0, 0x2F, 0x7C, 0xAB, 0x64, 0xA8, 0x17, 0xFC, 0xCA, 0x5D, 0x7B,
0xBA, 0xE0, 0x21, 0xE5, 0x72, 0x2E, 0x6F, 0x2E, 0x86, 0xD8, 0x95, 0x73, 0xDA,
0xAC, 0x1B, 0x53, 0xB9, 0x5F, 0x3F, 0xD7, 0x19, 0x0D, 0x25, 0x4F, 0xE1, 0x63,
0x63, 0x51, 0x8B, 0x0B, 0x64, 0x3F, 0xAD, 0x43, 0xB8, 0xA5, 0x1C, 0x5C, 0x34,
0xB3, 0xAE, 0x00, 0xA0, 0x63, 0xC5, 0xF6, 0x7F, 0x0B, 0x59, 0x68, 0x78, 0x73,
0xA6, 0x8C, 0x18, 0xA9, 0x02, 0x6D, 0xAF, 0xC3, 0x19, 0x01, 0x2E, 0xB8, 0x10,
0xE3, 0xC6, 0xCC, 0x40, 0xB4, 0x69, 0xA3, 0x46, 0x33, 0x69, 0x87, 0x6E, 0xC4,
0xBB, 0x17, 0xA6, 0xF3, 0xE8, 0xDD, 0xAD, 0x73,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, 0x2D, 0xD2, 0x08, 0x10, 0x1B, 0xAD, 0x44, 0x41, 0xE0, 0xFE, 0x79, 0xA0,
0x63, 0x93, 0x8A, 0xB1, 0x5D, 0xE9, 0xB0, 0xEE, 0x6F, 0x02, 0x03, 0x01, 0x00, 0x01};
static const uint8_t ec_keydata[] = {
0x04, 0xde, 0xa5, 0xe4, 0x5d, 0x0e, 0xa3, 0x7f, 0xc5, 0x66, 0x23, 0x2a, 0x50, 0x8f,
0x4a, 0xd2, 0x0e, 0xa1, 0x3d, 0x47, 0xe4, 0xbf, 0x5f, 0xa4, 0xd5, 0x4a, 0x57, 0xa0,
0xba, 0x01, 0x20, 0x42, 0x08, 0x70, 0x97, 0x49, 0x6e, 0xfc, 0x58, 0x3f, 0xed, 0x8b,
0x24, 0xa5, 0xb9, 0xbe, 0x9a, 0x51, 0xde, 0x06, 0x3f, 0x5a, 0x00, 0xa8, 0xb6, 0x98,
0xa1, 0x6f, 0xd7, 0xf2, 0x9b, 0x54, 0x85, 0xf3, 0x20};
static const uint8_t ec_keypair[] = {
0x68, 0x49, 0xf9, 0x7d, 0x10, 0x66, 0xf6, 0x99, 0x77, 0x59, 0x63, 0x7c, 0x7e, 0x38,
0x99, 0x46, 0x4c, 0xee, 0x3e, 0xc7, 0xac, 0x97, 0x06, 0x53, 0xa0, 0xbe, 0x07, 0x42};
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_get_key_lifetime 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
PSA_KEY_LIFETIME_VOLATILE, BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef NO_SUPPORT
/* PSA crypto doesn't support these test scenarios */
{"Test psa_get_key_lifetime 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
{0x24, 0x13, 0x61, 0x47, 0x61, 0xB8, 0xC8, 0xF0, 0xDF, 0xAB, 0x5A, 0x0E, 0x87,
0x40, 0xAC, 0xA3, 0x90, 0x77, 0x83, 0x52, 0x31, 0x74, 0xF9},
AES_24B_KEY_SIZE, PSA_KEY_USAGE_ENCRYPT, PSA_ALG_CTR,
PSA_KEY_LIFETIME_PERSISTENT, BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
},
{"Test psa_get_key_lifetime 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_DECRYPT, PSA_ALG_CTR,
PSA_KEY_LIFETIME_WRITE_ONCE, BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_get_key_lifetime 2048 RSA public key\n", 4, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
{0},
270, PSA_KEY_USAGE_SIGN, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
PSA_KEY_LIFETIME_VOLATILE, 2048, 270, PSA_SUCCESS
},
#endif
#endif
#ifdef NO_SUPPORT
/* PSA crypto doesn't support these test scenarios */
{"Test psa_get_key_lifetime with RSA 2048 keypair\n", 5, PSA_KEY_TYPE_RSA_KEYPAIR,
{0},
1193, PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
PSA_KEY_LIFETIME_PERSISTENT, 2048, 1193, PSA_SUCCESS
},
{"Test psa_get_key_lifetime with DES 64 bit key\n", 6, PSA_KEY_TYPE_DES,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
PSA_KEY_LIFETIME_WRITE_ONCE, BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_get_key_lifetime with Triple DES 2-Key\n", 7, PSA_KEY_TYPE_DES,
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
DES3_2KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
PSA_KEY_LIFETIME_VOLATILE, BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
#ifdef NO_SUPPORT
/* PSA crypto doesn't support these test scenarios */
{"Test psa_get_key_lifetime with Triple DES 3-Key\n", 8, PSA_KEY_TYPE_DES,
{0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
0xF1, 0xE0, 0xD3, 0xC2, 0xB5, 0xA4, 0x97, 0x86,
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10},
DES3_3KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
PSA_KEY_LIFETIME_PERSISTENT, BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
#ifdef ARCH_TEST_ECC_CURVE_SECP256R1
{"Test psa_get_key_lifetime with EC Public key\n", 9,
PSA_KEY_TYPE_ECC_PUBLIC_KEY(PSA_ECC_CURVE_SECP256R1),
{0},
65, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
PSA_KEY_LIFETIME_VOLATILE, 256, 65, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
{"Test psa_get_key_lifetime with EC keypair\n", 10,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
{0},
28, PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
PSA_KEY_LIFETIME_VOLATILE, 224, 28, PSA_SUCCESS
},
#endif
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_get_key_lifetime with negative cases\n", 11, PSA_KEY_TYPE_AES,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR, PSA_KEY_LIFETIME_VOLATILE,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c010.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 10)
#define TEST_DESC "Testing crypto key management APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c010_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c011(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c011, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,62 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c011.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c011_crypto_list[] = {
NULL,
psa_hash_setup_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_hash_setup_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(3));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C011_CLIENT_TESTS_H_
#define _TEST_C011_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c011)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c011_crypto_list[];
int32_t psa_hash_setup_test(security_t caller);
int32_t psa_get_key_lifetime_negative_test(security_t caller);
#endif /* _TEST_C011_CLIENT_TESTS_H_ */

View File

@ -1,120 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
psa_status_t expected_status;
} test_data;
static test_data check1[] = {
#ifdef ARCH_TEST_MD2
{"Test psa_hash_setup with MD2 algorithm\n",
PSA_ALG_MD2, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
{"Test psa_hash_setup with MD4 algorithm\n",
PSA_ALG_MD4, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
{"Test psa_hash_setup with MD5 algorithm\n",
PSA_ALG_MD5, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
{"Test psa_hash_setup with RIPEMD160 algorithm\n",
PSA_ALG_RIPEMD160, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
{"Test psa_hash_setup with SHA1 algorithm\n",
PSA_ALG_SHA_1, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
{"Test psa_hash_setup with SHA224 algorithm\n",
PSA_ALG_SHA_224, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
{"Test psa_hash_setup with SHA256 algorithm\n",
PSA_ALG_SHA_256, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
{"Test psa_hash_setup with SHA384 algorithm\n",
PSA_ALG_SHA_384, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
{"Test psa_hash_setup with SHA512 algorithm\n",
PSA_ALG_SHA_512, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512_224
{"Test psa_hash_setup with SHA512_224 algorithm\n",
PSA_ALG_SHA_512_224, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512_256
{"Test psa_hash_setup with SHA512_256 algorithm\n",
PSA_ALG_SHA_512_256, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA3_224
{"Test psa_hash_setup with SHA3_224 algorithm\n",
PSA_ALG_SHA3_224, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA3_256
{"Test psa_hash_setup with SHA3_256 algorithm\n",
PSA_ALG_SHA3_256, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA3_384
{"Test psa_hash_setup with SHA3_384 algorithm\n",
PSA_ALG_SHA3_384, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA3_512
{"Test psa_hash_setup with SHA3_512 algorithm\n",
PSA_ALG_SHA3_512, PSA_SUCCESS,
},
#endif
{"Test psa_hash_setup with Invalid algorithm\n",
PSA_ALG_INVALID, PSA_ERROR_INVALID_ARGUMENT,
},
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c011.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 11)
#define TEST_DESC "Testing crypto hash functions APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c011_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,10 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
#include "unity/unity.h"
void test_entry_c012(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c012, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,148 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c012.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c012_crypto_list[] = {
NULL,
psa_hash_update_test,
psa_hash_update_invalid_handle,
psa_hash_update_with_completed_handle,
NULL,
};
static int g_test_count = 1;
int32_t psa_hash_update_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
check1[i].input, check1[i].input_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_hash_update_invalid_handle(security_t caller)
{
psa_hash_operation_t operation;
uint8_t input[] = "Hello World";
size_t input_length = sizeof(input)/sizeof(input[0]);
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "Test psa_hash_update without hash setup\n", 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation, input, input_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(3));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
return VAL_STATUS_SUCCESS;
}
int32_t psa_hash_update_with_completed_handle(security_t caller)
{
psa_hash_operation_t operation;
uint8_t input[] = {0xbd};
size_t input_length = sizeof(input)/sizeof(input[0]);
psa_algorithm_t alg = PSA_ALG_SHA_256;
uint8_t hash[] = {0x68, 0x32, 0x57, 0x20, 0xAA, 0xBD, 0x7C, 0x82, 0xF3, 0x0F,
0x55, 0x4B, 0x31, 0x3D, 0x05, 0x70, 0xC9, 0x5A, 0xCC, 0xBB,
0x7D, 0xC4, 0xB5, 0xAA, 0xE1, 0x12, 0x04, 0xC0, 0x8F, 0xFE,
0x73, 0x2B};
size_t hash_length = sizeof(hash)/sizeof(hash[0]);
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "Test psa_hash_update with completed opertaion handle \n", 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
input, input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message and compare it with an expected value*/
status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, hash, hash_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation, input, input_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
return VAL_STATUS_SUCCESS;
}

View File

@ -1,32 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C012_CLIENT_TESTS_H_
#define _TEST_C012_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c012)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c012_crypto_list[];
int32_t psa_hash_update_test(security_t caller);
int32_t psa_hash_update_invalid_handle(security_t caller);
int32_t psa_hash_update_with_completed_handle(security_t caller);
#endif /* _TEST_C012_CLIENT_TESTS_H_ */

View File

@ -1,82 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
char input[15];
size_t input_length;
psa_status_t expected_status;
} test_data;
static test_data check1[] = {
#ifdef ARCH_TEST_MD2
{"Test psa_hash_update with MD2 algorithm\n",
PSA_ALG_MD2, "Hello World", 11, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
{"Test psa_hash_update with MD4 algorithm\n",
PSA_ALG_MD4, "Hello World", 11, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
{"Test psa_hash_update with MD5 algorithm\n",
PSA_ALG_MD5, "Hello World", 11, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
{"Test psa_hash_update with RIPEMD160 algorithm\n",
PSA_ALG_RIPEMD160, "Hello World", 11, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
{"Test psa_hash_update with SHA1 algorithm\n",
PSA_ALG_SHA_1, "Hello World", 11, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
{"Test psa_hash_update with SHA224 algorithm\n",
PSA_ALG_SHA_224, "Hello World", 11, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
{"Test psa_hash_update with SHA256 algorithm\n",
PSA_ALG_SHA_256, "Hello World", 11, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
{"Test psa_hash_update with SHA384 algorithm\n",
PSA_ALG_SHA_384, "Hello World", 11, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
{"Test psa_hash_update with SHA512 algorithm\n",
PSA_ALG_SHA_512, "Hello World", 11, PSA_SUCCESS,
},
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c012.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 12)
#define TEST_DESC "Testing crypto hash functions APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c012_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c013(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c013, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,135 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c013.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c013_crypto_list[] = {
NULL,
psa_hash_verify_test,
psa_hash_verify_inactive_operation_handle,
NULL,
};
static int g_test_count = 1;
int32_t psa_hash_verify_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
const char *hash;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (check1[i].alg == PSA_ALG_SHA_384)
hash = sha384_hash;
else if (check1[i].alg == PSA_ALG_SHA_512)
hash = sha512_hash;
else
hash = check1[i].hash;
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
&check1[i].input, check1[i].input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message and compare it with an expected value*/
status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, hash,
check1[i].hash_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_hash_verify_inactive_operation_handle(security_t caller)
{
psa_hash_operation_t operation, invalid_operation;
char input = 0xbd;
size_t input_length = 1;
psa_algorithm_t alg = PSA_ALG_SHA_256;
size_t hash_length = PSA_HASH_SIZE(alg);
char hash[] = {0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f,
0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70, 0xc9, 0x5a, 0xcc, 0xbb,
0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe,
0x73, 0x2b};
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "test psa_hash_verify with inactive & invalid operation handle\n", 0);
memset(&operation, 0, sizeof(operation));
memset(&invalid_operation, 0, sizeof(invalid_operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
&input, input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message and compare it with an expected value*/
status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, hash, hash_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Retry the operation with completed operation handle */
status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &operation, hash, hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
/* Retry the operation with invalid operation handle */
status = val->crypto_function(VAL_CRYPTO_HASH_VERIFY, &invalid_operation, hash, hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(7));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C013_CLIENT_TESTS_H_
#define _TEST_C013_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c013)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c013_crypto_list[];
int32_t psa_hash_verify_test(security_t caller);
int32_t psa_hash_verify_inactive_operation_handle(security_t caller);
#endif /* _TEST_C013_CLIENT_TESTS_H_ */

View File

@ -1,131 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
char input;
size_t input_length;
char hash[32];
size_t hash_length;
psa_status_t expected_status;
} test_data;
static const char sha384_hash[] = {
0x43, 0x72, 0xe3, 0x8a, 0x92, 0xa2, 0x8b, 0x5d, 0x2c, 0x39, 0x1e, 0x62,
0x45, 0x2a, 0x86, 0xd5, 0x0e, 0x02, 0x67, 0x22, 0x8b, 0xe1, 0x76, 0xc7, 0x7d, 0x24, 0x02, 0xef,
0xfe, 0x9f, 0xa5, 0x0d, 0xe4, 0x07, 0xbb, 0xb8, 0x51, 0xb3, 0x7d, 0x59, 0x04, 0xab, 0xa2, 0xde,
0xde, 0x74, 0xda, 0x2a};
static const char sha512_hash[] = {
0x29, 0x6e, 0x22, 0x67, 0xd7, 0x4c, 0x27, 0x8d, 0xaa, 0xaa, 0x94, 0x0d,
0x17, 0xb0, 0xcf, 0xb7, 0x4a, 0x50, 0x83, 0xf8, 0xe0, 0x69, 0x72, 0x6d, 0x8c, 0x84, 0x1c, 0xbe,
0x59, 0x6e, 0x04, 0x31, 0xcb, 0x77, 0x41, 0xa5, 0xb5, 0x0f, 0x71, 0x66, 0x6c, 0xfd, 0x54, 0xba,
0xcb, 0x7b, 0x00, 0xae, 0xa8, 0x91, 0x49, 0x9c, 0xf4, 0xef, 0x6a, 0x03, 0xc8, 0xa8, 0x3f, 0xe3,
0x7c, 0x3f, 0x7b, 0xaf};
static test_data check1[] = {
#ifdef ARCH_TEST_MD2
{"Test psa_hash_verify with MD2 algorithm\n",
PSA_ALG_MD2, 0xbd, 1,
{0x8c, 0x9c, 0x17, 0x66, 0x5d, 0x25, 0xb3, 0x5f, 0xc4, 0x13, 0xc4, 0x18, 0x05, 0xc6, 0x79, 0xcf},
16, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
{"Test psa_hash_verify with MD4 algorithm\n",
PSA_ALG_MD4, 0xbd, 1,
{0x18, 0xc3, 0x3f, 0x97, 0x29, 0x7e, 0xfe, 0x5f, 0x8a, 0x73, 0x22, 0x58, 0x28, 0x9f, 0xda, 0x25},
16, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
{"Test psa_hash_verify with MD5 algorithm\n",
PSA_ALG_MD5, 0xbd, 1,
{0xab, 0xae, 0x57, 0xcb, 0x56, 0x2e, 0xcf, 0x29, 0x5b, 0x4a, 0x37, 0xa7, 0x6e, 0xfe, 0x61, 0xfb},
16, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
{"Test psa_hash_verify with RIPEMD160 algorithm\n",
PSA_ALG_RIPEMD160, 0xbd, 1,
{0x50, 0x89, 0x26, 0x5e, 0xe5, 0xd9, 0xaf, 0x75, 0xd1, 0x2d, 0xbf, 0x7e, 0xa2, 0xf2, 0x7d, 0xbd,
0xee, 0x43, 0x5b, 0x37},
20, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
{"Test psa_hash_verify with SHA1 algorithm\n",
PSA_ALG_SHA_1, 0xbd, 1,
{0x90, 0x34, 0xaa, 0xf4, 0x51, 0x43, 0x99, 0x6a, 0x2b, 0x14, 0x46, 0x5c, 0x35, 0x2a, 0xb0, 0xc6,
0xfa, 0x26, 0xb2, 0x21},
20, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
{"Test psa_hash_verify with SHA224 algorithm\n",
PSA_ALG_SHA_224, 0xbd, 1,
{0xb1, 0xe4, 0x6b, 0xb9, 0xef, 0xe4, 0x5a, 0xf5, 0x54, 0x36, 0x34, 0x49, 0xc6, 0x94, 0x5a, 0x0d,
0x61, 0x69, 0xfc, 0x3a, 0x5a, 0x39, 0x6a, 0x56, 0xcb, 0x97, 0xcb, 0x57},
28, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
{"Test psa_hash_verify with SHA256 algorithm\n",
PSA_ALG_SHA_256, 0xbd, 1,
{0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
32, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
{"Test psa_hash_verify with SHA384 algorithm\n",
PSA_ALG_SHA_384, 0xbd, 1, {0}, 48, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
{"Test psa_hash_verify with SHA512 algorithm\n",
PSA_ALG_SHA_512, 0xbd, 1, {0}, 64, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
{"Test psa_hash_verify with incorrect expected hash\n",
PSA_ALG_SHA_256, 0xbd, 1,
{0x68, 0x32, 0x57, 0x20, 0xab, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x78},
32, PSA_ERROR_INVALID_SIGNATURE,
},
{"Test psa_hash_verify with incorrect hash length\n",
PSA_ALG_SHA_256, 0xbd, 1,
{0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
31, PSA_ERROR_INVALID_SIGNATURE,
},
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c013.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 13)
#define TEST_DESC "Testing crypto hash functions APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c013_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c014(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c014, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,186 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c014.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c014_crypto_list[] = {
NULL,
psa_hash_finish_test,
psa_hash_finish_inactive_operation_handle,
psa_hash_finish_invalid_hash_buffer_size,
NULL,
};
static int g_test_count = 1;
int32_t psa_hash_finish_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
const char *expected_hash;
char hash[HASH_64B];
size_t hash_length, hash_size = sizeof(hash)/sizeof(hash[0]);
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
if (check1[i].alg == PSA_ALG_SHA_384)
expected_hash = sha384_hash;
else if (check1[i].alg == PSA_ALG_SHA_512)
expected_hash = sha512_hash;
else
expected_hash = check1[i].hash;
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
&check1[i].input, check1[i].input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message */
status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
&hash_length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
if (check1[i].expected_status != PSA_SUCCESS)
{
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
continue;
}
TEST_ASSERT_EQUAL(hash_length, PSA_HASH_SIZE(check1[i].alg), TEST_CHECKPOINT_NUM(7));
TEST_ASSERT_MEMCMP(hash, expected_hash, hash_length, TEST_CHECKPOINT_NUM(8));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_hash_finish_inactive_operation_handle(security_t caller)
{
psa_hash_operation_t operation;
char input = 0xbd;
size_t input_length = 1;
psa_algorithm_t alg = PSA_ALG_SHA_256;
char hash[HASH_64B];
size_t hash_length, hash_size = sizeof(hash)/sizeof(hash[0]);
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "test psa_hash_finish with inactive operation handle\n", 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation,
&input, input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message */
status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
&hash_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Retry the operation with completed operation handle */
status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
&hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
return VAL_STATUS_SUCCESS;
}
int32_t psa_hash_finish_invalid_hash_buffer_size(security_t caller)
{
psa_hash_operation_t operation;
char input = 0xbd;
size_t input_length = 1;
psa_algorithm_t alg = PSA_ALG_SHA_256;
char hash[HASH_64B];
size_t hash_length, hash_size = 10;
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "test psa_hash_finish with invalid hash buffer size\n", 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation, &input, input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Finish the calculation of the hash of a message */
status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
&hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BUFFER_TOO_SMALL, TEST_CHECKPOINT_NUM(5));
/*Abort the hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
return VAL_STATUS_SUCCESS;
}

View File

@ -1,32 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C014_CLIENT_TESTS_H_
#define _TEST_C014_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c014)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c014_crypto_list[];
int32_t psa_hash_finish_test(security_t caller);
int32_t psa_hash_finish_inactive_operation_handle(security_t caller);
int32_t psa_hash_finish_invalid_hash_buffer_size(security_t caller);
#endif /* _TEST_C014_CLIENT_TESTS_H_ */

View File

@ -1,115 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
char input;
size_t input_length;
char hash[32];
size_t hash_length;
psa_status_t expected_status;
} test_data;
static const char sha384_hash[] = {
0x43, 0x72, 0xe3, 0x8a, 0x92, 0xa2, 0x8b, 0x5d, 0x2c, 0x39, 0x1e, 0x62,
0x45, 0x2a, 0x86, 0xd5, 0x0e, 0x02, 0x67, 0x22, 0x8b, 0xe1, 0x76, 0xc7, 0x7d, 0x24, 0x02, 0xef,
0xfe, 0x9f, 0xa5, 0x0d, 0xe4, 0x07, 0xbb, 0xb8, 0x51, 0xb3, 0x7d, 0x59, 0x04, 0xab, 0xa2, 0xde,
0xde, 0x74, 0xda, 0x2a};
static const char sha512_hash[] = {
0x29, 0x6e, 0x22, 0x67, 0xd7, 0x4c, 0x27, 0x8d, 0xaa, 0xaa, 0x94, 0x0d,
0x17, 0xb0, 0xcf, 0xb7, 0x4a, 0x50, 0x83, 0xf8, 0xe0, 0x69, 0x72, 0x6d, 0x8c, 0x84, 0x1c, 0xbe,
0x59, 0x6e, 0x04, 0x31, 0xcb, 0x77, 0x41, 0xa5, 0xb5, 0x0f, 0x71, 0x66, 0x6c, 0xfd, 0x54, 0xba,
0xcb, 0x7b, 0x00, 0xae, 0xa8, 0x91, 0x49, 0x9c, 0xf4, 0xef, 0x6a, 0x03, 0xc8, 0xa8, 0x3f, 0xe3,
0x7c, 0x3f, 0x7b, 0xaf};
static test_data check1[] = {
#ifdef ARCH_TEST_MD2
{"Test psa_hash_finish with MD2 algorithm\n",
PSA_ALG_MD2, 0xbd, 1,
{0x8c, 0x9c, 0x17, 0x66, 0x5d, 0x25, 0xb3, 0x5f, 0xc4, 0x13, 0xc4, 0x18, 0x05, 0xc6, 0x79, 0xcf},
16, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
{"Test psa_hash_finish with MD4 algorithm\n",
PSA_ALG_MD4, 0xbd, 1,
{0x18, 0xc3, 0x3f, 0x97, 0x29, 0x7e, 0xfe, 0x5f, 0x8a, 0x73, 0x22, 0x58, 0x28, 0x9f, 0xda, 0x25},
16, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
{"Test psa_hash_finish with MD5 algorithm\n",
PSA_ALG_MD5, 0xbd, 1,
{0xab, 0xae, 0x57, 0xcb, 0x56, 0x2e, 0xcf, 0x29, 0x5b, 0x4a, 0x37, 0xa7, 0x6e, 0xfe, 0x61, 0xfb},
16, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
{"Test psa_hash_finish with RIPEMD160 algorithm\n",
PSA_ALG_RIPEMD160, 0xbd, 1,
{0x50, 0x89, 0x26, 0x5e, 0xe5, 0xd9, 0xaf, 0x75, 0xd1, 0x2d, 0xbf, 0x7e, 0xa2, 0xf2, 0x7d, 0xbd,
0xee, 0x43, 0x5b, 0x37},
20, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
{"Test psa_hash_finish with SHA1 algorithm\n",
PSA_ALG_SHA_1, 0xbd, 1,
{0x90, 0x34, 0xaa, 0xf4, 0x51, 0x43, 0x99, 0x6a, 0x2b, 0x14, 0x46, 0x5c, 0x35, 0x2a, 0xb0, 0xc6,
0xfa, 0x26, 0xb2, 0x21},
20, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
{"Test psa_hash_finish with SHA224 algorithm\n",
PSA_ALG_SHA_224, 0xbd, 1,
{0xb1, 0xe4, 0x6b, 0xb9, 0xef, 0xe4, 0x5a, 0xf5, 0x54, 0x36, 0x34, 0x49, 0xc6, 0x94, 0x5a, 0x0d,
0x61, 0x69, 0xfc, 0x3a, 0x5a, 0x39, 0x6a, 0x56, 0xcb, 0x97, 0xcb, 0x57},
28, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
{"Test psa_hash_finish with SHA256 algorithm\n",
PSA_ALG_SHA_256, 0xbd, 1,
{0x68, 0x32, 0x57, 0x20, 0xaa, 0xbd, 0x7c, 0x82, 0xf3, 0x0f, 0x55, 0x4b, 0x31, 0x3d, 0x05, 0x70,
0xc9, 0x5a, 0xcc, 0xbb, 0x7d, 0xc4, 0xb5, 0xaa, 0xe1, 0x12, 0x04, 0xc0, 0x8f, 0xfe, 0x73, 0x2b},
32, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
{"Test psa_hash_finish with SHA384 algorithm\n",
PSA_ALG_SHA_384, 0xbd, 1, {0}, 48, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
{"Test psa_hash_finish with SHA512 algorithm\n",
PSA_ALG_SHA_512, 0xbd, 1, {0}, 64, PSA_SUCCESS,
},
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c014.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 14)
#define TEST_DESC "Testing crypto hash functions APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c014_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c015(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c015, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,110 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c015.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c015_crypto_list[] = {
NULL,
psa_hash_abort_test,
psa_hash_abort_before_operation_finish,
NULL,
};
static int g_test_count = 1;
int32_t psa_hash_abort_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
int32_t i, status;
psa_hash_operation_t operation;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, check1[i].alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Abort a hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(4));
/* Multiple hash abort should succeed */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_hash_abort_before_operation_finish(security_t caller)
{
psa_hash_operation_t operation;
char input = 0xbd;
size_t input_length = 1;
psa_algorithm_t alg = PSA_ALG_SHA_256;
char hash[HASH_64B];
size_t hash_length, hash_size = sizeof(hash)/sizeof(hash[0]);
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, "Test psa_hash_finish after calling psa_hash_abort\n", 0);
memset(&operation, 0, sizeof(operation));
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Start a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_SETUP, &operation, alg);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Add a message fragment to a multipart hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_UPDATE, &operation, &input, input_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Abort a hash operation */
status = val->crypto_function(VAL_CRYPTO_HASH_ABORT, &operation);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Finish the calculation of the hash of a message */
status = val->crypto_function(VAL_CRYPTO_HASH_FINISH, &operation, hash, hash_size,
&hash_length);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(6));
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C015_CLIENT_TESTS_H_
#define _TEST_C015_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c015)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c015_crypto_list[];
int32_t psa_hash_abort_test(security_t caller);
int32_t psa_hash_abort_before_operation_finish(security_t caller);
#endif /* _TEST_C015_CLIENT_TESTS_H_ */

View File

@ -1,80 +0,0 @@
/** @file
* Copyright (c) 2018-2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[50];
psa_algorithm_t alg;
psa_status_t expected_status;
} test_data;
static test_data check1[] = {
#ifdef ARCH_TEST_MD2
{"Test psa_hash_abort with MD2 algorithm\n",
PSA_ALG_MD2, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD4
{"Test psa_hash_abort with MD4 algorithm\n",
PSA_ALG_MD4, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_MD5
{"Test psa_hash_abort with MD5 algorithm\n",
PSA_ALG_MD5, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_RIPEMD160
{"Test psa_hash_abort with RIPEMD160 algorithm\n",
PSA_ALG_RIPEMD160, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA1
{"Test psa_hash_abort with SHA1 algorithm\n",
PSA_ALG_SHA_1, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA224
{"Test psa_hash_abort with SHA224 algorithm\n",
PSA_ALG_SHA_224, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA256
{"Test psa_hash_abort with SHA256 algorithm\n",
PSA_ALG_SHA_256, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA384
{"Test psa_hash_abort with SHA384 algorithm\n",
PSA_ALG_SHA_384, PSA_SUCCESS,
},
#endif
#ifdef ARCH_TEST_SHA512
{"Test psa_hash_abort with SHA512 algorithm\n",
PSA_ALG_SHA_512, PSA_SUCCESS,
},
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2018, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c015.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 15)
#define TEST_DESC "Testing crypto hash functions APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c015_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c016(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c016, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,174 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c016.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c016_crypto_list[] = {
NULL,
psa_generate_key_test,
psa_generate_key_negative_test,
NULL,
};
static int g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t psa_generate_key_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
uint32_t i, length;
psa_key_policy_t policy;
psa_key_type_t key_type;
size_t bits;
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Generate a key or key pair */
status = val->crypto_function(VAL_CRYPTO_GENERATE_KEY, check1[i].key_handle,
check1[i].key_type, check1[i].bits, check1[i].extra, check1[i].extra_size);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(5));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
/* Get basic metadata about a key */
status = val->crypto_function(VAL_CRYPTO_GET_KEY_INFORMATION, check1[i].key_handle,
&key_type, &bits);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
TEST_ASSERT_EQUAL(key_type, check1[i].key_type, TEST_CHECKPOINT_NUM(7));
TEST_ASSERT_EQUAL(bits, check1[i].expected_bit_length, TEST_CHECKPOINT_NUM(8));
/* Export a key in binary format */
status = val->crypto_function(VAL_CRYPTO_EXPORT_KEY, check1[i].key_handle, data,
BUFFER_SIZE, &length);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(9));
TEST_ASSERT_EQUAL(length, check1[i].expected_key_length, TEST_CHECKPOINT_NUM(10));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_generate_key_negative_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
uint32_t i;
psa_key_policy_t policy;
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
val->print(PRINT_TEST, "[Check %d] Test psa_generate_key with unallocated key handle\n",
g_test_count++);
/* Generate a key or key pair */
status = val->crypto_function(VAL_CRYPTO_GENERATE_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].bits, check2[i].extra, check2[i].extra_size);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(3));
val->print(PRINT_TEST, "[Check %d] Test psa_generate_key with zero as key handle\n",
g_test_count++);
/* Generate a key or key pair */
status = val->crypto_function(VAL_CRYPTO_GENERATE_KEY, 0, check2[i].key_type,
check2[i].bits, check2[i].extra, check2[i].extra_size);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(4));
val->print(PRINT_TEST, "[Check %d] Test psa_generate_key with pre-occupied key handle\n",
g_test_count++);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check2[i].usage,
check2[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check2[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Generate a key or key pair */
status = val->crypto_function(VAL_CRYPTO_GENERATE_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].bits, check2[i].extra, check2[i].extra_size);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(7));
/* Generate a key or key pair */
status = val->crypto_function(VAL_CRYPTO_GENERATE_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].bits, check2[i].extra, check2[i].extra_size);
TEST_ASSERT_EQUAL(status, PSA_ERROR_OCCUPIED_SLOT, TEST_CHECKPOINT_NUM(8));
val->print(PRINT_TEST, "[Check %d] Test psa_generate_key with destroyed key handle\n",
g_test_count++);
status = val->crypto_function(VAL_CRYPTO_DESTROY_KEY, check2[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(9));
/* Generate a key or key pair */
status = val->crypto_function(VAL_CRYPTO_GENERATE_KEY, check2[i].key_handle,
check2[i].key_type, check2[i].bits, check2[i].extra, check2[i].extra_size);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INVALID_HANDLE, TEST_CHECKPOINT_NUM(10));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,31 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C016_CLIENT_TESTS_H_
#define _TEST_C016_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c016)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c016_crypto_list[];
int32_t psa_generate_key_test(security_t caller);
int32_t psa_generate_key_negative_test(security_t caller);
#endif /* _TEST_C016_CLIENT_TESTS_H_ */

View File

@ -1,145 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
size_t bits;
void *extra;
size_t extra_size;
uint32_t expected_bit_length;
uint32_t expected_key_length;
psa_status_t expected_status;
} test_data;
#ifdef FUTURE_SUPPORT
static uint32_t rsa_extra = 3;
#endif
static test_data check1[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_generate_key 16 Byte AES\n", 1, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), NULL, 0,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_192
{"Test psa_generate_key 24 Byte AES\n", 2, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_24B_KEY_SIZE), NULL, 0,
BYTES_TO_BITS(AES_24B_KEY_SIZE), AES_24B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_generate_key 32 Byte AES\n", 3, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_32B_KEY_SIZE), NULL, 0,
BYTES_TO_BITS(AES_32B_KEY_SIZE), AES_32B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_1KEY
{"Test psa_generate_key with DES 64 bit key\n", 4, PSA_KEY_TYPE_DES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES_8B_KEY_SIZE), NULL, 0,
BYTES_TO_BITS(DES_8B_KEY_SIZE), DES_8B_KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_2KEY
{"Test psa_generate_key with Triple DES 2-Key\n", 5, PSA_KEY_TYPE_DES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_2KEY_SIZE), NULL, 0,
BYTES_TO_BITS(DES3_2KEY_SIZE), DES3_2KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_DES_3KEY
{"Test psa_generate_key with Triple DES 3-Key\n", 6, PSA_KEY_TYPE_DES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(DES3_3KEY_SIZE), NULL, 0,
BYTES_TO_BITS(DES3_3KEY_SIZE), DES3_3KEY_SIZE, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_AES_256
{"Test psa_generate_key with Null extra and Non-Zero extra size\n", 7, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_32B_KEY_SIZE), NULL, sizeof(uint32_t),
0, 0, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#endif
#ifdef FUTURE_SUPPORT
{"Test psa_generate_key with RSA 2048 Keypair\n", 8, PSA_KEY_TYPE_RSA_KEYPAIR,
PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, NULL, 0,
2048, 1193, PSA_SUCCESS
},
#endif
#ifdef ARCH_TEST_ECC_CURVE_SECP224R1
#ifdef ARCH_TEST_ASYMMETRIC_ENCRYPTION
{"Test psa_generate_key with ECC KeyPair\n", 9,
PSA_KEY_TYPE_ECC_KEYPAIR(PSA_ECC_CURVE_SECP224R1),
PSA_KEY_USAGE_EXPORT, PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION,
224, NULL, 0,
224, 28, PSA_SUCCESS
},
#endif
#endif
#ifdef FUTURE_SUPPORT
{"Test psa_generate_key with Non-Null extra for 32 Byte AES key\n", 10, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_32B_KEY_SIZE), &rsa_extra, sizeof(uint32_t),
0, 0, PSA_ERROR_INVALID_ARGUMENT
},
#endif
#ifdef ARCH_TEST_RSA_PKCS1V15_SIGN_RAW
#ifdef ARCH_TEST_RSA_2048
{"Test psa_generate_key with RSA 2048 Public key\n", 11, PSA_KEY_TYPE_RSA_PUBLIC_KEY,
PSA_KEY_USAGE_EXPORT | PSA_KEY_USAGE_SIGN | PSA_KEY_USAGE_VERIFY, PSA_ALG_RSA_PKCS1V15_SIGN_RAW,
2048, NULL, 0,
2048, 1193, PSA_ERROR_NOT_SUPPORTED
},
#endif
#endif
};
static test_data check2[] = {
#ifdef ARCH_TEST_CIPER_MODE_CTR
#ifdef ARCH_TEST_AES_128
{"Test psa_generate_key negative cases\n", 12, PSA_KEY_TYPE_AES,
PSA_KEY_USAGE_EXPORT, PSA_ALG_CTR,
BYTES_TO_BITS(AES_16B_KEY_SIZE), NULL, 0,
BYTES_TO_BITS(AES_16B_KEY_SIZE), AES_16B_KEY_SIZE, PSA_SUCCESS
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c016.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 16)
#define TEST_DESC "Testing crypto generator functions APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c016_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c017(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c017, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,74 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c017.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c017_crypto_list[] = {
NULL,
psa_generate_random_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_generate_random_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
uint32_t i, j, data_sum;
uint8_t data[BUFFER_SIZE] = {0};
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
/* Generate random bytes */
status = val->crypto_function(VAL_CRYPTO_GENERATE_RANDOM, data, check1[i].size);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(3));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
data_sum = 0;
/* Check that if generated data are zero */
for (j = 0; j < check1[i].size; j++)
{
data_sum += data[j];
data[j] = 0;
}
if (check1[i].size != 0)
TEST_ASSERT_NOT_EQUAL(data_sum, 0, TEST_CHECKPOINT_NUM(4));
else
TEST_ASSERT_EQUAL(data_sum, 0, TEST_CHECKPOINT_NUM(5));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,30 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C017_CLIENT_TESTS_H_
#define _TEST_C017_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c017)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c017_crypto_list[];
int32_t psa_generate_random_test(security_t caller);
#endif /* _TEST_C017_CLIENT_TESTS_H_ */

View File

@ -1,56 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
size_t size;
psa_status_t expected_status;
} test_data;
static test_data check1[] = {
{"Test psa_generate_random to get 0 Byte data\n", 0, PSA_SUCCESS
},
{"Test psa_generate_random to get 16 Byte data\n", 16, PSA_SUCCESS
},
{"Test psa_generate_random to get 24 Byte data\n", 24, PSA_SUCCESS
},
{"Test psa_generate_random to get 32 Byte data\n", 32, PSA_SUCCESS
},
{"Test psa_generate_random to get 64 Byte data\n", 64, PSA_SUCCESS
},
{"Test psa_generate_random to get 128 Byte data\n", 128, PSA_SUCCESS
},
{"Test psa_generate_random to get 256 Byte data\n", 256, PSA_SUCCESS
},
{"Test psa_generate_random to get 512 Byte data\n", 512, PSA_SUCCESS
},
{"Test psa_generate_random to get 1000 Byte data\n", 100, PSA_SUCCESS
},
{"Test psa_generate_random to get 1024 Byte data\n", 1024, PSA_SUCCESS
},
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c017.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 17)
#define TEST_DESC "Testing crypto generator functions APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c017_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c018(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c018, COMPLIANCE_TEST_CRYPTO);
}

View File

@ -1,146 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c018.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c018_crypto_list[] = {
NULL,
psa_generator_read_test,
NULL,
};
static int g_test_count = 1;
static uint8_t data[BUFFER_SIZE_HIGH];
int32_t psa_generator_read_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
uint32_t i, j, data_sum, remaining_size;
psa_key_policy_t policy;
psa_crypto_generator_t generator, invalid_generator;
int32_t status;
/* Initialize the PSA crypto library*/
status = val->crypto_function(VAL_CRYPTO_INIT);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(1));
for (i = 0; i < num_checks; i++)
{
val->print(PRINT_TEST, "[Check %d] ", g_test_count++);
val->print(PRINT_TEST, check1[i].test_desc, 0);
/* Initialize a key policy structure to a default that forbids all
* usage of the key
*/
val->crypto_function(VAL_CRYPTO_KEY_POLICY_INIT, &policy);
/* Setting up the watchdog timer for each check */
status = val->wd_reprogram_timer(WD_CRYPTO_TIMEOUT);
TEST_ASSERT_EQUAL(status, VAL_STATUS_SUCCESS, TEST_CHECKPOINT_NUM(2));
memset(&generator, 0, sizeof(generator));
memset(&invalid_generator, 0xDEADEAD, sizeof(invalid_generator));
memset(data, 0, sizeof(data));
/* Set the standard fields of a policy structure */
val->crypto_function(VAL_CRYPTO_KEY_POLICY_SET_USAGE, &policy, check1[i].usage,
check1[i].key_alg);
/* Allocate a key slot for a transient key */
status = val->crypto_function(VAL_CRYPTO_ALLOCATE_KEY, &check1[i].key_handle);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(3));
/* Set the usage policy on a key slot */
status = val->crypto_function(VAL_CRYPTO_SET_KEY_POLICY, check1[i].key_handle, &policy);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(4));
/* Import the key data into the key slot */
status = val->crypto_function(VAL_CRYPTO_IMPORT_KEY, check1[i].key_handle,
check1[i].key_type, check1[i].key_data, check1[i].key_length);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(5));
/* Set up a key derivation operation. Using this function to initialize the generate as
* XOR or PRNG generator initialization is not implemented.
*/
status = val->crypto_function(VAL_CRYPTO_KEY_DERIVATION, &generator, check1[i].key_handle,
check1[i].key_alg, &check1[i].salt, check1[i].salt_length, &check1[i].label,
check1[i].label_length, check1[i].capacity);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(6));
/* Read some data from a generator */
status = val->crypto_function(VAL_CRYPTO_GENERATOR_READ, &generator, data,
check1[i].size);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(7));
if (check1[i].expected_status != PSA_SUCCESS)
{
/* Abort a generator */
status = val->crypto_function(VAL_CRYPTO_GENERATOR_ABORT, &generator);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(8));
continue;
}
data_sum = 0;
/* Check that if generated data are zero */
for (j = 0; j < check1[i].size; j++)
{
data_sum += data[j];
}
memset(data, 0, sizeof(data));
TEST_ASSERT_NOT_EQUAL(data_sum, 0, TEST_CHECKPOINT_NUM(9));
remaining_size = check1[i].capacity - check1[i].size;
if (remaining_size > 0)
{
/* Read some data from a generator */
status = val->crypto_function(VAL_CRYPTO_GENERATOR_READ, &generator,
data, remaining_size);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
data_sum = 0;
/* Check that if generated data are zero */
for (j = 0; j < remaining_size; j++)
{
data_sum += data[j];
}
memset(data, 0, sizeof(data));
TEST_ASSERT_NOT_EQUAL(data_sum, 0, TEST_CHECKPOINT_NUM(11));
/* Read some data from a generator */
status = val->crypto_function(VAL_CRYPTO_GENERATOR_READ, &generator,
data, check1[i].size);
TEST_ASSERT_EQUAL(status, PSA_ERROR_INSUFFICIENT_CAPACITY, TEST_CHECKPOINT_NUM(12));
}
/* Read data using invalid generator handle */
status = val->crypto_function(VAL_CRYPTO_GENERATOR_READ, &invalid_generator,
data, 1);
TEST_ASSERT_EQUAL(status, PSA_ERROR_BAD_STATE, TEST_CHECKPOINT_NUM(13));
/* Abort a generator */
status = val->crypto_function(VAL_CRYPTO_GENERATOR_ABORT, &generator);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(14));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -1,30 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef _TEST_C018_CLIENT_TESTS_H_
#define _TEST_C018_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c018)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_c018_crypto_list[];
int32_t psa_generator_read_test(security_t caller);
#endif /* _TEST_C018_CLIENT_TESTS_H_ */

View File

@ -1,97 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_crypto.h"
typedef struct {
char test_desc[75];
psa_key_handle_t key_handle;
psa_key_type_t key_type;
uint8_t key_data[32];
uint32_t key_length;
psa_key_usage_t usage;
psa_algorithm_t key_alg;
uint8_t salt[16];
size_t salt_length;
uint8_t label[16];
size_t label_length;
size_t capacity;
size_t size;
psa_status_t expected_status;
} test_data;
static test_data check1[] = {
/* Covers the following cases
* - 16 Byte key
* - SHA 256
* - Output size less than generator capacity
*/
#ifdef ARCH_TEST_HKDF
#ifdef ARCH_TEST_SHA256
{"Test psa_generator_read to get 16 Byte data with SHA-256\n", 1, PSA_KEY_TYPE_DERIVE,
{0x49, 0x8E, 0xC7, 0x7D, 0x01, 0x95, 0x0D, 0x94, 0x2C, 0x16, 0xA5, 0x3E, 0x99,
0x5F, 0xC9},
AES_16B_KEY_SIZE, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_256),
{0}, 0, {0}, 0, 32,
16, PSA_SUCCESS
},
#endif
/* Covers the following cases
* - 32 Byte key
* - SHA 512
* - Output size equal to generator capacity
*/
#ifdef ARCH_TEST_SHA512
{"Test psa_generator_read to get 32 Byte data with SHA-512\n", 2, PSA_KEY_TYPE_DERIVE,
{0xEA, 0xD5, 0xE6, 0xC8, 0x51, 0xF9, 0xEC, 0xBB, 0x9B, 0x57, 0x7C, 0xED, 0xD2,
0x4B, 0x82, 0x84, 0x9F, 0x9F, 0xE6, 0x73, 0x21, 0x3D, 0x1A, 0x05, 0xC9, 0xED,
0xDF, 0x25, 0x17, 0x68, 0x86, 0xAE},
AES_32B_KEY_SIZE, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_512),
{0}, 0, {0}, 0, 64,
64, PSA_SUCCESS
},
#endif
/* Covers the following cases
* - 8 Byte Key
* - SHA 1
* - Output size greater than the generator capacity
*/
#ifdef ARCH_TEST_SHA1
{"Test psa_generator_read to get 8 Byte data with SHA-1\n", 3, PSA_KEY_TYPE_DERIVE,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_1),
{0}, 0, {0}, 0, 64,
70, PSA_ERROR_INSUFFICIENT_CAPACITY
},
{"Test psa_generator_read to request maximum capacity\n", 4, PSA_KEY_TYPE_DERIVE,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_1),
{0}, 0, {0}, 0, (255 * 20),
(255 * 20), PSA_SUCCESS
},
{"Test psa_generator_read to request maximum capacity +1\n", 5, PSA_KEY_TYPE_DERIVE,
{0x70, 0x24, 0x55, 0x0C, 0x14, 0x9D, 0xED, 0x29},
DES_8B_KEY_SIZE, PSA_KEY_USAGE_DERIVE, PSA_ALG_HKDF(PSA_ALG_SHA_1),
{0}, 0, {0}, 0, (255 * 20),
((255 * 20) + 1), PSA_ERROR_INSUFFICIENT_CAPACITY
},
#endif
#endif
};

View File

@ -1,53 +0,0 @@
/** @file
* Copyright (c) 2019, Arm Limited or its affiliates. All rights reserved.
* SPDX-License-Identifier : Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "val_interfaces.h"
#include "val_target.h"
#include "test_c018.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_CRYPTO_BASE, 18)
#define TEST_DESC "Testing crypto generator functions APIs\n"
TEST_PUBLISH(TEST_NUM, test_entry);
val_api_t *val = NULL;
psa_api_t *psa = NULL;
void test_entry(val_api_t *val_api, psa_api_t *psa_api)
{
int32_t status = VAL_STATUS_SUCCESS;
val = val_api;
psa = psa_api;
/* test init */
val->test_init(TEST_NUM, TEST_DESC, TEST_FIELD(TEST_ISOLATION_L1, WD_HIGH_TIMEOUT));
if (!IS_TEST_START(val->get_status()))
{
goto test_exit;
}
/* Execute list of tests available in test[num]_crypto_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_c018_crypto_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->crypto_function(VAL_CRYPTO_FREE);
val->test_exit();
}

View File

@ -1,9 +0,0 @@
#include "val_interfaces.h"
#include "pal_mbed_os_intf.h"
void test_entry_c019(val_api_t *val_api, psa_api_t *psa_api);
int main(void)
{
test_start(test_entry_c019, COMPLIANCE_TEST_CRYPTO);
}

Some files were not shown because too many files have changed in this diff Show More