From 967f161887dd261225331e9a68c2ee55c4c55b3d Mon Sep 17 00:00:00 2001 From: Alexander Vdolainen Date: Wed, 6 Jul 2016 05:35:30 +0300 Subject: [PATCH] sxt: sxt_reseed() --- include/sxt/lcrypt.h | 1 + include/sxt/sxt.h | 2 ++ sxt/core.c | 5 +++++ sxt/lcrypt.c | 12 ++++++++++++ 4 files changed, 20 insertions(+) diff --git a/include/sxt/lcrypt.h b/include/sxt/lcrypt.h index 5f40267..c8319fb 100644 --- a/include/sxt/lcrypt.h +++ b/include/sxt/lcrypt.h @@ -51,5 +51,6 @@ SHA512CTX sha512_init(void); void sha512_update(SHA512CTX c, const void *data, unsigned long len); void sha512_final(unsigned char *md, SHA512CTX c); +int lcrypt_reseed(void); #endif diff --git a/include/sxt/sxt.h b/include/sxt/sxt.h index 3beb949..a119c75 100644 --- a/include/sxt/sxt.h +++ b/include/sxt/sxt.h @@ -31,4 +31,6 @@ int sxt_init(void); int sxt_finish(void); +int sxt_reseed(void); + #endif /* __SXT_SXT_H__ */ diff --git a/sxt/core.c b/sxt/core.c index a708706..a2600b2 100644 --- a/sxt/core.c +++ b/sxt/core.c @@ -72,6 +72,11 @@ int sxt_finish(void) return 0; } +int sxt_reseed(void) +{ + return lcrypt_reseed(); +} + int sxt_get_random(void *data, int len, int pseudo) { if(pseudo) return RAND_bytes(data, len); diff --git a/sxt/lcrypt.c b/sxt/lcrypt.c index 84c3902..c66f922 100644 --- a/sxt/lcrypt.c +++ b/sxt/lcrypt.c @@ -27,9 +27,11 @@ #include #include #include +#include #include #include +#include #include #include @@ -171,3 +173,13 @@ int lcrypt_init_ciphers(void) return r; } +/* misc */ +int lcrypt_reseed(void) +{ +#ifndef WIN32 + struct timeval tv; + gettimeofday(&tv, NULL); + RAND_add(&tv, sizeof(struct timeval), 0.0); +#endif + return SXT_SUCCESS; +}