5 #include "sw/device/lib/base/status.h"
6 #include "sw/device/lib/crypto/drivers/entropy.h"
7 #include "sw/device/lib/crypto/impl/integrity.h"
8 #include "sw/device/lib/crypto/impl/keyblob.h"
12 #include "sw/device/lib/testing/randomness_quality.h"
13 #include "sw/device/lib/testing/test_framework/check.h"
18 #define MODULE_ID MAKE_MODULE_ID('t', 's', 't')
20 OTTF_DEFINE_TEST_CONFIG();
24 static const randomness_quality_significance_t kSignificance =
25 kRandomnessQualitySignificanceOnePercent;
28 static const uint8_t kPersonalizationData[5] = {0xf0, 0xf1, 0xf2, 0xf3, 0xf4};
30 .data = kPersonalizationData,
31 .len =
sizeof(kPersonalizationData),
36 .version = kOtcryptoLibVersion1,
37 .key_mode = kOtcryptoKeyModeAesCbc,
38 .key_length = 192 / 8,
40 .security_level = kOtcryptoKeySecurityLevelLow,
45 .version = kOtcryptoLibVersion1,
46 .key_mode = kOtcryptoKeyModeHmacSha256,
47 .key_length = 256 / 8,
49 .security_level = kOtcryptoKeySecurityLevelLow,
54 .version = kOtcryptoLibVersion1,
55 .key_mode = kOtcryptoKeyModeKmac128,
56 .key_length = 128 / 8,
58 .security_level = kOtcryptoKeySecurityLevelLow,
61 static status_t entropy_complex_init_test(
void) {
64 TRY(entropy_complex_init());
67 return entropy_complex_check();
81 size_t key_share_words = config.key_length /
sizeof(uint32_t);
82 uint32_t keyblob[key_share_words * 2];
83 memset(keyblob, 0,
sizeof(keyblob));
88 .keyblob_length =
sizeof(keyblob),
97 TRY(randomness_quality_monobit_test((
unsigned char *)keyblob,
sizeof(keyblob),
103 HARDENED_TRY(keyblob_to_shares(&key, &share0, &share1));
104 for (
size_t i = 0; i < key_share_words; i++) {
105 LOG_INFO(
"key[%d] = 0x%08x", i, share0[i] ^ share1[i]);
111 static status_t aes_keygen_test(
void) {
112 return basic_keygen_test(kAesKeyConfig);
115 static status_t hmac_keygen_test(
void) {
116 return basic_keygen_test(kHmacKeyConfig);
119 static status_t kmac_keygen_test(
void) {
120 return basic_keygen_test(kKmacKeyConfig);
123 static status_t generate_multiple_keys_test(
void) {
125 size_t key_share_words = kAesKeyConfig.key_length /
sizeof(uint32_t);
126 uint32_t keyblob_buffer[key_share_words * 4];
127 uint32_t *keyblob1 = keyblob_buffer;
128 uint32_t *keyblob2 = &keyblob_buffer[key_share_words * 2];
129 memset(keyblob_buffer, 0,
sizeof(keyblob_buffer));
133 .config = kAesKeyConfig,
134 .keyblob_length =
sizeof(keyblob_buffer) / 2,
138 .config = kAesKeyConfig,
139 .keyblob_length =
sizeof(keyblob_buffer) / 2,
147 TRY(randomness_quality_monobit_test((
unsigned char *)keyblob_buffer,
148 sizeof(keyblob_buffer), kSignificance));
161 return status_ok(result);