aboutsummaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2018-12-26 11:46:11 +0100
committerToni Uhlig <matzeton@googlemail.com>2018-12-26 11:46:11 +0100
commit4b33cf8cee7b048ebccfe83b27ce00e8bdd70a50 (patch)
treef2bc3f3c79a34054255db24853ea7d616ba1037e /src/utils.c
parent2c7c3b62df2661b3276253fb3d8d624d81c398a2 (diff)
replaced rand() with more "secure" random() // CID 301767
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 66ed4c0..12e7992 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -43,8 +43,12 @@
* Note that the source code is best viewed with tabs set to 4 spaces.
*/
+#include <stdio.h>
+#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
+#include <time.h>
+#include <assert.h>
#ifndef WIN32
#include <syslog.h>
@@ -142,3 +146,11 @@ void print_hexstr(unsigned char *buf, size_t siz) {
free(out);
}
#endif
+
+int pt_random(void) {
+ struct timespec ts;
+
+ assert(timespec_get(&ts, TIME_UTC));
+ srandom(ts.tv_nsec ^ ts.tv_sec);
+ return random();
+}