test: mbedtls: new test for PSA crypto initialization and RNG configuration

Add a simple test to showcase how RNG can be configured on different
platforms in order to allow Mbed TLS's PSA crypto implementation to
work properly.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
This commit is contained in:
Valerio Setti 2024-08-01 10:26:37 +02:00 committed by Anas Nashif
commit f23d800094
4 changed files with 82 additions and 0 deletions

View file

@ -0,0 +1,9 @@
# Copyright (c) 2024 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(mbedtls)
target_sources(app PRIVATE src/main.c)

View file

@ -0,0 +1,6 @@
CONFIG_ZTEST_STACK_SIZE=2048
CONFIG_ZTEST=y
CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_PSA_CRYPTO_C=y
CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG=y

View file

@ -0,0 +1,26 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Test psa_crypto_init() and psa_generate_random() on the PSA implementation
* provided by Mbed TLS (platforms using TFM are filtered out in the yaml file).
*/
#include <zephyr/ztest.h>
#include <psa/crypto.h>
ZTEST_USER(test_fn, test_mbedtls_psa)
{
uint8_t tmp[64];
zassert_equal(psa_crypto_init(), PSA_SUCCESS, "psa_crypto_init failed");
zassert_equal(psa_generate_random(tmp, sizeof(tmp)), PSA_SUCCESS,
"psa_generate_random failed");
}
ZTEST_SUITE(test_fn, NULL, NULL, NULL, NULL, NULL);

View file

@ -0,0 +1,41 @@
# The goal here is to showcase that Mbed TLS's PSA crypto implementation can be
# supported on any platform. A very minimal configuration is tested here: simply
# enable support for PSA crypto APIs in Mbed TLS and then test them with:
# - psa_crypto_init() which is required before any PSA crypto operation
# - psa_generate_random() which is always available as long as PSA crypto is
# initialized.
#
# Since it might take too long to execute this test on all platforms
# supported by Zephyr, we reduce to a very small selected group whose
# characteristics are:
# - no TF-M enabled devices because we assume that the TF-M implementation
# of PSA crypto is working fine on the platforms that support TF-M.
# - platform should be testable by the CI.
# - enable CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG in order to reduce as much
# as possible usage of legacy modules in Mbed TLS.
# - pick 1 platform which supports entropy driver and 1 which does not. The
# latter case will allow to test
# CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG.
common:
filter: not CONFIG_BUILD_WITH_TFM
tags:
- mbedtls
- psa
tests:
crypto.mbedtls_psa.with_entropy_driver:
filter: CONFIG_CSPRNG_ENABLED
# Pick a platform which has an entropy driver and enable it.
integration_platforms:
- native_sim/native/64
extra_configs:
- CONFIG_ENTROPY_GENERATOR=y
crypto.mbedtls_psa.without_entropy_driver:
filter: not CONFIG_CSPRNG_ENABLED
# Pick a platform which does not have an entropy driver. In this case we
# enable the timer random generator because it's always available on all
# platforms.
integration_platforms:
- qemu_x86
extra_configs:
- CONFIG_MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG_ALLOW_NON_CSPRNG=y
- CONFIG_TEST_RANDOM_GENERATOR=y