test: suites: pkcs7/x509parse: add missing PSA_INIT and PSA_DONE
Both PKCS7 and X509 rely on PK module under the hood and the latter can
use PSA to store keys and perform operations. Therefore psa_crypto_init()
must be called before any operation can be done with PKCS7 and X509.
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
diff --git a/tests/suites/test_suite_pkcs7.function b/tests/suites/test_suite_pkcs7.function
index e5dc4bd..0c4a00b 100644
--- a/tests/suites/test_suite_pkcs7.function
+++ b/tests/suites/test_suite_pkcs7.function
@@ -33,9 +33,17 @@
void pkcs7_asn1_fail(data_t *pkcs7_buf)
{
int res;
+
+ /* PKCS7 uses X509 which itself relies on PK under the hood and the latter
+ * can use PSA to store keys and perform operations so psa_crypto_init()
+ * must be called before. */
+ USE_PSA_INIT();
+
res = pkcs7_parse_buffer(pkcs7_buf->x, pkcs7_buf->len);
TEST_ASSERT(res != MBEDTLS_PKCS7_SIGNED_DATA);
+exit:
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -46,6 +54,11 @@
size_t buflen;
int res;
+ /* PKCS7 uses X509 which itself relies on PK under the hood and the latter
+ * can use PSA to store keys and perform operations so psa_crypto_init()
+ * must be called before. */
+ USE_PSA_INIT();
+
res = mbedtls_pk_load_file(pkcs7_file, &pkcs7_buf, &buflen);
TEST_EQUAL(res, 0);
@@ -54,6 +67,7 @@
exit:
mbedtls_free(pkcs7_buf);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -77,7 +91,7 @@
mbedtls_pkcs7 pkcs7;
mbedtls_x509_crt **crts = NULL;
- MD_OR_USE_PSA_INIT();
+ USE_PSA_INIT();
mbedtls_pkcs7_init(&pkcs7);
@@ -166,6 +180,6 @@
mbedtls_free(crts);
mbedtls_free(data);
mbedtls_free(pkcs7_buf);
- MD_OR_USE_PSA_DONE();
+ USE_PSA_DONE();
}
/* END_CASE */
diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function
index 7bcac86..8225adb 100644
--- a/tests/suites/test_suite_x509parse.function
+++ b/tests/suites/test_suite_x509parse.function
@@ -1668,6 +1668,9 @@
mbedtls_x509_crt crt;
mbedtls_x509_crt_init(&crt);
+ /* X509 relies on PK under the hood and the latter can use PSA to store keys
+ * and perform operations so psa_crypto_init() must be called before. */
+ USE_PSA_INIT();
TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, file), ref_ret);
@@ -1682,6 +1685,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */
@@ -1697,6 +1701,9 @@
char name_buf[128];
mbedtls_x509_crt_init(&crt);
+ /* X509 relies on PK under the hood and the latter can use PSA to store keys
+ * and perform operations so psa_crypto_init() must be called before. */
+ USE_PSA_INIT();
TEST_EQUAL(mbedtls_x509_crt_parse_file(&crt, file), ref_ret);
@@ -1748,6 +1755,7 @@
exit:
mbedtls_x509_crt_free(&crt);
+ USE_PSA_DONE();
}
/* END_CASE */