From 4e75b40d8a96c5d51490ddea43566fe8e6d4168c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 9 Apr 2022 02:28:05 +0000 Subject: Prepare for 2.12.0.0. librandom revamp. Signed-off-by: Laurent Bercot --- src/librandom/random_devurandom.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/librandom/random_devurandom.c (limited to 'src/librandom/random_devurandom.c') diff --git a/src/librandom/random_devurandom.c b/src/librandom/random_devurandom.c new file mode 100644 index 0000000..0ad752b --- /dev/null +++ b/src/librandom/random_devurandom.c @@ -0,0 +1,22 @@ +/* ISC license. */ + +#include + +#include +#include +#include +#include + +void random_devurandom (char *s, size_t n) +{ + static int random_fd = -1 ; + size_t r ; + if (random_fd < 0) + { + random_fd = openbc_read("/dev/urandom") ; + if (random_fd < 0) + strerr_diefu2sys(111, "open ", "/dev/urandom") ; + } + r = allread(random_fd, s, n) ; + if (r < n) strerr_diefu2sys(111, "read from ", "/dev/urandom") ; +} -- cgit v1.3.1