Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_random.c File Reference

Cryptographically secure random bytes and hex tokens. More...

#include "nilorea/n_random.h"
#include "nilorea/n_common.h"
#include "nilorea/n_hex.h"
#include "nilorea/n_log.h"
#include "nilorea/n_str.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for n_random.c:

Go to the source code of this file.

Functions

int n_random_bytes (unsigned char *buf, size_t n)
 fill buf with n cryptographically secure random bytes from the system RNG: BCryptGenRandom on Windows (there is no /dev/urandom there), otherwise getrandom(2) when available and /dev/urandom as the fallback.
static int n_random_from_urandom (unsigned char *buf, size_t n)
N_STR * n_random_hex_token (size_t nbytes)
 generate nbytes secure random bytes and return them as a lowercase hex N_STR (2*nbytes characters); free with free_nstr.

Detailed Description

Cryptographically secure random bytes and hex tokens.

Author
Castagnier Mickael
Version
1.0

Definition in file n_random.c.

Function Documentation

◆ n_random_from_urandom()

int n_random_from_urandom ( unsigned char * buf,
size_t n )
static

Definition at line 72 of file n_random.c.

References LOG_ERR, and n_log.

Referenced by n_random_bytes().

Here is the caller graph for this function: