From 6cff8357023adb4d5c9daa027522f883f3905f4c Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Thu, 22 Mar 2018 14:58:29 +0000 Subject: win32: allow use of shell's PRNG for /dev/urandom Allow either ISAAC or the shell's built-in pseudo-random number generator to be used for /dev/urandom. The latter is smaller so it's the default. --- win32/Kbuild | 11 ++++---- win32/sh_random.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 win32/sh_random.c (limited to 'win32') diff --git a/win32/Kbuild b/win32/Kbuild index 00950e0f7..f8c8fb5af 100644 --- a/win32/Kbuild +++ b/win32/Kbuild @@ -7,18 +7,19 @@ lib-y:= lib-$(CONFIG_PLATFORM_MINGW32) += env.o lib-$(CONFIG_PLATFORM_MINGW32) += fnmatch.o lib-$(CONFIG_PLATFORM_MINGW32) += fsync.o +lib-$(CONFIG_PLATFORM_MINGW32) += inet_pton.o lib-$(CONFIG_PLATFORM_MINGW32) += ioctl.o -lib-$(CONFIG_PLATFORM_MINGW32) += isaac.o +lib-$(CONFIG_FEATURE_PRNG_ISAAC) += isaac.o lib-$(CONFIG_PLATFORM_MINGW32) += mingw.o lib-$(CONFIG_PLATFORM_MINGW32) += process.o -lib-$(CONFIG_PLATFORM_MINGW32) += regex.o +lib-$(CONFIG_PLATFORM_MINGW32) += mntent.o lib-$(CONFIG_PLATFORM_MINGW32) += net.o -lib-$(CONFIG_PLATFORM_MINGW32) += inet_pton.o lib-$(CONFIG_PLATFORM_MINGW32) += poll.o -lib-$(CONFIG_PLATFORM_MINGW32) += select.o lib-$(CONFIG_PLATFORM_MINGW32) += popen.o +lib-$(CONFIG_PLATFORM_MINGW32) += regex.o +lib-$(CONFIG_PLATFORM_MINGW32) += select.o +lib-$(CONFIG_FEATURE_PRNG_SHELL) += sh_random.o lib-$(CONFIG_PLATFORM_MINGW32) += statfs.o -lib-$(CONFIG_PLATFORM_MINGW32) += mntent.o lib-$(CONFIG_PLATFORM_MINGW32) += strptime.o lib-$(CONFIG_PLATFORM_MINGW32) += system.o lib-$(CONFIG_PLATFORM_MINGW32) += termios.o diff --git a/win32/sh_random.c b/win32/sh_random.c new file mode 100644 index 000000000..2948e4a55 --- /dev/null +++ b/win32/sh_random.c @@ -0,0 +1,76 @@ +#include "libbb.h" +#include "../shell/random.h" + +/* call 'fn' to put data in 'dt' then copy it to generator state */ +#define GET_DATA(fn, dt) \ + fn(&dt); \ + u = (uint32_t *)&dt; \ + for (j=0; j 0; buf+=4, count-=4) { + value = full_random(&rnd); + memcpy(buf, ptr, count >= 4 ? 4 : count); + } + + return save_count; +} -- cgit v1.2.3-55-g6feb