]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
rand: use arc4random as fallback when available
authorHarry Sintonen <sintonen@iki.fi>
Sat, 4 Mar 2023 07:02:14 +0000 (09:02 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 6 Mar 2023 10:21:38 +0000 (11:21 +0100)
Normally curl uses cryptographically strong random provided by the
selected SSL backend. If compiled without SSL support, a naive built-in
function was used instead.

Generally this was okay, but it will result in some downsides for non-
SSL builds, such as predictable temporary file names.

This change ensures that arc4random will be used instead, if available.

Closes #10672

configure.ac
lib/rand.c

index 988183d5d194f0f68a3ea194666eb5c69e9ad529..f40652c07e8743d6a5c333252b4198a633968e04 100644 (file)
@@ -3626,7 +3626,8 @@ AC_CHECK_FUNCS([fnmatch \
   setrlimit \
   snprintf \
   utime \
-  utimes
+  utimes \
+  arc4random
 ],[
 ],[
   func="$ac_func"
index 4b6ac072e622cdc091dc33e4b2fb10278db63b33..9abb722d2bc35e3fbecce6082c3c844f14aae895 100644 (file)
 #ifdef HAVE_ARPA_INET_H
 #include <arpa/inet.h>
 #endif
+#ifdef HAVE_ARC4RANDOM
+/* Some platforms might have the prototype missing (ubuntu + libressl) */
+uint32_t arc4random(void);
+#endif
 
 #include <curl/curl.h>
 #include "vtls/vtls.h"
@@ -143,6 +147,11 @@ static CURLcode randit(struct Curl_easy *data, unsigned int *rnd)
   }
 #endif
 
+#ifdef HAVE_ARC4RANDOM
+  *rnd = (unsigned int)arc4random();
+  return CURLE_OK;
+#endif
+
 #if defined(RANDOM_FILE) && !defined(WIN32)
   if(!seeded) {
     /* if there's a random file to read a seed from, use it */