From 39ae0a5dcb115272eb97417ebb43d12d68d1271a Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 2 Sep 2021 13:10:33 +0100 Subject: win32: fix entropy collection for isaac The condition to detect the end of the environment string was wrong. Don't bother calculating the MD5SUM of the environment, just XOR the bytes into the data. This reduces bloat by 320 bytes but only in the non-default case. --- win32/isaac.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/win32/isaac.c b/win32/isaac.c index f419a3f2e..6b174b69e 100644 --- a/win32/isaac.c +++ b/win32/isaac.c @@ -118,7 +118,7 @@ static void randinit(isaac_t *t, int flag) fn(&dt); \ u = (uint32_t *)&dt; \ for (j=0; jrandrsl[i++] = *u++; \ + t->randrsl[i++ % 256] = *u++; \ } /* @@ -128,15 +128,14 @@ static void randinit(isaac_t *t, int flag) */ static void get_entropy(isaac_t *t) { - int i, j, len; + int i, j; FILETIME tm; MEMORYSTATUS ms; SYSTEM_INFO si; LARGE_INTEGER pc; uint32_t *u; char *env, *s; - md5_ctx_t ctx; - unsigned char buf[16]; + unsigned char *p; i = 0; t->randrsl[i++] = (uint32_t)GetProcessId(GetCurrentProcess()); @@ -150,27 +149,18 @@ static void get_entropy(isaac_t *t) env = GetEnvironmentStringsA(); - /* get length of environment: it ends with two nuls */ - for (s=env,len=0; *s && *(s+1); ++s,++len) - ; - - md5_begin(&ctx); - md5_hash(&ctx, env, len); - md5_end(&ctx, buf); + /* environment ends with two nuls */ + p = (unsigned char *)t->randrsl; + i *= sizeof(uint32_t); + for (s=env; *s || *(s+1); ++s) + p[i++ % (256 * sizeof(uint32_t))] ^= *s; FreeEnvironmentStringsA(env); - u = (uint32_t *)buf; - for (j=0; jrandrsl[i++] = *u++; - } - #if 0 { - unsigned char *p = (unsigned char *)t->randrsl; - - for (j=0; j