5 #include "hw/ip/aes/model/aes_modes.h"
8 #include "sw/device/lib/base/multibits.h"
11 #include "sw/device/lib/dif/dif_rv_core_ibex.h"
14 #include "sw/device/lib/testing/aes_testutils.h"
15 #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"
23 OTTF_DEFINE_TEST_CONFIG();
30 kDifAesBlockNumBytes = 4,
31 kDisableEntropyAtStartEn = 1,
34 static const uint8_t kKeyShare1[16] = {
35 0x0f, 0x1f, 0x2f, 0x3f, 0x4f, 0x5f, 0x6f, 0x7f,
36 0x8f, 0x9f, 0xaf, 0xbf, 0xcf, 0xdf, 0xef, 0xff,
41 uint8_t new_key_share0[
sizeof(kAesModesKey128)];
43 for (
size_t i = 0; i <
sizeof(kAesModesKey128); ++i) {
44 new_key_share0[i] = kAesModesKey128[i] ^ kKeyShare1[i] * (uint8_t)(index);
47 memcpy(key->share0, new_key_share0,
sizeof(key->share0));
48 memcpy(key->share1, kKeyShare1,
sizeof(key->share1));
52 bool aes_idle =
false;
53 bool input_ready =
false;
54 bool output_valid =
false;
61 generate_new_key(&key, 0);
71 .reseed_on_key_change =
true,
73 .ctrl_aux_lock =
false,
81 dif_rv_core_ibex_t rv_core_ibex;
82 TRY(dif_rv_core_ibex_init(
85 for (uint32_t i = 0; i <
ARRAYSIZE(plain_text); ++i) {
86 for (uint32_t j = 0; j < kDifAesBlockNumBytes; ++j) {
88 TRY(rv_core_ibex_testutils_get_rnd_data(&rv_core_ibex, 2000, &rand));
89 plain_text[i].data[j] = rand;
104 uint32_t num_of_blocks_loaded = 0;
108 LOG_INFO(
"Loading %d blocks without reading output to create back pressure",
110 for (uint32_t i = 0; i < kAesNumBlocks; ++i) {
115 }
while (!input_ready);
119 num_of_blocks_loaded++;
127 "ERROR: AES module not STALLED as expected after loading block %d",
129 LOG_INFO(
"AES module is stalled as expected after loading block %d", i);
136 uint32_t num_of_blocks_read = 0;
138 while (num_of_blocks_read < num_of_blocks_loaded) {
140 output_valid =
false;
143 }
while (!output_valid);
147 num_of_blocks_read++;
151 TRY_CHECK(!stall,
"ERROR: Block %u not successfully read",
152 num_of_blocks_read - 1);
155 TRY_CHECK(stall,
"ERROR:STALL condition did not occur...");
159 LOG_INFO(
"End AES encryption operation");
173 LOG_INFO(
"Entering AES aes_stall_test Test");
175 return status_ok(execute_test());