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/testing/aes_testutils.h"
15 #include "sw/device/lib/testing/csrng_testutils.h"
16 #include "sw/device/lib/testing/test_framework/check.h"
20 kTestTimeout = (1000 * 1000),
26 static const uint8_t kKeyShare1[] = {
27 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
28 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
29 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
32 static_assert(kDtAesCount >= 1,
"This test requires at least one AES instance");
33 static_assert(kDtCsrngCount >= 1,
34 "This test requires at least one CSRNG instance");
35 static_assert(kDtEdnCount >= 1,
"This test requires at least one EDN instance");
37 static dt_aes_t kTestAes = (dt_aes_t)0;
38 static dt_csrng_t kTestCsrng = (dt_csrng_t)0;
39 static dt_edn_t kTestEdn = (dt_edn_t)0;
41 OTTF_DEFINE_TEST_CONFIG();
43 status_t execute_test(
const dif_csrng_t *csrng,
const dif_edn_t *edn0) {
45 CHECK_STATUS_OK(aes_testutils_csrng_kat(csrng));
58 LOG_INFO(
"Testing AES with masking switched off");
61 CHECK_STATUS_OK(aes_testutils_masking_prng_zero_output_seed(csrng, edn0));
65 CHECK_DIF_OK(dif_aes_init_from_dt(kTestAes, &aes));
70 uint8_t key_share0[
sizeof(kAesModesKey128)];
71 for (
int i = 0; i <
sizeof(kAesModesKey128); ++i) {
72 key_share0[i] = kAesModesKey128[i] ^ kKeyShare1[i];
77 memcpy(key.share0, key_share0,
sizeof(key.share0));
78 memcpy(key.share1, kKeyShare1,
sizeof(key.share1));
89 .reseed_on_key_change =
false,
91 .ctrl_aux_lock =
false,
113 memcpy(plain_text[0].data, kAesModesPlainText,
sizeof(kAesModesPlainText));
119 (
size_t)kAesNumBlocks));
122 CHECK_ARRAYS_EQ((uint8_t *)cipher_text[0].data, kAesModesCipherTextEcb128,
123 sizeof(kAesModesCipherTextEcb128));
137 LOG_INFO(
"Testing CSRNG SW application interface");
142 CHECK_DIF_OK(dif_csrng_init_from_dt(kTestCsrng, &csrng));
143 CHECK_DIF_OK(dif_edn_init_from_dt(kTestEdn, &edn));
150 return status_ok(execute_test(&csrng, &edn));