Make rekey interval less predictable (#1331)

This commit is contained in:
Keelan Cannoo 2022-09-12 23:12:47 +04:00 committed by GitHub
parent 039e8d96a4
commit bb41229ff4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}