Rizin
unix-like reverse engineering framework and cli tools
random-getentropy.c File Reference
#include "uv.h"
#include "internal.h"
#include <stddef.h>
#include <dlfcn.h>

Go to the source code of this file.

Typedefs

typedef int(* uv__getentropy_cb) (void *, size_t)
 

Functions

static void uv__random_getentropy_init (void)
 
int uv__random_getentropy (void *buf, size_t buflen)
 

Variables

static uv__getentropy_cb uv__getentropy
 
static uv_once_t once = UV_ONCE_INIT
 

Typedef Documentation

◆ uv__getentropy_cb

typedef int(* uv__getentropy_cb) (void *, size_t)

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

Function Documentation

◆ uv__random_getentropy()

int uv__random_getentropy ( void *  buf,
size_t  buflen 
)

Definition at line 39 of file random-getentropy.c.

39  {
40  size_t pos;
41  size_t stride;
42 
44 
45  if (uv__getentropy == NULL)
46  return UV_ENOSYS;
47 
48  /* getentropy() returns an error for requests > 256 bytes. */
49  for (pos = 0, stride = 256; pos + stride < buflen; pos += stride)
50  if (uv__getentropy((char *) buf + pos, stride))
51  return UV__ERR(errno);
52 
53  if (uv__getentropy((char *) buf + pos, buflen - pos))
54  return UV__ERR(errno);
55 
56  return 0;
57 }
#define NULL
Definition: cris-opc.c:27
#define UV__ERR(x)
Definition: errno.h:29
voidpf void * buf
Definition: ioapi.h:138
static uv__getentropy_cb uv__getentropy
static void uv__random_getentropy_init(void)
static uv_once_t once
int pos
Definition: main.c:11
ut64 buflen
Definition: core.c:76
UV_EXTERN void uv_once(uv_once_t *guard, void(*callback)(void))
Definition: thread.c:419

References buflen, NULL, once, pos, UV__ERR, uv__getentropy, uv__random_getentropy_init(), and uv_once().

Referenced by uv__random().

◆ uv__random_getentropy_init()

static void uv__random_getentropy_init ( void  )
static

Definition at line 34 of file random-getentropy.c.

34  {
35  uv__getentropy = (uv__getentropy_cb) dlsym(RTLD_DEFAULT, "getentropy");
36 }
int(* uv__getentropy_cb)(void *, size_t)

References uv__getentropy.

Referenced by uv__random_getentropy().

Variable Documentation

◆ once

uv_once_t once = UV_ONCE_INIT
static

Definition at line 31 of file random-getentropy.c.

Referenced by uv__random_getentropy().

◆ uv__getentropy

uv__getentropy_cb uv__getentropy
static

Definition at line 30 of file random-getentropy.c.

Referenced by uv__random_getentropy(), and uv__random_getentropy_init().