]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
mbedtls: move the crypto init into the vtls init function
authorDaniel Stenberg <daniel@haxx.se>
Fri, 17 Oct 2025 20:47:28 +0000 (22:47 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 17 Oct 2025 21:33:12 +0000 (23:33 +0200)
Follow-up to 3a305831d1a9d10b2bfd4fa3939

Closes #19108

lib/easy.c
lib/vtls/mbedtls.c

index f12a8b143f0cc781c60c50937d13dbc39e43b29e..793a18f33eb88090ca72bcb56479d19ade337ce0 100644 (file)
 
 #include "easy_lock.h"
 
-#ifdef USE_MBEDTLS
-#include <psa/crypto.h>
-#endif
-
 /* The last 2 #include files should be in this order */
 #include "curl_memory.h"
 #include "memdebug.h"
@@ -141,24 +137,6 @@ curl_calloc_callback Curl_ccalloc = (curl_calloc_callback)calloc;
 static char *leakpointer;
 #endif
 
-static CURLcode crypto_init(void)
-{
-#ifdef USE_MBEDTLS
-  psa_status_t status;
-  status = psa_crypto_init();
-  if(status != PSA_SUCCESS)
-    return CURLE_FAILED_INIT;
-#endif
-  return CURLE_OK;
-}
-
-static void crypto_cleanup(void)
-{
-#ifdef USE_MBEDTLS
-  mbedtls_psa_crypto_free();
-#endif
-}
-
 /**
  * curl_global_init() globally initializes curl given a bitwise set of the
  * different features of what to initialize.
@@ -182,11 +160,6 @@ static CURLcode global_init(long flags, bool memoryfuncs)
     goto fail;
   }
 
-  if(crypto_init()) {
-    DEBUGF(curl_mfprintf(stderr, "Error: crypto_init failed\n"));
-    goto fail;
-  }
-
   if(!Curl_ssl_init()) {
     DEBUGF(curl_mfprintf(stderr, "Error: Curl_ssl_init failed\n"));
     goto fail;
@@ -325,8 +298,6 @@ void curl_global_cleanup(void)
 
   Curl_ssh_cleanup();
 
-  crypto_cleanup();
-
 #ifdef DEBUGBUILD
   free(leakpointer);
 #endif
index ebb8a4abc00955ed6c001be4fa57b122200c6aef..5ee0c814fd3dd38efe02476426b4645c140171f3 100644 (file)
@@ -1449,6 +1449,10 @@ static CURLcode mbedtls_connect(struct Curl_cfilter *cf,
  */
 static int mbedtls_init(void)
 {
+  psa_status_t status;
+  status = psa_crypto_init();
+  if(status != PSA_SUCCESS)
+    return 0;
   if(!Curl_mbedtlsthreadlock_thread_setup())
     return 0;
 #if defined(CURL_MBEDTLS_DRBG) && defined(HAS_THREADING_SUPPORT)
@@ -1463,6 +1467,7 @@ static void mbedtls_cleanup(void)
   entropy_cleanup_mutex(&ts_entropy);
 #endif
   (void)Curl_mbedtlsthreadlock_thread_cleanup();
+  mbedtls_psa_crypto_free();
 }
 
 static bool mbedtls_data_pending(struct Curl_cfilter *cf,