summaryrefslogtreecommitdiff
path: root/arc4random.c
diff options
context:
space:
mode:
authorKeelan Cannoo <96436249+Keelan10@users.noreply.github.com>2022-09-12 23:12:47 +0400
committerGitHub <noreply@github.com>2022-09-12 22:12:47 +0300
commitbb41229ff4dbd62084994c6b0b2052a321fd0ccf (patch)
treebc7584f90469e826bf29df90408af7a4c2a1df3f /arc4random.c
parent039e8d96a476a93874576d808242157698496f04 (diff)
downloadlibevent-bb41229ff4dbd62084994c6b0b2052a321fd0ccf.tar.gz
Make rekey interval less predictable (#1331)
Diffstat (limited to 'arc4random.c')
-rw-r--r--arc4random.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/arc4random.c b/arc4random.c
index c36e3c11..b5f66b4c 100644
--- a/arc4random.c
+++ b/arc4random.c
@@ -75,8 +75,7 @@
/* Add platform entropy 32 bytes (256 bits) at a time. */
#define ADD_ENTROPY 32
-/* Re-seed from the platform RNG after generating this many bytes. */
-#define BYTES_BEFORE_RESEED 1600000
+#define REKEY_BASE (1024*1024) /* NB. should be a power of 2 */
struct arc4_stream {
unsigned char i;
@@ -343,10 +342,13 @@ arc4_seed(void)
return ok ? 0 : -1;
}
+static inline unsigned int
+arc4_getword(void);
static int
arc4_stir(void)
{
int i;
+ ARC4RANDOM_UINT32 rekey_fuzz;
if (!rs_initialized) {
arc4_init();
@@ -377,7 +379,9 @@ arc4_stir(void)
for (i = 0; i < 12*256; i++)
(void)arc4_getbyte();
- arc4_count = BYTES_BEFORE_RESEED;
+ rekey_fuzz = arc4_getword();
+ /* rekey interval should not be predictable */
+ arc4_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE);
return 0;
}