5 #include "sw/device/lib/crypto/drivers/otbn.h"
6 #include "sw/device/lib/crypto/impl/keyblob.h"
9 #include "sw/device/lib/testing/entropy_testutils.h"
10 #include "sw/device/lib/testing/test_framework/check.h"
15 kP256PublicKeyWords = 512 / 32,
17 kP256SignatureWords = 512 / 32,
19 kP256PrivateKeyBytes = 256 / 8,
21 kP256SharedKeyBytes = 256 / 8,
23 kP256SharedKeyWords = kP256SharedKeyBytes /
sizeof(uint32_t),
28 .version = kOtcryptoLibVersion1,
29 .key_mode = kOtcryptoKeyModeEcdhP256,
30 .key_length = kP256PrivateKeyBytes,
32 .security_level = kOtcryptoKeySecurityLevelLow,
39 .version = kOtcryptoLibVersion1,
40 .key_mode = kOtcryptoKeyModeAesCtr,
41 .key_length = kP256SharedKeyBytes,
43 .security_level = kOtcryptoKeySecurityLevelLow,
48 uint32_t keyblobA[keyblob_num_words(kEcdhPrivateKeyConfig)];
50 .config = kEcdhPrivateKeyConfig,
51 .keyblob_length =
sizeof(keyblobA),
55 uint32_t keyblobB[keyblob_num_words(kEcdhPrivateKeyConfig)];
57 .config = kEcdhPrivateKeyConfig,
58 .keyblob_length =
sizeof(keyblobB),
64 uint32_t pkA[kP256PublicKeyWords] = {0};
65 uint32_t pkB[kP256PublicKeyWords] = {0};
67 .key_mode = kOtcryptoKeyModeEcdhP256,
68 .key_length =
sizeof(pkA),
72 .key_mode = kOtcryptoKeyModeEcdhP256,
73 .key_length =
sizeof(pkB),
86 CHECK_ARRAYS_NE(pkA, pkB,
ARRAYSIZE(pkA));
89 uint32_t shared_keyblobA[keyblob_num_words(kEcdhSharedKeyConfig)];
91 .config = kEcdhSharedKeyConfig,
92 .keyblob_length =
sizeof(shared_keyblobA),
93 .keyblob = shared_keyblobA,
96 uint32_t shared_keyblobB[keyblob_num_words(kEcdhSharedKeyConfig)];
98 .config = kEcdhSharedKeyConfig,
99 .keyblob_length =
sizeof(shared_keyblobB),
100 .keyblob = shared_keyblobB,
106 LOG_INFO(
"Generating shared secret (A)...");
111 LOG_INFO(
"Generating shared secret (B)...");
117 TRY(keyblob_to_shares(&shared_keyA, &keyA0, &keyA1));
120 TRY(keyblob_to_shares(&shared_keyB, &keyB0, &keyB1));
123 uint32_t keyA[kP256SharedKeyWords];
124 uint32_t keyB[kP256SharedKeyWords];
125 for (
size_t i = 0; i <
ARRAYSIZE(keyA); i++) {
126 keyA[i] = keyA0[i] ^ keyA1[i];
127 keyB[i] = keyB0[i] ^ keyB1[i];
129 CHECK_ARRAYS_EQ(keyA, keyB,
ARRAYSIZE(keyA));
134 OTTF_DEFINE_TEST_CONFIG();
137 CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
140 if (!status_ok(err)) {
142 LOG_INFO(
"OTBN error bits: 0x%08x", otbn_err_bits_get());
143 LOG_INFO(
"OTBN instruction count: 0x%08x", otbn_instruction_count_get());
145 CHECK_STATUS_OK(err);