1 /* $MirOS: src/sys/crypto/randimpl.h,v 1.3 2011/02/19 14:41:39 tg Exp $ */
2 
3 /*#define RNDEBUG*/
4 
5 /* contains RNG implementation details, DO NOT include in your code! */
6 
7 #ifndef __IMPLEMENTATION_OF_RANDOM_H__
8 #define __IMPLEMENTATION_OF_RANDOM_H__
9 
10 #include <dev/rndvar.h>
11 
12 /* there is actually only one of these, globally */
13 #ifndef IN_RANDOM_CORE
14 extern
15 #endif
16   struct {
17 	u_int add_ptr;
18 	u_int entropy_count;
19 	u_char input_rotate;
20 	u_int32_t pool[POOLWORDS];
21 	u_int asleep;
22 	u_int tmo;
23 } /* singleton */ random_state;
24 
25 /* import from kernel */
26 extern int hz;
27 
28 /* import from crypto/arc4random.c */
29 extern void arc4random_reinit(void *);
30 
31 /* import from crypto/randcore.c */
32 extern int rnd_attached;
33 extern void rnd_flush(void);
34 
35 #ifdef RNDEBUG
36 #define RD_INPUT	0x000F	/* input data */
37 #define RD_OUTPUT	0x00F0	/* output data */
38 #define RD_WAIT		0x0100	/* sleep/wakeup for good data */
39 #define	RD_ARC4RANDOM	0x0200	/* arc4random(9) */
40 #define RD_ARC4LOPOOL	0x0400	/* lopool collapser */
41 #define RD_HASHLOPOOL	0x0800	/* lopool hasher */
42 #define RD_ALWAYS	0x1000	/* always set, for errors */
43 #define RD_SRANDOM	0x2000	/* srandom() calls */
44 #define RD_ENQUEUE	0x4000	/* every enqueue (loud!) */
45 #ifdef IN_RANDOM_CORE
46 int rnd_debug = RD_ALWAYS;
47 #else
48 extern int rnd_debug;
49 #endif
50 extern int db_active;
51 extern void rnd_lopool_addvq(unsigned long);
52 #undef RNDEBUG
53 #define RNDEBUG(flag, ...)	do {				\
54 	if (!db_active && (rnd_debug & (flag)))			\
55 		printf(__VA_ARGS__);				\
56 } while (/* CONSTCOND */ 0)
57 #else
58 #define RNDEBUG(flag, ...)	/* nothing */
59 #define rnd_lopool_addvq	rnd_lopool_addv
60 #endif
61 
62 /* import from dev/rnd.c */
63 extern void rndpool_init(void);
64 
65 #endif
66