1- /* $NetBSD: arc4random.c,v 1.22 2014/06/07 20:55:47 roy Exp $ */
1+ /* $NetBSD: arc4random.c,v 1.23 2014/06/12 19:05:37 apb Exp $ */
22/* $OpenBSD: arc4random.c,v 1.6 2001/06/05 05:05:38 pvalchev Exp $ */
33
44/*
2727
2828#include <sys/cdefs.h>
2929#if defined(LIBC_SCCS ) && !defined(lint )
30- __RCSID ("$NetBSD: arc4random.c,v 1.22 2014/06/07 20:55:47 roy Exp $" );
30+ __RCSID ("$NetBSD: arc4random.c,v 1.23 2014/06/12 19:05:37 apb Exp $" );
3131#endif /* LIBC_SCCS and not lint */
3232
3333#include "namespace.h"
@@ -50,6 +50,8 @@ __weak_alias(arc4random_stir,_arc4random_stir)
5050__weak_alias (arc4random_uniform ,_arc4random_uniform )
5151#endif
5252
53+ #define REKEY_BYTES 1600000
54+
5355struct arc4_stream {
5456 bool inited ;
5557 uint8_t i ;
@@ -60,8 +62,12 @@ struct arc4_stream {
6062};
6163
6264#ifdef _REENTRANT
63- #define LOCK (rs ) if (__isthreaded) mutex_lock(&(rs)->mtx);
64- #define UNLOCK (rs ) if (__isthreaded) mutex_unlock(&(rs)->mtx);
65+ #define LOCK (rs ) do { \
66+ if (__isthreaded) mutex_lock(&(rs)->mtx);
67+ } while (/*CONSTCOND*/ 0 )
68+ #define UNLOCK (rs ) do { \
69+ if (__isthreaded) mutex_unlock(&(rs)->mtx); \
70+ } while (/*CONSTCOND*/ 0 )
6571#else
6672#define LOCK (rs )
6773#define UNLOCK (rs )
@@ -177,8 +183,8 @@ arc4_stir(struct arc4_stream *as)
177183 for (j = 0 ; j < __arraycount (as -> s ) * sizeof (uint32_t ); j ++ )
178184 arc4_getbyte (as );
179185
180- /* Stir again after swallowing 1600000 bytes or if the pid changes */
181- as -> count = 1600000 ;
186+ /* Stir again after REKEY_BYTES bytes, or if the pid changes */
187+ as -> count = REKEY_BYTES ;
182188}
183189
184190static inline void
0 commit comments