10 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
13 #include "sw/device/lib/testing/edn_testutils.h"
14 #include "sw/device/lib/testing/entropy_testutils.h"
16 #include "sw/device/lib/testing/rv_core_ibex_testutils.h"
17 #include "sw/device/lib/testing/test_framework/check.h"
19 #include "sw/device/tests/otbn_randomness_impl.h"
25 kEdnBootModeTimeout = (10 * 1000 * 1000),
26 kEdnBootModeOtbnRandomnessIterations = 1,
29 static dif_entropy_src_t entropy_src;
30 static dif_csrng_t csrng;
31 static dif_edn_t edn0;
32 static dif_edn_t edn1;
33 static dif_otbn_t otbn;
34 static dif_rv_core_ibex_t rv_core_ibex;
40 .route_to_firmware =
false,
41 .bypass_conditioner =
false,
43 .health_test_window_size = 0x0200,
47 OTTF_DEFINE_TEST_CONFIG();
50 static void init_peripherals(
void) {
51 CHECK_DIF_OK(dif_entropy_src_init(
53 CHECK_DIF_OK(dif_csrng_init(
61 CHECK_DIF_OK(dif_rv_core_ibex_init(
66 static void configure_otbn(
void) {
67 otbn_randomness_test_prepare(&otbn, kEdnBootModeOtbnRandomnessIterations);
71 static status_t entropy_config(
unsigned int round) {
78 TRY(entropy_testutils_stop_all());
107 kEdnBootModeTimeout);
119 kEdnBootModeTimeout);
134 static void consume_entropy(
unsigned int round,
136 dif_rv_core_ibex_rnd_status_t ibex_rnd_fips) {
137 uint32_t ibex_rnd_data;
138 dif_rv_core_ibex_rnd_status_t ibex_rnd_status;
139 dif_otbn_irq_state_snapshot_t intr_state;
140 CHECK_STATUS_OK(entropy_config(round));
147 CHECK_DIF_OK(dif_otbn_irq_get_state(&otbn, &intr_state));
148 CHECK(intr_state & 0x1);
149 CHECK_DIF_OK(dif_otbn_irq_acknowledge_all(&otbn));
154 CHECK_DIF_OK(dif_rv_core_ibex_read_rnd_data(&rv_core_ibex, &ibex_rnd_data));
155 IBEX_SPIN_FOR(rv_core_ibex_testutils_is_rnd_data_valid(&rv_core_ibex),
156 kEdnBootModeTimeout);
158 dif_rv_core_ibex_get_rnd_status(&rv_core_ibex, &ibex_rnd_status));
160 CHECK_DIF_OK(dif_rv_core_ibex_read_rnd_data(&rv_core_ibex, &ibex_rnd_data));
161 CHECK((ibex_rnd_status & kDifRvCoreIbexRndStatusFipsCompliant) ==
171 kDifRvCoreIbexRndStatusFipsCompliant);
173 consume_entropy(2, kDifOtbnErrBitsNoError, 0);
175 consume_entropy(3, kDifOtbnErrBitsNoError,
176 kDifRvCoreIbexRndStatusFipsCompliant);