d03ab969 |
1 | /* -*-c-*- |
2 | * |
4e66da02 |
3 | * $Id: noise.h,v 1.5 2004/04/02 01:03:49 mdw Exp $ |
d03ab969 |
4 | * |
099355bc |
5 | * Acquisition of environmental noise (Unix-specific) |
d03ab969 |
6 | * |
7 | * (c) 1998 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: noise.h,v $ |
4e66da02 |
33 | * Revision 1.5 2004/04/02 01:03:49 mdw |
34 | * Miscellaneous constification. |
35 | * |
25f654a7 |
36 | * Revision 1.4 2000/06/17 12:57:47 mdw |
37 | * New free counter noise generator, for use if /dev/random is |
38 | * unavailable. |
39 | * |
099355bc |
40 | * Revision 1.3 1999/12/22 15:57:55 mdw |
41 | * Label system-specific parts more clearly. |
42 | * |
b3f05084 |
43 | * Revision 1.2 1999/12/10 23:29:48 mdw |
44 | * Change header file guard names. |
45 | * |
d03ab969 |
46 | * Revision 1.1 1999/09/03 08:41:12 mdw |
47 | * Initial import. |
48 | * |
49 | */ |
50 | |
b3f05084 |
51 | #ifndef CATACOMB_NOISE_H |
52 | #define CATACOMB_NOISE_H |
d03ab969 |
53 | |
54 | #ifdef __cplusplus |
55 | extern "C" { |
56 | #endif |
57 | |
58 | /*----- Header files ------------------------------------------------------*/ |
59 | |
60 | #include <sys/types.h> |
61 | |
b3f05084 |
62 | #ifndef CATACOMB_RAND_H |
d03ab969 |
63 | # include "rand.h" |
64 | #endif |
65 | |
66 | /*----- Noise source definition -------------------------------------------*/ |
67 | |
4e66da02 |
68 | extern const rand_source noise_source; |
d03ab969 |
69 | |
70 | /*----- Magic numbers -----------------------------------------------------*/ |
71 | |
72 | #define NOISE_NOSETUID ((uid_t)-1) |
73 | #define NOISE_NOSETGID ((gid_t)-1) |
74 | |
75 | /*----- Functions provided ------------------------------------------------*/ |
76 | |
77 | /* --- @noise_timer@ --- * |
78 | * |
79 | * Arguments: @rand_pool *r@ = pointer to a randomness pool |
80 | * |
81 | * Returns: Nonzero if some randomness was contributed. |
82 | * |
83 | * Use: Contributes the current time to the randomness pool. |
84 | * A guess at the number of useful bits contributed is made, |
85 | * based on first and second order bit differences. This isn't |
86 | * ever-so reliable, but it's better than nothing. |
87 | */ |
88 | |
89 | extern int noise_timer(rand_pool */*r*/); |
90 | |
91 | /* --- @noise_devrandom@ --- * |
92 | * |
93 | * Arguments: @rand_pool *r@ = pointer to a randomness pool |
94 | * |
95 | * Returns: Nonzero if some randomness was contributed. |
96 | * |
97 | * Use: Attempts to obtain some randomness from the system entropy |
98 | * pool. All bits from the device are assumed to be good. |
99 | */ |
100 | |
101 | extern int noise_devrandom(rand_pool */*r*/); |
102 | |
103 | /* --- @noise_setid@ --- * |
104 | * |
105 | * Arguments: @uid_t uid@ = uid to set |
106 | * @gid_t gid@ = gid to set |
107 | * |
108 | * Returns: --- |
109 | * |
110 | * Use: Sets the user and group ids to be used by @noise_filter@ |
111 | * when running child processes. This is useful to avoid |
112 | * giving shell commands (even carefully written ones) undue |
099355bc |
113 | * privileges. This interface is Unix-specific. |
d03ab969 |
114 | */ |
115 | |
116 | extern void noise_setid(uid_t /*uid*/, gid_t /*gid*/); |
117 | |
118 | /* --- @noise_filter@ --- * |
119 | * |
120 | * Arguments: @rand_pool *r@ = pointer to a randomness pool |
121 | * @int good@ = number of good bits per 1024 bits |
122 | * @const char *c@ = shell command to run |
123 | * |
124 | * Returns: Nonzero if some randomness was contributed. |
125 | * |
126 | * Use: Attempts to execute a shell command, and dump it into the |
127 | * randomness pool. A very rough estimate of the number of |
128 | * good bits is made, based on the size of the command's output. |
129 | * This function calls @waitpid@, so be careful. Before execing |
130 | * the command, the process uid and gid are set to the values |
131 | * given to @noise_setid@, and an attempt is made to reset the |
132 | * list of supplementary groups. The environment passed to |
133 | * the command has been severly lobotimized. If the command |
134 | * fails to complete within a short time period, it is killed. |
135 | * Paranoid use of close-on-exec flags for file descriptors is |
136 | * recommended. |
099355bc |
137 | * |
138 | * This interface is Unix-specific. |
d03ab969 |
139 | */ |
140 | |
141 | extern int noise_filter(rand_pool */*r*/, int /*good*/, const char */*c*/); |
142 | |
25f654a7 |
143 | /* --- @noise_freewheel@ --- * |
144 | * |
145 | * Arguments: @rand_pool *r@ = pointer to a randomness pool |
146 | * |
147 | * Returns: Nonzero if some randomness was contributed. |
148 | * |
149 | * Use: Runs a free counter for a short while as a desparate attempt |
150 | * to get randomness from somewhere. This is actually quite |
151 | * effective. |
152 | */ |
153 | |
154 | int noise_freewheel(rand_pool */*r*/); |
155 | |
156 | /* --- @noise_enquire@ --- * |
157 | * |
158 | * Arguments: @rand_pool *r@ = pointer to a randomness pool |
159 | * |
160 | * Returns: Nonzero if some randomness was contributed. |
161 | * |
162 | * Use: Runs some shell commands to enquire about the prevailing |
163 | * environment. This can gather quite a lot of low-quality |
164 | * entropy. |
165 | */ |
166 | |
167 | extern int noise_enquire(rand_pool */*r*/); |
168 | |
d03ab969 |
169 | /* --- @noise_acquire@ --- * |
170 | * |
171 | * Arguments: @rand_pool *r@ = pointer to a randomness pool |
172 | * |
173 | * Returns: --- |
174 | * |
175 | * Use: Acquires some randomness from somewhere. |
176 | */ |
177 | |
178 | extern void noise_acquire(rand_pool */*r*/); |
179 | |
180 | /*----- That's all, folks -------------------------------------------------*/ |
181 | |
182 | #ifdef __cplusplus |
183 | } |
184 | #endif |
185 | |
186 | #endif |