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. --- shell/Kbuild.src | 1 + shell/random.c | 11 +++++++++++ shell/random.h | 3 +++ 3 files changed, 15 insertions(+) (limited to 'shell') diff --git a/shell/Kbuild.src b/shell/Kbuild.src index 6bba4989f..a287fce4e 100644 --- a/shell/Kbuild.src +++ b/shell/Kbuild.src @@ -9,3 +9,4 @@ lib-y:= INSERT lib-$(CONFIG_FEATURE_SH_MATH) += math.o +lib-$(CONFIG_FEATURE_PRNG_SHELL) += random.o diff --git a/shell/random.c b/shell/random.c index 5d3620516..614172279 100644 --- a/shell/random.c +++ b/shell/random.c @@ -19,6 +19,17 @@ # include "random.h" # define RAND_BASH_MASK 0x7fff +# if ENABLE_FEATURE_PRNG_SHELL +uint32_t FAST_FUNC +next_random(random_t *rnd) +{ + return full_random(rnd) & RAND_BASH_MASK; +} +# undef RAND_BASH_MASK +# define RAND_BASH_MASK 0xffffffff +# define next_random full_random +# endif + #else # include # include diff --git a/shell/random.h b/shell/random.h index c4eb44c13..75fe0f69f 100644 --- a/shell/random.h +++ b/shell/random.h @@ -35,6 +35,9 @@ typedef struct random_t { ((rnd)->galois_LFSR = 0) uint32_t next_random(random_t *rnd) FAST_FUNC; +#if ENABLE_FEATURE_PRNG_SHELL +uint32_t full_random(random_t *rnd) FAST_FUNC; +#endif POP_SAVED_FUNCTION_VISIBILITY -- cgit v1.2.3-55-g6feb