diff options
author | Ron Yorston <rmy@pobox.com> | 2018-03-22 14:45:06 +0000 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2018-03-22 14:50:24 +0000 |
commit | be9b9ed64e658889229e18e3d089df27d8b724c3 (patch) | |
tree | 9f6dd47bdf2ef40e86e113aeb8fc5d1a8ef4e9d3 | |
parent | b5c6c1e5506198d240dbc7f19caee8b95989aec3 (diff) | |
download | busybox-w32-be9b9ed64e658889229e18e3d089df27d8b724c3.tar.gz busybox-w32-be9b9ed64e658889229e18e3d089df27d8b724c3.tar.bz2 busybox-w32-be9b9ed64e658889229e18e3d089df27d8b724c3.zip |
win32: tighten up code slightly in isaac.c
-rw-r--r-- | win32/isaac.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/win32/isaac.c b/win32/isaac.c index ba51d199a..2b02eaff2 100644 --- a/win32/isaac.c +++ b/win32/isaac.c | |||
@@ -214,20 +214,12 @@ ssize_t get_random_bytes(void *buf, ssize_t count) | |||
214 | ptr = (unsigned char *)t->randrsl; | 214 | ptr = (unsigned char *)t->randrsl; |
215 | while (count > 0) { | 215 | while (count > 0) { |
216 | int bytes_left = RAND_BYTES - rand_index; | 216 | int bytes_left = RAND_BYTES - rand_index; |
217 | ssize_t delta = MIN(bytes_left, count); | ||
217 | 218 | ||
218 | if (bytes_left >= count) { | 219 | memcpy(buf, ptr+rand_index, delta); |
219 | /* we have enough random bytes */ | 220 | buf += delta; |
220 | memcpy(buf, ptr+rand_index, count); | 221 | count -= delta; |
221 | rand_index += count; | 222 | rand_index += delta; |
222 | count = 0; | ||
223 | } | ||
224 | else { | ||
225 | /* insufficient bytes, use what we have */ | ||
226 | memcpy(buf, ptr+rand_index, bytes_left); | ||
227 | buf += bytes_left; | ||
228 | count -= bytes_left; | ||
229 | rand_index += bytes_left; | ||
230 | } | ||
231 | 223 | ||
232 | if (rand_index >= RAND_BYTES) { | 224 | if (rand_index >= RAND_BYTES) { |
233 | /* generate more */ | 225 | /* generate more */ |