diff options
Diffstat (limited to 'tests/vb2_common2_tests.c')
-rw-r--r-- | tests/vb2_common2_tests.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/vb2_common2_tests.c b/tests/vb2_common2_tests.c index e793e57a..18398c11 100644 --- a/tests/vb2_common2_tests.c +++ b/tests/vb2_common2_tests.c @@ -19,6 +19,28 @@ static const uint8_t test_data[] = "This is some test data to sign."; static const uint32_t test_size = sizeof(test_data); +static const uint8_t test_data_sha1[VB2_SHA1_DIGEST_SIZE] = { + 0x6f, 0xde, 0xe7, 0x73, 0x93, 0xbe, 0x23, 0x34, + 0xb3, 0x54, 0xc2, 0xe9, 0x18, 0xb8, 0x1b, 0xf8, + 0x99, 0x36, 0x63, 0x09, +}; +static const uint8_t test_data_sha256[VB2_SHA256_DIGEST_SIZE] = { + 0xc0, 0x2c, 0xdb, 0x18, 0xe4, 0xd9, 0xfc, 0x65, + 0xcb, 0xea, 0x11, 0x8e, 0x9e, 0x1c, 0x51, 0x2d, + 0xeb, 0x69, 0x5f, 0x56, 0x1f, 0xd8, 0x77, 0x7b, + 0x7d, 0x9d, 0x4f, 0x21, 0x81, 0xac, 0x9e, 0xd5, +}; +static const uint8_t test_data_sha512[VB2_SHA512_DIGEST_SIZE] = { + 0x0e, 0x0c, 0x9c, 0xf7, 0x08, 0x28, 0xee, 0xd7, + 0x0d, 0x62, 0xf5, 0x46, 0xa1, 0x2d, 0xf3, 0x79, + 0x41, 0x0c, 0x80, 0xbf, 0xaf, 0x1f, 0xfa, 0x41, + 0xdb, 0x8e, 0x30, 0x02, 0x16, 0xf1, 0x4b, 0x2c, + 0x67, 0x1f, 0x5b, 0xfb, 0x06, 0x49, 0xc9, 0xf4, + 0x6b, 0x62, 0xb9, 0x27, 0x94, 0xc3, 0xf4, 0xb8, + 0xc7, 0x23, 0x40, 0xc5, 0xfb, 0x74, 0xab, 0xa4, + 0x63, 0xfd, 0x3f, 0xf3, 0x2b, 0xa3, 0xc5, 0x3b, +}; +static const uint8_t *hwcrypto_next_hash; static enum hwcrypto_state { HWCRYPTO_OK, @@ -44,9 +66,23 @@ static vb2_error_t hwcrypto_mock(enum hwcrypto_state *state) return VB2_ERROR_MOCK; } -vb2_error_t vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm hash_alg, +vb2_error_t vb2ex_hwcrypto_digest_init(enum vb2_hash_algorithm algo, uint32_t data_size) { + switch (algo) { + case VB2_HASH_SHA1: + hwcrypto_next_hash = test_data_sha1; + break; + case VB2_HASH_SHA256: + hwcrypto_next_hash = test_data_sha256; + break; + case VB2_HASH_SHA512: + hwcrypto_next_hash = test_data_sha512; + break; + default: + TEST_TRUE(false, " no mock hash for algorithm"); + break; + } return hwcrypto_mock(&hwcrypto_state_digest); } @@ -58,6 +94,7 @@ vb2_error_t vb2ex_hwcrypto_digest_extend(const uint8_t *buf, uint32_t size) vb2_error_t vb2ex_hwcrypto_digest_finalize(uint8_t *digest, uint32_t digest_size) { + memcpy(digest, hwcrypto_next_hash, digest_size); return hwcrypto_mock(&hwcrypto_state_digest); } |