mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
Make rekey interval less predictable (#1331)
This commit is contained in:
parent
039e8d96a4
commit
bb41229ff4
10
arc4random.c
10
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user