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 = 256 / 32,
23 static const uint32_t kBasicTestKey[] = {
24 0xea10ff1b, 0x04b2b9a5, 0x2a23f3d6, 0x518e3e57,
25 0xc3687ba2, 0xea6d3619, 0xb0916bf2, 0x347a2f71,
30 static const uint32_t kLongTestKey[] = {
31 0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0x13121110, 0x17161514,
32 0x1b1a1918, 0x1f1e1d1c, 0x23222120, 0x27262524, 0x2b2a2928, 0x2f2e2d2c,
33 0x33323130, 0x37363534, 0x3b3a3938, 0x3f3e3d3c, 0x43424140,
38 static const uint32_t kTestMask[
ARRAYSIZE(kLongTestKey)] = {
39 0x8cb847c3, 0xc6d34f36, 0x72edbf7b, 0x9bc0317f, 0x8f003c7f, 0x1d7ba049,
40 0xfd463b63, 0xbb720c44, 0x784c215e, 0xeb101d65, 0x35beb911, 0xab481345,
41 0xa7ebc3e3, 0x04b2a1b9, 0x764a9630, 0x78b8f9c5, 0x3f2a1d8e,
53 static status_t run_test(
const uint32_t *key,
size_t key_len,
55 const uint32_t *exp_tag) {
58 .version = kOtcryptoLibVersion1,
59 .key_mode = kOtcryptoKeyModeHmacSha256,
60 .key_length = key_len,
63 .security_level = kOtcryptoKeySecurityLevelLow,
66 uint32_t keyblob[keyblob_num_words(config)];
67 TRY(keyblob_from_key_and_mask(key, kTestMask, config, keyblob));
71 .keyblob_length =
sizeof(keyblob),
74 blinded_key.checksum = integrity_blinded_checksum(&blinded_key);
76 uint32_t act_tag[kTagLenWords];
83 TRY_CHECK_ARRAYS_EQ(act_tag, exp_tag, kTagLenWords);
94 const char plaintext[] =
"Test message.";
96 .data = (
unsigned char *)plaintext,
97 .len =
sizeof(plaintext) - 1,
99 const uint32_t exp_tag[] = {
100 0x025b59b4, 0x38162abe, 0x36663189, 0xe1ec5666,
101 0x959b742b, 0x525e81a2, 0x535387d6, 0x6f12f309,
103 return run_test(kBasicTestKey,
sizeof(kBasicTestKey), msg_buf, exp_tag);
113 const uint32_t exp_tag[] = {
114 0xbb5c42a9, 0x0e3ad140, 0x61679107, 0xa34a6cc0,
115 0x53306979, 0xfa8a5061, 0xbc8b2ee6, 0xa499c0a5,
121 return run_test(kBasicTestKey,
sizeof(kBasicTestKey), msg_buf, exp_tag);
130 static status_t long_key_test(
void) {
131 const char plaintext[] =
"Test message.";
133 .data = (
unsigned char *)plaintext,
134 .len =
sizeof(plaintext) - 1,
136 const uint32_t exp_tag[] = {
137 0xa477ab6f, 0x73fae19d, 0x4f7fa9df, 0xd556b936,
138 0x1dd1af52, 0xcd84f577, 0x32835c8c, 0x36682ad3,
140 return run_test(kLongTestKey,
sizeof(kLongTestKey), msg_buf, exp_tag);
143 OTTF_DEFINE_TEST_CONFIG();
146 static volatile status_t test_result;
149 test_result = OK_STATUS();
150 CHECK_STATUS_OK(entropy_complex_init());
154 return status_ok(test_result);