#define RAND_POOLSZ 128 /* Input pool size in bytes */
#define RAND_BUFSZ 512 /* Output buffer size in bytes */
-#define RAND_SECSZ 20 /* Secret octets in output buffer */
+#define RAND_SECSZ 32 /* Secret octets in output buffer */
+#define RAND_KEYSZ 32 /* Recommended random key size */
#define RAND_IBITS (RAND_POOLSZ * 8)
#define RAND_OBITS (RAND_BUFSZ * 8)
typedef struct rand_pool {
octet pool[RAND_POOLSZ]; /* Actual contents of the pool */
- unsigned i; /* Current index into pool */
- unsigned irot; /* Current rotation applied */
+ unsigned gen; /* Generation number */
+ unsigned short i; /* Current index into pool */
+ unsigned short irot; /* Current rotation applied */
unsigned ibits; /* Number of good bits in pool */
octet buf[RAND_BUFSZ]; /* Random octet output buffer */
unsigned o; /* Current index into buffer */
unsigned obits; /* Number of good bits in buffer */
- rmd160_mackey k; /* Secret key for this pool */
+ union { octet k[RAND_KEYSZ]; rmd160_mackey _; } k; /* Key for the pool */
const struct rand_source *s; /* System-specific noise source */
} rand_pool;
extern void rand_init(rand_pool */*r*/);
+/* --- @rand_generation@ --- *
+ *
+ * Arguments: ---
+ *
+ * Returns: A nonzero generation number.
+ *
+ * Use: Returns a generation number for the current process. Each
+ * pool has its own number. If this matches the process number
+ * then all is well. If it doesn't match, then the pool needs
+ * to be cleaned before its next use.
+ */
+
+extern unsigned rand_generation(void);
+
/* --- @rand_noisesrc@ --- *
*
* Arguments: @rand_pool *r@ = pointer to a randomness pool
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