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 = 384 / 32,
23 static const uint32_t kBasicTestKey[] = {
24 0x57ae5177, 0x4fa70bbc, 0x1aba5c9d, 0x43958d45, 0xfe702c34, 0x2f5e2f10,
25 0x50c239b3, 0xf110560f, 0x7c6a2732, 0xcd397db8, 0xeaef22e5, 0xd18da16b};
29 static const uint32_t kLongTestKey[] = {
30 0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0x13121110, 0x17161514,
31 0x1b1a1918, 0x1f1e1d1c, 0x23222120, 0x27262524, 0x2b2a2928, 0x2f2e2d2c,
32 0x33323130, 0x37363534, 0x3b3a3938, 0x3f3e3d3c, 0x43424140, 0x03020100,
33 0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0x13121110, 0x17161514, 0x1b1a1918,
34 0x1f1e1d1c, 0x23222120, 0x27262524, 0x2b2a2928, 0x2f2e2d2c, 0x33323130,
35 0x37363534, 0x3b3a3938, 0x3f3e3d3c, 0x43424140,
40 static const uint32_t kTestMask[
ARRAYSIZE(kLongTestKey)] = {
41 0x8cb847c3, 0xc6d34f36, 0x72edbf7b, 0x9bc0317f, 0x8f003c7f, 0x1d7ba049,
42 0xfd463b63, 0xbb720c44, 0x784c215e, 0xeb101d65, 0x35beb911, 0xab481345,
43 0xa7ebc3e3, 0x04b2a1b9, 0x764a9630, 0x78b8f9c5, 0x3f2a1d8e, 0x8cb847c3,
44 0xc6d34f36, 0x72edbf7b, 0x9bc0317f, 0x8f003c7f, 0x1d7ba049, 0xfd463b63,
45 0xbb720c44, 0x784c215e, 0xeb101d65, 0x35beb911, 0xab481345, 0xa7ebc3e3,
46 0x04b2a1b9, 0x764a9630, 0x78b8f9c5, 0x3f2a1d8e,
58 static status_t run_test(
const uint32_t *key,
size_t key_len,
60 const uint32_t *exp_tag) {
63 .version = kOtcryptoLibVersion1,
64 .key_mode = kOtcryptoKeyModeHmacSha384,
65 .key_length = key_len,
68 .security_level = kOtcryptoKeySecurityLevelLow,
71 uint32_t keyblob[keyblob_num_words(config)];
72 TRY(keyblob_from_key_and_mask(key, kTestMask, config, keyblob));
76 .keyblob_length =
sizeof(keyblob),
79 blinded_key.checksum = integrity_blinded_checksum(&blinded_key);
81 uint32_t act_tag[kTagLenWords];
88 TRY_CHECK_ARRAYS_EQ(act_tag, exp_tag, kTagLenWords);
100 const char plaintext[] =
"Test message.";
102 .data = (
unsigned char *)plaintext,
103 .len =
sizeof(plaintext) - 1,
105 const uint32_t exp_tag[] = {
106 0xe069ba2f, 0x9751a19b, 0x378df8af, 0x00eeaa68, 0x5789b69c, 0xcd1dc363,
107 0x6d14d0f1, 0xd062444e, 0xed683c1a, 0xe1cee642, 0xa44b7be6, 0x0518dd8b,
109 return run_test(kBasicTestKey,
sizeof(kBasicTestKey), msg_buf, exp_tag);
120 const uint32_t exp_tag[] = {
121 0xe97192b6, 0xa45d5f4f, 0xb2cd3703, 0x2b41d3f2, 0x7b8b566d, 0x716fa851,
122 0x4f45f809, 0x6c27343c, 0x985b4af4, 0xabe37c99, 0x0b17598f, 0xf9711f6e,
128 return run_test(kBasicTestKey,
sizeof(kBasicTestKey), msg_buf, exp_tag);
138 static status_t long_key_test(
void) {
139 const char plaintext[] =
"Test message.";
141 .data = (
unsigned char *)plaintext,
142 .len =
sizeof(plaintext) - 1,
144 const uint32_t exp_tag[] = {
145 0x2d6accaa, 0x92eead9a, 0x7c46788c, 0xb081a802, 0x6b8afc0a, 0xcf094d00,
146 0x92a4b805, 0x5c5f1a65, 0x98bcd4f8, 0xbdb29885, 0x72f05431, 0xc08db439,
148 return run_test(kLongTestKey,
sizeof(kLongTestKey), msg_buf, exp_tag);
151 OTTF_DEFINE_TEST_CONFIG();
154 static volatile status_t test_result;
157 test_result = OK_STATUS();
158 CHECK_STATUS_OK(entropy_complex_init());
162 return status_ok(test_result);