Move psa_crypto_init() after other init calls
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c
index 4fae3b2..07016e4 100644
--- a/programs/x509/cert_app.c
+++ b/programs/x509/cert_app.c
@@ -149,15 +149,6 @@
char *p, *q;
const char *pers = "cert_app";
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_status_t status = psa_crypto_init();
- if (status != PSA_SUCCESS) {
- mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
- (int) status);
- goto exit;
- }
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
-
/*
* Set to sane values
*/
@@ -175,6 +166,15 @@
memset(&cacrl, 0, sizeof(mbedtls_x509_crl));
#endif
+#if defined(MBEDTLS_USE_PSA_CRYPTO)
+ psa_status_t status = psa_crypto_init();
+ if (status != PSA_SUCCESS) {
+ mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
+ (int) status);
+ goto exit;
+ }
+#endif /* MBEDTLS_USE_PSA_CRYPTO */
+
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
diff --git a/programs/x509/cert_req.c b/programs/x509/cert_req.c
index 2f4bd0e..a3fd6e2 100644
--- a/programs/x509/cert_req.c
+++ b/programs/x509/cert_req.c
@@ -155,6 +155,15 @@
mbedtls_ctr_drbg_context ctr_drbg;
const char *pers = "csr example app";
+ /*
+ * Set to sane values
+ */
+ mbedtls_x509write_csr_init(&req);
+ mbedtls_pk_init(&key);
+ mbedtls_ctr_drbg_init(&ctr_drbg);
+ memset(buf, 0, sizeof(buf));
+ mbedtls_entropy_init(&entropy);
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
@@ -164,14 +173,6 @@
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- /*
- * Set to sane values
- */
- mbedtls_x509write_csr_init(&req);
- mbedtls_pk_init(&key);
- mbedtls_ctr_drbg_init(&ctr_drbg);
- memset(buf, 0, sizeof(buf));
-
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
@@ -303,7 +304,6 @@
mbedtls_printf(" . Seeding the random number generator...");
fflush(stdout);
- mbedtls_entropy_init(&entropy);
if ((ret = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *) pers,
strlen(pers))) != 0) {
diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c
index 18a05ca..f7cf712 100644
--- a/programs/x509/cert_write.c
+++ b/programs/x509/cert_write.c
@@ -226,15 +226,6 @@
mbedtls_ctr_drbg_context ctr_drbg;
const char *pers = "crt example app";
-#if defined(MBEDTLS_USE_PSA_CRYPTO)
- psa_status_t status = psa_crypto_init();
- if (status != PSA_SUCCESS) {
- mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
- (int) status);
- goto exit;
- }
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
-
/*
* Set to sane values
*/
@@ -250,6 +241,15 @@
mbedtls_x509_crt_init(&issuer_crt);
memset(buf, 0, 1024);
+#if defined(MBEDTLS_USE_PSA_CRYPTO)
+ psa_status_t status = psa_crypto_init();
+ if (status != PSA_SUCCESS) {
+ mbedtls_fprintf(stderr, "Failed to initialize PSA Crypto implementation: %d\n",
+ (int) status);
+ goto exit;
+ }
+#endif /* MBEDTLS_USE_PSA_CRYPTO */
+
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
diff --git a/programs/x509/crl_app.c b/programs/x509/crl_app.c
index 5a07963..1208f04 100644
--- a/programs/x509/crl_app.c
+++ b/programs/x509/crl_app.c
@@ -67,6 +67,11 @@
int i;
char *p, *q;
+ /*
+ * Set to sane values
+ */
+ mbedtls_x509_crl_init(&crl);
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
@@ -76,11 +81,6 @@
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- /*
- * Set to sane values
- */
- mbedtls_x509_crl_init(&crl);
-
if (argc < 2) {
usage:
mbedtls_printf(USAGE);
diff --git a/programs/x509/req_app.c b/programs/x509/req_app.c
index a5fb1b6..07cbd4f 100644
--- a/programs/x509/req_app.c
+++ b/programs/x509/req_app.c
@@ -67,6 +67,11 @@
int i;
char *p, *q;
+ /*
+ * Set to sane values
+ */
+ mbedtls_x509_csr_init(&csr);
+
#if defined(MBEDTLS_USE_PSA_CRYPTO)
psa_status_t status = psa_crypto_init();
if (status != PSA_SUCCESS) {
@@ -76,11 +81,6 @@
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- /*
- * Set to sane values
- */
- mbedtls_x509_csr_init(&csr);
-
if (argc < 2) {
usage:
mbedtls_printf(USAGE);