Skip to content

Commit 1f29b99

Browse files
author
Netanel Gonen
committed
add tests to PSA entropy injection
1 parent 9b7136b commit 1f29b99

File tree

23 files changed

+798
-1168
lines changed

23 files changed

+798
-1168
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* Copyright (c) 2017-2018 ARM Limited
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/***********************************************************************************************************************
19+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20+
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
21+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22+
**********************************************************************************************************************/
23+
24+
#include "spm_panic.h"
25+
#include "spm_internal.h"
26+
#include "handles_manager.h"
27+
#include "cmsis.h"
28+
#include "psa_test_its_reset_partition.h"
29+
#include "psa_its_partition.h"
30+
#include "psa_psa_f_partition.h"
31+
32+
extern const uint32_t psa_f_external_sids[4];
33+
34+
spm_partition_t g_partitions[3] = {
35+
{
36+
.partition_id = TEST_ITS_RESET_ID,
37+
.thread_id = 0,
38+
.flags_rot_srv = TEST_ITS_RESET_WAIT_ANY_SID_MSK,
39+
.flags_interrupts = 0,
40+
.rot_services = NULL,
41+
.rot_services_count = TEST_ITS_RESET_ROT_SRV_COUNT,
42+
.extern_sids = NULL,
43+
.extern_sids_count = TEST_ITS_RESET_EXT_ROT_SRV_COUNT,
44+
.irq_mapper = NULL,
45+
},
46+
{
47+
.partition_id = ITS_ID,
48+
.thread_id = 0,
49+
.flags_rot_srv = ITS_WAIT_ANY_SID_MSK,
50+
.flags_interrupts = 0,
51+
.rot_services = NULL,
52+
.rot_services_count = ITS_ROT_SRV_COUNT,
53+
.extern_sids = NULL,
54+
.extern_sids_count = ITS_EXT_ROT_SRV_COUNT,
55+
.irq_mapper = NULL,
56+
},
57+
{
58+
.partition_id = PSA_F_ID,
59+
.thread_id = 0,
60+
.flags_rot_srv = PSA_F_WAIT_ANY_SID_MSK,
61+
.flags_interrupts = 0,
62+
.rot_services = NULL,
63+
.rot_services_count = PSA_F_ROT_SRV_COUNT,
64+
.extern_sids = psa_f_external_sids,
65+
.extern_sids_count = PSA_F_EXT_ROT_SRV_COUNT,
66+
.irq_mapper = NULL,
67+
},
68+
};
69+
70+
/* Check all the defined memory regions for overlapping. */
71+
72+
/* A list of all the memory regions. */
73+
const mem_region_t *mem_regions = NULL;
74+
75+
const uint32_t mem_region_count = 0;
76+
77+
// forward declaration of partition initializers
78+
void test_its_reset_init(spm_partition_t *partition);
79+
void its_init(spm_partition_t *partition);
80+
void psa_f_init(spm_partition_t *partition);
81+
82+
uint32_t init_partitions(spm_partition_t **partitions)
83+
{
84+
if (NULL == partitions) {
85+
SPM_PANIC("partitions is NULL!\n");
86+
}
87+
88+
test_its_reset_init(&(g_partitions[0]));
89+
its_init(&(g_partitions[1]));
90+
psa_f_init(&(g_partitions[2]));
91+
92+
*partitions = g_partitions;
93+
return 3;
94+
}
95+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* Copyright (c) 2018 ARM Limited
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef TARGET_PSA
19+
#error [NOT_SUPPORTED] ITS tests can run only on PSA-enabled targets.
20+
#endif // TARGET_PSA
21+
22+
#include "test_pits.h"
23+
#include "test_pits_impl.h"
24+
25+
psa_its_status_t test_psa_its_reset(void)
26+
{
27+
return test_psa_its_reset_impl();
28+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/* Copyright (c) 2018 ARM Limited
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#include <string.h>
18+
#include <stdlib.h>
19+
#include "psa_prot_internal_storage.h"
20+
#include "test_pits_impl.h"
21+
#include "kv_config.h"
22+
#include "KVMap.h"
23+
#include "KVStore.h"
24+
#include "mbed_error.h"
25+
26+
#ifdef __cplusplus
27+
extern "C"
28+
{
29+
#endif
30+
31+
using namespace mbed;
32+
33+
#define STR_EXPAND(tok) #tok
34+
35+
psa_its_status_t test_psa_its_reset_impl(void)
36+
{
37+
psa_its_status_t status = PSA_ITS_SUCCESS;
38+
39+
int kv_status = kv_init_storage_config();
40+
if (kv_status != MBED_SUCCESS) {
41+
return PSA_ITS_ERROR_STORAGE_FAILURE;
42+
}
43+
44+
KVMap &kv_map = KVMap::get_instance();
45+
KVStore *kvstore = kv_map.get_main_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
46+
if (!kvstore) {
47+
return PSA_ITS_ERROR_STORAGE_FAILURE;
48+
}
49+
50+
if (kvstore->reset() != MBED_SUCCESS) {
51+
status = PSA_ITS_ERROR_STORAGE_FAILURE;
52+
}
53+
54+
return status;
55+
}
56+
57+
#ifdef __cplusplus
58+
}
59+
#endif
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/* Copyright (c) 2018 ARM Limited
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef __PITS_IMPL_H__
19+
#define __PITS_IMPL_H__
20+
21+
#include "psa_prot_internal_storage.h"
22+
23+
#ifdef __cplusplus
24+
extern "C"
25+
{
26+
#endif
27+
28+
psa_its_status_t test_psa_its_reset_impl(void);
29+
30+
#ifdef __cplusplus
31+
}
32+
#endif
33+
34+
#endif // __PITS_IMPL_H__
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* Copyright (c) 2017-2018 ARM Limited
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "spm_client.h"
19+
#include "psa_prot_internal_storage.h"
20+
#include "test_pits.h"
21+
#include "psa_test_its_reset_ifs.h"
22+
23+
psa_its_status_t test_psa_its_reset(void)
24+
{
25+
psa_handle_t conn = psa_connect(TEST_PSA_ITS_RESET, 1);
26+
if (conn <= PSA_NULL_HANDLE) {
27+
return PSA_ITS_ERROR_STORAGE_FAILURE;
28+
}
29+
30+
psa_error_t status = psa_call(conn, NULL, 0, NULL, 0);
31+
if (status == PSA_DROP_CONNECTION) {
32+
status = PSA_ITS_ERROR_STORAGE_FAILURE;
33+
}
34+
35+
psa_close(conn);
36+
return status;
37+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/* Copyright (c) 2017-2018 ARM Limited
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
/***********************************************************************************************************************
19+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
20+
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
21+
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
22+
**********************************************************************************************************************/
23+
24+
#include "cmsis.h"
25+
#include "mbed_toolchain.h" /* For using MBED_ALIGN macro */
26+
#include "rtx_os.h"
27+
#include "spm_panic.h"
28+
#include "spm_internal.h"
29+
#include "psa_test_its_reset_partition.h"
30+
#include "psa_test_its_reset_ifs.h"
31+
32+
33+
/* Threads stacks */
34+
MBED_ALIGN(8) uint8_t test_its_reset_thread_stack[1024] = {0};
35+
36+
/* Threads control blocks */
37+
osRtxThread_t test_its_reset_thread_cb = {0};
38+
39+
/* Thread attributes - for thread initialization */
40+
osThreadAttr_t test_its_reset_thread_attr = {
41+
.name = "test_its_reset",
42+
.attr_bits = 0,
43+
.cb_mem = &test_its_reset_thread_cb,
44+
.cb_size = sizeof(test_its_reset_thread_cb),
45+
.stack_mem = test_its_reset_thread_stack,
46+
.stack_size = 1024,
47+
.priority = osPriorityNormal,
48+
.tz_module = 0,
49+
.reserved = 0
50+
};
51+
52+
spm_rot_service_t test_its_reset_rot_services[TEST_ITS_RESET_ROT_SRV_COUNT] = {
53+
{
54+
.sid = TEST_PSA_ITS_RESET,
55+
.mask = TEST_PSA_ITS_RESET_MSK,
56+
.partition = NULL,
57+
.min_version = 1,
58+
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
59+
.allow_nspe = true,
60+
.queue = {
61+
.head = NULL,
62+
.tail = NULL
63+
}
64+
},
65+
};
66+
67+
68+
static osRtxMutex_t test_its_reset_mutex = {0};
69+
static const osMutexAttr_t test_its_reset_mutex_attr = {
70+
.name = "test_its_reset_mutex",
71+
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
72+
.cb_mem = &test_its_reset_mutex,
73+
.cb_size = sizeof(test_its_reset_mutex),
74+
};
75+
76+
77+
extern void test_pits_entry(void *ptr);
78+
79+
void test_its_reset_init(spm_partition_t *partition)
80+
{
81+
if (NULL == partition) {
82+
SPM_PANIC("partition is NULL!\n");
83+
}
84+
85+
partition->mutex = osMutexNew(&test_its_reset_mutex_attr);
86+
if (NULL == partition->mutex) {
87+
SPM_PANIC("Failed to create mutex for secure partition test_its_reset!\n");
88+
}
89+
90+
for (uint32_t i = 0; i < TEST_ITS_RESET_ROT_SRV_COUNT; ++i) {
91+
test_its_reset_rot_services[i].partition = partition;
92+
}
93+
partition->rot_services = test_its_reset_rot_services;
94+
95+
partition->thread_id = osThreadNew(test_pits_entry, NULL, &test_its_reset_thread_attr);
96+
if (NULL == partition->thread_id) {
97+
SPM_PANIC("Failed to create start main thread of partition test_its_reset!\n");
98+
}
99+
}

0 commit comments

Comments
 (0)