a pretty empty type, but it would be good to flesh it out so each random state will be separated from one another. Right now they all just lock around rand(), which isn't perfect, but good enough for what I need today.
70 lines
1.6 KiB
C
70 lines
1.6 KiB
C
#ifndef ISC_RANDOM_H
|
|
#define ISC_RANDOM_H 1
|
|
|
|
#include <isc/lang.h>
|
|
#include <isc/int.h>
|
|
#include <isc/mutex.h>
|
|
#include <isc/result.h>
|
|
|
|
/*
|
|
* Implements a random state pool which will let the caller return a
|
|
* series of possibly non-reproducable random values. Note that the
|
|
* strength of these numbers is not all that high, and should not be
|
|
* used in cryptography functions.
|
|
*/
|
|
|
|
ISC_LANG_BEGINDECLS
|
|
|
|
typedef struct {
|
|
unsigned int magic;
|
|
#if 0
|
|
isc_mutex_t lock;
|
|
#endif
|
|
} isc_random_t;
|
|
#define ISC_RANDOM_MAGIC 0x52416e64 /* RAnd. */
|
|
#define ISC_RANDOM_VALID(x) ((x) != NULL && (x->magic) == ISC_RANDOM_MAGIC)
|
|
|
|
isc_result_t isc_random_init(isc_random_t *r);
|
|
/*
|
|
* Initialize a random state.
|
|
*
|
|
* This function must be called before using any of the following functions.
|
|
*
|
|
* Requires:
|
|
* r != NULL.
|
|
*/
|
|
|
|
isc_result_t isc_random_invalidate(isc_random_t *r);
|
|
/*
|
|
* Invalidate a random state. This will wipe any information contained in
|
|
* the state and make it unusable.
|
|
*
|
|
* Requires:
|
|
* r be a valid pool.
|
|
*/
|
|
|
|
void isc_random_seed(isc_random_t *r, isc_uint32_t seed);
|
|
/*
|
|
* Set the initial seed of the random state. Note that on some systems
|
|
* the private state isn't all that private, and setting the seed may
|
|
* alter numbers returned to other state pools.
|
|
*
|
|
* Requires:
|
|
* r be a valid pool.
|
|
*/
|
|
|
|
void isc_random_get(isc_random_t *r, isc_uint32_t *val);
|
|
/*
|
|
* Get a random value. Note that on some systems the private state isn't
|
|
* all that private, and getting a value may alter what other state pools
|
|
* would have returned.
|
|
*
|
|
* Requires:
|
|
* r be a valid pool.
|
|
* val != NULL.
|
|
*/
|
|
|
|
ISC_LANG_ENDDECLS
|
|
|
|
#endif /* ISC_RANDOM_H */
|