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