entropy.c File Reference

This is the system independent part of the entropy module. It is compiled via inclusion from the relevant OS source file, ie, unix/entropy.c or win32/entropy.c. More...

#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <isc/buffer.h>
#include <isc/entropy.h>
#include <isc/keyboard.h>
#include <isc/list.h>
#include <isc/magic.h>
#include <isc/mem.h>
#include <isc/msgs.h>
#include <isc/mutex.h>
#include <isc/platform.h>
#include <isc/region.h>
#include <isc/sha1.h>
#include <isc/string.h>
#include <isc/time.h>
#include <isc/util.h>

Go to the source code of this file.

Data Structures

struct  isc_entropypool_t
 Entropy Pool. More...
struct  isc_entropy
struct  sample_queue_t
 Sample Queue. More...
struct  isc_entropysamplesource_t
struct  isc_cbsource_t
struct  isc_entropyfilesource_t
struct  isc_entropysource

Defines

#define ENTROPY_MAGIC   ISC_MAGIC('E', 'n', 't', 'e')
#define SOURCE_MAGIC   ISC_MAGIC('E', 'n', 't', 's')
#define VALID_ENTROPY(e)   ISC_MAGIC_VALID(e, ENTROPY_MAGIC)
#define VALID_SOURCE(s)   ISC_MAGIC_VALID(s, SOURCE_MAGIC)
#define RND_POOLWORDS   128
 Size of entropy pool in 32-bit words. This _MUST_ be a power of 2.
#define RND_POOLBYTES   (RND_POOLWORDS * 4)
 Pool in bytes.
#define RND_POOLBITS   (RND_POOLWORDS * 32)
 Pool in bits.
#define RND_ENTROPY_THRESHOLD   10
 Number of bytes returned per hash. This must be true: threshold * 2 <= digest_size_in_bytes.
#define THRESHOLD_BITS   (RND_ENTROPY_THRESHOLD * 8)
#define RND_EVENTQSIZE   32
 Size of the input event queue in samples.
#define RND_INITIALIZE   128
 The number of times we'll "reseed" for pseudorandom seeds. This is an extremely weak pseudorandom seed. If the caller is using lots of pseudorandom data and they cannot provide a stronger random source, there is little we can do other than hope they're smart enough to call _adddata() with something better than we can come up with.
#define ENTROPY_SOURCETYPE_SAMPLE   1
 Type is a sample source.
#define ENTROPY_SOURCETYPE_FILE   2
 Type is a file source.
#define ENTROPY_SOURCETYPE_CALLBACK   3
 Type is a callback source.
#define ENTROPY_SOURCETYPE_USOCKET   4
 Type is a Unix socket source.
#define TAP1   99
 The random pool "taps".
#define TAP2   59
 The random pool "taps".
#define TAP3   31
 The random pool "taps".
#define TAP4   9
 The random pool "taps".
#define TAP5   7
 The random pool "taps".

Functions

static void samplequeue_release (isc_entropy_t *ent, sample_queue_t *sq)
static isc_result_t samplesource_allocate (isc_entropy_t *ent, sample_queue_t *sq)
static void add_entropy (isc_entropy_t *ent, isc_uint32_t entropy)
 Add in entropy, even when the value we're adding in could be very large.
static void subtract_entropy (isc_entropy_t *ent, isc_uint32_t entropy)
 Decrement the amount of entropy the pool has.
static void add_pseudo (isc_entropy_t *ent, isc_uint32_t pseudo)
static void subtract_pseudo (isc_entropy_t *ent, isc_uint32_t pseudo)
static void entropypool_add_word (isc_entropypool_t *rp, isc_uint32_t val)
static void entropypool_adddata (isc_entropy_t *ent, void *p, unsigned int len, isc_uint32_t entropy)
static void reseed (isc_entropy_t *ent)
static unsigned int estimate_entropy (sample_queue_t *sq, isc_uint32_t t)
static unsigned int crunchsamples (isc_entropy_t *ent, sample_queue_t *sq)
static unsigned int get_from_callback (isc_entropysource_t *source, unsigned int desired, isc_boolean_t blocking)
isc_result_t isc_entropy_getdata (isc_entropy_t *ent, void *data, unsigned int length, unsigned int *returned, unsigned int flags)
 Extract data from the entropy pool. This may load the pool from various sources.
static void isc_entropypool_init (isc_entropypool_t *pool)
static void isc_entropypool_invalidate (isc_entropypool_t *pool)
isc_result_t isc_entropy_create (isc_mem_t *mctx, isc_entropy_t **entp)
 Create a new entropy object.
static void destroysource (isc_entropysource_t **sourcep)
static isc_boolean_t destroy_check (isc_entropy_t *ent)
static void destroy (isc_entropy_t **entp)
void isc_entropy_destroysource (isc_entropysource_t **sourcep)
 Removes an entropy source from the entropy system.
isc_result_t isc_entropy_createcallbacksource (isc_entropy_t *ent, isc_entropystart_t start, isc_entropyget_t get, isc_entropystop_t stop, void *arg, isc_entropysource_t **sourcep)
 Create an entropy source that is polled via a callback.
void isc_entropy_stopcallbacksources (isc_entropy_t *ent)
 Call the stop functions for callback sources that have had their start functions called.
isc_result_t isc_entropy_createsamplesource (isc_entropy_t *ent, isc_entropysource_t **sourcep)
 Create an entropy source that consists of samples. Each sample is added to the source via isc_entropy_addsamples(), below.
static isc_result_t addsample (sample_queue_t *sq, isc_uint32_t sample, isc_uint32_t extra)
isc_result_t isc_entropy_addsample (isc_entropysource_t *source, isc_uint32_t sample, isc_uint32_t extra)
 Add a sample to the sample source.
isc_result_t isc_entropy_addcallbacksample (isc_entropysource_t *source, isc_uint32_t sample, isc_uint32_t extra)
void isc_entropy_putdata (isc_entropy_t *ent, void *data, unsigned int length, isc_uint32_t entropy)
 Add "length" bytes in "data" to the entropy pool, incrementing the pool's entropy count by "entropy.".
static void dumpstats (isc_entropy_t *ent, FILE *out)
void isc_entropy_stats (isc_entropy_t *ent, FILE *out)
 Dump some (trivial) stats to the stdio stream "out".
unsigned int isc_entropy_status (isc_entropy_t *ent)
void isc_entropy_attach (isc_entropy_t *ent, isc_entropy_t **entp)
void isc_entropy_detach (isc_entropy_t **entp)
 Detaches from an entropy object.
static isc_result_t kbdstart (isc_entropysource_t *source, void *arg, isc_boolean_t blocking)
static void kbdstop (isc_entropysource_t *source, void *arg)
static isc_result_t kbdget (isc_entropysource_t *source, void *arg, isc_boolean_t blocking)
isc_result_t isc_entropy_usebestsource (isc_entropy_t *ectx, isc_entropysource_t **source, const char *randomfile, int use_keyboard)
 Use whatever source of entropy is best.
static void fillpool (isc_entropy_t *, unsigned int, isc_boolean_t)
 Declarations for function provided by the system dependent sources that include this file.
static int wait_for_sources (isc_entropy_t *)
 Declarations for function provided by the system dependent sources that include this file.
static void destroyfilesource (isc_entropyfilesource_t *source)
 Declarations for function provided by the system dependent sources that include this file.
static void destroyusocketsource (isc_entropyusocketsource_t *source)
 Declarations for function provided by the system dependent sources that include this file.


Detailed Description

This is the system independent part of the entropy module. It is compiled via inclusion from the relevant OS source file, ie, unix/entropy.c or win32/entropy.c.

Author:
Much of this code is modeled after the NetBSD /dev/random implementation, written by Michael Graff <explorer@netbsd.org>.

Definition in file entropy.c.


Define Documentation

#define ENTROPY_MAGIC   ISC_MAGIC('E', 'n', 't', 'e')

Definition at line 53 of file entropy.c.

Referenced by isc_entropy_create().

#define SOURCE_MAGIC   ISC_MAGIC('E', 'n', 't', 's')

Definition at line 54 of file entropy.c.

Referenced by isc_entropy_createcallbacksource(), isc_entropy_createfilesource(), and isc_entropy_createsamplesource().

#define VALID_ENTROPY (  )     ISC_MAGIC_VALID(e, ENTROPY_MAGIC)

Definition at line 56 of file entropy.c.

Referenced by fillpool(), isc_entropy_attach(), isc_entropy_createcallbacksource(), isc_entropy_createfilesource(), isc_entropy_createsamplesource(), isc_entropy_destroysource(), isc_entropy_detach(), isc_entropy_getdata(), isc_entropy_putdata(), isc_entropy_stats(), isc_entropy_stopcallbacksources(), and isc_entropy_usebestsource().

#define VALID_SOURCE ( s   )     ISC_MAGIC_VALID(s, SOURCE_MAGIC)

Definition at line 57 of file entropy.c.

Referenced by isc_entropy_addcallbacksample(), isc_entropy_addsample(), and isc_entropy_destroysource().

#define RND_POOLWORDS   128

Size of entropy pool in 32-bit words. This _MUST_ be a power of 2.

Definition at line 67 of file entropy.c.

Referenced by entropypool_add_word(), and isc_entropypool_init().

#define RND_POOLBYTES   (RND_POOLWORDS * 4)

Pool in bytes.

Definition at line 69 of file entropy.c.

Referenced by isc_entropy_getdata(), isc_entropypool_init(), and isc_entropypool_invalidate().

#define RND_POOLBITS   (RND_POOLWORDS * 32)

Pool in bits.

Definition at line 71 of file entropy.c.

Referenced by add_entropy(), add_pseudo(), and fillpool().

#define RND_ENTROPY_THRESHOLD   10

Number of bytes returned per hash. This must be true: threshold * 2 <= digest_size_in_bytes.

Definition at line 77 of file entropy.c.

Referenced by isc_entropy_getdata().

#define THRESHOLD_BITS   (RND_ENTROPY_THRESHOLD * 8)

Definition at line 78 of file entropy.c.

Referenced by fillpool(), isc_entropy_getdata(), and isc_entropy_putdata().

#define RND_EVENTQSIZE   32

Size of the input event queue in samples.

Definition at line 83 of file entropy.c.

Referenced by addsample(), samplequeue_release(), and samplesource_allocate().

#define RND_INITIALIZE   128

The number of times we'll "reseed" for pseudorandom seeds. This is an extremely weak pseudorandom seed. If the caller is using lots of pseudorandom data and they cannot provide a stronger random source, there is little we can do other than hope they're smart enough to call _adddata() with something better than we can come up with.

Definition at line 92 of file entropy.c.

#define ENTROPY_SOURCETYPE_SAMPLE   1

Type is a sample source.

Definition at line 161 of file entropy.c.

Referenced by destroysource(), and isc_entropy_createsamplesource().

#define ENTROPY_SOURCETYPE_FILE   2

Type is a file source.

Definition at line 162 of file entropy.c.

Referenced by destroy(), destroy_check(), destroysource(), fillpool(), isc_entropy_createfilesource(), and wait_for_sources().

#define ENTROPY_SOURCETYPE_CALLBACK   3

Type is a callback source.

Definition at line 163 of file entropy.c.

Referenced by destroysource(), fillpool(), isc_entropy_addcallbacksample(), isc_entropy_createcallbacksource(), and isc_entropy_stopcallbacksources().

#define ENTROPY_SOURCETYPE_USOCKET   4

Type is a Unix socket source.

Definition at line 164 of file entropy.c.

Referenced by destroy(), destroy_check(), destroysource(), fillpool(), isc_entropy_createfilesource(), and wait_for_sources().

#define TAP1   99

The random pool "taps".

Definition at line 170 of file entropy.c.

Referenced by entropypool_add_word().

#define TAP2   59

The random pool "taps".

Definition at line 171 of file entropy.c.

Referenced by entropypool_add_word().

#define TAP3   31

The random pool "taps".

Definition at line 172 of file entropy.c.

Referenced by entropypool_add_word().

#define TAP4   9

The random pool "taps".

Definition at line 173 of file entropy.c.

Referenced by entropypool_add_word().

#define TAP5   7

The random pool "taps".

Definition at line 174 of file entropy.c.

Referenced by entropypool_add_word().


Function Documentation

static void fillpool ( isc_entropy_t ,
unsigned  int,
isc_boolean_t   
) [static]

Declarations for function provided by the system dependent sources that include this file.

Referenced by isc_entropy_getdata().

static int wait_for_sources ( isc_entropy_t  )  [static]

Declarations for function provided by the system dependent sources that include this file.

Referenced by fillpool().

static void destroyfilesource ( isc_entropyfilesource_t source  )  [static]

Declarations for function provided by the system dependent sources that include this file.

Referenced by destroysource().

static void destroyusocketsource ( isc_entropyusocketsource_t source  )  [static]

Declarations for function provided by the system dependent sources that include this file.

Referenced by destroysource().

static void samplequeue_release ( isc_entropy_t ent,
sample_queue_t sq 
) [static]

Definition at line 197 of file entropy.c.

References sample_queue_t::extra, isc_mem_put, isc_entropy::mctx, REQUIRE, RND_EVENTQSIZE, and sample_queue_t::samples.

Referenced by destroysource().

static isc_result_t samplesource_allocate ( isc_entropy_t ent,
sample_queue_t sq 
) [static]

Definition at line 208 of file entropy.c.

References sample_queue_t::extra, isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_entropy::mctx, sample_queue_t::nsamples, RND_EVENTQSIZE, and sample_queue_t::samples.

Referenced by isc_entropy_createcallbacksource(), and isc_entropy_createsamplesource().

static void add_entropy ( isc_entropy_t ent,
isc_uint32_t  entropy 
) [inline, static]

Add in entropy, even when the value we're adding in could be very large.

Definition at line 230 of file entropy.c.

References isc_entropypool_t::entropy, ISC_MIN, isc_entropy::pool, and RND_POOLBITS.

Referenced by entropypool_adddata(), isc_entropy_addsample(), and isc_entropy_getdata().

static void subtract_entropy ( isc_entropy_t ent,
isc_uint32_t  entropy 
) [inline, static]

Decrement the amount of entropy the pool has.

Definition at line 243 of file entropy.c.

References isc_entropypool_t::entropy, ISC_MIN, and isc_entropy::pool.

Referenced by isc_entropy_getdata().

static void add_pseudo ( isc_entropy_t ent,
isc_uint32_t  pseudo 
) [inline, static]

Add in entropy, even when the value we're adding in could be very large.

Definition at line 253 of file entropy.c.

References ISC_MIN, isc_entropy::pool, isc_entropypool_t::pseudo, and RND_POOLBITS.

Referenced by isc_entropy_getdata().

static void subtract_pseudo ( isc_entropy_t ent,
isc_uint32_t  pseudo 
) [inline, static]

Decrement the amount of pseudo the pool has.

Definition at line 266 of file entropy.c.

References ISC_MIN, isc_entropy::pool, and isc_entropypool_t::pseudo.

Referenced by entropypool_adddata().

static void entropypool_add_word ( isc_entropypool_t rp,
isc_uint32_t  val 
) [inline, static]

Add one word to the pool, rotating the input as needed.

Definition at line 275 of file entropy.c.

References isc_entropypool_t::cursor, isc_entropypool_t::pool, RND_POOLWORDS, isc_entropypool_t::rotate, TAP1, TAP2, TAP3, TAP4, and TAP5.

Referenced by entropypool_adddata().

static void entropypool_adddata ( isc_entropy_t ent,
void *  p,
unsigned int  len,
isc_uint32_t  entropy 
) [static]

Add a buffer's worth of data to the pool.

Requires that the lock is held on the entropy pool.

Definition at line 315 of file entropy.c.

References add_entropy(), entropypool_add_word(), isc_entropy::pool, and subtract_pseudo().

Referenced by crunchsamples(), get_from_filesource(), get_from_usocketsource(), isc_entropy_getdata(), isc_entropy_putdata(), and reseed().

static void reseed ( isc_entropy_t ent  )  [inline, static]

After we've reseeded 100 times, only add new timing info every 50 requests. This will keep us from using lots and lots of CPU just to return bad pseudorandom data anyway.

Definition at line 373 of file entropy.c.

References entropypool_adddata(), isc_entropy::initcount, and TIME_NOW.

Referenced by isc_entropy_getdata(), and isc_lfsr_init().

static unsigned int estimate_entropy ( sample_queue_t sq,
isc_uint32_t  t 
) [inline, static]

If the time counter has overflowed, calculate the real difference. If it has not, it is simpler.

Definition at line 399 of file entropy.c.

References sample_queue_t::last_delta, sample_queue_t::last_delta2, and sample_queue_t::last_time.

Referenced by crunchsamples().

static unsigned int crunchsamples ( isc_entropy_t ent,
sample_queue_t sq 
) [static]

Definition at line 446 of file entropy.c.

References entropypool_adddata(), estimate_entropy(), sample_queue_t::extra, sample_queue_t::last_delta, sample_queue_t::last_delta2, sample_queue_t::last_time, sample_queue_t::nsamples, and sample_queue_t::samples.

Referenced by get_from_callback(), and isc_entropy_addsample().

static unsigned int get_from_callback ( isc_entropysource_t source,
unsigned int  desired,
isc_boolean_t  blocking 
) [static]

Definition at line 486 of file entropy.c.

References isc_cbsource_t::arg, crunchsamples(), isc_entropysource::ent, isc_cbsource_t::getfunc, ISC_MIN, ISC_R_NOTBLOCKING, ISC_R_QUEUEFULL, ISC_R_SUCCESS, ISC_TRUE, isc_cbsource_t::samplequeue, isc_entropysource::sources, isc_cbsource_t::start_called, and isc_cbsource_t::startfunc.

Referenced by fillpool().

isc_result_t isc_entropy_getdata ( isc_entropy_t ent,
void *  data,
unsigned int  length,
unsigned int *  returned,
unsigned int  flags 
)

Extract data from the entropy pool. This may load the pool from various sources.

Do this by stiring the pool and returning a part of hash as randomness. Note that no secrets are given away here since parts of the hash are xored together before returned.

Honor the request from the caller to only return good data, any data, etc.

Definition at line 538 of file entropy.c.

References add_entropy(), add_pseudo(), digest, isc_entropypool_t::entropy, entropypool_adddata(), fillpool(), hash, isc_entropy::initialized, ISC_ENTROPY_BLOCKING, ISC_ENTROPY_GOODONLY, ISC_ENTROPY_PARTIAL, ISC_FALSE, ISC_MAX, ISC_MIN, ISC_R_NOENTROPY, ISC_R_SUCCESS, ISC_SHA1_DIGESTLENGTH, isc_sha1_final(), isc_sha1_init(), isc_sha1_update(), ISC_TF, isc_entropy::lock, LOCK, isc_entropypool_t::pool, isc_entropy::pool, REQUIRE, reseed(), RND_ENTROPY_THRESHOLD, RND_POOLBYTES, subtract_entropy(), THRESHOLD_BITS, UNLOCK, and VALID_ENTROPY.

Referenced by chacha_stir(), create_view(), dns_tkey_processquery(), dst__entropy_getdata(), dst__entropy_status(), isc_hash_ctxinit(), isc_rng_create(), load_configuration(), and setup_system().

static void isc_entropypool_init ( isc_entropypool_t pool  )  [static]

Definition at line 664 of file entropy.c.

References isc_entropypool_t::cursor, isc_entropypool_t::entropy, isc_entropypool_t::pool, isc_entropypool_t::pseudo, RND_POOLBYTES, RND_POOLWORDS, and isc_entropypool_t::rotate.

Referenced by isc_entropy_create().

static void isc_entropypool_invalidate ( isc_entropypool_t pool  )  [static]

Definition at line 673 of file entropy.c.

References isc_entropypool_t::cursor, isc_entropypool_t::entropy, isc_entropypool_t::pool, isc_entropypool_t::pseudo, RND_POOLBYTES, and isc_entropypool_t::rotate.

Referenced by destroy().

isc_result_t isc_entropy_create ( isc_mem_t mctx,
isc_entropy_t **  entp 
)

Create a new entropy object.

Definition at line 682 of file entropy.c.

References ENTROPY_MAGIC, isc_entropy::initcount, isc_entropy::initialized, isc_entropypool_init(), ISC_LIST_INIT, isc_mem_attach(), isc_mem_get, isc_mem_put, isc_mutex_init, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_entropy::lock, isc_entropy::magic, isc_entropy::mctx, isc_entropy::nextsource, isc_entropy::nsources, isc_entropy::pool, isc_entropy::refcnt, and REQUIRE.

Referenced by create_managers(), dns_test_begin(), ISC_LIST(), isc_test_begin(), main(), setup(), setup_entropy(), and setup_libs().

static void destroysource ( isc_entropysource_t **  sourcep  )  [static]

Requires "ent" be locked.

Definition at line 728 of file entropy.c.

References isc_cbsource_t::arg, destroyfilesource(), destroyusocketsource(), isc_entropysource::ent, ENTROPY_SOURCETYPE_CALLBACK, ENTROPY_SOURCETYPE_FILE, ENTROPY_SOURCETYPE_SAMPLE, ENTROPY_SOURCETYPE_USOCKET, ISC_FALSE, ISC_LIST_UNLINK, isc_mem_put, isc_entropy::mctx, isc_entropy::nextsource, isc_entropy::nsources, REQUIRE, isc_cbsource_t::samplequeue, samplequeue_release(), isc_entropysource::sources, isc_cbsource_t::start_called, isc_cbsource_t::stopfunc, and isc_entropysource::type.

Referenced by destroy(), and isc_entropy_destroysource().

static isc_boolean_t destroy_check ( isc_entropy_t ent  )  [inline, static]

Definition at line 770 of file entropy.c.

References ENTROPY_SOURCETYPE_FILE, ENTROPY_SOURCETYPE_USOCKET, ISC_FALSE, ISC_LIST_HEAD, ISC_LIST_NEXT, ISC_TRUE, isc_entropy::refcnt, and isc_entropysource::type.

Referenced by isc_entropy_destroysource(), and isc_entropy_detach().

static void destroy ( isc_entropy_t **  entp  )  [static]

Definition at line 792 of file entropy.c.

References DESTROYLOCK, destroysource(), ENTROPY_SOURCETYPE_FILE, ENTROPY_SOURCETYPE_USOCKET, isc_entropypool_invalidate(), ISC_LIST_EMPTY, ISC_LIST_HEAD, isc_mem_detach(), isc_mem_put, isc_entropy::lock, LOCK, isc_entropy::mctx, isc_entropy::pool, isc_entropy::refcnt, REQUIRE, isc_entropysource::type, and UNLOCK.

void isc_entropy_destroysource ( isc_entropysource_t **  sourcep  ) 

Removes an entropy source from the entropy system.

Definition at line 838 of file entropy.c.

References destroy(), destroy_check(), destroysource(), isc_entropysource::ent, isc_entropy::lock, LOCK, REQUIRE, UNLOCK, VALID_ENTROPY, and VALID_SOURCE.

Referenced by cleanup_entropy().

isc_result_t isc_entropy_createcallbacksource ( isc_entropy_t ent,
isc_entropystart_t  start,
isc_entropyget_t  get,
isc_entropystop_t  stop,
void *  arg,
isc_entropysource_t **  sourcep 
)

Create an entropy source that is polled via a callback.

This would be used when keyboard input is used, or a GUI input method. It can also be used to hook in any external entropy source.

Samples are added via isc_entropy_addcallbacksample(), below. _addcallbacksample() is the only function which may be called from within an entropy API callback function.

Definition at line 865 of file entropy.c.

References isc_cbsource_t::arg, isc_entropysource::ent, ENTROPY_SOURCETYPE_CALLBACK, isc_cbsource_t::getfunc, ISC_FALSE, ISC_LINK_INIT, ISC_LIST_APPEND, isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_entropy::lock, LOCK, isc_entropysource::magic, isc_entropy::mctx, isc_entropy::nsources, REQUIRE, isc_cbsource_t::samplequeue, samplesource_allocate(), SOURCE_MAGIC, isc_entropysource::sources, isc_cbsource_t::start_called, isc_cbsource_t::startfunc, isc_cbsource_t::stopfunc, isc_entropysource::total, isc_entropysource::type, UNLOCK, and VALID_ENTROPY.

Referenced by isc_entropy_usebestsource().

void isc_entropy_stopcallbacksources ( isc_entropy_t ent  ) 

Call the stop functions for callback sources that have had their start functions called.

Definition at line 932 of file entropy.c.

References isc_cbsource_t::arg, ENTROPY_SOURCETYPE_CALLBACK, ISC_FALSE, ISC_LIST_HEAD, ISC_LIST_NEXT, isc_entropy::lock, LOCK, REQUIRE, isc_entropysource::sources, isc_cbsource_t::start_called, isc_cbsource_t::stopfunc, isc_entropysource::type, UNLOCK, and VALID_ENTROPY.

Referenced by main(), and signwithkey().

isc_result_t isc_entropy_createsamplesource ( isc_entropy_t ent,
isc_entropysource_t **  sourcep 
)

Create an entropy source that consists of samples. Each sample is added to the source via isc_entropy_addsamples(), below.

Definition at line 957 of file entropy.c.

References isc_entropysource::ent, ENTROPY_SOURCETYPE_SAMPLE, ISC_LINK_INIT, ISC_LIST_APPEND, isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_SUCCESS, isc_entropy::lock, LOCK, isc_entropysource::magic, isc_entropy::mctx, isc_entropy::nsources, REQUIRE, samplesource_allocate(), SOURCE_MAGIC, isc_entropysource::sources, isc_entropysource::total, isc_entropysource::type, UNLOCK, and VALID_ENTROPY.

static isc_result_t addsample ( sample_queue_t sq,
isc_uint32_t  sample,
isc_uint32_t  extra 
) [static]

Add a sample, and return ISC_R_SUCCESS if the queue has become full, ISC_R_NOENTROPY if it has space remaining, and ISC_R_NOMORE if the queue was full when this function was called.

Definition at line 1016 of file entropy.c.

References sample_queue_t::extra, ISC_R_NOMORE, ISC_R_QUEUEFULL, ISC_R_SUCCESS, sample_queue_t::nsamples, RND_EVENTQSIZE, and sample_queue_t::samples.

Referenced by isc_entropy_addcallbacksample(), and isc_entropy_addsample().

isc_result_t isc_entropy_addsample ( isc_entropysource_t source,
isc_uint32_t  sample,
isc_uint32_t  extra 
)

Add a sample to the sample source.

The sample MUST be a timestamp that increases over time, with the exception of wrap-around for extremely high resolution timers which will quickly wrap-around a 32-bit integer.

The "extra" parameter is used only to add a bit more unpredictable data. It is not used other than included in the hash of samples.

When in an entropy API callback function, _addcallbacksource() must be used. At all other times, _addsample() must be used.

Definition at line 1031 of file entropy.c.

References add_entropy(), addsample(), crunchsamples(), isc_entropysource::ent, entropy, ISC_R_QUEUEFULL, isc_entropy::lock, LOCK, REQUIRE, isc_entropysource::sources, UNLOCK, and VALID_SOURCE.

isc_result_t isc_entropy_addcallbacksample ( isc_entropysource_t source,
isc_uint32_t  sample,
isc_uint32_t  extra 
)

Definition at line 1058 of file entropy.c.

References addsample(), ENTROPY_SOURCETYPE_CALLBACK, REQUIRE, isc_entropysource::sources, isc_entropysource::type, and VALID_SOURCE.

Referenced by kbdget().

void isc_entropy_putdata ( isc_entropy_t ent,
void *  data,
unsigned int  length,
isc_uint32_t  entropy 
)

Add "length" bytes in "data" to the entropy pool, incrementing the pool's entropy count by "entropy.".

These bytes will prime the pseudorandom portion even if no entropy is actually added.

Definition at line 1074 of file entropy.c.

References entropypool_adddata(), isc_entropy::initialized, isc_entropy::lock, LOCK, REQUIRE, THRESHOLD_BITS, UNLOCK, and VALID_ENTROPY.

Referenced by dst__entropy_status().

static void dumpstats ( isc_entropy_t ent,
FILE *  out 
) [static]

Definition at line 1090 of file entropy.c.

References isc_entropypool_t::cursor, isc_entropypool_t::entropy, isc_entropy::initcount, isc_entropy::initialized, ISC_MSG_ENTROPYSTATS, isc_msgcat_get(), ISC_MSGSET_ENTROPY, isc_entropy::nextsource, isc_entropy::nsources, isc_entropy::pool, isc_entropypool_t::pseudo, isc_entropy::refcnt, and isc_entropypool_t::rotate.

Referenced by isc_entropy_stats().

void isc_entropy_stats ( isc_entropy_t ent,
FILE *  out 
)

Dump some (trivial) stats to the stdio stream "out".

Definition at line 1108 of file entropy.c.

References dumpstats(), isc_entropy::lock, LOCK, REQUIRE, UNLOCK, and VALID_ENTROPY.

unsigned int isc_entropy_status ( isc_entropy_t ent  ) 

Definition at line 1117 of file entropy.c.

References isc_entropypool_t::entropy, isc_entropy::lock, LOCK, isc_entropy::pool, and UNLOCK.

Referenced by dst__entropy_status().

void isc_entropy_attach ( isc_entropy_t ent,
isc_entropy_t **  entp 
)

Attaches to an entropy object.

Definition at line 1128 of file entropy.c.

References isc_entropy::lock, LOCK, isc_entropy::refcnt, REQUIRE, UNLOCK, and VALID_ENTROPY.

Referenced by dns_dispatchmgr_create(), dns_tkeyctx_create(), dst_lib_init2(), isc_hash_ctxcreate(), and load_configuration().

void isc_entropy_detach ( isc_entropy_t **  entp  ) 

Detaches from an entropy object.

Definition at line 1141 of file entropy.c.

References destroy(), destroy_check(), isc_entropy::lock, LOCK, isc_entropy::refcnt, REQUIRE, UNLOCK, and VALID_ENTROPY.

Referenced by cleanup(), cleanup_entropy(), destroy(), destroy_libs(), destroy_mgr(), dns_test_end(), dns_tkeyctx_destroy(), dst_lib_destroy(), isc_test_end(), load_configuration(), main(), and setup().

static isc_result_t kbdstart ( isc_entropysource_t source,
void *  arg,
isc_boolean_t  blocking 
) [static]

Definition at line 1163 of file entropy.c.

References ISC_FALSE, isc_keyboard_open(), ISC_R_NOENTROPY, ISC_TRUE, and UNUSED.

Referenced by isc_entropy_usebestsource().

static void kbdstop ( isc_entropysource_t source,
void *  arg 
) [static]

Definition at line 1189 of file entropy.c.

References isc_keyboard_canceled(), isc_keyboard_close(), and UNUSED.

Referenced by isc_entropy_usebestsource().

static isc_result_t kbdget ( isc_entropysource_t source,
void *  arg,
isc_boolean_t  blocking 
) [static]

Definition at line 1200 of file entropy.c.

References isc_entropy_addcallbacksample(), isc_keyboard_getchar(), ISC_R_NOTBLOCKING, ISC_R_SUCCESS, isc_time_nanoseconds(), TIME_NOW, and UNUSED.

Referenced by isc_entropy_usebestsource().

isc_result_t isc_entropy_usebestsource ( isc_entropy_t ectx,
isc_entropysource_t **  source,
const char *  randomfile,
int  use_keyboard 
)

Use whatever source of entropy is best.

Notes:

Returns:

Definition at line 1234 of file entropy.c.

References isc_entropy_createcallbacksource(), isc_entropy_createfilesource(), ISC_ENTROPY_KEYBOARDMAYBE, ISC_ENTROPY_KEYBOARDNO, ISC_ENTROPY_KEYBOARDYES, ISC_FALSE, ISC_R_NOENTROPY, ISC_R_SUCCESS, ISC_TF, ISC_TRUE, kbdget(), kbdstart(), kbdstop(), pk11_rand_seed_fromfile(), REQUIRE, and VALID_ENTROPY.

Referenced by ISC_LIST(), and setup_entropy().


Generated on Tue Apr 28 17:41:14 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha