diff options
author | Remco Rijnders <remco@webconquest.com> | 2020-08-31 13:10:25 -0400 |
---|---|---|
committer | Remco Rijnders <remco@webconquest.com> | 2020-09-14 08:59:00 -0400 |
commit | 8ccd96dbb699912c1f9cc2291c76f5da39e3d06e (patch) | |
tree | 42726420a4f6cd669bed546e3a9fc082c8878d04 /init.c | |
parent | 56de020a2e67d383040cf22e543b87e4bac77446 (diff) |
Implement LFRS113 PRNG functions
- Instead of relying on random() implementations which can be of
questionable quality or relying on the presence of /dev/urandom, we
implement our own PRNG implementation that uses the LFRS113 PRNG algorithm
by Pierre L'Ecuyer.
We seed this PRNG with values based on time, pid and ppid. It is OK if not
all seeds are of the highest quality as all four seeds would have to be
known to predict the numbers generated. In addition to this, we also use
/dev/urandom values (if available) that we mix into our four seeds.
In case we are reseeding we will also reuse our existing state information
for setting the new seed values.
- Add a function to Base64 encode 96 random bits
Diffstat (limited to 'init.c')
-rw-r--r-- | init.c | 20 |
1 files changed, 0 insertions, 20 deletions
@@ -39,8 +39,6 @@ #include "mutt_ssl.h" #endif - - #include "mx.h" #include "init.h" #include "mailbox.h" @@ -3558,23 +3556,6 @@ static int mutt_execute_commands (LIST *p) return 0; } -static void mutt_srandom (void) -{ - struct timeval tv; - unsigned seed; - - gettimeofday(&tv, NULL); - /* POSIX.1-2008 states that seed is 'unsigned' without specifying its width. - * Use as many of the lower order bits from the current time of day as the seed. - * If the upper bound is truncated, that is fine. - * - * tv_sec is integral of type integer or float. Cast to 'long long' before - * bitshift in case it is a float. - */ - seed = ((LONGLONG) tv.tv_sec << 20) | tv.tv_usec; - srandom(seed); -} - static char* mutt_find_cfg (const char *home, const char *xdg_cfg_home) { const char* names[] = @@ -3633,7 +3614,6 @@ void mutt_init (int skip_sys_rc, LIST *commands) MUTT_HASH_ALLOW_DUPS); mutt_menu_init (); - mutt_srandom (); mutt_buffer_pool_init (); buffer = mutt_buffer_pool_get (); |