2000-06-03 02:15:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2000 Internet Software Consortium.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
|
|
|
|
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
|
|
|
|
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
|
|
|
|
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
|
|
|
|
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <isc/buffer.h>
|
|
|
|
#include <isc/entropy.h>
|
|
|
|
#include <isc/region.h>
|
|
|
|
#include <isc/string.h>
|
|
|
|
#include <isc/util.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Much of this code is modeled after the NetBSD /dev/random implementation,
|
|
|
|
* written by Michael Graff <explorer@netbsd.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/***
|
|
|
|
*** "constants." Do not change these unless you _really_ know what
|
|
|
|
*** you are doing.
|
|
|
|
***/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* size of entropy pool in 32-bit words. This _MUST_ be a power of 2.
|
|
|
|
*/
|
|
|
|
#define RND_POOLWORDS 128
|
|
|
|
#define RND_POOLBITS (RND_POOLWORDS * 32)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Number of bytes returned per hash.
|
|
|
|
*/
|
|
|
|
#define RND_ENTROPY_THRESHOLD 12
|
|
|
|
|
|
|
|
/*
|
2000-06-07 22:15:55 +00:00
|
|
|
* Size of the input event queue.
|
2000-06-03 02:15:08 +00:00
|
|
|
*/
|
|
|
|
#define RND_EVENTQSIZE 128
|
|
|
|
|
|
|
|
typedef struct {
|
2000-06-03 05:38:29 +00:00
|
|
|
isc_uint32_t cursor; /* current add point in the pool */
|
|
|
|
isc_uint32_t entropy; /* current entropy estimate in bits */
|
|
|
|
isc_uint32_t rotate; /* how many bits to rotate by */
|
|
|
|
isc_uint32_t pool[RND_POOLWORDS]; /* random pool data */
|
2000-06-03 02:15:08 +00:00
|
|
|
} isc_rndpool_t;
|
|
|
|
|
|
|
|
typedef struct {
|
2000-06-03 05:38:29 +00:00
|
|
|
isc_uint32_t last_time; /* last time recorded */
|
|
|
|
isc_uint32_t last_delta; /* last delta value */
|
|
|
|
isc_uint32_t last_delta2; /* last delta2 value */
|
2000-06-07 22:15:55 +00:00
|
|
|
isc_uint32_t entropy; /* entropy believed to be in samples */
|
|
|
|
isc_uint32_t nsamples; /* number of samples filled in */
|
|
|
|
isc_uint32_t *samples; /* the samples */
|
|
|
|
isc_uint32_t *extra; /* extra samples added in */
|
|
|
|
} isc_rndsamplesource_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int fd; /* fd for the file, or -1 if closed */
|
|
|
|
} isc_rndfilesource_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned int type;
|
|
|
|
unsigned int flags; /* flags */
|
2000-06-03 05:38:29 +00:00
|
|
|
isc_uint32_t total; /* entropy from this source */
|
2000-06-07 22:15:55 +00:00
|
|
|
char name[32];
|
|
|
|
union {
|
|
|
|
isc_rndsamplesource_t samplesource;
|
|
|
|
isc_rndfilesource_t filesource;
|
|
|
|
} sources;
|
2000-06-03 02:15:08 +00:00
|
|
|
} isc_rndsource_t;
|
|
|
|
|
2000-06-07 22:15:55 +00:00
|
|
|
#define RND_TYPE_SAMPLE 1 /* Type is a sample source */
|
|
|
|
#define RND_TYPE_FILE 2 /* Type is a file source */
|
2000-06-03 02:15:08 +00:00
|
|
|
|
2000-06-07 22:15:55 +00:00
|
|
|
isc_result_t
|
|
|
|
isc_entropy_create(isc_mem_t *mctx, isc_entropy_t **entp) {
|
|
|
|
}
|
2000-06-03 02:15:08 +00:00
|
|
|
|
2000-06-07 22:15:55 +00:00
|
|
|
isc_result_t
|
|
|
|
isc_entropy_destroy(isc_entropy_t **entp) {
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
isc_entropy_createfilesource(isc_entropy_t *ent, const char *fname,
|
|
|
|
unsigned int flags,
|
|
|
|
isc_entropysource_t **sourcep)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
isc_entropy_destroysource(isc_entropysource_t **sourcep) {
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
isc_entropy_createsamplesource(isc_entropy_t *ent,
|
|
|
|
isc_entropysource_t **sourcep)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
isc_entropy_addsample(isc_entropysource_t *source, isc_uint32_t sample,
|
|
|
|
isc_uint32_t extra, isc_boolean_t has_entropy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t
|
|
|
|
isc_entropy_getdata(isc_entropy_t *ent, void *data, unsigned int length,
|
|
|
|
unsigned int *returned, unsigned int flags)
|
|
|
|
{
|
|
|
|
}
|