Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / sys / rndio.h @ 13

History | View | Annotate | Download (5.94 KB)

1 13 up20180614
/*        $NetBSD: rndio.h,v 1.2 2015/09/06 06:01:02 dholland Exp $        */
2
3
/*-
4
 * Copyright (c) 1997 The NetBSD Foundation, Inc.
5
 * All rights reserved.
6
 *
7
 * This code is derived from software contributed to The NetBSD Foundation
8
 * by Michael Graff <explorer@flame.org>.  This code uses ideas and
9
 * algorithms from the Linux driver written by Ted Ts'o.
10
 *
11
 * Redistribution and use in source and binary forms, with or without
12
 * modification, are permitted provided that the following conditions
13
 * are met:
14
 * 1. Redistributions of source code must retain the above copyright
15
 *    notice, this list of conditions and the following disclaimer.
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
 *
20
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
 * POSSIBILITY OF SUCH DAMAGE.
31
 */
32
33
#ifndef        _SYS_RNDIO_H
34
#define        _SYS_RNDIO_H
35
36
#include <sys/types.h>
37
#include <sys/sha1.h>
38
#include <sys/ioccom.h>
39
40
/*
41
 * Exposed "size" of entropy pool, for convenience in load/save
42
 * from userspace.  Do not assume this is the same as the actual in-kernel
43
 * pool size!
44
 */
45
#define RND_SAVEWORDS        128
46
typedef struct {
47
        uint32_t entropy;
48
        uint8_t data[RND_SAVEWORDS * sizeof(uint32_t)];
49
        uint8_t digest[SHA1_DIGEST_LENGTH];
50
} rndsave_t;
51
52
/* Statistics exposed by RNDGETPOOLSTAT */
53
typedef struct
54
{
55
        uint32_t        poolsize;
56
        uint32_t         threshold;
57
        uint32_t        maxentropy;
58
59
        uint32_t        added;
60
        uint32_t        curentropy;
61
        uint32_t        removed;
62
        uint32_t        discarded;
63
        uint32_t        generated;
64
} rndpoolstat_t;
65
66
/* Sanitized random source view for userspace */
67
typedef struct {
68
        char                name[16];        /* device name */
69
        uint32_t        total;                /* entropy from this source */
70
        uint32_t        type;                /* type */
71
        uint32_t        flags;                /* flags */
72
} rndsource_t;
73
74
typedef struct {
75
        rndsource_t        rt;
76
        uint32_t        dt_samples;        /* time-delta samples input */
77
        uint32_t        dt_total;        /* time-delta entropy estimate */
78
        uint32_t        dv_samples;        /* value-delta samples input */
79
        uint32_t        dv_total;        /* value-delta entropy estimate */
80
} rndsource_est_t;
81
82
/*
83
 * Flags to control the source.  Low byte is type, upper bits are flags.
84
 */
85
#define RND_FLAG_NO_ESTIMATE        0x00000100
86
#define RND_FLAG_NO_COLLECT        0x00000200
87
#define RND_FLAG_FAST                0x00000400        /* process samples in bulk */
88
#define RND_FLAG_HASCB                0x00000800        /* has get callback */
89
#define RND_FLAG_COLLECT_TIME        0x00001000        /* use timestamp as input */
90
#define RND_FLAG_COLLECT_VALUE        0x00002000        /* use value as input */
91
#define RND_FLAG_ESTIMATE_TIME        0x00004000        /* estimate entropy on time */
92
#define RND_FLAG_ESTIMATE_VALUE        0x00008000        /* estimate entropy on value */
93
#define        RND_FLAG_HASENABLE        0x00010000        /* has enable/disable fns */
94
#define RND_FLAG_DEFAULT        (RND_FLAG_COLLECT_VALUE|RND_FLAG_COLLECT_TIME|\
95
                                 RND_FLAG_ESTIMATE_TIME)
96
97
#define        RND_TYPE_UNKNOWN        0        /* unknown source */
98
#define        RND_TYPE_DISK                1        /* source is physical disk */
99
#define        RND_TYPE_NET                2        /* source is a network device */
100
#define        RND_TYPE_TAPE                3        /* source is a tape drive */
101
#define        RND_TYPE_TTY                4        /* source is a tty device */
102
#define        RND_TYPE_RNG                5        /* source is a hardware RNG */
103
#define RND_TYPE_SKEW                6        /* source is skew between clocks */
104
#define RND_TYPE_ENV                7        /* source is temp or fan sensor */
105
#define RND_TYPE_VM                8        /* source is VM system events */
106
#define RND_TYPE_POWER                9        /* source is power events */
107
#define        RND_TYPE_MAX                9        /* last type id used */
108
109
#define        RND_MAXSTATCOUNT        10        /* 10 sources at once max */
110
111
/*
112
 * return "count" random entries, starting at "start"
113
 */
114
typedef struct {
115
        uint32_t        start;
116
        uint32_t        count;
117
        rndsource_t        source[RND_MAXSTATCOUNT];
118
} rndstat_t;
119
120
/*
121
 * return "count" random entries with estimates, starting at "start"
122
 */
123
typedef struct {
124
        uint32_t        start;
125
        uint32_t        count;
126
        rndsource_est_t        source[RND_MAXSTATCOUNT];
127
} rndstat_est_t;
128
129
/*
130
 * return information on a specific source by name
131
 */
132
typedef struct {
133
        char                name[16];
134
        rndsource_t        source;
135
} rndstat_name_t;
136
137
typedef struct {
138
        char                name[16];
139
        rndsource_est_t        source;
140
} rndstat_est_name_t;
141
142
143
/*
144
 * set/clear device flags.  If type is set to 0xff, the name is used
145
 * instead.  Otherwise, the flags set/cleared apply to all devices of
146
 * the specified type, and the name is ignored.
147
 */
148
typedef struct {
149
        char                name[16];        /* the name we are adjusting */
150
        uint32_t        type;                /* the type of device we want */
151
        uint32_t        flags;                /* flags to set or clear */
152
        uint32_t        mask;                /* mask for the flags we are setting */
153
} rndctl_t;
154
155
/*
156
 * Add entropy to the pool.  len is the data length, in bytes.
157
 * entropy is the number of bits of estimated entropy in the data.
158
 */
159
typedef struct {
160
        uint32_t        len;
161
        uint32_t        entropy;
162
        u_char                data[RND_SAVEWORDS * sizeof(uint32_t)];
163
} rnddata_t;
164
165
#define        RNDGETENTCNT        _IOR('R',  101, uint32_t) /* get entropy count */
166
#define        RNDGETSRCNUM        _IOWR('R', 102, rndstat_t) /* get rnd source info */
167
#define        RNDGETSRCNAME        _IOWR('R', 103, rndstat_name_t) /* get src by name */
168
#define        RNDCTL                _IOW('R',  104, rndctl_t)  /* set/clear source flags */
169
#define        RNDADDDATA        _IOW('R',  105, rnddata_t) /* add data to the pool */
170
#define        RNDGETPOOLSTAT        _IOR('R',  106, rndpoolstat_t) /* get statistics */
171
#define        RNDGETESTNUM        _IOWR('R', 107, rndstat_est_t) /* get srcest */
172
#define        RNDGETESTNAME        _IOWR('R', 108, rndstat_est_name_t) /* " by name */
173
174
#endif        /* _SYS_RNDIO_H */