RSE: Rename TRNG tests to Random generation
The way random generation is exposed by the BL1 shared library is
now different and not strictly related to the TRNG access, hence
rename the tests to reduce confusion.
Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: Iac23fe736e7cb40c3a6bacc6793f53be96122590
diff --git a/tests_reg/test/bl1/bl1_1/CMakeLists.txt b/tests_reg/test/bl1/bl1_1/CMakeLists.txt
index f385394..ce0a33d 100644
--- a/tests_reg/test/bl1/bl1_1/CMakeLists.txt
+++ b/tests_reg/test/bl1/bl1_1/CMakeLists.txt
@@ -1,5 +1,5 @@
#-------------------------------------------------------------------------------
-# Copyright (c) 2021-2023, Arm Limited. All rights reserved.
+# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -36,7 +36,7 @@
)
add_subdirectory(suites/crypto)
-add_subdirectory(suites/trng)
+add_subdirectory(suites/random)
add_subdirectory(suites/integration)
add_subdirectory(suites/extra)
@@ -56,7 +56,7 @@
platform_bl1_1_interface
bl1_1_shared_lib_interface
bl1_1_test_suite_crypto
- bl1_1_test_suite_trng
+ bl1_1_test_suite_random
bl1_1_test_suite_integration
${BL1_1_PLATFORM_SPECIFIC_LINK_LIBRARIES}
)
diff --git a/tests_reg/test/bl1/bl1_1/bl1_1_suites.c b/tests_reg/test/bl1/bl1_1/bl1_1_suites.c
index bd34127..8bdfcce 100644
--- a/tests_reg/test/bl1/bl1_1/bl1_1_suites.c
+++ b/tests_reg/test/bl1/bl1_1/bl1_1_suites.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,7 +8,7 @@
#include "test_framework.h"
#include "bl1_1_crypto_tests.h"
-#include "bl1_1_trng_tests.h"
+#include "bl1_1_random_generation_tests.h"
#include "bl1_1_integration_tests.h"
#include "extra_bl1_1_tests.h"
@@ -19,7 +19,7 @@
static struct test_suite_t test_suites[] = {
{®ister_testsuite_bl1_crypto_interface, 0, 0, 0},
- {®ister_testsuite_bl1_trng_interface, 0, 0, 0},
+ {®ister_testsuite_bl1_random_generation_interface, 0, 0, 0},
{®ister_testsuite_bl1_1_integration, 0, 0, 0},
#ifdef EXTRA_BL1_1_TEST_SUITE
diff --git a/tests_reg/test/bl1/bl1_1/suites/random/CMakeLists.txt b/tests_reg/test/bl1/bl1_1/suites/random/CMakeLists.txt
new file mode 100644
index 0000000..5ce316f
--- /dev/null
+++ b/tests_reg/test/bl1/bl1_1/suites/random/CMakeLists.txt
@@ -0,0 +1,25 @@
+#-------------------------------------------------------------------------------
+# SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+add_library(bl1_1_test_suite_random)
+
+target_sources(bl1_1_test_suite_random
+ PRIVATE
+ bl1_1_random_generation_tests.c
+)
+
+target_include_directories(bl1_1_test_suite_random
+ PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+target_link_libraries(bl1_1_test_suite_random
+ PRIVATE
+ tfm_test_framework_common
+ bl1_1_shared_lib_interface
+ ${BL1_1_PLATFORM_SPECIFIC_LINK_LIBRARIES}
+)
diff --git a/tests_reg/test/bl1/bl1_1/suites/random/bl1_1_random_generation_tests.c b/tests_reg/test/bl1/bl1_1/suites/random/bl1_1_random_generation_tests.c
new file mode 100644
index 0000000..c53cff3
--- /dev/null
+++ b/tests_reg/test/bl1/bl1_1/suites/random/bl1_1_random_generation_tests.c
@@ -0,0 +1,107 @@
+/*
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "bl1_1_random_generation_tests.h"
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdbool.h>
+
+#include "test_framework_helpers.h"
+#include "bl1_random.h"
+
+#define TEST_VAL_AM 512
+#define REPEAT_THRESHOLD (TEST_VAL_AM / 16)
+
+static void tfm_bl1_random_generate_test_3001(struct test_result_t *ret)
+{
+ uint8_t buf[TEST_VAL_AM];
+ size_t buf_idx;
+ uint16_t table[UINT8_MAX + 1];
+ size_t table_idx;
+ bool failed = false;
+ int rc;
+
+ memset(table, 0, sizeof(table));
+ rc = bl1_random_generate_secure(buf, sizeof(buf));
+ if (rc) {
+ TEST_FAIL("Random generation returned error");
+ return;
+ }
+
+ /* Count the amount of each byte value that's emitted by the DRBG */
+ for (buf_idx = 0; buf_idx < sizeof(buf); buf_idx++) {
+ table[buf[buf_idx]] += 1;
+ }
+
+ /* If any of the counts is over the repeat threshold (currently P >= 1/16,
+ * it is a failure.
+ */
+ for (table_idx = 0; table_idx < (sizeof(table) / sizeof(table[0])); table_idx++) {
+ if (table[table_idx] >= REPEAT_THRESHOLD) {
+ TEST_LOG("Byte 0x%x was repeated %d times\r\n", table_idx,
+ table[table_idx]);
+ failed = true;
+ }
+ }
+
+ if (failed) {
+ TEST_FAIL("Byte was repeated too many times");
+ return;
+ }
+
+ ret->val = TEST_PASSED;
+ return;
+}
+
+static void tfm_bl1_random_generate_test_3002(struct test_result_t *ret)
+{
+ int rc;
+
+ rc = bl1_random_generate_secure(NULL, 128);
+ if (rc == 0) {
+ TEST_FAIL("Random generation should have failed");
+ return;
+ }
+
+ ret->val = TEST_PASSED;
+ return;
+}
+
+
+static void tfm_bl1_random_generate_test_3003(struct test_result_t *ret)
+{
+ int rc;
+
+ rc = bl1_random_generate_secure(NULL, 0);
+ if (rc) {
+ TEST_FAIL("Random generation should have succeeded");
+ return;
+ }
+
+ ret->val = TEST_PASSED;
+ return;
+}
+
+static struct test_t random_generation_tests[] = {
+ {&tfm_bl1_random_generate_test_3001, "TFM_BL1_RANDOM_TEST_3001",
+ "Secure random generation repeated bytes test" },
+ {&tfm_bl1_random_generate_test_3002, "TFM_BL1_RANDOM_TEST_3002",
+ "Secure random generation null-pointer test" },
+ {&tfm_bl1_random_generate_test_3003, "TFM_BL1_RANDOM_TEST_3003",
+ "Secure random generation zero-length output test" },
+};
+
+void register_testsuite_bl1_random_generation_interface(struct test_suite_t *p_test_suite)
+{
+ uint32_t list_size = (sizeof(random_generation_tests) / sizeof(random_generation_tests[0]));
+
+ set_testsuite("BL1 random generation interface test (TFM_BL1_RANDOM_TEST_3XXX)",
+ random_generation_tests, list_size, p_test_suite);
+}
diff --git a/tests_reg/test/bl1/bl1_1/suites/random/bl1_1_random_generation_tests.h b/tests_reg/test/bl1/bl1_1/suites/random/bl1_1_random_generation_tests.h
new file mode 100644
index 0000000..d440d75
--- /dev/null
+++ b/tests_reg/test/bl1/bl1_1/suites/random/bl1_1_random_generation_tests.h
@@ -0,0 +1,23 @@
+/*
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#ifndef __BL1_1_RANDOM_GENERATION_TESTS_H__
+#define __BL1_1_RANDOM_GENERATION_TESTS_H__
+
+#include "test_framework.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void register_testsuite_bl1_random_generation_interface(struct test_suite_t *p_test_suite);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BL1_1_RANDOM_GENERATION_TESTS_H__ */
diff --git a/tests_reg/test/bl1/bl1_1/suites/trng/CMakeLists.txt b/tests_reg/test/bl1/bl1_1/suites/trng/CMakeLists.txt
deleted file mode 100644
index e172995..0000000
--- a/tests_reg/test/bl1/bl1_1/suites/trng/CMakeLists.txt
+++ /dev/null
@@ -1,25 +0,0 @@
-#-------------------------------------------------------------------------------
-# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-#-------------------------------------------------------------------------------
-
-add_library(bl1_1_test_suite_trng)
-
-target_sources(bl1_1_test_suite_trng
- PRIVATE
- ./bl1_1_trng_tests.c
-)
-
-target_include_directories(bl1_1_test_suite_trng
- PUBLIC
- .
-)
-
-target_link_libraries(bl1_1_test_suite_trng
- PRIVATE
- tfm_test_framework_common
- bl1_1_shared_lib_interface
- ${BL1_1_PLATFORM_SPECIFIC_LINK_LIBRARIES}
-)
diff --git a/tests_reg/test/bl1/bl1_1/suites/trng/bl1_1_trng_tests.c b/tests_reg/test/bl1/bl1_1/suites/trng/bl1_1_trng_tests.c
deleted file mode 100644
index bf6ff57..0000000
--- a/tests_reg/test/bl1/bl1_1/suites/trng/bl1_1_trng_tests.c
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include "bl1_1_trng_tests.h"
-
-#include <stdint.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
-#include <stdbool.h>
-
-#include "test_framework_helpers.h"
-#include "trng.h"
-
-#define TEST_VAL_AM 512
-#define REPEAT_THRESHOLD (TEST_VAL_AM / 16)
-
-static void tfm_bl1_trng_test_3001(struct test_result_t *ret)
-{
- uint8_t buf[TEST_VAL_AM];
- size_t buf_idx;
- uint16_t table[UINT8_MAX + 1];
- size_t table_idx;
- bool failed = false;
- int rc;
-
- memset(table, 0, sizeof(table));
- rc = bl1_trng_generate_random(buf, sizeof(buf));
- if (rc) {
- TEST_FAIL("TRNG returned error");
- return;
- }
-
- /* Count the amount of each byte value that's emitted by the TRNG */
- for (buf_idx = 0; buf_idx < sizeof(buf); buf_idx++) {
- table[buf[buf_idx]] += 1;
- }
-
- /* If any of the counts is over the repeat threshold (currently P >= 1/16,
- * it is a failure. Note that we can't make this too close to P = 1/256 as
- * this would lead to unpredictable failures even with unbiased TRNGs.
- */
- for (table_idx = 0; table_idx < (sizeof(table) / sizeof(table[0])); table_idx++) {
- if (table[table_idx] >= REPEAT_THRESHOLD) {
- TEST_LOG("Byte 0x%x was repeated %d times\r\n", table_idx,
- table[table_idx]);
- failed = true;
- }
- }
-
- if (failed) {
- TEST_FAIL("Byte was repeated too many times");
- return;
- }
-
- ret->val = TEST_PASSED;
- return;
-}
-
-static void tfm_bl1_trng_test_3002(struct test_result_t *ret)
-{
- int rc;
-
- rc = bl1_trng_generate_random(NULL, 128);
- if (rc == 0) {
- TEST_FAIL("TRNG returned success");
- return;
- }
-
- ret->val = TEST_PASSED;
- return;
-}
-
-
-static void tfm_bl1_trng_test_3003(struct test_result_t *ret)
-{
- int rc;
-
- rc = bl1_trng_generate_random(NULL, 0);
- if (rc) {
- TEST_FAIL("TRNG returned failure");
- return;
- }
-
- ret->val = TEST_PASSED;
- return;
-}
-
-static struct test_t trng_tests[] = {
- {&tfm_bl1_trng_test_3001, "TFM_BL1_TRNG_TEST_3001",
- "TRNG repeated bytes test" },
- {&tfm_bl1_trng_test_3002, "TFM_BL1_TRNG_TEST_3002",
- "TRNG output null-pointer test" },
- {&tfm_bl1_trng_test_3003, "TFM_BL1_TRNG_TEST_3003",
- "TRNG output zero-length test" },
-};
-
-void register_testsuite_bl1_trng_interface(struct test_suite_t *p_test_suite)
-{
- uint32_t list_size = (sizeof(trng_tests) / sizeof(trng_tests[0]));
-
- set_testsuite("TRNG interface test (TFM_BL1_TRNG_TEST_3XXX)",
- trng_tests, list_size, p_test_suite);
-}
diff --git a/tests_reg/test/bl1/bl1_1/suites/trng/bl1_1_trng_tests.h b/tests_reg/test/bl1/bl1_1/suites/trng/bl1_1_trng_tests.h
deleted file mode 100644
index fe64377..0000000
--- a/tests_reg/test/bl1/bl1_1/suites/trng/bl1_1_trng_tests.h
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#ifndef BL1_1_TRNG_TESTS_H
-#define BL1_1_TRNG_TESTS_H
-
-#include "test_framework.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void register_testsuite_bl1_trng_interface(struct test_suite_t *p_test_suite);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* BL1_1_TRNG_TESTS_H */