diff options
Diffstat (limited to 'win32/isaac.c')
-rw-r--r-- | win32/isaac.c | 42 |
1 files changed, 6 insertions, 36 deletions
diff --git a/win32/isaac.c b/win32/isaac.c index 6b174b69e..19b96de94 100644 --- a/win32/isaac.c +++ b/win32/isaac.c | |||
@@ -18,6 +18,7 @@ You may use this code in any way you wish, and it is free. No warrantee. | |||
18 | public domain. | 18 | public domain. |
19 | */ | 19 | */ |
20 | #include "libbb.h" | 20 | #include "libbb.h" |
21 | #include <ntsecapi.h> | ||
21 | 22 | ||
22 | typedef struct { | 23 | typedef struct { |
23 | /* external results */ | 24 | /* external results */ |
@@ -113,14 +114,6 @@ static void randinit(isaac_t *t, int flag) | |||
113 | isaac(t); /* fill in the first set of results */ | 114 | isaac(t); /* fill in the first set of results */ |
114 | } | 115 | } |
115 | 116 | ||
116 | /* call 'fn' to put data in 'dt' then copy it to generator state */ | ||
117 | #define GET_DATA(fn, dt) \ | ||
118 | fn(&dt); \ | ||
119 | u = (uint32_t *)&dt; \ | ||
120 | for (j=0; j<sizeof(dt)/sizeof(uint32_t); ++j) { \ | ||
121 | t->randrsl[i++ % 256] = *u++; \ | ||
122 | } | ||
123 | |||
124 | /* | 117 | /* |
125 | * Stuff a few bytes of random-ish data into the generator state. | 118 | * Stuff a few bytes of random-ish data into the generator state. |
126 | * This is unlikely to be very robust: don't rely on it for | 119 | * This is unlikely to be very robust: don't rely on it for |
@@ -128,37 +121,14 @@ static void randinit(isaac_t *t, int flag) | |||
128 | */ | 121 | */ |
129 | static void get_entropy(isaac_t *t) | 122 | static void get_entropy(isaac_t *t) |
130 | { | 123 | { |
131 | int i, j; | 124 | if (!RtlGenRandom(t->randrsl, sizeof(uint32_t)*256)) |
132 | FILETIME tm; | 125 | GetSystemTimeAsFileTime((FILETIME *)t->randrsl); |
133 | MEMORYSTATUS ms; | ||
134 | SYSTEM_INFO si; | ||
135 | LARGE_INTEGER pc; | ||
136 | uint32_t *u; | ||
137 | char *env, *s; | ||
138 | unsigned char *p; | ||
139 | |||
140 | i = 0; | ||
141 | t->randrsl[i++] = (uint32_t)GetProcessId(GetCurrentProcess()); | ||
142 | t->randrsl[i++] = (uint32_t)GetCurrentThreadId(); | ||
143 | t->randrsl[i++] = (uint32_t)GetTickCount(); | ||
144 | |||
145 | GET_DATA(GetSystemTimeAsFileTime, tm) | ||
146 | GET_DATA(GlobalMemoryStatus, ms) | ||
147 | GET_DATA(GetSystemInfo, si) | ||
148 | GET_DATA(QueryPerformanceCounter, pc) | ||
149 | |||
150 | env = GetEnvironmentStringsA(); | ||
151 | |||
152 | /* environment ends with two nuls */ | ||
153 | p = (unsigned char *)t->randrsl; | ||
154 | i *= sizeof(uint32_t); | ||
155 | for (s=env; *s || *(s+1); ++s) | ||
156 | p[i++ % (256 * sizeof(uint32_t))] ^= *s; | ||
157 | |||
158 | FreeEnvironmentStringsA(env); | ||
159 | 126 | ||
160 | #if 0 | 127 | #if 0 |
161 | { | 128 | { |
129 | unsigned char *p = (unsigned char *)t->randrsl; | ||
130 | int j; | ||
131 | |||
162 | for (j=0; j<256; ++j) { | 132 | for (j=0; j<256; ++j) { |
163 | fprintf(stderr, "%02x", p[j]); | 133 | fprintf(stderr, "%02x", p[j]); |
164 | if ((j&31) == 31) { | 134 | if ((j&31) == 31) { |