X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Frandom-util.c;h=2f468db770d6d24fd8fa838dc8aa5a195f34d5b1;hb=5489ba3e334d21609a042d5dc1615323f2903181;hp=b230044f50994a12070c3a842c18563148211438;hpb=3b22396a4b2767a98172f6915929c47738cb0a1e;p=elogind.git diff --git a/src/basic/random-util.c b/src/basic/random-util.c index b230044f5..2f468db77 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -17,21 +17,24 @@ along with systemd; If not, see . ***/ -#include +#include #include -#include -#include #include -#include +#include +#include +#include +#include +#include + #ifdef HAVE_SYS_AUXV_H #include #endif -#include +#include "fd-util.h" +#include "io-util.h" +#include "missing.h" #include "random-util.h" #include "time-util.h" -#include "missing.h" -#include "util.h" int dev_urandom(void *p, size_t n) { static int have_syscall = -1; @@ -92,17 +95,18 @@ void initialize_srand(void) { if (srand_called) return; - x = 0; - #ifdef HAVE_SYS_AUXV_H - /* The kernel provides us with a bit of entropy in auxv, so - * let's try to make use of that to seed the pseudo-random - * generator. It's better than nothing... */ + /* The kernel provides us with 16 bytes of entropy in auxv, so let's try to make use of that to seed the + * pseudo-random generator. It's better than nothing... */ auxv = (void*) getauxval(AT_RANDOM); - if (auxv) - x ^= *(unsigned*) auxv; + if (auxv) { + assert_cc(sizeof(x) < 16); + memcpy(&x, auxv, sizeof(x)); + } else #endif + x = 0; + x ^= (unsigned) now(CLOCK_REALTIME); x ^= (unsigned) gettid();