Free psa crypto at the end of programs when initialized
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c
index 07016e4..721de84 100644
--- a/programs/x509/cert_app.c
+++ b/programs/x509/cert_app.c
@@ -461,6 +461,7 @@
#endif
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
+ mbedtls_psa_crypto_free();
#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
diff --git a/programs/x509/cert_req.c b/programs/x509/cert_req.c
index a3fd6e2..43b1eb1 100644
--- a/programs/x509/cert_req.c
+++ b/programs/x509/cert_req.c
@@ -374,6 +374,7 @@
mbedtls_pk_free(&key);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
+ mbedtls_psa_crypto_free();
#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c
index f7cf712..bf46799 100644
--- a/programs/x509/cert_write.c
+++ b/programs/x509/cert_write.c
@@ -726,6 +726,7 @@
mbedtls_mpi_free(&serial);
mbedtls_ctr_drbg_free(&ctr_drbg);
mbedtls_entropy_free(&entropy);
+ mbedtls_psa_crypto_free();
#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
diff --git a/programs/x509/crl_app.c b/programs/x509/crl_app.c
index 1208f04..f99d9ac 100644
--- a/programs/x509/crl_app.c
+++ b/programs/x509/crl_app.c
@@ -136,6 +136,7 @@
exit:
mbedtls_x509_crl_free(&crl);
+ mbedtls_psa_crypto_free();
#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");
diff --git a/programs/x509/load_roots.c b/programs/x509/load_roots.c
index 87187e6..bca6e88 100644
--- a/programs/x509/load_roots.c
+++ b/programs/x509/load_roots.c
@@ -127,11 +127,6 @@
struct mbedtls_timing_hr_time timer;
unsigned long ms;
- if (argc <= 1) {
- mbedtls_printf(USAGE);
- goto exit;
- }
-
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
@@ -141,6 +136,11 @@
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
+ if (argc <= 1) {
+ mbedtls_printf(USAGE);
+ goto exit;
+ }
+
opt.filenames = NULL;
opt.iterations = DFL_ITERATIONS;
opt.prime_cache = DFL_PRIME_CACHE;
@@ -200,6 +200,7 @@
exit_code = MBEDTLS_EXIT_SUCCESS;
exit:
+ mbedtls_psa_crypto_free();
mbedtls_exit(exit_code);
}
#endif /* necessary configuration */
diff --git a/programs/x509/req_app.c b/programs/x509/req_app.c
index 07cbd4f..b1fc98c 100644
--- a/programs/x509/req_app.c
+++ b/programs/x509/req_app.c
@@ -136,6 +136,7 @@
exit:
mbedtls_x509_csr_free(&csr);
+ mbedtls_psa_crypto_free();
#if defined(_WIN32)
mbedtls_printf(" + Press Enter to exit this program.\n");