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 kP384PublicKeyWords = 768 / 32,
17 kP384SignatureWords = 768 / 32,
19 kP384PrivateKeyBytes = 384 / 8,
21 kP384SharedKeyBytes = 384 / 8,
23 kP384SharedKeyWords = kP384SharedKeyBytes /
sizeof(uint32_t),
28 .version = kOtcryptoLibVersion1,
29 .key_mode = kOtcryptoKeyModeEcdhP384,
30 .key_length = kP384PrivateKeyBytes,
32 .security_level = kOtcryptoKeySecurityLevelLow,
39 .version = kOtcryptoLibVersion1,
40 .key_mode = kOtcryptoKeyModeAesCtr,
41 .key_length = kP384SharedKeyBytes,
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[kP384PublicKeyWords] = {0};
65 uint32_t pkB[kP384PublicKeyWords] = {0};
67 .key_mode = kOtcryptoKeyModeEcdhP384,
68 .key_length =
sizeof(pkA),
72 .key_mode = kOtcryptoKeyModeEcdhP384,
73 .key_length =
sizeof(pkB),
86 CHECK_ARRAYS_NE(pkA, pkB,
ARRAYSIZE(pkA));
88 CHECK_ARRAYS_NE(keyblobA, keyblobB,
ARRAYSIZE(keyblobA));
91 uint32_t shared_keyblobA[keyblob_num_words(kEcdhSharedKeyConfig)];
93 .config = kEcdhSharedKeyConfig,
94 .keyblob_length =
sizeof(shared_keyblobA),
95 .keyblob = shared_keyblobA,
98 uint32_t shared_keyblobB[keyblob_num_words(kEcdhSharedKeyConfig)];
100 .config = kEcdhSharedKeyConfig,
101 .keyblob_length =
sizeof(shared_keyblobB),
102 .keyblob = shared_keyblobB,
108 LOG_INFO(
"Generating shared secret (A)...");
113 LOG_INFO(
"Generating shared secret (B)...");
119 TRY(keyblob_to_shares(&shared_keyA, &keyA0, &keyA1));
122 TRY(keyblob_to_shares(&shared_keyB, &keyB0, &keyB1));
125 uint32_t keyA[kP384SharedKeyWords];
126 uint32_t keyB[kP384SharedKeyWords];
127 for (
size_t i = 0; i <
ARRAYSIZE(keyA); i++) {
128 keyA[i] = keyA0[i] ^ keyA1[i];
129 keyB[i] = keyB0[i] ^ keyB1[i];
131 CHECK_ARRAYS_EQ(keyA, keyB,
ARRAYSIZE(keyA));
136 OTTF_DEFINE_TEST_CONFIG();
139 CHECK_STATUS_OK(entropy_testutils_auto_mode_init());
142 if (!status_ok(err)) {
144 LOG_INFO(
"OTBN error bits: 0x%08x", otbn_err_bits_get());
145 LOG_INFO(
"OTBN instruction count: 0x%08x", otbn_instruction_count_get());
147 CHECK_STATUS_OK(err);