Skip to content

Commit 847807e

Browse files
authored
Merge pull request #12955 from Patater/replace-mbed-psa-with-tfm
Replace Mbed PSA with TF-M PSA
2 parents 9fc1221 + 4961d4a commit 847807e

File tree

340 files changed

+27059
-4152
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

340 files changed

+27059
-4152
lines changed

.astyleignore

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,8 @@
22
^cmsis
33
^features/cryptocell
44
^features/FEATURE_BLE
5-
^features/FEATURE_EXPERIMENTAL_API/TARGET_MBED_PSA_SRV
6-
^features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/services/attestation/attestation.h
7-
^features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/services/attestation/COMPONENT_PSA_SRV_IMPL/tfm_impl
8-
^features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/services/attestation/qcbor
9-
^features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/services/crypto/COMPONENT_PSA_SRV_IPC/crypto_struct_ipc.h
10-
^features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/TARGET_TFM
11-
^features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/TESTS
5+
^features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV
6+
^features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM
127
^features/frameworks
138
^features/lwipstack/lwip
149
^features/lwipstack/lwip-sys

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,6 @@ test_suite.json
9797

9898
# default delivery dir
9999
DELIVERY/
100+
101+
# Directory used to clone and build TF-M
102+
features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_TFM/TARGET_IGNORE/

LICENSE.md

Lines changed: 3 additions & 2 deletions

TESTS/configs/baremetal.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"utest",
66
"unity",
77
"psa",
8+
"psa-services",
89
"mbedtls",
910
"psa-compliance-framework",
1011
"filesystem",

TESTS/mbed_hal/trng/main.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 ARM Limited. All rights reserved.
2+
* Copyright (c) 2018-2020 ARM Limited. All rights reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
* Licensed under the Apache License, Version 2.0 (the License); you may
55
* not use this file except in compliance with the License.
@@ -69,33 +69,6 @@
6969

7070
using namespace utest::v1;
7171

72-
#if (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
73-
#include "entropy.h"
74-
#include "entropy_poll.h"
75-
#include "crypto.h"
76-
#if !defined(MAX)
77-
#define MAX(a,b) (((a)>(b))?(a):(b))
78-
#endif
79-
80-
/* Calculating the minimum allowed entropy size in bytes */
81-
#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE \
82-
MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
83-
84-
void inject_entropy_for_psa()
85-
{
86-
if (psa_crypto_init() == PSA_ERROR_INSUFFICIENT_ENTROPY) {
87-
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
88-
/* inject some a seed for test*/
89-
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
90-
seed[i] = i;
91-
}
92-
93-
/* don't really care if this succeed this is just to make crypto init pass*/
94-
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
95-
}
96-
}
97-
#endif // (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
98-
9972
static int fill_buffer_trng(uint8_t *buffer, trng_t *trng_obj, size_t trng_len)
10073
{
10174
size_t temp_size = 0, output_length = 0;
@@ -275,9 +248,6 @@ int main()
275248
#if defined(MBEDTLS_PLATFORM_C)
276249
ret = mbedtls_platform_setup(NULL);
277250
#endif /* MBEDTLS_PLATFORM_C */
278-
#if (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
279-
inject_entropy_for_psa();
280-
#endif
281251
ret = !Harness::run(specification);
282252
#if defined(MBEDTLS_PLATFORM_C)
283253
mbedtls_platform_teardown(NULL);

TESTS/mbedtls/sanity/main.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Arm Limited and affiliates
2+
* Copyright (c) 2018-2020, Arm Limited and affiliates
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,12 +15,11 @@
1515
* limitations under the License.
1616
*/
1717

18-
#if ((!defined(TARGET_PSA)) || (!defined(MBEDTLS_PSA_CRYPTO_C)))
18+
#if ((!defined(FEATURE_PSA)) || (!defined(MBEDTLS_PSA_CRYPTO_C)))
1919
#error [NOT_SUPPORTED] Mbed Crypto is OFF - skipping.
2020
#else
2121

2222
#include "psa/crypto.h"
23-
2423
#include <stdio.h>
2524
#include "mbed.h"
2625
#include "greentea-client/test_env.h"
@@ -31,7 +30,7 @@
3130

3231
using namespace utest::v1;
3332

34-
#if defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
33+
#if defined(MBEDTLS_ENTROPY_NV_SEED)
3534

3635
#if !defined(MAX)
3736
#define MAX(a,b) (((a)>(b))?(a):(b))
@@ -48,7 +47,7 @@ void inject_entropy()
4847
}
4948
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
5049
}
51-
#endif // defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
50+
#endif // defined(MBEDTLS_ENTROPY_NV_SEED)
5251

5352
void test_crypto_random(void)
5453
{
@@ -431,12 +430,12 @@ void test_crypto_hash_clone(void)
431430
utest::v1::status_t case_setup_handler(const Case *const source, const size_t index_of_case)
432431
{
433432
psa_status_t status = psa_crypto_init();
434-
#if defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC)
433+
#if defined(MBEDTLS_ENTROPY_NV_SEED)
435434
if (status == PSA_ERROR_INSUFFICIENT_ENTROPY) {
436435
inject_entropy();
437436
status = psa_crypto_init();
438437
}
439-
#endif /* defined(MBEDTLS_ENTROPY_NV_SEED) || defined(COMPONENT_PSA_SRV_IPC) */
438+
#endif /* defined(MBEDTLS_ENTROPY_NV_SEED) */
440439
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
441440
return greentea_case_setup_handler(source, index_of_case);
442441
}

TESTS/mbedtls/selftest/main.cpp

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2016 ARM Limited
2+
* Copyright (c) 2016-2020 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -87,32 +87,6 @@ Case cases[] = {
8787
#endif /* MBEDTLS_SELF_TEST */
8888
};
8989

90-
#if (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
91-
#include "crypto.h"
92-
#if !defined(MAX)
93-
#define MAX(a,b) (((a)>(b))?(a):(b))
94-
#endif
95-
96-
/* Calculating the minimum allowed entropy size in bytes */
97-
#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE \
98-
MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
99-
100-
void inject_entropy_for_psa()
101-
{
102-
if (psa_crypto_init() == PSA_ERROR_INSUFFICIENT_ENTROPY) {
103-
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
104-
/* inject some a seed for test*/
105-
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
106-
seed[i] = i;
107-
}
108-
109-
/* don't really care if this succeed this is just to make crypto init pass*/
110-
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
111-
}
112-
}
113-
#endif // (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
114-
115-
11690
utest::v1::status_t test_setup(const size_t num_cases)
11791
{
11892
GREENTEA_SETUP(120, "default_auto");
@@ -131,10 +105,6 @@ int main()
131105
}
132106
#endif
133107

134-
#if (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
135-
inject_entropy_for_psa();
136-
#endif
137-
138108
ret = (Harness::run(specification) ? 0 : 1);
139109
#if defined(MBEDTLS_PLATFORM_C)
140110
mbedtls_platform_teardown(NULL);

cmsis/TARGET_CORTEX_M/mbed_tz_context.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* @date 10. January 2018
66
******************************************************************************/
77
/*
8-
* Copyright (c) 2016-2018 Arm Limited. All rights reserved.
8+
* Copyright (c) 2016-2020 Arm Limited. All rights reserved.
99
*
1010
* SPDX-License-Identifier: Apache-2.0
1111
*
@@ -22,7 +22,7 @@
2222
* limitations under the License.
2323
*/
2424

25-
#if !TARGET_TFM
25+
#if !FEATURE_TFM
2626

2727
#if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
2828

@@ -204,4 +204,4 @@ uint32_t TZ_StoreContext_S (TZ_MemoryId_t id) {
204204
}
205205
#endif
206206

207-
#endif // !TARGET_TFM
207+
#endif // !FEATURE_TFM

features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/TESTS/attestation/main.cpp renamed to features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/attestation/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019 ARM Limited. All rights reserved.
2+
* Copyright (c) 2019-2020 ARM Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -135,7 +135,7 @@ utest::v1::status_t case_setup_handler(const Case *const source, const size_t in
135135
psa_status_t status;
136136
status = mbed_psa_reboot_and_request_new_security_state(PSA_LIFECYCLE_ASSEMBLY_AND_TEST);
137137
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
138-
#if (defined(COMPONENT_PSA_SRV_IPC) || defined(MBEDTLS_ENTROPY_NV_SEED))
138+
#if defined(MBEDTLS_ENTROPY_NV_SEED)
139139
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
140140
/* inject some seed for test*/
141141
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {

features/FEATURE_EXPERIMENTAL_API/TARGET_PSA/TARGET_MBED_PSA_SRV/TESTS/crypto_init/main.cpp renamed to features/FEATURE_EXPERIMENTAL_API/FEATURE_PSA/TARGET_MBED_PSA_SRV/TESTS/crypto_init/main.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018 ARM Limited. All rights reserved.
2+
* Copyright (c) 2018-2020 ARM Limited. All rights reserved.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
@@ -46,31 +46,6 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
4646
return greentea_test_setup_handler(number_of_cases);
4747
}
4848

49-
static void check_multi_crypto_init_deinit()
50-
{
51-
#if !defined(COMPONENT_PSA_SRV_IPC)
52-
TEST_SKIP();
53-
#endif
54-
uint8_t output[TEST_RANDOM_SIZE] = {0};
55-
56-
psa_status_t status = psa_crypto_init();
57-
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
58-
59-
status = psa_crypto_init();
60-
TEST_ASSERT_EQUAL(PSA_SUCCESS, status);
61-
62-
status = psa_generate_random(output, sizeof(output));
63-
TEST_ASSERT_NOT_EQUAL(PSA_ERROR_BAD_STATE, status);
64-
65-
mbedtls_psa_crypto_free();
66-
status = psa_generate_random(output, sizeof(output));
67-
TEST_ASSERT_NOT_EQUAL(PSA_ERROR_BAD_STATE, status);
68-
69-
mbedtls_psa_crypto_free();
70-
status = psa_generate_random(output, sizeof(output));
71-
TEST_ASSERT_EQUAL(PSA_ERROR_BAD_STATE, status);
72-
}
73-
7449
static void check_crypto_init_deinit()
7550
{
7651
psa_status_t status;
@@ -93,14 +68,13 @@ static void check_crypto_init_deinit()
9368

9469
Case cases[] = {
9570
Case("PSA crypto-init De-init", check_crypto_init_deinit),
96-
Case("PSA crypto- multiple init De-init", check_multi_crypto_init_deinit),
9771
};
9872

9973
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
10074

10175
int main()
10276
{
103-
#if (defined(COMPONENT_PSA_SRV_IPC) || defined(MBEDTLS_ENTROPY_NV_SEED))
77+
#if defined(MBEDTLS_ENTROPY_NV_SEED)
10478
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
10579
/* inject some a seed for test*/
10680
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {

0 commit comments

Comments
 (0)