Setup / deinitialize PSA in pk tests only if no MD is used

Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
diff --git a/tests/include/test/psa_crypto_helpers.h b/tests/include/test/psa_crypto_helpers.h
index 4302345..bc2b016 100644
--- a/tests/include/test/psa_crypto_helpers.h
+++ b/tests/include/test/psa_crypto_helpers.h
@@ -276,15 +276,17 @@
         }                                                                  \
     }                                                                      \
     while( 0 )
-#else
-/* Define empty macros so that we can use them in the preamble and teardown
- * of every test function that uses PSA conditionally based on
- * MBEDTLS_PSA_CRYPTO_C. */
-#define PSA_INIT( ) ( (void) 0 )
-#define PSA_DONE( ) ( (void) 0 )
 
+#if !defined(MBEDTLS_MD_C)
+#define PSA_INIT_IF_NO_MD( ) PSA_INIT( )
+#define PSA_DONE_IF_NO_MD( ) PSA_DONE( )
+#endif
 #endif /* MBEDTLS_PSA_CRYPTO_C */
 
+#if defined(MBEDTLS_MD_C)
+#define PSA_INIT_IF_NO_MD( ) ( (void) 0 )
+#define PSA_DONE_IF_NO_MD( ) ( (void) 0 )
+#endif
 /** \def USE_PSA_INIT
  *
  * Call this macro to initialize the PSA subsystem if #MBEDTLS_USE_PSA_CRYPTO
diff --git a/tests/suites/test_suite_pkcs5.function b/tests/suites/test_suite_pkcs5.function
index e2347cc..fcbf9b1 100644
--- a/tests/suites/test_suite_pkcs5.function
+++ b/tests/suites/test_suite_pkcs5.function
@@ -14,14 +14,14 @@
 {
     unsigned char key[100];
 
-    PSA_INIT();
+    PSA_INIT_IF_NO_MD();
     TEST_ASSERT( mbedtls_pkcs5_pbkdf2_hmac_ext( hash, pw_str->x, pw_str->len,
                                                 salt_str->x, salt_str->len,
                                                 it_cnt, key_len, key ) == 0 );
 
     TEST_ASSERT( mbedtls_test_hexcmp( key, result_key_string->x,
                                       key_len, result_key_string->len ) == 0 );
-    PSA_DONE();
+    PSA_DONE_IF_NO_MD();
 }
 /* END_CASE */
 
@@ -33,7 +33,7 @@
     mbedtls_asn1_buf params;
     unsigned char *my_out = NULL;
 
-    PSA_INIT();
+    PSA_INIT_IF_NO_MD();
 
     params.tag = params_tag;
     params.p = params_hex->x;
@@ -50,7 +50,7 @@
 
 exit:
     mbedtls_free( my_out );
-    PSA_DONE();
+    PSA_DONE_IF_NO_MD();
 }
 /* END_CASE */
 
diff --git a/tests/suites/test_suite_pkparse.function b/tests/suites/test_suite_pkparse.function
index 1e003b9..8ca3aca 100644
--- a/tests/suites/test_suite_pkparse.function
+++ b/tests/suites/test_suite_pkparse.function
@@ -17,7 +17,7 @@
     int res;
     char *pwd = password;
 
-    PSA_INIT();
+    PSA_INIT_IF_NO_MD();
     mbedtls_pk_init( &ctx );
 
     if( strcmp( pwd, "NULL" ) == 0 )
@@ -38,7 +38,7 @@
 
 exit:
     mbedtls_pk_free( &ctx );
-    PSA_DONE();
+    PSA_DONE_IF_NO_MD();
 }
 /* END_CASE */
 
@@ -48,7 +48,7 @@
     mbedtls_pk_context ctx;
     int res;
 
-    PSA_INIT();
+    PSA_INIT_IF_NO_MD();
     mbedtls_pk_init( &ctx );
 
     res = mbedtls_pk_parse_public_keyfile( &ctx, key_file );
@@ -65,7 +65,7 @@
 
 exit:
     mbedtls_pk_free( &ctx );
-    PSA_DONE();
+    PSA_DONE_IF_NO_MD();
 }
 /* END_CASE */