diff options
author | 2016-05-30 17:52:26 +0000 | |
---|---|---|
committer | 2016-05-30 17:52:26 +0000 | |
commit | d18fc0f09a349229965ff4dc19fe799c20348ef6 (patch) | |
tree | baf275fce7ea4dc080ef2f6836381e77a67f38fc | |
parent | Some tests for \<; will be fixed by martijn@'s upcoming commit to process.c (diff) | |
download | wireguard-openbsd-d18fc0f09a349229965ff4dc19fe799c20348ef6.tar.xz wireguard-openbsd-d18fc0f09a349229965ff4dc19fe799c20348ef6.zip |
include rdtsc in the rdrand callback. some systems don't have rdrand yet,
but rdtsc may provide a few bits. ok deraadt
-rw-r--r-- | sys/arch/amd64/amd64/autoconf.c | 8 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/cpu.c | 40 |
2 files changed, 22 insertions, 26 deletions
diff --git a/sys/arch/amd64/amd64/autoconf.c b/sys/arch/amd64/amd64/autoconf.c index 5c7566a12c4..f34e557c575 100644 --- a/sys/arch/amd64/amd64/autoconf.c +++ b/sys/arch/amd64/amd64/autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: autoconf.c,v 1.45 2015/12/27 04:31:34 jsg Exp $ */ +/* $OpenBSD: autoconf.c,v 1.46 2016/05/30 17:52:26 tedu Exp $ */ /* $NetBSD: autoconf.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -139,10 +139,8 @@ cpu_configure(void) timeout_set(&viac3_rnd_tmo, viac3_rnd, &viac3_rnd_tmo); viac3_rnd(&viac3_rnd_tmo); } - if (has_rdrand || has_rdseed) { - timeout_set(&rdrand_tmo, rdrand, &rdrand_tmo); - rdrand(&rdrand_tmo); - } + timeout_set(&rdrand_tmo, rdrand, &rdrand_tmo); + rdrand(&rdrand_tmo); #ifdef CRYPTO /* * Also, if the chip has crypto available, enable it. diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index ea7553acbfd..0cad54c30f6 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.98 2016/05/03 08:30:15 kettenis Exp $ */ +/* $OpenBSD: cpu.c,v 1.99 2016/05/30 17:52:26 tedu Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -879,28 +879,26 @@ rdrand(void *v) union { uint64_t u64; uint32_t u32[2]; - } r; + } r, t; uint8_t valid; - int i; - if (has_rdrand == 0 && has_rdseed == 0) - return; - for (i = 0; i < 2; i++) { - if (has_rdseed) - __asm volatile( - "rdseed %0\n\t" - "setc %1\n" - : "=r" (r.u64), "=qm" (valid) ); - if (has_rdseed == 0 || valid == 0) - __asm volatile( - "rdrand %0\n\t" - "setc %1\n" - : "=r" (r.u64), "=qm" (valid) ); - if (valid) { - add_true_randomness(r.u32[0]); - add_true_randomness(r.u32[1]); - } - } + if (has_rdseed) + __asm volatile( + "rdseed %0\n\t" + "setc %1\n" + : "=r" (r.u64), "=qm" (valid) ); + if (has_rdrand && (has_rdseed == 0 || valid == 0)) + __asm volatile( + "rdrand %0\n\t" + "setc %1\n" + : "=r" (r.u64), "=qm" (valid) ); + + t.u64 = rdtsc(); + + if (valid) + t.u64 ^= r.u64; + add_true_randomness(t.u32[0]); + add_true_randomness(t.u32[1]); if (tmo) timeout_add_msec(tmo, 10); |