Skip to content

Commit 2df2fc7

Browse files
Oren Cohenorenc17
authored andcommitted
Fix PSA-HAL, TRNG, TLS tests
1 parent 251a270 commit 2df2fc7

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

TESTS/mbed_hal/spm/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#error [NOT_SUPPORTED] this test is supported on GCC only
2424
#endif
2525

26+
#if defined(TARGET_FUTURE_SEQUANA_PSA)
27+
#error [NOT_SUPPORTED] Disable this Test until FUTURE_SEQUANA_PSA enables Memory protection
28+
#endif
29+
2630
#include "utest/utest.h"
2731
#include "unity/unity.h"
2832
#include "greentea-client/test_env.h"

TESTS/mbed_hal/trng/main.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@
6666

6767
using namespace utest::v1;
6868

69+
#if (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
70+
#include "entropy.h"
71+
#include "entropy_poll.h"
72+
#include "crypto.h"
73+
#if !defined(MAX)
74+
#define MAX(a,b) (((a)>(b))?(a):(b))
75+
#endif
76+
77+
/* Calculating the minimum allowed entropy size in bytes */
78+
#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE \
79+
MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
80+
81+
void inject_entropy_for_psa()
82+
{
83+
if (psa_crypto_init() == PSA_ERROR_INSUFFICIENT_ENTROPY) {
84+
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
85+
/* inject some a seed for test*/
86+
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
87+
seed[i] = i;
88+
}
89+
90+
/* don't really care if this succeed this is just to make crypto init pass*/
91+
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
92+
}
93+
}
94+
#endif // (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
95+
6996
static int fill_buffer_trng(uint8_t *buffer, trng_t *trng_obj, size_t trng_len)
7097
{
7198
size_t temp_size = 0, output_length = 0;
@@ -241,7 +268,13 @@ Specification specification(greentea_test_setup, cases, greentea_test_teardown_h
241268

242269
int main()
243270
{
271+
#if (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
272+
inject_entropy_for_psa();
273+
#endif
244274
bool ret = !Harness::run(specification);
245275

246276
return ret;
247277
}
278+
279+
280+

TESTS/mbedtls/selftest/main.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,32 @@ Case cases[] = {
8484
#endif /* MBEDTLS_SELF_TEST */
8585
};
8686

87+
#if (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
88+
#include "crypto.h"
89+
#if !defined(MAX)
90+
#define MAX(a,b) (((a)>(b))?(a):(b))
91+
#endif
92+
93+
/* Calculating the minimum allowed entropy size in bytes */
94+
#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE \
95+
MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
96+
97+
void inject_entropy_for_psa()
98+
{
99+
if (psa_crypto_init() == PSA_ERROR_INSUFFICIENT_ENTROPY) {
100+
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
101+
/* inject some a seed for test*/
102+
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
103+
seed[i] = i;
104+
}
105+
106+
/* don't really care if this succeed this is just to make crypto init pass*/
107+
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
108+
}
109+
}
110+
#endif // (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
111+
112+
87113
utest::v1::status_t test_setup(const size_t num_cases)
88114
{
89115
GREENTEA_SETUP(120, "default_auto");
@@ -101,6 +127,11 @@ int main()
101127
return 1;
102128
}
103129
#endif
130+
131+
#if (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
132+
inject_entropy_for_psa();
133+
#endif
134+
104135
ret = (Harness::run(specification) ? 0 : 1);
105136
#if defined(MBEDTLS_PLATFORM_C)
106137
mbedtls_platform_teardown(NULL);

0 commit comments

Comments
 (0)