aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManish V Badarkhe <manish.badarkhe@arm.com>2022-11-09 17:27:06 +0100
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>2022-11-09 17:27:06 +0100
commit68f764d27ddfe2f108a82cdaa016e3014117a970 (patch)
tree4fb5f8fa30600287c1d0b8abb37de998a1670f9b
parent0fcfd47a5936180b754819ee928e8d5af173c5d2 (diff)
parentafcf4668ac738f45ffe3f238d1b2d90020de759c (diff)
downloadtf-a-tests-68f764d27ddfe2f108a82cdaa016e3014117a970.tar.gz
Merge "refact(trng): cleanup TRNG service tests"
-rw-r--r--docs/about/features.rst2
-rw-r--r--include/runtime_services/trng.h19
-rw-r--r--tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c15
-rw-r--r--tftf/tests/tests-trng.mk7
4 files changed, 25 insertions, 18 deletions
diff --git a/docs/about/features.rst b/docs/about/features.rst
index dbaec1279..dbdb3244b 100644
--- a/docs/about/features.rst
+++ b/docs/about/features.rst
@@ -19,6 +19,7 @@ not exhaustive):
- `Firmware update`_ (or recovery mode)
- `EL3 payload boot flow`_
- Secure partition support
+- `True Random Number Generator Firmware Interface (TRNG_FW)`_
These tests are not a compliance test suite for the Arm interface standards used
in TF-A (such as PSCI).
@@ -55,3 +56,4 @@ Still to come
.. _TSP: https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git/tree/bl32/tsp
.. _Firmware update: https://trustedfirmware-a.readthedocs.io/en/latest/components/firmware-update.html
.. _EL3 payload boot flow: https://trustedfirmware-a.readthedocs.io/en/latest/design/alt-boot-flows.html#el3-payloads-alternative-boot-flow
+.. _TRNG_FW: https://developer.arm.com/documentation/den0098/latest
diff --git a/include/runtime_services/trng.h b/include/runtime_services/trng.h
index a5d8e4d12..41600b485 100644
--- a/include/runtime_services/trng.h
+++ b/include/runtime_services/trng.h
@@ -42,12 +42,12 @@
#define SMC_TRNG_RND 0x84000053
#define TRNG_MAX_BITS U(96)
#define TRNG_ENTROPY_MASK U(0xFFFFFFFF)
-#endif
+#endif /* __aarch64__ */
/*
* Number of TRNG calls defined in the TRNG specification.
*/
-#define TRNG_NUM_CALLS 4
+#define TRNG_NUM_CALLS (4U)
#ifndef __ASSEMBLY__
typedef struct {
@@ -67,17 +67,16 @@ smc_ret_values tftf_trng_rnd(uint32_t nbits);
/*******************************************************************************
* TRNG version
******************************************************************************/
-#define TRNG_MAJOR_VER_SHIFT (16)
-#define TRNG_VERSION(major, minor) ((major << TRNG_MAJOR_VER_SHIFT) \
- | minor)
+#define TRNG_MAJOR_VER_SHIFT (16)
+#define TRNG_VERSION(major, minor) ((major << TRNG_MAJOR_VER_SHIFT)| minor)
/*******************************************************************************
* TRNG error codes
******************************************************************************/
-#define TRNG_E_SUCCESS (0)
-#define TRNG_E_NOT_SUPPORTED (-1)
-#define TRNG_E_INVALID_PARAMS (-2)
-#define TRNG_E_NO_ENTOPY (-3)
-#define TRNG_E_NOT_IMPLEMENTED (-4)
+#define TRNG_E_SUCCESS (0)
+#define TRNG_E_NOT_SUPPORTED (-1)
+#define TRNG_E_INVALID_PARAMS (-2)
+#define TRNG_E_NO_ENTROPY (-3)
+#define TRNG_E_NOT_IMPLEMENTED (-4)
#endif /* __TRNG_H__ */
diff --git a/tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c b/tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c
index 64b8db78f..72a4ec5ab 100644
--- a/tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c
+++ b/tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -29,7 +29,6 @@ test_result_t test_trng_version(void)
return TEST_RESULT_SKIPPED;
}
-
if (version < TRNG_VERSION(1, 0)) {
return TEST_RESULT_FAIL;
}
@@ -51,8 +50,7 @@ test_result_t test_trng_features(void)
return TEST_RESULT_SKIPPED;
}
- if (!(tftf_trng_feature_implemented(SMC_TRNG_VERSION) &&
- tftf_trng_feature_implemented(SMC_TRNG_FEATURES) &&
+ if (!(tftf_trng_feature_implemented(SMC_TRNG_FEATURES) &&
tftf_trng_feature_implemented(SMC_TRNG_UUID) &&
tftf_trng_feature_implemented(SMC_TRNG_RND))) {
return TEST_RESULT_FAIL;
@@ -75,6 +73,11 @@ test_result_t test_trng_rnd(void)
return TEST_RESULT_SKIPPED;
}
+ /* Ensure function is implemented before requesting Entropy */
+ if (!(tftf_trng_feature_implemented(SMC_TRNG_RND))) {
+ return TEST_RESULT_FAIL;
+ }
+
/* Test invalid entropy sizes */
rnd_out = tftf_trng_rnd(U(0));
if (rnd_out.ret0 != TRNG_E_INVALID_PARAMS) {
@@ -97,7 +100,7 @@ test_result_t test_trng_rnd(void)
/* For N = 1, all returned entropy bits should be 0
* except the least significant bit */
rnd_out = tftf_trng_rnd(U(1));
- if (rnd_out.ret0 == TRNG_E_NO_ENTOPY) {
+ if (rnd_out.ret0 == TRNG_E_NO_ENTROPY) {
WARN("There is not a single bit of entropy\n");
return TEST_RESULT_SKIPPED;
}
@@ -116,7 +119,7 @@ test_result_t test_trng_rnd(void)
/* For N = MAX_BITS-1, the most significant bit should be 0 */
rnd_out = tftf_trng_rnd(TRNG_MAX_BITS - U(1));
- if (rnd_out.ret0 == TRNG_E_NO_ENTOPY) {
+ if (rnd_out.ret0 == TRNG_E_NO_ENTROPY) {
WARN("There is not a single bit of entropy\n");
return TEST_RESULT_SKIPPED;
}
diff --git a/tftf/tests/tests-trng.mk b/tftf/tests/tests-trng.mk
index d2842964e..abeb5b544 100644
--- a/tftf/tests/tests-trng.mk
+++ b/tftf/tests/tests-trng.mk
@@ -1,7 +1,10 @@
#
-# Copyright (c) 2021, Arm Limited. All rights reserved.
+# Copyright (c) 2021-2022, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
-TESTS_SOURCES += tftf/tests/runtime_services/standard_service/trng/api_tests/test_trng.c
+TESTS_SOURCES += \
+ $(addprefix tftf/tests/runtime_services/standard_service/, \
+ /trng/api_tests/test_trng.c \
+ )