Fix PSA-HAL, TRNG, TLS tests

pull/8745/head
Oren Cohen 2018-12-05 19:40:59 +02:00 committed by Oren Cohen
parent 251a270942
commit 2df2fc7d29
No known key found for this signature in database
GPG Key ID: 6F54A3184C6F8FF9
3 changed files with 68 additions and 0 deletions

View File

@ -23,6 +23,10 @@
#error [NOT_SUPPORTED] this test is supported on GCC only
#endif
#if defined(TARGET_FUTURE_SEQUANA_PSA)
#error [NOT_SUPPORTED] Disable this Test until FUTURE_SEQUANA_PSA enables Memory protection
#endif
#include "utest/utest.h"
#include "unity/unity.h"
#include "greentea-client/test_env.h"

View File

@ -66,6 +66,33 @@
using namespace utest::v1;
#if (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
#include "entropy.h"
#include "entropy_poll.h"
#include "crypto.h"
#if !defined(MAX)
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
/* Calculating the minimum allowed entropy size in bytes */
#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE \
MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
void inject_entropy_for_psa()
{
if (psa_crypto_init() == PSA_ERROR_INSUFFICIENT_ENTROPY) {
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
/* inject some a seed for test*/
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
seed[i] = i;
}
/* don't really care if this succeed this is just to make crypto init pass*/
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
}
}
#endif // (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
static int fill_buffer_trng(uint8_t *buffer, trng_t *trng_obj, size_t trng_len)
{
size_t temp_size = 0, output_length = 0;
@ -241,7 +268,13 @@ Specification specification(greentea_test_setup, cases, greentea_test_teardown_h
int main()
{
#if (defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
inject_entropy_for_psa();
#endif
bool ret = !Harness::run(specification);
return ret;
}

View File

@ -84,6 +84,32 @@ Case cases[] = {
#endif /* MBEDTLS_SELF_TEST */
};
#if (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
#include "crypto.h"
#if !defined(MAX)
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
/* Calculating the minimum allowed entropy size in bytes */
#define MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE \
MAX(MBEDTLS_ENTROPY_MIN_PLATFORM, MBEDTLS_ENTROPY_BLOCK_SIZE)
void inject_entropy_for_psa()
{
if (psa_crypto_init() == PSA_ERROR_INSUFFICIENT_ENTROPY) {
uint8_t seed[MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE] = {0};
/* inject some a seed for test*/
for (int i = 0; i < MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE; ++i) {
seed[i] = i;
}
/* don't really care if this succeed this is just to make crypto init pass*/
mbedtls_psa_inject_entropy(seed, MBEDTLS_PSA_INJECT_ENTROPY_MIN_SIZE);
}
}
#endif // (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
utest::v1::status_t test_setup(const size_t num_cases)
{
GREENTEA_SETUP(120, "default_auto");
@ -101,6 +127,11 @@ int main()
return 1;
}
#endif
#if (defined(MBEDTLS_ENTROPY_C) && defined(TARGET_PSA) && defined(COMPONENT_PSA_SRV_IPC) && defined(MBEDTLS_PSA_CRYPTO_C))
inject_entropy_for_psa();
#endif
ret = (Harness::run(specification) ? 0 : 1);
#if defined(MBEDTLS_PLATFORM_C)
mbedtls_platform_teardown(NULL);