aboutsummaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
authorPrzemek Stekiel <przemyslaw.stekiel@mobica.com>2023-04-17 11:10:05 +0200
committerPrzemek Stekiel <przemyslaw.stekiel@mobica.com>2023-04-17 11:10:05 +0200
commita0a1c1eab514b4b2a12cdcc03d0c3631ee4f468d (patch)
treeeff2ad75d2ce3b8fd5d4a83ed7d2ea499e025780 /programs
parent6260ee9cabfe6b80867d67762a0fc7c0b6ac62ba (diff)
downloadmbedtls-a0a1c1eab514b4b2a12cdcc03d0c3631ee4f468d.zip
mbedtls-a0a1c1eab514b4b2a12cdcc03d0c3631ee4f468d.tar.gz
mbedtls-a0a1c1eab514b4b2a12cdcc03d0c3631ee4f468d.tar.bz2
Move psa_crypto_init() after other init calls
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
Diffstat (limited to 'programs')
-rw-r--r--programs/ssl/dtls_client.c22
-rw-r--r--programs/ssl/dtls_server.c20
-rw-r--r--programs/ssl/mini_client.c22
-rw-r--r--programs/ssl/ssl_client1.c21
-rw-r--r--programs/ssl/ssl_fork_server.c18
-rw-r--r--programs/ssl/ssl_mail_client.c20
-rw-r--r--programs/ssl/ssl_pthread_server.c20
-rw-r--r--programs/ssl/ssl_server.c20
-rw-r--r--programs/x509/cert_app.c18
-rw-r--r--programs/x509/cert_req.c18
-rw-r--r--programs/x509/cert_write.c18
-rw-r--r--programs/x509/crl_app.c10
-rw-r--r--programs/x509/req_app.c10
13 files changed, 119 insertions, 118 deletions
diff --git a/programs/ssl/dtls_client.c b/programs/ssl/dtls_client.c
index f8bde8f..240e7ae 100644
--- a/programs/ssl/dtls_client.c
+++ b/programs/ssl/dtls_client.c
@@ -97,16 +97,6 @@ int main(int argc, char *argv[])
((void) argc);
((void) argv);
-#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);
- ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
- goto exit;
- }
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
-
#if defined(MBEDTLS_DEBUG_C)
mbedtls_debug_set_threshold(DEBUG_LEVEL);
#endif
@@ -119,11 +109,21 @@ int main(int argc, char *argv[])
mbedtls_ssl_config_init(&conf);
mbedtls_x509_crt_init(&cacert);
mbedtls_ctr_drbg_init(&ctr_drbg);
+ mbedtls_entropy_init(&entropy);
+
+#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);
+ ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
+ goto exit;
+ }
+#endif /* MBEDTLS_USE_PSA_CRYPTO */
mbedtls_printf("\n . 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/ssl/dtls_server.c b/programs/ssl/dtls_server.c
index 14c7141..a72eb15 100644
--- a/programs/ssl/dtls_server.c
+++ b/programs/ssl/dtls_server.c
@@ -106,16 +106,6 @@ int main(void)
mbedtls_ssl_cache_context cache;
#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);
- ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
- goto exit;
- }
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
-
mbedtls_net_init(&listen_fd);
mbedtls_net_init(&client_fd);
mbedtls_ssl_init(&ssl);
@@ -129,6 +119,16 @@ int main(void)
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
+#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);
+ ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
+ goto exit;
+ }
+#endif /* MBEDTLS_USE_PSA_CRYPTO */
+
#if defined(MBEDTLS_DEBUG_C)
mbedtls_debug_set_threshold(DEBUG_LEVEL);
#endif
diff --git a/programs/ssl/mini_client.c b/programs/ssl/mini_client.c
index 4cecd26..98052da 100644
--- a/programs/ssl/mini_client.c
+++ b/programs/ssl/mini_client.c
@@ -166,16 +166,6 @@ int main(void)
mbedtls_ssl_config conf;
mbedtls_ctr_drbg_init(&ctr_drbg);
-#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);
- ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
- goto exit;
- }
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
-
/*
* 0. Initialize and setup stuff
*/
@@ -185,8 +175,18 @@ int main(void)
#if defined(MBEDTLS_X509_CRT_PARSE_C)
mbedtls_x509_crt_init(&ca);
#endif
-
mbedtls_entropy_init(&entropy);
+
+#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);
+ ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
+ goto exit;
+ }
+#endif /* MBEDTLS_USE_PSA_CRYPTO */
+
if (mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
(const unsigned char *) pers, strlen(pers)) != 0) {
ret = ctr_drbg_seed_failed;
diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c
index a497c60..c7aaf49 100644
--- a/programs/ssl/ssl_client1.c
+++ b/programs/ssl/ssl_client1.c
@@ -83,15 +83,6 @@ int main(void)
mbedtls_debug_set_threshold(DEBUG_LEVEL);
#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 */
-
/*
* 0. Initialize the RNG and the session data
*/
@@ -100,11 +91,21 @@ int main(void)
mbedtls_ssl_config_init(&conf);
mbedtls_x509_crt_init(&cacert);
mbedtls_ctr_drbg_init(&ctr_drbg);
+ mbedtls_entropy_init(&entropy);
+
+#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 */
mbedtls_printf("\n . 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/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c
index 34dadbd..123091d 100644
--- a/programs/ssl/ssl_fork_server.c
+++ b/programs/ssl/ssl_fork_server.c
@@ -96,15 +96,6 @@ int main(void)
mbedtls_x509_crt srvcert;
mbedtls_pk_context pkey;
-#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 */
-
mbedtls_net_init(&listen_fd);
mbedtls_net_init(&client_fd);
mbedtls_ssl_init(&ssl);
@@ -114,6 +105,15 @@ int main(void)
mbedtls_x509_crt_init(&srvcert);
mbedtls_ctr_drbg_init(&ctr_drbg);
+#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 */
+
signal(SIGCHLD, SIG_IGN);
/*
diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c
index 182eae9..5ac726f 100644
--- a/programs/ssl/ssl_mail_client.c
+++ b/programs/ssl/ssl_mail_client.c
@@ -358,15 +358,6 @@ int main(int argc, char *argv[])
char *p, *q;
const int *list;
-#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 */
-
/*
* Make sure memory references are valid in case we exit early.
*/
@@ -378,6 +369,16 @@ int main(int argc, char *argv[])
mbedtls_x509_crt_init(&clicert);
mbedtls_pk_init(&pkey);
mbedtls_ctr_drbg_init(&ctr_drbg);
+ mbedtls_entropy_init(&entropy);
+
+#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:
@@ -467,7 +468,6 @@ usage:
mbedtls_printf("\n . 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/ssl/ssl_pthread_server.c b/programs/ssl/ssl_pthread_server.c
index 9576062..206d8f3 100644
--- a/programs/ssl/ssl_pthread_server.c
+++ b/programs/ssl/ssl_pthread_server.c
@@ -306,16 +306,6 @@ int main(void)
mbedtls_ssl_cache_context cache;
#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);
- ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
- goto exit;
- }
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
-
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C)
mbedtls_memory_buffer_alloc_init(alloc_buf, sizeof(alloc_buf));
#endif
@@ -342,6 +332,16 @@ int main(void)
*/
mbedtls_entropy_init(&entropy);
+#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);
+ ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
+ goto exit;
+ }
+#endif /* MBEDTLS_USE_PSA_CRYPTO */
+
/*
* 1a. Seed the random number generator
*/
diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c
index 22bfd42..d70fdb1 100644
--- a/programs/ssl/ssl_server.c
+++ b/programs/ssl/ssl_server.c
@@ -92,16 +92,6 @@ int main(void)
mbedtls_ssl_cache_context cache;
#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);
- ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
- goto exit;
- }
-#endif /* MBEDTLS_USE_PSA_CRYPTO */
-
mbedtls_net_init(&listen_fd);
mbedtls_net_init(&client_fd);
mbedtls_ssl_init(&ssl);
@@ -114,6 +104,16 @@ int main(void)
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
+#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);
+ ret = MBEDTLS_ERR_SSL_HW_ACCEL_FAILED;
+ goto exit;
+ }
+#endif /* MBEDTLS_USE_PSA_CRYPTO */
+
#if defined(MBEDTLS_DEBUG_C)
mbedtls_debug_set_threshold(DEBUG_LEVEL);
#endif
diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c
index b212ac3..13d96ea 100644
--- a/programs/x509/cert_app.c
+++ b/programs/x509/cert_app.c
@@ -145,15 +145,6 @@ int main(int argc, char *argv[])
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
*/
@@ -171,6 +162,15 @@ int main(int argc, char *argv[])
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 0d71f4d..a3eafff 100644
--- a/programs/x509/cert_req.c
+++ b/programs/x509/cert_req.c
@@ -172,6 +172,15 @@ int main(int argc, char *argv[])
const char *pers = "csr example app";
mbedtls_x509_san_list *cur, *prev;
+ /*
+ * 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) {
@@ -181,14 +190,6 @@ int main(int argc, char *argv[])
}
#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);
@@ -397,7 +398,6 @@ usage:
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 bdcae9e..7b47e54 100644
--- a/programs/x509/cert_write.c
+++ b/programs/x509/cert_write.c
@@ -315,15 +315,6 @@ int main(int argc, char *argv[])
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
*/
@@ -339,6 +330,15 @@ int main(int argc, char *argv[])
memset(buf, 0, sizeof(buf));
memset(serial, 0, sizeof(serial));
+#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 840f74e..f45d0b8 100644
--- a/programs/x509/crl_app.c
+++ b/programs/x509/crl_app.c
@@ -65,6 +65,11 @@ int main(int argc, char *argv[])
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) {
@@ -74,11 +79,6 @@ int main(int argc, char *argv[])
}
#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 b866c8e..c63f896 100644
--- a/programs/x509/req_app.c
+++ b/programs/x509/req_app.c
@@ -65,6 +65,11 @@ int main(int argc, char *argv[])
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) {
@@ -74,11 +79,6 @@ int main(int argc, char *argv[])
}
#endif /* MBEDTLS_USE_PSA_CRYPTO */
- /*
- * Set to sane values
- */
- mbedtls_x509_csr_init(&csr);
-
if (argc < 2) {
usage:
mbedtls_printf(USAGE);