6 #include "sw/device/lib/crypto/drivers/otbn.h"
7 #include "sw/device/lib/crypto/impl/rsa/rsa_datatypes.h"
12 #include "sw/device/lib/testing/entropy_testutils.h"
13 #include "sw/device/lib/testing/test_framework/check.h"
17 #define MODULE_ID MAKE_MODULE_ID('t', 's', 't')
20 static const unsigned char kTestMessage[] =
"Test message.";
21 static const size_t kTestMessageLen =
sizeof(kTestMessage) - 1;
26 status_t keygen_then_sign_test(
void) {
30 memset(public_key_data, 0,
sizeof(public_key_data));
32 .key_mode = kTestKeyMode,
34 .key = public_key_data,
38 size_t keyblob_words =
40 uint32_t keyblob[keyblob_words];
41 memset(keyblob, 0,
sizeof(keyblob));
45 .version = kOtcryptoLibVersion1,
46 .key_mode = kTestKeyMode,
49 .security_level = kOtcryptoKeySecurityLevelLow,
56 LOG_INFO(
"Starting keypair generation...");
58 LOG_INFO(
"Keypair generation complete.");
59 LOG_INFO(
"OTBN instruction count: %u", otbn_instruction_count_get());
70 TRY_CHECK(pk->e == 65537);
74 TRY_CHECK_ARRAYS_EQ(pk->n.data, sk->n.data,
ARRAYSIZE(pk->n.data));
78 bool d_large_enough =
false;
79 for (
size_t i = kRsa2048NumWords / 2; i < kRsa2048NumWords; i++) {
80 if (sk->d.data[i] != 0) {
81 d_large_enough =
true;
84 TRY_CHECK(d_large_enough);
88 .len = kTestMessageLen};
89 uint32_t msg_digest_data[kSha256DigestWords];
91 .data = msg_digest_data,
93 .mode = kOtcryptoHashModeSha256,
97 uint32_t sig[kRsa2048NumWords];
100 .len = kRsa2048NumWords,
104 .len = kRsa2048NumWords,
108 LOG_INFO(
"Starting signature generation...");
111 LOG_INFO(
"Signature generation complete.");
112 LOG_INFO(
"OTBN instruction count: %u", otbn_instruction_count_get());
116 LOG_INFO(
"Starting signature verification...");
119 const_sig_buf, &verification_result));
120 LOG_INFO(
"Signature verification complete.");
121 LOG_INFO(
"OTBN instruction count: %u", otbn_instruction_count_get());
128 OTTF_DEFINE_TEST_CONFIG();
131 CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
135 return status_ok(test_result);