yarrow.h revision 62765
1258945Sroberto/*-
2258945Sroberto * Copyright (c) 2000 Mark R V Murray
3258945Sroberto * All rights reserved.
4258945Sroberto *
5258945Sroberto * Redistribution and use in source and binary forms, with or without
6258945Sroberto * modification, are permitted provided that the following conditions
7258945Sroberto * are met:
8258945Sroberto * 1. Redistributions of source code must retain the above copyright
9258945Sroberto *    notice, this list of conditions and the following disclaimer
10258945Sroberto *    in this position and unchanged.
11258945Sroberto * 2. Redistributions in binary form must reproduce the above copyright
12258945Sroberto *    notice, this list of conditions and the following disclaimer in the
13258945Sroberto *    documentation and/or other materials provided with the distribution.
14258945Sroberto *
15258945Sroberto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16258945Sroberto * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17258945Sroberto * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18258945Sroberto * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19258945Sroberto * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20258945Sroberto * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21258945Sroberto * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22258945Sroberto * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23258945Sroberto * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24258945Sroberto * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25258945Sroberto *
26258945Sroberto * $FreeBSD: head/sys/dev/random/yarrow.h 62765 2000-07-07 09:03:59Z markm $
27258945Sroberto */
28258945Sroberto
29258945Sroberto#define ENTROPYBIN	256	/* buckets to harvest entropy events */
30258945Sroberto#define ENTROPYSOURCE	2	/* entropy sources (actually classes)    */
31258945Sroberto				/* The entropy classes will as follows:  */
32258945Sroberto				/*    0 - Keyboard                       */
33258945Sroberto				/*    1 - Mouse                          */
34258945Sroberto				/* to start with. More will be added     */
35258945Sroberto
36258945Sroberto#define TIMEBIN		16	/* max value for Pt/t */
37258945Sroberto#define KEYSIZE		32	/* 32 bytes == 256 bits */
38258945Sroberto
39258945Sroberto#define FAST		0
40258945Sroberto#define SLOW		1
41258945Sroberto
42258945Srobertovoid random_init(void);
43258945Srobertovoid random_deinit(void);
44258945Srobertovoid random_init_harvester(void (*)(struct timespec *, u_int64_t, u_int, u_int, u_int));
45258945Srobertovoid random_deinit_harvester(void);
46258945Sroberto
47258945Sroberto/* This is the beasite that needs protecting. It contains all of the
48258945Sroberto * state that we are excited about.
49258945Sroberto * This is a biiig structure. It may move over to a malloc(9)ed
50258945Sroberto * replacement.
51258945Sroberto */
52258945Srobertostruct random_state {
53258945Sroberto	u_int64_t counter;	/* C */
54258945Sroberto	BF_KEY key;		/* K */
55258945Sroberto	int gengateinterval;	/* Pg */
56258945Sroberto	int bins;		/* Pt/t */
57258945Sroberto	u_char ivec[8];		/* Blowfish internal */
58258945Sroberto	int outputblocks;	/* count output blocks for gates */
59258945Sroberto	u_int slowoverthresh;	/* slow pool overthreshhold reseed count */
60258945Sroberto	struct pool {
61258945Sroberto		struct source {
62258945Sroberto			struct entropy {
63258945Sroberto				struct timespec	nanotime;
64258945Sroberto				u_int64_t data;
65258945Sroberto			} entropy[ENTROPYBIN];	/* entropy units - must each
66258945Sroberto					   	be <= KEYSIZE */
67258945Sroberto			u_int bits;	/* estimated bits of entropy */
68258945Sroberto			u_int frac;	/* fractional bits of entropy
69258945Sroberto					   (given as 1024/n) */
70258945Sroberto			u_int current;	/* next insertion point */
71258945Sroberto		} source[ENTROPYSOURCE];
72258945Sroberto		u_int thresh;	/* pool reseed threshhold */
73258945Sroberto	} pool[2];		/* pool[0] is fast, pool[1] is slow */
74258945Sroberto	int which;		/* toggle - shows the current insertion pool */
75258945Sroberto};
76258945Sroberto
77258945Srobertoextern struct random_state random_state;
78258945Sroberto