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