Change header file guard names.
[u/mdw/catacomb] / noise.h
1 /* -*-c-*-
2 *
3 * $Id: noise.h,v 1.2 1999/12/10 23:29:48 mdw Exp $
4 *
5 * Acquisition of environmental noise (Unix specific)
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 $
33 * Revision 1.2 1999/12/10 23:29:48 mdw
34 * Change header file guard names.
35 *
36 * Revision 1.1 1999/09/03 08:41:12 mdw
37 * Initial import.
38 *
39 */
40
41 #ifndef CATACOMB_NOISE_H
42 #define CATACOMB_NOISE_H
43
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47
48 /*----- Header files ------------------------------------------------------*/
49
50 #include <sys/types.h>
51
52 #ifndef CATACOMB_RAND_H
53 # include "rand.h"
54 #endif
55
56 /*----- Noise source definition -------------------------------------------*/
57
58 extern rand_source noise_source;
59
60 /*----- Magic numbers -----------------------------------------------------*/
61
62 #define NOISE_NOSETUID ((uid_t)-1)
63 #define NOISE_NOSETGID ((gid_t)-1)
64
65 /*----- Functions provided ------------------------------------------------*/
66
67 /* --- @noise_timer@ --- *
68 *
69 * Arguments: @rand_pool *r@ = pointer to a randomness pool
70 *
71 * Returns: Nonzero if some randomness was contributed.
72 *
73 * Use: Contributes the current time to the randomness pool.
74 * A guess at the number of useful bits contributed is made,
75 * based on first and second order bit differences. This isn't
76 * ever-so reliable, but it's better than nothing.
77 */
78
79 extern int noise_timer(rand_pool */*r*/);
80
81 /* --- @noise_devrandom@ --- *
82 *
83 * Arguments: @rand_pool *r@ = pointer to a randomness pool
84 *
85 * Returns: Nonzero if some randomness was contributed.
86 *
87 * Use: Attempts to obtain some randomness from the system entropy
88 * pool. All bits from the device are assumed to be good.
89 */
90
91 extern int noise_devrandom(rand_pool */*r*/);
92
93 /* --- @noise_setid@ --- *
94 *
95 * Arguments: @uid_t uid@ = uid to set
96 * @gid_t gid@ = gid to set
97 *
98 * Returns: ---
99 *
100 * Use: Sets the user and group ids to be used by @noise_filter@
101 * when running child processes. This is useful to avoid
102 * giving shell commands (even carefully written ones) undue
103 * privileges.
104 */
105
106 extern void noise_setid(uid_t /*uid*/, gid_t /*gid*/);
107
108 /* --- @noise_filter@ --- *
109 *
110 * Arguments: @rand_pool *r@ = pointer to a randomness pool
111 * @int good@ = number of good bits per 1024 bits
112 * @const char *c@ = shell command to run
113 *
114 * Returns: Nonzero if some randomness was contributed.
115 *
116 * Use: Attempts to execute a shell command, and dump it into the
117 * randomness pool. A very rough estimate of the number of
118 * good bits is made, based on the size of the command's output.
119 * This function calls @waitpid@, so be careful. Before execing
120 * the command, the process uid and gid are set to the values
121 * given to @noise_setid@, and an attempt is made to reset the
122 * list of supplementary groups. The environment passed to
123 * the command has been severly lobotimized. If the command
124 * fails to complete within a short time period, it is killed.
125 * Paranoid use of close-on-exec flags for file descriptors is
126 * recommended.
127 */
128
129 extern int noise_filter(rand_pool */*r*/, int /*good*/, const char */*c*/);
130
131 /* --- @noise_acquire@ --- *
132 *
133 * Arguments: @rand_pool *r@ = pointer to a randomness pool
134 *
135 * Returns: ---
136 *
137 * Use: Acquires some randomness from somewhere.
138 */
139
140 extern void noise_acquire(rand_pool */*r*/);
141
142 /*----- That's all, folks -------------------------------------------------*/
143
144 #ifdef __cplusplus
145 }
146 #endif
147
148 #endif