5 #include "hw/ip/aes/model/aes_modes.h"
8 #include "sw/device/lib/base/multibits.h"
11 #include "sw/device/lib/dif/dif_csrng_shared.h"
14 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
17 #include "sw/device/lib/testing/aes_testutils.h"
18 #include "sw/device/lib/testing/csrng_testutils.h"
19 #include "sw/device/lib/testing/entropy_testutils.h"
20 #include "sw/device/lib/testing/rv_core_ibex_testutils.h"
21 #include "sw/device/lib/testing/test_framework/check.h"
27 OTTF_DEFINE_TEST_CONFIG();
34 kDifAesBlockNumBytes = 4,
35 kDisableEntropyAtStartEn = 1,
38 static const uint8_t kKeyShare1[16] = {
39 0x0f, 0x1f, 0x2f, 0x3f, 0x4f, 0x5f, 0x6f, 0x7f,
40 0x8f, 0x9f, 0xaf, 0xbf, 0xcf, 0xdf, 0xef, 0xff,
44 static dif_edn_t edn0, edn1;
45 static dif_csrng_t csrng;
46 static dif_entropy_src_t entropy_src;
49 status_t disable_entropy_complex(
void) {
52 TRY(entropy_testutils_stop_all());
53 LOG_INFO(
"The entire entropy complex is stopped");
58 status_t enable_entropy_complex(
void) {
61 TRY(entropy_testutils_auto_mode_init());
62 LOG_INFO(
"The entire entropy complex is enabled");
68 uint8_t new_key_share0[
sizeof(kAesModesKey128)];
70 for (
size_t i = 0; i <
sizeof(kAesModesKey128); ++i) {
71 new_key_share0[i] = kAesModesKey128[i] ^ kKeyShare1[i] * (uint8_t)(index);
74 memcpy(key->share0, new_key_share0,
sizeof(key->share0));
75 memcpy(key->share1, kKeyShare1,
sizeof(key->share1));
79 bool aes_idle =
false;
80 bool input_ready =
false;
81 bool output_valid =
false;
84 "Testing aes_prng_reseed_test with number of blocks: %d (Block 0 to %d), "
85 "and disabling entropy at start enable"
87 kAesNumBlocks, kAesNumBlocks - 1, kDisableEntropyAtStartEn);
96 TRY(dif_entropy_src_init(
100 generate_new_key(&key, 0);
110 .reseed_on_key_change =
true,
112 .ctrl_aux_lock =
false,
120 dif_rv_core_ibex_t rv_core_ibex;
121 TRY(dif_rv_core_ibex_init(
124 for (uint32_t i = 0; i <
ARRAYSIZE(plain_text); ++i) {
125 for (uint32_t j = 0; j < kDifAesBlockNumBytes; ++j) {
127 TRY(rv_core_ibex_testutils_get_rnd_data(&rv_core_ibex, 2000, &rand));
128 plain_text[i].data[j] = rand;
142 if (kDisableEntropyAtStartEn == 1) {
144 "Disabling entropy complex to induce AES stall before starting AES");
145 CHECK_STATUS_OK(disable_entropy_complex());
150 for (
int i = 0; i < kAesNumBlocks; ++i) {
160 }
while (!input_ready);
172 if (i == 0 && kDisableEntropyAtStartEn == 1) {
174 "Checking AES status OutputValid status after stopping "
176 output_valid =
false;
179 "ERROR:AES encryption AES encryption generated output_valid after "
180 "stopping entropy indicating no stall!");
182 "AES encryption is waiting for output_valid as expected at block "
186 LOG_INFO(
"Enabling entropy complex at block %d", i);
187 CHECK_STATUS_OK(enable_entropy_complex());
192 output_valid =
false;
195 }
while (!output_valid);
202 LOG_INFO(
"End AES encryption operation");
216 LOG_INFO(
"Entering AES aes_force_prng_reseed_test Test");
218 return status_ok(execute_test());