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>
... | ... |
@@ -610,6 +610,7 @@ init_port_share(struct context *c) |
610 | 610 |
|
611 | 611 |
#endif /* if PORT_SHARE */ |
612 | 612 |
|
613 |
+ |
|
613 | 614 |
bool |
614 | 615 |
init_static(void) |
615 | 616 |
{ |
... | ... |
@@ -619,8 +620,20 @@ init_static(void) |
619 | 619 |
crypto_init_dmalloc(); |
620 | 620 |
#endif |
621 | 621 |
|
622 |
- init_random_seed(); /* init random() function, only used as |
|
623 |
- * source for weak random numbers */ |
|
622 |
+ |
|
623 |
+ /* |
|
624 |
+ * Initialize random number seed. random() is only used |
|
625 |
+ * when "weak" random numbers are acceptable. |
|
626 |
+ * SSL library routines are always used when cryptographically |
|
627 |
+ * strong random numbers are required. |
|
628 |
+ */ |
|
629 |
+ struct timeval tv; |
|
630 |
+ if (!gettimeofday(&tv, NULL)) |
|
631 |
+ { |
|
632 |
+ const unsigned int seed = (unsigned int) tv.tv_sec ^ tv.tv_usec; |
|
633 |
+ srandom(seed); |
|
634 |
+ } |
|
635 |
+ |
|
624 | 636 |
error_reset(); /* initialize error.c */ |
625 | 637 |
reset_check_status(); /* initialize status check code in socket.c */ |
626 | 638 |
|
... | ... |
@@ -405,25 +405,6 @@ openvpn_popen(const struct argv *a, const struct env_set *es) |
405 | 405 |
|
406 | 406 |
|
407 | 407 |
/* |
408 |
- * Initialize random number seed. random() is only used |
|
409 |
- * when "weak" random numbers are acceptable. |
|
410 |
- * OpenSSL routines are always used when cryptographically |
|
411 |
- * strong random numbers are required. |
|
412 |
- */ |
|
413 |
- |
|
414 |
-void |
|
415 |
-init_random_seed(void) |
|
416 |
-{ |
|
417 |
- struct timeval tv; |
|
418 |
- |
|
419 |
- if (!gettimeofday(&tv, NULL)) |
|
420 |
- { |
|
421 |
- const unsigned int seed = (unsigned int) tv.tv_sec ^ tv.tv_usec; |
|
422 |
- srandom(seed); |
|
423 |
- } |
|
424 |
-} |
|
425 |
- |
|
426 |
-/* |
|
427 | 408 |
* Set environmental variable (int or string). |
428 | 409 |
* |
429 | 410 |
* On Posix, we use putenv for portability, |
... | ... |
@@ -100,9 +100,6 @@ void set_std_files_to_null(bool stdin_only); |
100 | 100 |
extern int inetd_socket_descriptor; |
101 | 101 |
void save_inetd_socket_descriptor(void); |
102 | 102 |
|
103 |
-/* init random() function, only used as source for weak random numbers, when !ENABLE_CRYPTO */ |
|
104 |
-void init_random_seed(void); |
|
105 |
- |
|
106 | 103 |
/* set/delete environmental variable */ |
107 | 104 |
void setenv_str_ex(struct env_set *es, |
108 | 105 |
const char *name, |