Skip to content

Commit

Permalink
Make rekey interval less predictable (libevent#1331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keelan10 authored Sep 12, 2022
1 parent 039e8d9 commit bb41229
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions arc4random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit bb41229

Please sign in to comment.