diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2022-04-09 02:28:05 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2022-04-09 02:28:05 +0000 |
commit | 4e75b40d8a96c5d51490ddea43566fe8e6d4168c (patch) | |
tree | 06358f285c713a7f05297cb7d2826319d6561683 /src/librandom/random_buf_early.c | |
parent | 1fedaae65b56b8548cdf2d8c26e2becece5fec07 (diff) | |
download | skalibs-4e75b40d8a96c5d51490ddea43566fe8e6d4168c.tar.xz |
Prepare for 2.12.0.0. librandom revamp.
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/librandom/random_buf_early.c')
-rw-r--r-- | src/librandom/random_buf_early.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/librandom/random_buf_early.c b/src/librandom/random_buf_early.c new file mode 100644 index 0000000..a306239 --- /dev/null +++ b/src/librandom/random_buf_early.c @@ -0,0 +1,54 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> + +#if defined(SKALIBS_HASARC4RANDOM) + +#include <skalibs/nonposix.h> +#include <stdlib.h> +#include <skalibs/random.h> + +void random_buf_early (char *s, size_t n) +{ + arc4random_buf(s, n) ; +} + +#elif defined(SKALIBS_HASGETRANDOM) && defined(SKALIBS_HASGRNDINSECURE) + +#include <sys/random.h> + +#include <skalibs/random.h> + +void random_buf_early (char *s, size_t n) +{ + while (n) + { + ssize_t r = getrandom(s, n, GRND_INSECURE) ; + if (r >= 0) + { + s += r ; + n -= r ; + } + } +} + +#elif defined(SKALIBS_HASDEVURANDOM) + +#include "random-internal.h" + +void random_buf_early (char *s, size_t n) +{ + random_devurandom(s, n) ; +} + +#else + +#include <skalibs/surf.h> +#include <skalibs/random.h> + +void random_buf_early (char *s, size_t n) +{ + autosurf(s, n) ; +} + +#endif |