boot/efi: Fix boot1's compilation with -fno-common.
[dragonfly.git] / sys / sys / random.h
1 /*
2  * random.h -- A strong random number generator
3  *
4  * $FreeBSD: src/sys/sys/random.h,v 1.19.2.2 2002/09/17 17:11:54 sam Exp $
5  *
6  * Version 0.95, last modified 18-Oct-95
7  * 
8  * Copyright Theodore Ts'o, 1994, 1995.  All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, and the entire permission notice in its entirety,
15  *    including the disclaimer of warranties.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. The name of the author may not be used to endorse or promote
20  *    products derived from this software without specific prior
21  *    written permission.
22  * 
23  * ALTERNATIVELY, this product may be distributed under the terms of
24  * the GNU Public License, in which case the provisions of the GPL are
25  * required INSTEAD OF the above restrictions.  (This clause is
26  * necessary due to a potential bad interaction between the GPL and
27  * the restrictions contained in a BSD-style copyright.)
28  * 
29  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
30  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
31  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
32  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
33  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
34  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
35  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
37  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
39  * OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41
42 /*
43  * Many kernel routines will have a use for good random numbers,
44  * for example, for truly random TCP sequence numbers, which prevent
45  * certain forms of TCP spoofing attacks.
46  * 
47  */
48
49 #ifndef _SYS_RANDOM_H_
50 #define _SYS_RANDOM_H_
51
52 #ifndef _SYS_TYPES_H_
53 #include <sys/types.h>
54 #endif
55 #ifndef _SYS_IOCCOM_H_
56 #include <sys/ioccom.h>
57 #endif
58
59 #define MEM_SETIRQ      _IOW('r', 1, u_int16_t) /* set interrupt */
60 #define MEM_CLEARIRQ    _IOW('r', 2, u_int16_t) /* clear interrupt */
61 #define MEM_RETURNIRQ   _IOR('r', 3, u_int16_t) /* obsolete */
62 #define MEM_FINDIRQ     _IOWR('r', 4, u_int16_t) /* next interrupt */
63
64 /*
65  * getrandom()
66  */
67 #define GRND_RANDOM     0x0001
68 #define GRND_NONBLOCK   0x0002
69 #define GRND_INSECURE   0x0004
70
71 #ifdef _KERNEL
72
73 /*
74  * XXX: consider only statically allocating some, and allocating
75  *      most others dynamically.
76  */
77 #define RAND_SRC_UNKNOWN        0x0000
78 #define RAND_SRC_SEEDING        0x0001
79 #define RAND_SRC_TIMING         0x0002
80 #define RAND_SRC_INTR           0x0003
81 #define RAND_SRC_RDRAND         0x0004
82 #define RAND_SRC_PADLOCK        0x0005
83 #define RAND_SRC_GLXSB          0x0006
84 #define RAND_SRC_HIFN           0x0007
85 #define RAND_SRC_UBSEC          0x0008
86 #define RAND_SRC_SAFE           0x0009
87 #define RAND_SRC_VIRTIO         0x000a
88 #define RAND_SRC_THREAD1        0x000b
89 #define RAND_SRC_THREAD2        0x000c
90 #define RAND_SRC_THREAD3        0x000d
91
92 #define RAND_SRC_MASK           0x00FF
93
94 #define RAND_SRCF_PCPU          0x0100
95
96 /* Type of the cookie passed to add_interrupt_randomness. */
97
98 struct random_softc {
99         int             sc_intr;
100         int             sc_enabled;
101 };
102
103 /* Exported functions */
104
105 void rand_initialize(void);
106 void add_keyboard_randomness(u_char scancode);
107 void add_interrupt_randomness(int intr);
108 int add_buffer_randomness(const char *, int);
109 int add_buffer_randomness_src(const char *, int, int srcid);
110
111 u_int read_random(void *buf, u_int size, int unlimited);
112 struct knote;
113 int random_filter_read(struct knote *kn, long hint);
114
115 #endif /* _KERNEL */
116
117 ssize_t getrandom(void *buf, size_t buflen, unsigned int flags);
118
119 #endif /* !_SYS_RANDOM_H_ */