#include "arena.h"
#include "blowfish-cbc.h"
#include "paranoia.h"
+
+#define RAND__HACKS
#include "rand.h"
#include "rmd160.h"
#include "rmd160-hmac.h"
static const grand_ops gops;
-typedef struct gctx {
+typedef struct rand__gctx {
grand r;
rand_pool p;
} gctx;
-static gctx *pool = 0; /* Default random pool */
+gctx rand_global = {
+ { &gops },
+ { { 0 }, 0, 0, 0,
+ { 0 }, RAND_SECSZ, 0,
+ { { 0xb7, 0xb0, 0xb4, 0xdb, 0x59, 0x75, 0x49, 0x32,
+ 0x1a, 0x8d, 0x4b, 0x86, 0x3a, 0x38, 0xfd, 0x59,
+ 0xc1, 0x63, 0x66, 0xd9 }, 64,
+ { 0x91, 0x9a, 0xe6, 0xa1, 0x9d, 0x3a, 0x86, 0xef,
+ 0xb2, 0xb9, 0xca, 0xfc, 0x26, 0xf8, 0xb1, 0x04,
+ 0x4a, 0x41, 0xc4, 0x7a }, 64 },
+ 0 }
+};
/*----- Macros ------------------------------------------------------------*/
-#define RAND_RESOLVE(r) do { \
- if ((r) == RAND_GLOBAL) { \
- if (!pool) \
- pool = (gctx *)rand_create(); \
- (r) = &pool->p; \
- } \
-} while (0)
+#define RAND_RESOLVE(r) \
+ do { if ((r) == RAND_GLOBAL) r = &rand_global.p; } while (0)
#define TIMER(r) do { \
if ((r)->s && (r)->s->timer) \
/*----- Generic random number generator interface -------------------------*/
-#define GRESOLVE(g, r) do { \
- if (r != &rand_global) \
- g = (gctx *)r; \
- else { \
- if (!pool) \
- pool = (gctx *)rand_create(); \
- g = pool; \
- } \
-} while (0)
-
static void gdestroy(grand *r)
{
- gctx *g;
- GRESOLVE(g, r);
- if (g != pool) {
+ gctx *g = (gctx *)r;
+ if (g != &rand_global) {
BURN(*g);
S_DESTROY(g);
}
static int gmisc(grand *r, unsigned op, ...)
{
- gctx *g;
+ gctx *g = (gctx *)r;
va_list ap;
int rc = 0;
va_start(ap, op);
- GRESOLVE(g, r);
switch (op) {
case GRAND_CHECK:
switch (va_arg(ap, unsigned)) {
static octet gbyte(grand *r)
{
- gctx *g;
+ gctx *g = (gctx *)r;
octet o;
- GRESOLVE(g, r);
rand_getgood(&g->p, &o, 1);
return (o);
}
static uint32 gword(grand *r)
{
- gctx *g;
+ gctx *g = (gctx *)r;
octet b[4];
- GRESOLVE(g, r);
rand_getgood(&g->p, &b, sizeof(b));
return (LOAD32(b));
}
static void gfill(grand *r, void *p, size_t sz)
{
- gctx *g;
- GRESOLVE(g, r);
+ gctx *g = (gctx *)r;
rand_get(&g->p, p, sz);
}
gword, gbyte, gword, grand_range, gfill
};
-grand rand_global = { &gops };
-
/* --- @rand_create@ --- *
*
* Arguments: ---