]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
cleanup: Move init_random_seed() to where it is being used
authorDavid Sommerseth <davids@openvpn.net>
Tue, 25 Jul 2017 15:07:23 +0000 (17:07 +0200)
committerDavid Sommerseth <davids@openvpn.net>
Fri, 11 Aug 2017 19:57:05 +0000 (21:57 +0200)
The init_random_seed() function is only used by the init_static() in
init.c.  As this function was pretty basic and it is only being called
once, it was merged into init_static() instead of keeping it as a separate
function.

(I agree that calling functions often makes the code more readable, but
I would rather see that as a part of cleaning up the whole init_static()
function - in fact when moving all "unit tests" in init_static() to cmocka,
it will not be too bad in the end.)

Signed-off-by: David Sommerseth <davids@openvpn.net>
Acked-by: Steffan Karger <steffan@karger.me>
Message-Id: <20170725150723.14919-1-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15136.html
Signed-off-by: David Sommerseth <davids@openvpn.net>
(cherry picked from commit e74e3a4db891b3ace0a96461c597d86e87be06f0)

src/openvpn/init.c
src/openvpn/misc.c
src/openvpn/misc.h

index efe634f4eae3a16aa320fe5fccd89ea254d37d5b..858614d3c0d5fc29edbc7ee582ec3bab435bae32 100644 (file)
@@ -610,6 +610,7 @@ init_port_share(struct context *c)
 
 #endif /* if PORT_SHARE */
 
+
 bool
 init_static(void)
 {
@@ -619,8 +620,20 @@ init_static(void)
     crypto_init_dmalloc();
 #endif
 
-    init_random_seed();         /* init random() function, only used as
-                                 * source for weak random numbers */
+
+    /*
+     * Initialize random number seed.  random() is only used
+     * when "weak" random numbers are acceptable.
+     * SSL library routines are always used when cryptographically
+     * strong random numbers are required.
+     */
+    struct timeval tv;
+    if (!gettimeofday(&tv, NULL))
+    {
+        const unsigned int seed = (unsigned int) tv.tv_sec ^ tv.tv_usec;
+        srandom(seed);
+    }
+
     error_reset();              /* initialize error.c */
     reset_check_status();       /* initialize status check code in socket.c */
 
index 8a76bba89c6c7c23fefd82a9d986d8d132eb9dae..aff1bb2e53d5f22541a25812440b27f00a8c39e3 100644 (file)
@@ -404,25 +404,6 @@ openvpn_popen(const struct argv *a,  const struct env_set *es)
 
 
 
-/*
- * Initialize random number seed.  random() is only used
- * when "weak" random numbers are acceptable.
- * OpenSSL routines are always used when cryptographically
- * strong random numbers are required.
- */
-
-void
-init_random_seed(void)
-{
-    struct timeval tv;
-
-    if (!gettimeofday(&tv, NULL))
-    {
-        const unsigned int seed = (unsigned int) tv.tv_sec ^ tv.tv_usec;
-        srandom(seed);
-    }
-}
-
 /*
  * Set environmental variable (int or string).
  *
index 734e679c5edfab6a534b76ddf4bf5097a4465d24..a7aa7622af30adc624030df57f10f1fc2c8985cd 100644 (file)
@@ -100,9 +100,6 @@ void set_std_files_to_null(bool stdin_only);
 extern int inetd_socket_descriptor;
 void save_inetd_socket_descriptor(void);
 
-/* init random() function, only used as source for weak random numbers, when !ENABLE_CRYPTO */
-void init_random_seed(void);
-
 /* set/delete environmental variable */
 void setenv_str_ex(struct env_set *es,
                    const char *name,