svn commit: r230230 - head/sys/dev/random
Andrey Chernov
ache at FreeBSD.ORG
Thu Jan 26 17:50:24 UTC 2012
> On Thu, Jan 26, 2012 at 11:32:38AM -0500, John Baldwin wrote:
> > Atomics don't operate on enums. You'll need to make it an int and just use
> > #define's for the 3 states.
--- sys/libkern.h.old 2012-01-16 07:15:12.000000000 +0400
+++ sys/libkern.h 2012-01-26 21:40:21.000000000 +0400
@@ -72,6 +72,10 @@ static __inline quad_t qabs(quad_t a) {
/* Prototypes for non-quad routines. */
struct malloc_type;
+#define ARC4_ENTR_NONE 0 /* Don't have entropy yet. */
+#define ARC4_ENTR_HAVE 1 /* Have entropy. */
+#define ARC4_ENTR_SEED 2 /* Reseeding. */
+extern volatile int arc4rand_iniseed_state;
uint32_t arc4random(void);
void arc4rand(void *ptr, u_int len, int reseed);
int bcmp(const void *, const void *, size_t);
--- dev/random/randomdev_soft.c.old 2011-03-02 01:42:19.000000000 +0300
+++ dev/random/randomdev_soft.c 2012-01-26 19:35:12.000000000 +0400
@@ -366,6 +366,8 @@ random_yarrow_unblock(void)
selwakeuppri(&random_systat.rsel, PUSER);
wakeup(&random_systat);
}
+ (void)atomic_cmpset_int(&arc4rand_iniseed_state,
+ ARC4_ENTR_NONE, ARC4_ENTR_HAVE);
}
static int
--- libkern/arc4random.c.old 2008-08-08 01:51:09.000000000 +0400
+++ libkern/arc4random.c 2012-01-26 21:40:47.000000000 +0400
@@ -24,6 +24,8 @@ __FBSDID("$FreeBSD: src/sys/libkern/arc4
#define ARC4_RESEED_SECONDS 300
#define ARC4_KEYBYTES (256 / 8)
+volatile int arc4rand_iniseed_state = ARC4_ENTR_NONE;
+
static u_int8_t arc4_i, arc4_j;
static int arc4_numruns = 0;
static u_int8_t arc4_sbox[256];
@@ -130,7 +132,9 @@ arc4rand(void *ptr, u_int len, int resee
struct timeval tv;
getmicrouptime(&tv);
- if (reseed ||
+ if (atomic_cmpset_int(&arc4rand_iniseed_state,
+ ARC4_ENTR_HAVE, ARC4_ENTR_SEED) ||
+ reseed ||
(arc4_numruns > ARC4_RESEED_BYTES) ||
(tv.tv_sec > arc4_t_reseed))
arc4_randomstir();
--
http://ache.vniz.net/
More information about the svn-src-head
mailing list