[api-tests]: Updated to cb58d2c

pull/9312/head
Nir Sonnenschein 2019-03-03 15:51:26 +02:00
parent ca06f94c67
commit b64fb53d43
302 changed files with 25649 additions and 0 deletions

View File

@ -0,0 +1,22 @@
# PSA Initial Attestation Testcase checklist
| Test | Return value | API | Test Algorithm | Test Cases |
|-----------|--------------------------------------|-------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| test_a001 | PSA_ATTEST_ERR_SUCCESS | psa_initial_attest_get_token()<br />psa_initial_attest_get_token_size() | 1. Provide correct inputs to API with described challenge sizes <br />2. Expect API to return this define as return value each time <br />3. Verify the token | 1. Challenge_size = 32 <br />2. Challenge_size = 48 <br />3. Challenge_size = 64 |
| | PSA_ATTEST_ERR_INVALID_INPUT | psa_initial_attest_get_token()<br />psa_initial_attest_get_token_size() | 1. Provide described challenge sizes to the API along with other valid parameters <br />2. Expect API to return this define as return value each time | 1. Challenge_size is zero <br />2. Invalid challenge size between 0 and 32 <br />3. Invalid challenge size between 32 and 64 <br />4. Challenge_size is greater than MAX_CHALLENGE_SIZE |
| | PSA_ATTEST_ERR_TOKEN_BUFFER_OVERFLOW | psa_initial_attest_get_token() | 1. Provide described taken size to the API along with other valid parameters <br />2. Expect API to return this define as return value each time | Pass the token_size which less than actual/required token size |
| | PSA_ATTEST_ERR_INIT_FAILED | psa_initial_attest_get_token()<br />psa_initial_attest_get_token_size() | Can't simulate. Test can't generate stimulus where attestation initialisation fails | |
| | PSA_ATTEST_ERR_CLAIM_UNAVAILABLE | psa_initial_attest_get_token() | Can't simulate. Test can't generate stimulus where claim can unavailable | |
| | PSA_ATTEST_ERR_GENERAL | psa_initial_attest_get_token()<br />psa_initial_attest_get_token_size() | Can't simulate. Test can't generate stimulus where unexpected error happened during API operation | |
## Note
1. In verifying the token, only the data type of claims and presence of the mandatory claims are checked and the values of the claims are not checked.
2. Checks related to token signature validation will be part of future release
# License
Arm PSA test suite is distributed under Apache v2.0 License.
--------------
*Copyright (c) 2019, Arm Limited and Contributors. All rights reserved.*

View File

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_a001.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,105 @@
/** @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_a001.h"
#include "test_data.h"
client_test_t test_a001_attestation_list[] = {
NULL,
psa_initial_attestation_get_token_test,
psa_initial_attestation_get_token_size_test,
NULL,
};
static int g_test_count = 1;
int32_t psa_initial_attestation_get_token_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
uint32_t i, status, token_size;
uint8_t challenge[PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64+1];
uint8_t token_buffer[TOKEN_SIZE];
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(challenge, 0x2a, sizeof(challenge));
memset(token_buffer, 0, sizeof(token_buffer));
status = val->attestation_function(VAL_INITIAL_ATTEST_GET_TOKEN_SIZE,
check1[i].challenge_size, &token_size);
if (status != PSA_SUCCESS)
{
if (check1[i].challenge_size != PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32 ||
check1[i].challenge_size != PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48 ||
check1[i].challenge_size != PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64)
{
token_size = check1[i].token_size;
check1[i].challenge_size = check1[i].actual_challenge_size;
}
else
return status;
}
status = val->attestation_function(VAL_INITIAL_ATTEST_GET_TOKEN, challenge,
check1[i].challenge_size, token_buffer, &token_size);
TEST_ASSERT_EQUAL(status, check1[i].expected_status, TEST_CHECKPOINT_NUM(1));
if (check1[i].expected_status != PSA_SUCCESS)
continue;
/* Validate the token */
status = val->attestation_function(VAL_INITIAL_ATTEST_VERIFY_TOKEN, challenge,
check1[i].challenge_size, token_buffer, token_size);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(2));
}
return VAL_STATUS_SUCCESS;
}
int32_t psa_initial_attestation_get_token_size_test(security_t caller)
{
int num_checks = sizeof(check2)/sizeof(check2[0]);
uint32_t i, status, token_size;
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);
status = val->attestation_function(VAL_INITIAL_ATTEST_GET_TOKEN_SIZE,
check2[i].challenge_size, &token_size);
TEST_ASSERT_EQUAL(status, check2[i].expected_status, TEST_CHECKPOINT_NUM(1));
if (check2[i].expected_status != PSA_SUCCESS)
continue;
if (token_size < check2[i].challenge_size)
{
val->print(PRINT_ERROR, "Token size less than challenge size\n", 0);
return VAL_STATUS_INSUFFICIENT_SIZE;
}
}
return VAL_STATUS_SUCCESS;
}

View File

@ -0,0 +1,33 @@
/** @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_A001_CLIENT_TESTS_H_
#define _TEST_A001_CLIENT_TESTS_H_
#include "val_attestation.h"
#define test_entry CONCAT(test_entry_, a001)
#define val CONCAT(val,test_entry)
#define psa CONCAT(psa,test_entry)
#define TOKEN_SIZE 512
extern val_api_t *val;
extern psa_api_t *psa;
extern client_test_t test_a001_attestation_list[];
int32_t psa_initial_attestation_get_token_test(security_t caller);
int32_t psa_initial_attestation_get_token_size_test(security_t caller);
#endif /* _TEST_A001_CLIENT_TESTS_H_ */

View File

@ -0,0 +1,103 @@
/** @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_attestation.h"
typedef struct {
char test_desc[100];
uint32_t challenge_size;
uint32_t actual_challenge_size;
uint32_t token_size;
psa_status_t expected_status;
} test_data;
static test_data check1[] = {
{"Test psa_initial_attestation_get_token with Challenge 32\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32, TOKEN_SIZE, PSA_SUCCESS
},
{"Test psa_initial_attestation_get_token with Challenge 48\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48, TOKEN_SIZE, PSA_SUCCESS
},
{"Test psa_initial_attestation_get_token with Challenge 64\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64, TOKEN_SIZE, PSA_SUCCESS
},
{"Test psa_initial_attestation_get_token with zero challenge size\n",
0, 0, TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
},
{"Test psa_initial_attestation_get_token with small challenge size\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1,
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
},
{"Test psa_initial_attestation_get_token with invalid challenge size\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32+1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32+1,
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
},
{"Test psa_initial_attestation_get_token with large challenge size\n",
MAX_CHALLENGE_SIZE+1, MAX_CHALLENGE_SIZE+1, TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
},
{"Test psa_initial_attestation_get_token with zero as token size\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32,
0, PSA_ATTEST_ERR_INVALID_INPUT
},
{"Test psa_initial_attestation_get_token with small token size\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32,
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_ATTEST_ERR_TOKEN_BUFFER_OVERFLOW
},
};
static test_data check2[] = {
{"Test psa_initial_attestation_get_token_size with Challenge 32\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32, TOKEN_SIZE, PSA_SUCCESS
},
{"Test psa_initial_attestation_get_token_size with Challenge 48\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_48, TOKEN_SIZE, PSA_SUCCESS
},
{"Test psa_initial_attestation_get_token_size with Challenge 64\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_64, TOKEN_SIZE, PSA_SUCCESS
},
{"Test psa_initial_attestation_get_token_size with zero challenge size\n",
0, 0,
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
},
{"Test psa_initial_attestation_get_token_size with small challenge size\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32-1,
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
},
{"Test psa_initial_attestation_get_token_size with invalid challenge size\n",
PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32+1, PSA_INITIAL_ATTEST_CHALLENGE_SIZE_32+1,
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
},
{"Test psa_initial_attestation_get_token_size with large challenge size\n",
MAX_CHALLENGE_SIZE+1, MAX_CHALLENGE_SIZE+1,
TOKEN_SIZE, PSA_ATTEST_ERR_INVALID_INPUT
},
};

View File

@ -0,0 +1,52 @@
/** @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_a001.h"
#define TEST_NUM VAL_CREATE_TEST_ID(VAL_INITIAL_ATTESTATION_BASE, 1)
#define TEST_DESC "Testing initial attestation 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]_attestation_list from Non-secure side*/
status = val->execute_non_secure_tests(TEST_NUM, test_a001_attestation_list, FALSE);
if (VAL_ERROR(status))
{
goto test_exit;
}
test_exit:
val->test_exit();
}

View File

@ -0,0 +1,574 @@
# 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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c001.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,73 @@
/** @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

@ -0,0 +1,34 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c002.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,217 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,299 @@
/** @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,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, 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_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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c003.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,220 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,289 @@
/** @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, 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, 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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_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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c004.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,258 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,312 @@
/** @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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, 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, 0x40, 0xae,
0x01, 0x4a, 0x00, 0xcb, 0xf7};
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,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8B, 0xD4, 0x6A, 0x77, 0x55, 0xD6, 0x70, 0xD9, 0x6B, 0xBB, 0xF1, 0xEE,
0x39, 0x04, 0x38, 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_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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c005.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,182 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,274 @@
/** @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, 0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, 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_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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c006.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,178 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,273 @@
/** @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, 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01};
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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c007.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,188 @@
/** @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

@ -0,0 +1,32 @@
/** @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

@ -0,0 +1,285 @@
/** @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, 0x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f, 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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c008.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,181 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,272 @@
/** @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, 0x0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 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_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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c009.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,85 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,86 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c010.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,168 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,275 @@
/** @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, 0x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 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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c011.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,62 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,120 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c012.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,148 @@
/** @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

@ -0,0 +1,32 @@
/** @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

@ -0,0 +1,82 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c013.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,135 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,131 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c014.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,186 @@
/** @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

@ -0,0 +1,32 @@
/** @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

@ -0,0 +1,115 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c015.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,110 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,80 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c016.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,174 @@
/** @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

@ -0,0 +1,31 @@
/** @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

@ -0,0 +1,145 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c017.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,74 @@
/** @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

@ -0,0 +1,30 @@
/** @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

@ -0,0 +1,56 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c018.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,146 @@
/** @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

@ -0,0 +1,30 @@
/** @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

@ -0,0 +1,97 @@
/** @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

@ -0,0 +1,53 @@
/** @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

@ -0,0 +1,20 @@
# * 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.
#**/
CC_SOURCE = test_entry.c test_c019.c
CC_OPTIONS =
AS_SOURCE =
AS_OPTIONS =

View File

@ -0,0 +1,121 @@
/** @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_c019.h"
#include "test_data.h"
#include "val_crypto.h"
client_test_t test_c019_crypto_list[] = {
NULL,
psa_get_generator_capacity_test,
NULL,
};
static int g_test_count = 1;
static uint8_t data[BUFFER_SIZE];
int32_t psa_get_generator_capacity_test(security_t caller)
{
int num_checks = sizeof(check1)/sizeof(check1[0]);
uint32_t i, remaining_size;
size_t capacity;
psa_key_policy_t policy;
psa_crypto_generator_t 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(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));
/* Retrieve the current capacity of a generator */
status = val->crypto_function(VAL_CRYPTO_GET_GENERATOR_CAPACITY, &generator, &capacity);
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;
}
TEST_ASSERT_EQUAL(capacity, check1[i].capacity, TEST_CHECKPOINT_NUM(9));
/* Generate random bytes */
status = val->crypto_function(VAL_CRYPTO_GENERATOR_READ, &generator, data,
check1[i].size);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(10));
remaining_size = check1[i].capacity - check1[i].size;
/* Retrieve the current capacity of a generator */
status = val->crypto_function(VAL_CRYPTO_GET_GENERATOR_CAPACITY, &generator, &capacity);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(11));
TEST_ASSERT_EQUAL(capacity, remaining_size, TEST_CHECKPOINT_NUM(12));
/* Abort a generator */
status = val->crypto_function(VAL_CRYPTO_GENERATOR_ABORT, &generator);
TEST_ASSERT_EQUAL(status, PSA_SUCCESS, TEST_CHECKPOINT_NUM(13));
}
return VAL_STATUS_SUCCESS;
}

View File

@ -0,0 +1,30 @@
/** @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_C019_CLIENT_TESTS_H_
#define _TEST_C019_CLIENT_TESTS_H_
#include "val_crypto.h"
#define test_entry CONCAT(test_entry_,c019)
#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_c019_crypto_list[];
int32_t psa_get_generator_capacity_test(security_t caller);
#endif /* _TEST_C019_CLIENT_TESTS_H_ */

View File

@ -0,0 +1,70 @@
/** @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_get_capacity 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_get_capacity 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
#endif
};

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