From: David Sommerseth Date: Tue, 25 Jul 2017 15:07:23 +0000 (+0200) Subject: cleanup: Move init_random_seed() to where it is being used X-Git-Tag: v2.4.4~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4bd2f4ef5b765ede3df9ae77b16cbeed5b4f7963;p=thirdparty%2Fopenvpn.git cleanup: Move init_random_seed() to where it is being used 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 Acked-by: Steffan Karger 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 (cherry picked from commit e74e3a4db891b3ace0a96461c597d86e87be06f0) --- diff --git a/src/openvpn/init.c b/src/openvpn/init.c index efe634f4e..858614d3c 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -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 */ diff --git a/src/openvpn/misc.c b/src/openvpn/misc.c index 8a76bba89..aff1bb2e5 100644 --- a/src/openvpn/misc.c +++ b/src/openvpn/misc.c @@ -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). * diff --git a/src/openvpn/misc.h b/src/openvpn/misc.h index 734e679c5..a7aa7622a 100644 --- a/src/openvpn/misc.h +++ b/src/openvpn/misc.h @@ -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,