Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update arc4random.c less predictable rekey #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/arc4random.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#define ARC4R_IVSZ 8
#define ARC4R_BLOCKSZ 64
#define ARC4R_RSBUFSZ (16*ARC4R_BLOCKSZ)
#define REKEY_BASE (1024*1024) //base 2


typedef struct
{
Expand Down Expand Up @@ -110,7 +112,7 @@ static void
_rs_stir(rand_state* st)
{
u8 rnd[ARC4R_KEYSZ + ARC4R_IVSZ];

uint32_t rekey_fuzz = 0;

int r = getentropy(rnd, sizeof rnd);
assert(r == 0);
Expand All @@ -120,8 +122,10 @@ _rs_stir(rand_state* st)
/* invalidate rs_buf */
st->rs_have = 0;
memset(st->rs_buf, 0, sizeof st->rs_buf);

st->rs_count = 1600000;

//st->rs_count = 1600000;
chacha_encrypt_bytes(&st->rs_chacha, (uint8_t *)&rekey_fuzz,(uint8_t *)&rekey_fuzz, sizeof(rekey_fuzz));
st->rs_count = REKEY_BASE + (rekey_fuzz % REKEY_BASE);
}


Expand Down