X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/d03ab969116fe715d569304c1c474749b2f64529..42ca150ce7fa024a8fd6a4c9433b613175270eb4:/rand.h diff --git a/rand.h b/rand.h index 8ccd38c..5d542b8 100644 --- a/rand.h +++ b/rand.h @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: rand.h,v 1.1 1999/09/03 08:41:12 mdw Exp $ + * $Id$ * * Secure random number generator * * (c) 1999 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,26 +15,18 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. */ -/*----- Revision history --------------------------------------------------* - * - * $Log: rand.h,v $ - * Revision 1.1 1999/09/03 08:41:12 mdw - * Initial import. - * - */ - /*----- Notes on the random number generator ------------------------------* * * The algorithm is one of the author's own devising. It may therefore be @@ -47,7 +39,7 @@ * concerns I expressed about the Linux generator in a Usenet article to * sci.crypt. * - * The generator is divided into two parts: an input pool and an outpu + * The generator is divided into two parts: an input pool and an output * buffer. New random data is placed into the pool in the way described * below, which is shamelessly stolen from the Linux /dev/random generator. * The only interaction that the pool has on the output buffer is through the @@ -74,8 +66,8 @@ * an adversary has to guess before predicting generator output. */ -#ifndef RAND_H -#define RAND_H +#ifndef CATACOMB_RAND_H +#define CATACOMB_RAND_H #ifdef __cplusplus extern "C" { @@ -85,12 +77,18 @@ #include -#include "rmd160-hmac.h" +#ifndef CATACOMB_GRAND_H +# include "grand.h" +#endif + +#ifndef CATACOMB_RMD160_HMAC_H +# include "rmd160-hmac.h" +#endif /*----- Magic numbers -----------------------------------------------------*/ -#define RAND_POOLSZ 1279 /* Input pool size in bytes */ -#define RAND_BUFSZ 1024 /* Output buffer size in bytes */ +#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_IBITS (RAND_POOLSZ * 8) @@ -154,6 +152,21 @@ extern void rand_init(rand_pool */*r*/); extern void rand_noisesrc(rand_pool */*r*/, const rand_source */*s*/); +/* --- @rand_seed@ --- * + * + * Arguments: @rand_pool *r@ = pointer to a randomness pool + * @unsigned bits@ = number of bits to ensure + * + * Returns: --- + * + * Use: Ensures that there are at least @bits@ good bits of entropy + * in the pool. It is recommended that you call this after + * initializing a new pool. Requesting @bits > RAND_IBITS@ is + * doomed to failure (and is an error). + */ + +extern void rand_seed(rand_pool */*r*/, unsigned /*bits*/); + /* --- @rand_key@ --- * * * Arguments: @rand_pool *r@ = pointer to a randomness pool @@ -191,9 +204,9 @@ extern void rand_add(rand_pool */*r*/, /* --- @rand_goodbits@ --- * * - * Arguments: @rand_pool *r@ = pointer to a randomness pool + * Arguments: @rand_pool *r@ = pointer to a randomness pool * - * Returns: Estimate of the number of good bits remaining in the pool. + * Returns: Estimate of the number of good bits remaining in the pool. */ extern unsigned rand_goodbits(rand_pool */*r*/); @@ -235,7 +248,7 @@ extern void rand_stretch(rand_pool */*r*/); * Use: Gets random data from the pool. The pool's contents can't be * determined from the output of this function; nor can the * output data be determined from a knowledge of the data input - * to the pool wihtout also having knowledge of the secret key. + * to the pool without also having knowledge of the secret key. * The good bits counter is decremented, although no special * action is taken if it reaches zero. */ @@ -261,6 +274,38 @@ extern void rand_get(rand_pool */*r*/, void */*p*/, size_t /*sz*/); extern void rand_getgood(rand_pool */*r*/, void */*p*/, size_t /*sz*/); +/*----- Generic random number generator interface -------------------------*/ + +/* --- Miscellaneous operations --- */ + +enum { + RAND_GATE = GRAND_SPECIFIC('R'), /* No args */ + RAND_STRETCH, /* No args */ + RAND_KEY, /* @const void *k, size_t sz@ */ + RAND_NOISESRC, /* @const rand_source *s@ */ + RAND_SEED, /* @unsigned bits@ */ + RAND_TIMER, /* No args */ + RAND_GOODBITS, /* No args */ + RAND_ADD /* @const void *p, size_t sz,@ + * @unsigned goodbits */ +}; + +/* --- Default random number generator --- */ + +extern grand rand_global; + +/* --- @rand_create@ --- * + * + * Arguments: --- + * + * Returns: Pointer to a generic generator. + * + * Use: Constructs a generic generator interface over a Catacomb + * entropy pool generator. + */ + +extern grand *rand_create(void); + /*----- That's all, folks -------------------------------------------------*/ #ifdef __cplusplus