5 #include "sw/device/lib/crypto/drivers/entropy.h"
6 #include "sw/device/lib/crypto/impl/integrity.h"
7 #include "sw/device/lib/crypto/impl/keyblob.h"
11 #include "sw/device/lib/testing/test_framework/check.h"
18 kTagLenWords = 512 / 32,
23 static const uint32_t kBasicTestKey[] = {
24 0x7b8779ba, 0x687c02b2, 0x695cef9b, 0x99a07c56, 0xd9287997, 0x5cc0820a,
25 0x99c3185d, 0x9f09d467, 0xd7f8b964, 0xd62c19dd, 0xb52f90e5, 0x1a60fb99,
26 0xb0ec7968, 0xbf81b0fd, 0xc1a4751b, 0xa46588ed,
32 static const uint32_t kLongTestKey[] = {
33 0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0x13121110, 0x17161514,
34 0x1b1a1918, 0x1f1e1d1c, 0x23222120, 0x27262524, 0x2b2a2928, 0x2f2e2d2c,
35 0x33323130, 0x37363534, 0x3b3a3938, 0x3f3e3d3c, 0x43424140, 0x03020100,
36 0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0x13121110, 0x17161514, 0x1b1a1918,
37 0x1f1e1d1c, 0x23222120, 0x27262524, 0x2b2a2928, 0x2f2e2d2c, 0x33323130,
38 0x37363534, 0x3b3a3938, 0x3f3e3d3c, 0x43424140,
43 static const uint32_t kTestMask[
ARRAYSIZE(kLongTestKey)] = {
44 0x8cb847c3, 0xc6d34f36, 0x72edbf7b, 0x9bc0317f, 0x8f003c7f, 0x1d7ba049,
45 0xfd463b63, 0xbb720c44, 0x784c215e, 0xeb101d65, 0x35beb911, 0xab481345,
46 0xa7ebc3e3, 0x04b2a1b9, 0x764a9630, 0x78b8f9c5, 0x3f2a1d8e, 0x8cb847c3,
47 0xc6d34f36, 0x72edbf7b, 0x9bc0317f, 0x8f003c7f, 0x1d7ba049, 0xfd463b63,
48 0xbb720c44, 0x784c215e, 0xeb101d65, 0x35beb911, 0xab481345, 0xa7ebc3e3,
49 0x04b2a1b9, 0x764a9630, 0x78b8f9c5, 0x3f2a1d8e,
61 static status_t run_test(
const uint32_t *key,
size_t key_len,
63 const uint32_t *exp_tag) {
66 .version = kOtcryptoLibVersion1,
67 .key_mode = kOtcryptoKeyModeHmacSha512,
68 .key_length = key_len,
71 .security_level = kOtcryptoKeySecurityLevelLow,
74 uint32_t keyblob[keyblob_num_words(config)];
75 TRY(keyblob_from_key_and_mask(key, kTestMask, config, keyblob));
79 .keyblob_length =
sizeof(keyblob),
82 blinded_key.checksum = integrity_blinded_checksum(&blinded_key);
84 uint32_t act_tag[kTagLenWords];
91 TRY_CHECK_ARRAYS_EQ(act_tag, exp_tag, kTagLenWords);
103 const char plaintext[] =
"Test message.";
105 .data = (
unsigned char *)plaintext,
106 .len =
sizeof(plaintext) - 1,
108 const uint32_t exp_tag[] = {
109 0x7b3674a5, 0x0c12844c, 0x2e3aef0b, 0xb875560c, 0x1ff2e06f, 0x2cc80c98,
110 0x34b621fe, 0x2ad1d342, 0x7a37332d, 0x16d97164, 0x15b3b97e, 0x3b274355,
111 0xe24621ac, 0x5dc90862, 0x270749c3, 0xba027841,
114 return run_test(kBasicTestKey,
sizeof(kBasicTestKey), msg_buf, exp_tag);
125 const uint32_t exp_tag[] = {
126 0x225f72ef, 0x887e5c5b, 0x5cfbab0a, 0xd5d8d63d, 0xaf7a02f3, 0x502e531a,
127 0x8ae4652f, 0xcf96911c, 0x4fe412f7, 0xd900273b, 0xa32123c0, 0xc5b9b763,
128 0x928b591a, 0x7037a726, 0xdf196d4a, 0x2d589cf7,
135 return run_test(kBasicTestKey,
sizeof(kBasicTestKey), msg_buf, exp_tag);
145 static status_t long_key_test(
void) {
146 const char plaintext[] =
"Test message.";
148 .data = (
unsigned char *)plaintext,
149 .len =
sizeof(plaintext) - 1,
151 const uint32_t exp_tag[] = {
152 0xe5c6186f, 0xdf98244d, 0xe0d63bd7, 0x5da8384b, 0xfcfc942c, 0x4ee5c72a,
153 0x8458eba2, 0xb0ebe4a8, 0x4f95e0a5, 0xc2fdc57e, 0xae153c6b, 0x206670d8,
154 0xa3972dd7, 0xb686b9f0, 0x50d5b231, 0x4d729c24,
157 return run_test(kLongTestKey,
sizeof(kLongTestKey), msg_buf, exp_tag);
160 OTTF_DEFINE_TEST_CONFIG();
163 static volatile status_t test_result;
166 test_result = OK_STATUS();
167 CHECK_STATUS_OK(entropy_complex_init());
171 return status_ok(test_result);