From 1f45b674743d0d46ada3b59c1a5e2046357816de Mon Sep 17 00:00:00 2001 From: Jerry Yu Date: Sat, 12 Mar 2022 19:24:50 +0800 Subject: [PATCH] Add unit tests Signed-off-by: Jerry Yu --- tests/suites/test_suite_pk.data | 5 +++++ tests/suites/test_suite_pk.function | 30 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tests/suites/test_suite_pk.data b/tests/suites/test_suite_pk.data index 7d4fbcd8e7..b9a8d5d3b0 100644 --- a/tests/suites/test_suite_pk.data +++ b/tests/suites/test_suite_pk.data @@ -340,3 +340,8 @@ pk_psa_sign:MBEDTLS_ECP_DP_BP384R1:PSA_ECC_FAMILY_BRAINPOOL_P_R1:384 PSA wrapped sign: BP512R1 depends_on:MBEDTLS_ECP_DP_BP512R1_ENABLED pk_psa_sign:MBEDTLS_ECP_DP_BP512R1:PSA_ECC_FAMILY_BRAINPOOL_P_R1:512 + +PK test valid mebdtls_pk_sign_ext +depends_on:MBEDTLS_X509_RSASSA_PSS_SUPPORT:MBEDTLS_SHA512_C +pk_psa_sign_ext:MBEDTLS_PK_RSA:2048:MBEDTLS_PK_RSASSA_PSS:MBEDTLS_MD_SHA512 + diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function index ed3d602313..e89ae74a14 100644 --- a/tests/suites/test_suite_pk.function +++ b/tests/suites/test_suite_pk.function @@ -1087,3 +1087,33 @@ exit: USE_PSA_DONE( ); } /* END_CASE */ + +/* BEGIN_CASE depends_on:MBEDTLS_USE_PSA_CRYPTO */ +void pk_psa_sign_ext( int pk_type, int parameter, int key_pk_type, int md_alg ) +{ + mbedtls_pk_context pk; + size_t sig_len; + unsigned char sig[MBEDTLS_PK_SIGNATURE_MAX_SIZE]; + unsigned char hash[MBEDTLS_MD_MAX_SIZE]; + size_t hash_len = sizeof( hash ); + + memset( hash, 0x2a, sizeof hash ); + memset( sig, 0, sizeof sig ); + + mbedtls_pk_init( &pk ); + USE_PSA_INIT(); + + TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( pk_type ) ) == 0 ); + + TEST_ASSERT( pk_genkey( &pk, parameter ) == 0 ); + + TEST_ASSERT( mbedtls_pk_sign_ext( key_pk_type, &pk, md_alg, hash, hash_len, + sig, sizeof sig , &sig_len, + mbedtls_test_rnd_std_rand, NULL ) == 0 ); + +exit: + mbedtls_pk_free( &pk ); + USE_PSA_DONE( ); +} +/* END_CASE */ +