Add tests to PSA entropy injection

pull/8804/head
Mohammad AboMokh 2018-11-21 17:19:23 +02:00 committed by mohammad1603
parent 587fdbb447
commit 1325084b1a
13 changed files with 778 additions and 0 deletions

View File

@ -0,0 +1,95 @@
/* Copyright (c) 2017-2018 ARM Limited
*
* 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.
*/
/***********************************************************************************************************************
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**********************************************************************************************************************/
#include "spm_panic.h"
#include "spm_internal.h"
#include "handles_manager.h"
#include "cmsis.h"
#include "psa_test_its_reset_partition.h"
#include "psa_its_partition.h"
#include "psa_psa_f_partition.h"
extern const uint32_t psa_f_external_sids[4];
spm_partition_t g_partitions[3] = {
{
.partition_id = TEST_ITS_RESET_ID,
.thread_id = 0,
.flags_rot_srv = TEST_ITS_RESET_WAIT_ANY_SID_MSK,
.flags_interrupts = 0,
.rot_services = NULL,
.rot_services_count = TEST_ITS_RESET_ROT_SRV_COUNT,
.extern_sids = NULL,
.extern_sids_count = TEST_ITS_RESET_EXT_ROT_SRV_COUNT,
.irq_mapper = NULL,
},
{
.partition_id = ITS_ID,
.thread_id = 0,
.flags_rot_srv = ITS_WAIT_ANY_SID_MSK,
.flags_interrupts = 0,
.rot_services = NULL,
.rot_services_count = ITS_ROT_SRV_COUNT,
.extern_sids = NULL,
.extern_sids_count = ITS_EXT_ROT_SRV_COUNT,
.irq_mapper = NULL,
},
{
.partition_id = PSA_F_ID,
.thread_id = 0,
.flags_rot_srv = PSA_F_WAIT_ANY_SID_MSK,
.flags_interrupts = 0,
.rot_services = NULL,
.rot_services_count = PSA_F_ROT_SRV_COUNT,
.extern_sids = psa_f_external_sids,
.extern_sids_count = PSA_F_EXT_ROT_SRV_COUNT,
.irq_mapper = NULL,
},
};
/* Check all the defined memory regions for overlapping. */
/* A list of all the memory regions. */
const mem_region_t *mem_regions = NULL;
const uint32_t mem_region_count = 0;
// forward declaration of partition initializers
void test_its_reset_init(spm_partition_t *partition);
void its_init(spm_partition_t *partition);
void psa_f_init(spm_partition_t *partition);
uint32_t init_partitions(spm_partition_t **partitions)
{
if (NULL == partitions) {
SPM_PANIC("partitions is NULL!\n");
}
test_its_reset_init(&(g_partitions[0]));
its_init(&(g_partitions[1]));
psa_f_init(&(g_partitions[2]));
*partitions = g_partitions;
return 3;
}

View File

@ -0,0 +1,28 @@
/* Copyright (c) 2018 ARM Limited
*
* 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 TARGET_PSA
#error [NOT_SUPPORTED] ITS tests can run only on PSA-enabled targets.
#endif // TARGET_PSA
#include "test_pits.h"
#include "test_pits_impl.h"
psa_its_status_t test_psa_its_reset(void)
{
return test_psa_its_reset_impl();
}

View File

@ -0,0 +1,59 @@
/* Copyright (c) 2018 ARM Limited
*
* 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 <string.h>
#include <stdlib.h>
#include "psa_prot_internal_storage.h"
#include "test_pits_impl.h"
#include "kv_config.h"
#include "KVMap.h"
#include "KVStore.h"
#include "mbed_error.h"
#ifdef __cplusplus
extern "C"
{
#endif
using namespace mbed;
#define STR_EXPAND(tok) #tok
psa_its_status_t test_psa_its_reset_impl(void)
{
psa_its_status_t status = PSA_ITS_SUCCESS;
int kv_status = kv_init_storage_config();
if (kv_status != MBED_SUCCESS) {
return PSA_ITS_ERROR_STORAGE_FAILURE;
}
KVMap &kv_map = KVMap::get_instance();
KVStore *kvstore = kv_map.get_main_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
if (!kvstore) {
return PSA_ITS_ERROR_STORAGE_FAILURE;
}
if (kvstore->reset() != MBED_SUCCESS) {
status = PSA_ITS_ERROR_STORAGE_FAILURE;
}
return status;
}
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,34 @@
/* Copyright (c) 2018 ARM Limited
*
* 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 __PITS_IMPL_H__
#define __PITS_IMPL_H__
#include "psa_prot_internal_storage.h"
#ifdef __cplusplus
extern "C"
{
#endif
psa_its_status_t test_psa_its_reset_impl(void);
#ifdef __cplusplus
}
#endif
#endif // __PITS_IMPL_H__

View File

@ -0,0 +1,37 @@
/* Copyright (c) 2017-2018 ARM Limited
*
* 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 "spm_client.h"
#include "psa_prot_internal_storage.h"
#include "test_pits.h"
#include "psa_test_its_reset_ifs.h"
psa_its_status_t test_psa_its_reset(void)
{
psa_handle_t conn = psa_connect(TEST_PSA_ITS_RESET, 1);
if (conn <= PSA_NULL_HANDLE) {
return PSA_ITS_ERROR_STORAGE_FAILURE;
}
psa_error_t status = psa_call(conn, NULL, 0, NULL, 0);
if (status == PSA_DROP_CONNECTION) {
status = PSA_ITS_ERROR_STORAGE_FAILURE;
}
psa_close(conn);
return status;
}

View File

@ -0,0 +1,99 @@
/* Copyright (c) 2017-2018 ARM Limited
*
* 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.
*/
/***********************************************************************************************************************
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**********************************************************************************************************************/
#include "cmsis.h"
#include "mbed_toolchain.h" /* For using MBED_ALIGN macro */
#include "rtx_os.h"
#include "spm_panic.h"
#include "spm_internal.h"
#include "psa_test_its_reset_partition.h"
#include "psa_test_its_reset_ifs.h"
/* Threads stacks */
MBED_ALIGN(8) uint8_t test_its_reset_thread_stack[1024] = {0};
/* Threads control blocks */
osRtxThread_t test_its_reset_thread_cb = {0};
/* Thread attributes - for thread initialization */
osThreadAttr_t test_its_reset_thread_attr = {
.name = "test_its_reset",
.attr_bits = 0,
.cb_mem = &test_its_reset_thread_cb,
.cb_size = sizeof(test_its_reset_thread_cb),
.stack_mem = test_its_reset_thread_stack,
.stack_size = 1024,
.priority = osPriorityNormal,
.tz_module = 0,
.reserved = 0
};
spm_rot_service_t test_its_reset_rot_services[TEST_ITS_RESET_ROT_SRV_COUNT] = {
{
.sid = TEST_PSA_ITS_RESET,
.mask = TEST_PSA_ITS_RESET_MSK,
.partition = NULL,
.min_version = 1,
.min_version_policy = PSA_MINOR_VERSION_POLICY_RELAXED,
.allow_nspe = true,
.queue = {
.head = NULL,
.tail = NULL
}
},
};
static osRtxMutex_t test_its_reset_mutex = {0};
static const osMutexAttr_t test_its_reset_mutex_attr = {
.name = "test_its_reset_mutex",
.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust,
.cb_mem = &test_its_reset_mutex,
.cb_size = sizeof(test_its_reset_mutex),
};
extern void test_pits_entry(void *ptr);
void test_its_reset_init(spm_partition_t *partition)
{
if (NULL == partition) {
SPM_PANIC("partition is NULL!\n");
}
partition->mutex = osMutexNew(&test_its_reset_mutex_attr);
if (NULL == partition->mutex) {
SPM_PANIC("Failed to create mutex for secure partition test_its_reset!\n");
}
for (uint32_t i = 0; i < TEST_ITS_RESET_ROT_SRV_COUNT; ++i) {
test_its_reset_rot_services[i].partition = partition;
}
partition->rot_services = test_its_reset_rot_services;
partition->thread_id = osThreadNew(test_pits_entry, NULL, &test_its_reset_thread_attr);
if (NULL == partition->thread_id) {
SPM_PANIC("Failed to create start main thread of partition test_its_reset!\n");
}
}

View File

@ -0,0 +1,54 @@
/* Copyright (c) 2017-2018 ARM Limited
*
* 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.
*/
/***********************************************************************************************************************
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**********************************************************************************************************************/
#ifndef PSA_TEST_ITS_RESET_PARTITION_H
#define PSA_TEST_ITS_RESET_PARTITION_H
#define TEST_ITS_RESET_ID 11
#define TEST_ITS_RESET_ROT_SRV_COUNT (1UL)
#define TEST_ITS_RESET_EXT_ROT_SRV_COUNT (0UL)
/* TEST_ITS_RESET event flags */
#define TEST_ITS_RESET_RESERVED1_POS (1UL)
#define TEST_ITS_RESET_RESERVED1_MSK (1UL << TEST_ITS_RESET_RESERVED1_POS)
#define TEST_ITS_RESET_RESERVED2_POS (2UL)
#define TEST_ITS_RESET_RESERVED2_MSK (1UL << TEST_ITS_RESET_RESERVED2_POS)
#define TEST_PSA_ITS_RESET_MSK_POS (4UL)
#define TEST_PSA_ITS_RESET_MSK (1UL << TEST_PSA_ITS_RESET_MSK_POS)
#define TEST_ITS_RESET_WAIT_ANY_SID_MSK (\
TEST_PSA_ITS_RESET_MSK)
/*
#define TEST_ITS_RESET_WAIT_ANY_MSK (\
TEST_ITS_RESET_WAIT_ANY_SID_MSK) | \
PSA_DOORBELL)
*/
#endif // PSA_TEST_ITS_RESET_PARTITION_H

View File

@ -0,0 +1,59 @@
/* Copyright (c) 2018 ARM Limited
*
* 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 <string.h>
#include <stdlib.h>
#include "psa_prot_internal_storage.h"
#include "test_pits_impl.h"
#include "kv_config.h"
#include "KVMap.h"
#include "KVStore.h"
#include "mbed_error.h"
#ifdef __cplusplus
extern "C"
{
#endif
using namespace mbed;
#define STR_EXPAND(tok) #tok
psa_its_status_t test_psa_its_reset_impl(void)
{
psa_its_status_t status = PSA_ITS_SUCCESS;
int kv_status = kv_init_storage_config();
if (kv_status != MBED_SUCCESS) {
return PSA_ITS_ERROR_STORAGE_FAILURE;
}
KVMap &kv_map = KVMap::get_instance();
KVStore *kvstore = kv_map.get_main_kv_instance(STR_EXPAND(MBED_CONF_STORAGE_DEFAULT_KV));
if (!kvstore) {
return PSA_ITS_ERROR_STORAGE_FAILURE;
}
if (kvstore->reset() != MBED_SUCCESS) {
status = PSA_ITS_ERROR_STORAGE_FAILURE;
}
return status;
}
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,65 @@
/* Copyright (c) 2017-2018 ARM Limited
*
* 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.
*/
// -------------------------------------- Includes -----------------------------------
#include <string.h>
#include "cmsis_os2.h"
#include "spm_server.h"
#include "spm_panic.h"
#include "psa_test_its_reset_partition.h"
#include "psa_prot_internal_storage.h"
#include "test_pits_impl.h"
#ifdef __cplusplus
extern "C"
{
#endif
void test_pits_entry(void *ptr)
{
uint32_t signals = 0;
psa_msg_t msg = {0};
psa_error_t status = PSA_SUCCESS;
while (1) {
signals = psa_wait_any(PSA_BLOCK);
if ((signals & TEST_PSA_ITS_RESET_MSK) != 0) {
psa_get(TEST_PSA_ITS_RESET_MSK, &msg);
switch (msg.type) {
case PSA_IPC_CONNECT: //fallthrough
case PSA_IPC_DISCONNECT: {
break;
}
case PSA_IPC_CALL: {
status = test_psa_its_reset_impl();
break;
}
default: {
SPM_PANIC("Unexpected message type %d!", (int)(msg.type));
break;
}
}
psa_reply(msg.handle, status);
}
}
}
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,29 @@
/* Copyright (c) 2017-2018 ARM Limited
*
* 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.
*/
/***********************************************************************************************************************
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* THIS FILE IS AN AUTO-GENERATED FILE - DO NOT MODIFY IT.
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
**********************************************************************************************************************/
#ifndef PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H
#define PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H
#define TEST_PSA_ITS_RESET 0x00011A04
#endif // PSA_TEST_ITS_RESET_PARTITION_ROT_SERVICES_H

View File

@ -0,0 +1,50 @@
/* Copyright (c) 2018 ARM Limited
*
* 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_INTERNAL_TRUSTED_STORAGE_H__
#define __TEST_INTERNAL_TRUSTED_STORAGE_H__
/** @file
@brief This file describes the PSA Internal Trusted Storage API
*/
#include <stddef.h>
#include <stdint.h>
#include "psa_prot_internal_storage.h"
#ifdef __cplusplus
extern "C"
{
#endif
/**
* \brief Remove the provided key and its associated data from the storage
*
* \param[in] uid The uid value
*
* \return A status indicating the success/failure of the operation
*
* \retval PSA_ITS_SUCCESS The operation completed successfully
* \retval PSA_ITS_ERROR_STORAGE_FAILURE The operation failed because the physical storage has failed (Fatal error)
*/
psa_its_status_t test_psa_its_reset(void);
#ifdef __cplusplus
}
#endif
#endif // __TEST_INTERNAL_TRUSTED_STORAGE_H__

View File

@ -0,0 +1,21 @@
{
"name": "TEST_ITS_RESET",
"type": "APPLICATION-ROT",
"priority": "NORMAL",
"id": "0x0000000B",
"entry_point": "test_pits_entry",
"stack_size": "0x400",
"heap_size": "0x400",
"services": [{
"name": "TEST_PSA_ITS_RESET",
"identifier": "0x00011A04",
"signal": "TEST_PSA_ITS_RESET_MSK",
"non_secure_clients": true,
"minor_version": 1,
"minor_policy": "RELAXED"
}
],
"source_files": [
"COMPONENT_SPE/test_pits_reset_partition.c"
]
}

View File

@ -0,0 +1,148 @@
/*
* Copyright (c) 2018 ARM Limited. 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 TARGET_PSA
#error [NOT_SUPPORTED] PSA entropy injection tests can run only on PSA-enabled targets.
#endif // TARGET_PSA
#include "greentea-client/test_env.h"
#include "unity/unity.h"
#include "utest/utest.h"
#include "psa_prot_internal_storage.h"
#include "test_pits.h"
#include "entropy.h"
#include "entropy_poll.h"
#include "crypto.h"
using namespace utest::v1;
uint8_t seed[MBEDTLS_ENTROPY_MAX_SEED_SIZE+2] = {0};
void validate_entropy_seed_injection( int seed_length_a,
int expected_status_a,
int seed_length_b,
int expected_status_b )
{
psa_status_t status;
uint8_t output[32] = { 0 };
uint8_t zeros[32] = { 0 };
status = mbedtls_psa_inject_entropy( seed, seed_length_a );
TEST_ASSERT( status == expected_status_a );
status = mbedtls_psa_inject_entropy( seed, seed_length_b );
TEST_ASSERT( status == expected_status_b );
TEST_ASSERT( psa_crypto_init( ) == PSA_SUCCESS );
TEST_ASSERT( psa_generate_random( output, sizeof( output ) ) == PSA_SUCCESS );
TEST_ASSERT( memcmp( output , zeros, sizeof( output ) ) != 0 );
}
void run_entropy_inject_with_crypto_init( )
{
psa_its_status_t its_status;
psa_status_t status;
status = psa_crypto_init();
TEST_ASSERT( status == PSA_ERROR_INSUFFICIENT_ENTROPY );
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_MIN_PLATFORM );
TEST_ASSERT( status == PSA_SUCCESS );
status = psa_crypto_init();
TEST_ASSERT( status == PSA_SUCCESS );
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_MIN_PLATFORM );
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
mbedtls_psa_crypto_free( );
/* The seed is written by nv_seed callback functions therefore the injection will fail */
status = mbedtls_psa_inject_entropy( seed, MBEDTLS_ENTROPY_MIN_PLATFORM );
TEST_ASSERT( status == PSA_ERROR_NOT_PERMITTED );
}
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
#ifndef NO_GREENTEA
GREENTEA_SETUP(60, "default_auto");
#endif
return greentea_test_setup_handler(number_of_cases);
}
static void injection_small_good()
{
#if (MBEDTLS_ENTROPY_MIN_PLATFORM > MBEDTLS_ENTROPY_BLOCK_SIZE)
validate_entropy_seed_injection( MBEDTLS_ENTROPY_MIN_PLATFORM, PSA_SUCCESS, MBEDTLS_ENTROPY_MIN_PLATFORM, PSA_ERROR_NOT_PERMITTED);
#else
validate_entropy_seed_injection( MBEDTLS_ENTROPY_BLOCK_SIZE, PSA_SUCCESS, MBEDTLS_ENTROPY_BLOCK_SIZE, PSA_ERROR_NOT_PERMITTED);
#endif
}
static void injection_big_good()
{
validate_entropy_seed_injection(MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS, MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_ERROR_NOT_PERMITTED);
}
static void injection_too_small()
{
validate_entropy_seed_injection((MBEDTLS_ENTROPY_MIN_PLATFORM - 1), PSA_ERROR_INVALID_ARGUMENT, MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS);
}
static void injection_too_big()
{
validate_entropy_seed_injection((MBEDTLS_ENTROPY_MAX_SEED_SIZE + 1), PSA_ERROR_INVALID_ARGUMENT, MBEDTLS_ENTROPY_MAX_SEED_SIZE, PSA_SUCCESS);
}
static void injection_and_init_deinit()
{
run_entropy_inject_with_crypto_init();
}
/***************************************************************************************/
utest::v1::status_t case_teardown_handler(const Case *const source, const size_t passed, const size_t failed, const failure_t reason)
{
psa_status_t status;
status = test_psa_its_reset();
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
mbedtls_psa_crypto_free( );
return STATUS_CONTINUE;
}
utest::v1::status_t case_setup_handler(const utest::v1::Case*, unsigned int)
{
psa_status_t status;
status = test_psa_its_reset();
TEST_ASSERT_EQUAL(PSA_ITS_SUCCESS, status);
/* fill seed in some data */
for( size_t i = 0; i < MBEDTLS_ENTROPY_MAX_SEED_SIZE+2; ++i)
{
seed[i] = i;
}
return STATUS_CONTINUE;
}
Case cases[] = {
Case("PSA entropy injection small good", case_setup_handler, injection_small_good, case_teardown_handler),
Case("PSA entropy injection big good", case_setup_handler, injection_big_good, case_teardown_handler),
Case("PSA entropy injection too big", case_setup_handler, injection_too_big, case_teardown_handler),
Case("PSA entropy injection too small", case_setup_handler, injection_too_small, case_teardown_handler),
Case("PSA entropy injection before and after init", case_setup_handler, injection_and_init_deinit, case_teardown_handler),
};
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main()
{
return !Harness::run(specification);
}