Skip to content

Commit 88e0846

Browse files
Add dedicated test cases for psa_hash_compare
psa_hash_compare is tested for good cases and invalid-signature cases in hash_compute_compare. Also test invalid-argument cases. Also run a few autonomous test cases with valid arguments.
1 parent 29eb80d commit 88e0846

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

tests/suites/test_suite_psa_crypto.data

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,35 @@ PSA hash compute: output buffer too small
787787
depends_on:MBEDTLS_SHA256_C
788788
hash_compute_fail:PSA_ALG_SHA_256:"":31:PSA_ERROR_BUFFER_TOO_SMALL
789789

790+
PSA hash compare: bad algorithm (unknown hash)
791+
hash_compare_fail:PSA_ALG_CATEGORY_HASH:"":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855":PSA_ERROR_NOT_SUPPORTED
792+
793+
PSA hash compare: bad algorithm (wildcard)
794+
hash_compare_fail:PSA_ALG_ANY_HASH:"":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855":PSA_ERROR_NOT_SUPPORTED
795+
796+
PSA hash compare: bad algorithm (not a hash)
797+
hash_compare_fail:PSA_ALG_HMAC(PSA_ALG_SHA_256):"":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855":PSA_ERROR_INVALID_ARGUMENT
798+
799+
PSA hash compare: hash of a prefix
800+
depends_on:MBEDTLS_SHA256_C
801+
hash_compare_fail:PSA_ALG_SHA_256:"00":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855":PSA_ERROR_INVALID_SIGNATURE
802+
803+
PSA hash compare: hash with flipped bit
804+
depends_on:MBEDTLS_SHA256_C
805+
hash_compare_fail:PSA_ALG_SHA_256:"":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b854":PSA_ERROR_INVALID_SIGNATURE
806+
807+
PSA hash compare: hash with trailing garbage
808+
depends_on:MBEDTLS_SHA256_C
809+
hash_compare_fail:PSA_ALG_SHA_256:"":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b85500":PSA_ERROR_INVALID_SIGNATURE
810+
811+
PSA hash compare: truncated hash
812+
depends_on:MBEDTLS_SHA256_C
813+
hash_compare_fail:PSA_ALG_SHA_256:"":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8":PSA_ERROR_INVALID_SIGNATURE
814+
815+
PSA hash compare: good
816+
depends_on:MBEDTLS_SHA256_C
817+
hash_compare_fail:PSA_ALG_SHA_256:"":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855":PSA_SUCCESS
818+
790819
PSA hash compute: good, SHA-1
791820
depends_on:MBEDTLS_SHA1_C
792821
hash_compute_compare:PSA_ALG_SHA_1:"42749e":"a444319e9b6cc1e8464c511ec0969c37d6bb2619"

tests/suites/test_suite_psa_crypto.function

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,6 +2456,26 @@ exit:
24562456
}
24572457
/* END_CASE */
24582458

2459+
/* BEGIN_CASE */
2460+
void hash_compare_fail( int alg_arg, data_t *input,
2461+
data_t *reference_hash,
2462+
int expected_status_arg )
2463+
{
2464+
psa_algorithm_t alg = alg_arg;
2465+
psa_status_t expected_status = expected_status_arg;
2466+
psa_status_t status;
2467+
2468+
PSA_ASSERT( psa_crypto_init( ) );
2469+
2470+
status = psa_hash_compare( alg, input->x, input->len,
2471+
reference_hash->x, reference_hash->len );
2472+
TEST_EQUAL( status, expected_status );
2473+
2474+
exit:
2475+
PSA_DONE( );
2476+
}
2477+
/* END_CASE */
2478+
24592479
/* BEGIN_CASE */
24602480
void hash_compute_compare( int alg_arg, data_t *input,
24612481
data_t *expected_output )

0 commit comments

Comments
 (0)