5 #include "sw/device/lib/crypto/drivers/entropy.h"
6 #include "sw/device/lib/crypto/impl/status.h"
9 #include "sw/device/lib/testing/test_framework/check.h"
16 static const unsigned char kOneBlockMessage[] =
"abc";
17 static const size_t kOneBlockMessageLen = 3;
18 static const uint8_t kOneBlockExpDigest[] = {
19 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, 0xb5, 0xa0, 0x3d, 0x69,
20 0x9a, 0xc6, 0x50, 0x07, 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
21 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed, 0x80, 0x86, 0x07, 0x2b,
22 0xa1, 0xe7, 0xcc, 0x23, 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7};
28 static const unsigned char kTwoBlockMessage[] =
29 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjk"
30 "lmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
31 static const size_t kTwoBlockMessageLen =
sizeof(kTwoBlockMessage) - 1;
32 static const uint8_t kTwoBlockExpDigest[] = {
33 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, 0x3d, 0x19, 0x2f, 0xc7,
34 0x82, 0xcd, 0x1b, 0x47, 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
35 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12, 0xfc, 0xc7, 0xc7, 0x1a,
36 0x55, 0x7e, 0x2d, 0xb9, 0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39};
43 static const uint8_t kEmptyExpDigest[] = {
44 0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38, 0x4c, 0xd9, 0x32, 0x7e,
45 0xb1, 0xb1, 0xe3, 0x6a, 0x21, 0xfd, 0xb7, 0x11, 0x14, 0xbe, 0x07, 0x43,
46 0x4c, 0x0c, 0xc7, 0xbf, 0x63, 0xf6, 0xe1, 0xda, 0x27, 0x4e, 0xde, 0xbf,
47 0xe7, 0x6f, 0x65, 0xfb, 0xd5, 0x1a, 0xd2, 0xf1, 0x48, 0x98, 0xb9, 0x5b,
53 status_t sha384_test(
const unsigned char *msg,
const size_t msg_len,
54 const uint8_t *expected_digest) {
62 uint32_t actual_digest_data[384 / 32];
64 .data = actual_digest_data,
66 .mode = kOtcryptoHashModeSha384,
71 TRY_CHECK_ARRAYS_EQ((
unsigned char *)actual_digest_data, expected_digest,
72 sizeof(actual_digest_data));
80 status_t sha384_streaming_test(
const unsigned char *msg,
size_t msg_len,
81 const uint8_t *expected_digest) {
88 size_t len = (msg_len <= 5) ? msg_len : 5;
99 uint32_t actual_digest_data[384 / 32];
101 .data = actual_digest_data,
103 .mode = kOtcryptoHashModeSha384,
108 TRY_CHECK_ARRAYS_EQ((
unsigned char *)actual_digest_data, expected_digest,
109 sizeof(actual_digest_data));
115 return sha384_test(NULL, 0, kEmptyExpDigest);
118 static status_t one_block_test(
void) {
119 return sha384_test(kOneBlockMessage, kOneBlockMessageLen, kOneBlockExpDigest);
122 static status_t two_block_test(
void) {
123 return sha384_test(kTwoBlockMessage, kTwoBlockMessageLen, kTwoBlockExpDigest);
126 static status_t streaming_test(
void) {
127 return sha384_streaming_test(kTwoBlockMessage, kTwoBlockMessageLen,
131 OTTF_DEFINE_TEST_CONFIG();
134 static volatile status_t test_result;
137 test_result = OK_STATUS();
138 CHECK_STATUS_OK(entropy_complex_init());
143 return status_ok(test_result);