/*----- Header files ------------------------------------------------------*/
+#include "config.h"
+
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <mLib/sub.h>
#include "arena.h"
+#include "dispatch.h"
#include "paranoia.h"
#define RAND__HACKS
if (r->gen != gen) { r->gen = gen; rand_gate(r); } \
} while (0)
-#define TIMER(r) do { \
- if ((r)->s && (r)->s->timer) \
- (r)->s->timer(r); \
+static int quick(rand_pool *);
+#define QUICK(r) do { \
+ quick(r); \
+ if ((r)->s && (r)->s->timer) (r)->s->timer(r); \
} while (0)
/*----- Main code ---------------------------------------------------------*/
r->s = s;
}
+/* --- @rand_quick@ --- *
+ *
+ * Arguments: @rand_pool *r@ = pointer to a randomness pool
+ *
+ * Returns: Zero on success; @-1@ on failure.
+ *
+ * Use Attempts to use some machine-specific `quick' source of
+ * entropy to top up @r@. This may not do anything at all on
+ * many systems.
+ */
+
+CPU_DISPATCH(static, return, int, quick, (rand_pool *r), (r),
+ pick_quick, trivial_quick);
+
+static int trivial_quick(rand_pool *r) { return (-1); }
+
+static quick__functype *pick_quick(void)
+{
+ DISPATCH_PICK_FALLBACK(rand_quick, trivial_quick);
+}
+
+int rand_quick(rand_pool *r) { RAND_RESOLVE(r); return (quick(r)); }
+
/* --- @rand_seed@ --- *
*
* Arguments: @rand_pool *r@ = pointer to a randomness pool
CIPHER_CTX cc;
RAND_RESOLVE(r);
- TIMER(r);
+ QUICK(r);
/* --- Hash up all the data in the pool --- */
r->obits = RAND_OBITS;
} else
r->ibits = 0;
- TIMER(r);
+ QUICK(r);
}
/* --- @rand_stretch@ --- *
CIPHER_CTX cc;
RAND_RESOLVE(r);
- TIMER(r);
+ QUICK(r);
/* --- Hash up all the data in the buffer --- */
/* --- Reset the various state variables --- */
r->o = RAND_SECSZ;
- TIMER(r);
+ QUICK(r);
}
/* --- @rand_get@ --- *
RAND_RESOLVE(r);
GENCHECK(r);
- TIMER(r);
+ QUICK(r);
if (!sz)
return;
return;
}
GENCHECK(r);
- TIMER(r);
+ QUICK(r);
while (sz) {
size_t chunk = sz;
rand_seed(&g->p, va_arg(ap, unsigned));
break;
case RAND_TIMER:
- TIMER(&g->p);
+ QUICK(&g->p);
break;
case RAND_GOODBITS:
rc = rand_goodbits(&g->p);
extern void rand_key(rand_pool */*r*/, const void */*k*/, size_t /*sz*/);
+/* --- @rand_quick@ --- *
+ *
+ * Arguments: @rand_pool *r@ = pointer to a randomness pool
+ *
+ * Returns: Zero on success; @-1@ on failure.
+ *
+ * Use Attempts to use some machine-specific `quick' source of
+ * entropy to top up @r@. This may not do anything at all on
+ * many systems.
+ */
+
+extern int rand_quick(rand_pool */*r*/);
+
/* --- @rand_add@ --- *
*
* Arguments: @rand_pool *r@ = pointer to a randomness pool