X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb/blobdiff_plain/a7a76ebd30d6af9302fa58b4acad09c465cbac78..7b0d1a63587f3cb1ae3bb8b248bbb1b82bdca7bd:/rand/rand.h diff --git a/rand/rand.h b/rand/rand.h index 389526d2..5584c54d 100644 --- a/rand/rand.h +++ b/rand/rand.h @@ -87,7 +87,8 @@ #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) @@ -98,13 +99,14 @@ 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; @@ -131,6 +133,20 @@ typedef struct rand_source { 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 @@ -179,6 +195,19 @@ extern void rand_seed(rand_pool */*r*/, unsigned /*bits*/); 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