summaryrefslogtreecommitdiff
path: root/lib/nettle
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-03-20 16:31:42 +0100
committerNikos Mavrogiannopoulos <nmav@redhat.com>2017-03-20 16:33:14 +0100
commitc4842a21f65c7fc9a27932eb1792b1fc9e65f722 (patch)
treec6ab16a57a4d40fe090399119763e59ae02f4264 /lib/nettle
parente4f71929c2cb1590cb49771def810413aeef832a (diff)
downloadgnutls-c4842a21f65c7fc9a27932eb1792b1fc9e65f722.tar.gz
nettle/rnd: use gettime() instead of gnutls_time()
The gnulib gettime() maps to gettimeofday() or clock_gettime() which are both implemented as fast system calls - see vdso(7)- and as such are available without a switch to kernel mode. Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
Diffstat (limited to 'lib/nettle')
-rw-r--r--lib/nettle/rnd.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lib/nettle/rnd.c b/lib/nettle/rnd.c
index a02c72f519..f374253df8 100644
--- a/lib/nettle/rnd.c
+++ b/lib/nettle/rnd.c
@@ -168,7 +168,7 @@ wrap_nettle_rnd(void *_ctx, int level, void *data, size_t datasize)
struct prng_ctx_st *prng_ctx;
int ret, reseed = 0;
uint8_t new_key[PRNG_KEY_SIZE];
- time_t now;
+ struct timespec now; /* current time */
if (level == GNUTLS_RND_RANDOM || level == GNUTLS_RND_KEY)
prng_ctx = &ctx->normal;
@@ -183,7 +183,7 @@ wrap_nettle_rnd(void *_ctx, int level, void *data, size_t datasize)
*/
memset(data, 0, datasize);
- now = gnutls_time(0);
+ gettime(&now);
/* We re-seed based on time in addition to output data. That is,
* to prevent a temporal state compromise to become permanent for low
@@ -191,7 +191,7 @@ wrap_nettle_rnd(void *_ctx, int level, void *data, size_t datasize)
if (unlikely(_gnutls_detect_fork(prng_ctx->forkid))) {
reseed = 1;
} else {
- if (now > prng_ctx->last_reseed + prng_reseed_time[level])
+ if (now.tv_sec > prng_ctx->last_reseed + prng_reseed_time[level])
reseed = 1;
}
@@ -216,7 +216,7 @@ wrap_nettle_rnd(void *_ctx, int level, void *data, size_t datasize)
goto cleanup;
}
- prng_ctx->last_reseed = now;
+ prng_ctx->last_reseed = now.tv_sec;
prng_ctx->forkid = _gnutls_get_forkid();
}