arc4random (again)
Lorenzo Beretta <[email protected]> Fri, 29 May 2015 17:54:16 +0200
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <[email protected]> |
It's only stirred after first handling out 256 zeroes
- seeing the offending code right there in my previous message probably
makes it the worst bugreport ever :)
Initializing n adds some bytes to arc4random.o, which go away inverting
its meaning (ie, n = "# of uint32 available before next stir")
"n-=1" because I almost sent a patch with "n--"
Index: lib/arc4random.c
===================================================================
RCS file: /cvs/dietlibc/lib/arc4random.c,v
retrieving revision 1.2
diff -u -r1.2 arc4random.c
--- lib/arc4random.c 26 May 2015 02:55:23 -0000 1.2
+++ lib/arc4random.c 29 May 2015 15:46:39 -0000
@@ -7,8 +7,8 @@
/* These come from OpenBSD: */
uint32_t arc4random(void) {
- if (n>=sizeof(buf)/sizeof(buf[0])) arc4random_stir();
- return buf[n++];
+ if (n == 0) arc4random_stir();
+ return buf[n-=1];
}
void arc4random_buf(void* Buf, size_t N) {
@@ -41,7 +41,7 @@
}
void arc4random_stir(void) {
- n=0;
+ n=sizeof(buf)/sizeof(buf[0]);
if ((size_t)getrandom(buf,sizeof(buf),GRND_NONBLOCK) != sizeof(buf))
abort();
}