Skip to content

Commit c7a63c2

Browse files
author
dsl
committed
arc4 is a random number sequence, there is no point using its own
output values to determine a number of output values to skip. Skipping values on any possibly random event might be worth while, as might using the keying algorithm to stir in a possibly random value.
1 parent be24195 commit c7a63c2

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

lib/libc/gen/arc4random.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: arc4random.c,v 1.18 2012/08/20 20:27:46 dsl Exp $ */
1+
/* $NetBSD: arc4random.c,v 1.19 2012/08/20 20:32:09 dsl Exp $ */
22
/* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */
33

44
/*
@@ -27,7 +27,7 @@
2727

2828
#include <sys/cdefs.h>
2929
#if defined(LIBC_SCCS) && !defined(lint)
30-
__RCSID("$NetBSD: arc4random.c,v 1.18 2012/08/20 20:27:46 dsl Exp $");
30+
__RCSID("$NetBSD: arc4random.c,v 1.19 2012/08/20 20:32:09 dsl Exp $");
3131
#endif /* LIBC_SCCS and not lint */
3232

3333
#include "namespace.h"
@@ -214,7 +214,6 @@ arc4random_buf(void *buf, size_t len)
214214
uint8_t *bp = buf;
215215
uint8_t *ep = bp + len;
216216
uint8_t i, j;
217-
int skip;
218217

219218
LOCK(&rs);
220219
arc4_check_init(&rs);
@@ -223,10 +222,6 @@ arc4random_buf(void *buf, size_t len)
223222
i = rs.i;
224223
j = rs.j;
225224

226-
skip = arc4_getbyte_ij(&rs, &i, &j) % 3;
227-
while (skip--)
228-
(void)arc4_getbyte_ij(&rs, &i, &j);
229-
230225
while (bp < ep)
231226
*bp++ = arc4_getbyte_ij(&rs, &i, &j);
232227
rs.i = i;
@@ -266,9 +261,6 @@ arc4random_uniform(uint32_t upper_bound)
266261
LOCK(&rs);
267262
arc4_check_init(&rs);
268263

269-
if (arc4_getbyte(&rs) & 1)
270-
(void)arc4_getbyte(&rs);
271-
272264
/*
273265
* This could theoretically loop forever but each retry has
274266
* p > 0.5 (worst case, usually far better) of selecting a

0 commit comments

Comments
 (0)