rand: replace time() with time_stamp() as entropy source

time_stamp() has bigger precision.
This commit is contained in:
Dmitry Podgorny
2016-09-02 17:38:42 +03:00
parent c0a224cf84
commit b6fcb7035d
2 changed files with 7 additions and 6 deletions

View File

@@ -212,9 +212,7 @@ static int Hash_DRBG_Generate(Hash_DRBG_CTX *ctx, uint8_t *output,
#define ENTROPY_ACCUMULATE(ptr, last, type, arg) \ #define ENTROPY_ACCUMULATE(ptr, last, type, arg) \
do { \ do { \
type __arg = (type)(arg); \ type __arg = (type)(arg); \
if ((char*)ptr + sizeof(__arg) < (char*)last && \ if ((char*)ptr + sizeof(__arg) < (char*)last) { \
__arg != (type)-1) \
{ \
*(type*)ptr = __arg; \ *(type*)ptr = __arg; \
ptr = (void*)((char*)ptr + sizeof(__arg)); \ ptr = (void*)((char*)ptr + sizeof(__arg)); \
} \ } \
@@ -228,8 +226,8 @@ static void xmpp_rand_reseed(xmpp_rand_t *rand)
size_t len; size_t len;
/* entropy: /* entropy:
* 1. time(2) * 1. time_stamp()
* 2. clock(3) if != -1 * 2. clock(3)
* 3. xmpp_rand_t address to make unique seed within one process * 3. xmpp_rand_t address to make unique seed within one process
* 4. counter to make unique seed within one context * 4. counter to make unique seed within one context
* 5. stack address * 5. stack address
@@ -240,7 +238,7 @@ static void xmpp_rand_reseed(xmpp_rand_t *rand)
* XXX 6 and 7 are not implemented yet. * XXX 6 and 7 are not implemented yet.
*/ */
ENTROPY_ACCUMULATE(ptr, last, time_t, time(NULL)); ENTROPY_ACCUMULATE(ptr, last, uint64_t, time_stamp());
ENTROPY_ACCUMULATE(ptr, last, clock_t, clock()); ENTROPY_ACCUMULATE(ptr, last, clock_t, clock());
ENTROPY_ACCUMULATE(ptr, last, void *, rand); ENTROPY_ACCUMULATE(ptr, last, void *, rand);
ENTROPY_ACCUMULATE(ptr, last, unsigned, ++rand->reseed_count); ENTROPY_ACCUMULATE(ptr, last, unsigned, ++rand->reseed_count);

View File

@@ -28,6 +28,9 @@ void xmpp_free(const xmpp_ctx_t * const ctx, void *p) { }
int xmpp_snprintf (char *str, size_t count, const char *fmt, ...) { int xmpp_snprintf (char *str, size_t count, const char *fmt, ...) {
return 0; return 0;
} }
uint64_t time_stamp(void) {
return 0;
}
static struct { static struct {
const char *entropy_input; const char *entropy_input;