5 #include "dt/dt_otbn.h"
9 #include "sw/device/lib/testing/entropy_testutils.h"
11 #include "sw/device/lib/testing/test_framework/check.h"
32 static_assert(kDtOtbnCount >= 1,
33 "This test requires at least one OTBN instance");
35 static dt_otbn_t kTestOtbn = (dt_otbn_t)0;
37 OTTF_DEFINE_TEST_CONFIG();
42 static void check_otbn_insn_cnt(dif_otbn_t *otbn, uint32_t expected_insn_cnt) {
45 CHECK(insn_cnt == expected_insn_cnt,
46 "Expected to execute %d instructions, but got %d.", expected_insn_cnt,
61 static void test_barrett384(dif_otbn_t *otbn) {
62 enum { kDataSizeBytes = 48 };
67 static const uint8_t a[kDataSizeBytes] = {10};
70 static uint8_t b[kDataSizeBytes] = {20};
74 static const uint8_t m[kDataSizeBytes] = {
75 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
76 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
77 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff,
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
83 static const uint8_t u[kDataSizeBytes] = {
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
87 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01};
90 uint8_t c[kDataSizeBytes] = {0};
93 static const uint8_t c_expected[kDataSizeBytes] = {200};
108 for (
int i = 0; i <
sizeof(c); ++i) {
109 CHECK(c[i] == c_expected[i],
110 "Unexpected result c at byte %d: 0x%x (actual) != 0x%x (expected)", i,
111 c[i], c_expected[i]);
114 check_otbn_insn_cnt(otbn, 174);
127 static void test_err_test(dif_otbn_t *otbn) {
138 check_otbn_insn_cnt(otbn, 1);
141 static void test_sec_wipe(dif_otbn_t *otbn) {
146 CHECK(otbn_status == kDifOtbnStatusBusySecWipeDmem);
151 CHECK(otbn_status == kDifOtbnStatusBusySecWipeImem);
156 CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
159 CHECK_DIF_OK(dif_otbn_init_from_dt(kTestOtbn, &otbn));
161 test_barrett384(&otbn);
162 test_sec_wipe(&otbn);
163 test_err_test(&otbn);