chiark / gitweb /
New source file added to maintain a randomness pool.
[become] / src / rand.h
1 /* -*-c-*-
2  *
3  * $Id: rand.h,v 1.1 1997/08/07 09:46:05 mdw Exp $
4  *
5  * Random number generation
6  *
7  * (c) 1997 EBI
8  */
9
10 /*----- Licencing notice --------------------------------------------------*
11  *
12  * This file is part of Become.
13  *
14  * Become is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * Become 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 General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with Become; if not, write to the Free Software
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  */
28
29 /*----- Revision history --------------------------------------------------*
30  *
31  * $Log: rand.h,v $
32  * Revision 1.1  1997/08/07 09:46:05  mdw
33  * New source file added to maintain a randomness pool.
34  *
35  */
36
37 #ifndef RAND_H
38 #define RAND_H
39
40 #ifdef __cplusplus
41   extern "C" {
42 #endif
43
44 /*----- Required headers --------------------------------------------------*/
45
46 #include <stdio.h>
47
48 #ifndef ICRYPT_H
49 #  include "icrypt.h"
50 #endif
51
52 /*----- Functions provided ------------------------------------------------*/
53
54 /* --- @rand_read@ --- *
55  *
56  * Arguments:   @FILE *fp@ = pointer to file to read from
57  *
58  * Returns:     ---
59  *
60  * Use:         Reads a random number seed from the stream.
61  */
62
63 extern void rand_read(FILE */*fp*/);
64
65 /* --- @rand_write@ --- *
66  *
67  * Arguments:   @FILE *fp@ = pointer to file to write on
68  *
69  * Returns:     ---
70  *
71  * Use:         Writes a random number seed back to the stream.
72  */
73
74 extern void rand_write(FILE */*fp*/);
75
76 /* --- @rand_clear@ --- *
77  *
78  * Arguments:   ---
79  *
80  * Returns:     ---
81  *
82  * Use:         Clears the random number pool.
83  */
84
85 extern void rand_clear(void);
86
87 /* --- @rand_encrypt@ --- *
88  *
89  * Arguments:   @icrypt_job *j@ = pointer to an encryption job to apply
90  *
91  * Returns:     ---
92  *
93  * Use:         Encrypts the randomness pool with a given key.  This should
94  *              be done before use, in case the pool gets compromised.
95  */
96
97 extern void rand_encrypt(icrypt_job */*j*/);
98
99 /* --- @rand_add@ --- *
100  *
101  * Arguments:   @const void *p@ = pointer to some data
102  *              @size_t sz@ = size of the data in bytes
103  *
104  * Returns:     ---
105  *
106  * Use:         Adds entropy to the pool.
107  */
108
109 extern void rand_add(const void */*p*/, size_t /*sz*/);
110
111 /* --- @rand_extract@ --- *
112  *
113  * Arguments:   @unsigned char *b@ = pointer to output buffer
114  *              @size_t sz@ = number of bytes wanted
115  *
116  * Returns:     ---
117  *
118  * Use:         Produces a number of random bytes.
119  */
120
121 extern void rand_extract(unsigned char */*b*/, size_t /*sz*/);
122
123 /* --- @rand_churn@ --- *
124  *
125  * Arguments:   ---
126  *
127  * Returns:     ---
128  *
129  * Use:         Churns the randomness pool completely.  The pool is replaced
130  *              by repeated MD5-ings of itself.
131  */
132
133 extern void rand_churn(void);
134
135 /*----- That's all, folks -------------------------------------------------*/
136
137 #ifdef __cplusplus
138   }
139 #endif
140
141 #endif