mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-23 20:15:19 -07:00
Move the randombytes_block_on_dev_random() function up
This commit is contained in:
parent
e1abc1de7e
commit
32e36af97e
@ -247,6 +247,34 @@ randombytes_linux_getrandom(void * const buf_, size_t size)
|
||||
# endif
|
||||
|
||||
# ifndef NONEXISTENT_DEV_RANDOM
|
||||
|
||||
# ifdef BLOCK_ON_DEV_RANDOM
|
||||
static int
|
||||
randombytes_block_on_dev_random(void)
|
||||
{
|
||||
struct pollfd pfd;
|
||||
int fd;
|
||||
int pret;
|
||||
|
||||
fd = open("/dev/random", O_RDONLY);
|
||||
if (fd == -1) {
|
||||
return 0;
|
||||
}
|
||||
pfd.fd = fd;
|
||||
pfd.events = POLLIN;
|
||||
pfd.revents = 0;
|
||||
do {
|
||||
pret = poll(&pfd, 1, -1);
|
||||
} while (pret < 0 && (errno == EINTR || errno == EAGAIN));
|
||||
if (pret != 1) {
|
||||
(void) close(fd);
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
return close(fd);
|
||||
}
|
||||
# endif
|
||||
|
||||
static int
|
||||
randombytes_internal_random_random_dev_open(void)
|
||||
{
|
||||
@ -311,33 +339,6 @@ safe_read(const int fd, void * const buf_, size_t size)
|
||||
return (ssize_t) (buf - (unsigned char *) buf_);
|
||||
}
|
||||
|
||||
# ifdef BLOCK_ON_DEV_RANDOM
|
||||
static int
|
||||
randombytes_block_on_dev_random(void)
|
||||
{
|
||||
struct pollfd pfd;
|
||||
int fd;
|
||||
int pret;
|
||||
|
||||
fd = open("/dev/random", O_RDONLY);
|
||||
if (fd == -1) {
|
||||
return 0;
|
||||
}
|
||||
pfd.fd = fd;
|
||||
pfd.events = POLLIN;
|
||||
pfd.revents = 0;
|
||||
do {
|
||||
pret = poll(&pfd, 1, -1);
|
||||
} while (pret < 0 && (errno == EINTR || errno == EAGAIN));
|
||||
if (pret != 1) {
|
||||
(void) close(fd);
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
return close(fd);
|
||||
}
|
||||
# endif
|
||||
|
||||
# endif /* !NONEXISTENT_DEV_RANDOM */
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user