Skip to content

Commit 29bcb2e

Browse files
itayzafrirOren Cohen
authored andcommitted
Add mbed-crypto hash verify test
1 parent 118f353 commit 29bcb2e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

TESTS/mbed-crypto/sanity/main.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,26 @@ void test_crypto_asymmetric_encrypt_decrypt(void)
7575
mbedtls_psa_crypto_free();
7676
}
7777

78+
void test_crypto_hash_verify(void)
79+
{
80+
psa_algorithm_t alg = PSA_ALG_SHA_256;
81+
psa_hash_operation_t operation;
82+
/* SHA-256 hash of an empty string */
83+
static const unsigned char hash[] = {
84+
0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8,
85+
0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
86+
0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55
87+
};
88+
89+
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_crypto_init());
90+
91+
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_setup(&operation, alg));
92+
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_verify(&operation, hash, sizeof(hash)));
93+
TEST_ASSERT_EQUAL(PSA_SUCCESS, psa_hash_abort(&operation));
94+
95+
mbedtls_psa_crypto_free();
96+
}
97+
7898
utest::v1::status_t case_failure_handler(const Case *const source, const failure_t reason)
7999
{
80100
mbedtls_psa_crypto_free();
@@ -91,6 +111,7 @@ utest::v1::status_t test_setup(const size_t number_of_cases)
91111
Case cases[] = {
92112
Case("mbed-crypto random", test_crypto_random, case_failure_handler),
93113
Case("mbed-crypto asymmetric encrypt/decrypt", test_crypto_asymmetric_encrypt_decrypt, case_failure_handler),
114+
Case("mbed-crypto hash verify", test_crypto_hash_verify, case_failure_handler),
94115
};
95116

96117
Specification specification(test_setup, cases);

0 commit comments

Comments
 (0)