Rizin
unix-like reverse engineering framework and cli tools
random-devurandom.c File Reference
#include "uv.h"
#include "internal.h"
#include <sys/stat.h>
#include <unistd.h>

Go to the source code of this file.

Functions

int uv__random_readpath (const char *path, void *buf, size_t buflen)
 
static void uv__random_devurandom_init (void)
 
int uv__random_devurandom (void *buf, size_t buflen)
 

Variables

static uv_once_t once = UV_ONCE_INIT
 
static int status
 

Function Documentation

◆ uv__random_devurandom()

int uv__random_devurandom ( void *  buf,
size_t  buflen 
)

Definition at line 86 of file random-devurandom.c.

86  {
88 
89  if (status != 0)
90  return status;
91 
92  return uv__random_readpath("/dev/urandom", buf, buflen);
93 }
voidpf void * buf
Definition: ioapi.h:138
int uv__random_readpath(const char *path, void *buf, size_t buflen)
static int status
static uv_once_t once
static void uv__random_devurandom_init(void)
ut64 buflen
Definition: core.c:76
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419

References buflen, once, status, uv__random_devurandom_init(), uv__random_readpath(), and uv_once().

Referenced by uv__random().

◆ uv__random_devurandom_init()

static void uv__random_devurandom_init ( void  )
static

Definition at line 74 of file random-devurandom.c.

74  {
75  char c;
76 
77  /* Linux's random(4) man page suggests applications should read at least
78  * once from /dev/random before switching to /dev/urandom in order to seed
79  * the system RNG. Reads from /dev/random can of course block indefinitely
80  * until entropy is available but that's the point.
81  */
82  status = uv__random_readpath("/dev/random", &c, 1);
83 }
#define c(i)
Definition: sha256.c:43

References c, status, and uv__random_readpath().

Referenced by uv__random_devurandom().

◆ uv__random_readpath()

int uv__random_readpath ( const char *  path,
void *  buf,
size_t  buflen 
)

Definition at line 32 of file random-devurandom.c.

32  {
33  struct stat s;
34  size_t pos;
35  ssize_t n;
36  int fd;
37 
39 
40  if (fd < 0)
41  return fd;
42 
43  if (fstat(fd, &s)) {
44  uv__close(fd);
45  return UV__ERR(errno);
46  }
47 
48  if (!S_ISCHR(s.st_mode)) {
49  uv__close(fd);
50  return UV_EIO;
51  }
52 
53  for (pos = 0; pos != buflen; pos += n) {
54  do
55  n = read(fd, (char*) buf + pos, buflen - pos);
56  while (n == -1 && errno == EINTR);
57 
58  if (n == -1) {
59  uv__close(fd);
60  return UV__ERR(errno);
61  }
62 
63  if (n == 0) {
64  uv__close(fd);
65  return UV_EIO;
66  }
67  }
68 
69  uv__close(fd);
70  return 0;
71 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset fstat
Definition: sflib.h:107
#define UV__ERR(x)
Definition: errno.h:29
int n
Definition: mipsasm.c:19
static RzSocket * s
Definition: rtr.c:28
#define EINTR
Definition: sftypes.h:114
#define O_RDONLY
Definition: sftypes.h:486
int ssize_t
Definition: sftypes.h:39
Definition: sftypes.h:80
int pos
Definition: main.c:11
int uv__open_cloexec(const char *path, int flags)
Definition: core.c:1003
int uv__close(int fd)
Definition: core.c:569
static const z80_opcode fd[]
Definition: z80_tab.h:997
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References buflen, EINTR, fd, fstat, n, O_RDONLY, path, pos, read(), s, uv__close(), UV__ERR, and uv__open_cloexec().

Referenced by uv__random(), uv__random_devurandom(), and uv__random_devurandom_init().

Variable Documentation

◆ once

uv_once_t once = UV_ONCE_INIT
static

Definition at line 28 of file random-devurandom.c.

Referenced by uv__random_devurandom().

◆ status

int status
static

Definition at line 29 of file random-devurandom.c.

Referenced by uv__random_devurandom(), and uv__random_devurandom_init().