23RCSID(
"$Id: 53d17290f509aa100f98509181d11143fd590fab $")
25#include <freeradius-devel/util/rand.h>
26#include <freeradius-devel/util/hash.h>
45 fd = open(
"/dev/urandom", O_RDONLY);
50 rcode = read(fd, p, (
size_t) (end - p));
51 if ((rcode < 0) && (errno != EINTR))
break;
52 if (rcode > 0) p += rcode;
129 size_t buflen = length;
134 for (i = 0; i < buflen; i += 4) {
136 memcpy(
buffer + i, &x,
sizeof(x));
151 memcpy(
buffer, &x, buflen);
166 unsigned int word, mod;
172 static char randstr_punc[] =
"!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
173 static char randstr_salt[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmopqrstuvwxyz/.";
179 static char randstr_otp[] =
"469ACGHJKLMNPQRUVWXYabdfhijkprstuvwxyz";
185#define fill(_expr) do { \
187 if ((mod = ((p - out) & (sizeof(word) - 1))) == 0) word = fr_rand(); \
188 byte = ((uint8_t *)&word)[mod]; \
197 fill(
'a' + (
byte % 26));
204 fill(
'A' + (
byte % 26));
211 fill(
'0' + (
byte % 10));
218 fill(randstr_salt[
byte % (
sizeof(randstr_salt) - 3)]);
225 fill(randstr_punc[
byte % (
sizeof(randstr_punc) - 1)]);
232 fill(
'!' + (
byte % 95));
239 fill(randstr_salt[
byte % (
sizeof(randstr_salt) - 1)]);
247 fill(randstr_otp[
byte % (
sizeof(randstr_otp) - 1)]);
281 ctx->
a = (36969 * (ctx->
a & 0xffff)) + (ctx->
a >> 16);
282 ctx->
b = (18000 * (ctx->
b & 0xffff)) + (ctx->
b >> 16);
284 return (ctx->
a << 16) + ctx->
b;
static int const char char buffer[256]
uint32_t fr_hash_update(void const *data, size_t size, uint32_t hash)
void fr_isaac_init(fr_randctx *ctx, int flag)
void fr_isaac(fr_randctx *ctx)
static _Thread_local fr_randctx fr_rand_pool
A pool of pre-generated random integers.
uint32_t fr_fast_rand(fr_fast_rand_t *ctx)
static _Thread_local bool fr_rand_initialized
void fr_rand_str(uint8_t *out, size_t len, char class)
Generate a random string.
uint32_t fr_rand(void)
Return a 32-bit random number.
void fr_rand_buffer(void *start, size_t length)
void fr_rand_mixin(void const *data, size_t size)
Mix data into the random number generator.
Smaller fast random number generator.
static unsigned int hash(char const *username, unsigned int tablesize)
#define fr_time()
Allow us to arbitrarily manipulate time.
static uint64_t fr_unix_time_unwrap(fr_unix_time_t time)
static fr_unix_time_t fr_time_to_unix_time(fr_time_t when)
Convert an fr_time_t (internal time) to our version of unix time (wallclock time)
static size_t char ** out