5 #include "dt/dt_kmac.h"
11 #include "sw/device/lib/testing/test_framework/check.h"
14 OTTF_DEFINE_TEST_CONFIG();
16 #define DIGEST_LEN_CSHAKE_MAX 4
27 const char *function_name;
28 size_t function_name_len;
30 const char *customization_string;
31 size_t customization_string_len;
33 const uint32_t digest[DIGEST_LEN_CSHAKE_MAX];
43 .message =
"OpenTitan",
46 .function_name_len = 0,
47 .customization_string =
"",
48 .customization_string_len = 0,
49 .digest = {0x235a6522, 0x3bd735ac, 0x77832247, 0xc6b12919},
54 .message =
"OpenTitan",
57 .function_name_len = 1,
58 .customization_string =
"",
59 .customization_string_len = 0,
60 .digest = {0xf2f20928, 0xa2a59a0, 0xfc1e5d5d, 0x1cee38d0},
65 .message =
"OpenTitan",
68 .function_name_len = 0,
69 .customization_string =
"Ibex",
70 .customization_string_len = 4,
71 .digest = {0xcd582d56, 0x59e88860, 0xa4344c29, 0x5576778f},
76 .message =
"OpenTitan",
78 .function_name =
"Ibex",
79 .function_name_len = 4,
80 .customization_string =
81 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
82 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f",
83 .customization_string_len = 32,
84 .digest = {0xda353307, 0xdf18e570, 0x6211cee0, 0x716e816c},
90 LOG_INFO(
"Running KMAC DIF cSHAKE test...");
94 dt_kmac_t kKmacDt = (dt_kmac_t)0;
95 static_assert(kDtKmacCount >= 1,
96 "This test requires at least one KMAC instance");
98 CHECK_DIF_OK(dif_kmac_init_from_dt(kKmacDt, &kmac));
103 .entropy_seed = {0xb153e3fe, 0x09596819, 0x3e85a6e8, 0xb6dcdaba,
104 0x50dc409c, 0x11e1ebd1},
110 for (
int i = 0; i <
ARRAYSIZE(cshake_tests); ++i) {
115 test.function_name_len, &n));
119 test.customization_string,
test.customization_string_len, &s));
124 test.customization_string_len == 0 ? NULL : &s;
129 test.message_len, NULL));
130 uint32_t out[DIGEST_LEN_CSHAKE_MAX];
131 CHECK(DIGEST_LEN_CSHAKE_MAX >=
test.digest_len);
133 test.digest_len, NULL,
135 CHECK_DIF_OK(
dif_kmac_end(&kmac, &kmac_operation_state));
137 for (
int j = 0; j <
test.digest_len; ++j) {
138 CHECK(out[j] ==
test.digest[j],
139 "test %d: mismatch at %d got=0x%x want=0x%x", i, j, out[j],