1/* rand-internal.h - header to glue the random functions
2 *	Copyright (C) 1998, 2002 Free Software Foundation, Inc.
3 *
4 * This file is part of Libgcrypt.
5 *
6 * Libgcrypt is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser general Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
10 *
11 * Libgcrypt is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef G10_RAND_INTERNAL_H
21#define G10_RAND_INTERNAL_H
22
23#include "../src/cipher-proto.h"
24
25/* Constants used to define the origin of random added to the pool.
26   The code is sensitive to the order of the values.  */
27enum random_origins
28  {
29    RANDOM_ORIGIN_INIT = 0,      /* Used only for initialization. */
30    RANDOM_ORIGIN_EXTERNAL = 1,  /* Added from an external source.  */
31    RANDOM_ORIGIN_FASTPOLL = 2,  /* Fast random poll function.  */
32    RANDOM_ORIGIN_SLOWPOLL = 3,  /* Slow poll function.  */
33    RANDOM_ORIGIN_EXTRAPOLL = 4  /* Used to mark an extra pool seed
34                                    due to a GCRY_VERY_STRONG_RANDOM
35                                    random request.  */
36  };
37
38
39
40/*-- random.c --*/
41void _gcry_random_progress (const char *what, int printchar,
42                            int current, int total);
43
44
45/*-- random-csprng.c --*/
46void _gcry_rngcsprng_initialize (int full);
47void _gcry_rngcsprng_dump_stats (void);
48void _gcry_rngcsprng_secure_alloc (void);
49void _gcry_rngcsprng_enable_quick_gen (void);
50void _gcry_rngcsprng_set_daemon_socket (const char *socketname);
51int  _gcry_rngcsprng_use_daemon (int onoff);
52int  _gcry_rngcsprng_is_faked (void);
53gcry_error_t _gcry_rngcsprng_add_bytes (const void *buf, size_t buflen,
54                                        int quality);
55void *_gcry_rngcsprng_get_bytes (size_t nbytes,
56                                 enum gcry_random_level level);
57void *_gcry_rngcsprng_get_bytes_secure (size_t nbytes,
58                                        enum gcry_random_level level);
59void _gcry_rngcsprng_randomize (void *buffer, size_t length,
60                                enum gcry_random_level level);
61void _gcry_rngcsprng_set_seed_file (const char *name);
62void _gcry_rngcsprng_update_seed_file (void);
63void _gcry_rngcsprng_fast_poll (void);
64void _gcry_rngcsprng_create_nonce (void *buffer, size_t length);
65
66/*-- random-rngcsprng.c --*/
67void _gcry_rngfips_initialize (int full);
68void _gcry_rngfips_dump_stats (void);
69int  _gcry_rngfips_is_faked (void);
70gcry_error_t _gcry_rngfips_add_bytes (const void *buf, size_t buflen,
71                                        int quality);
72void *_gcry_rngfips_get_bytes (size_t nbytes,
73                               enum gcry_random_level level);
74void *_gcry_rngfips_get_bytes_secure (size_t nbytes,
75                                      enum gcry_random_level level);
76void _gcry_rngfips_randomize (void *buffer, size_t length,
77                                enum gcry_random_level level);
78void _gcry_rngfips_create_nonce (void *buffer, size_t length);
79
80gcry_error_t _gcry_rngfips_selftest (selftest_report_func_t report);
81
82gcry_err_code_t _gcry_rngfips_init_external_test (void **r_context,
83                                                  unsigned int flags,
84                                                  const void *key,
85                                                  size_t keylen,
86                                                  const void *seed,
87                                                  size_t seedlen,
88                                                  const void *dt,
89                                                  size_t dtlen);
90gcry_err_code_t _gcry_rngfips_run_external_test (void *context,
91                                                 char *buffer, size_t buflen);
92void _gcry_rngfips_deinit_external_test (void *context);
93
94
95
96
97
98/*-- rndlinux.c --*/
99int _gcry_rndlinux_gather_random (void (*add) (const void *, size_t,
100                                               enum random_origins),
101                                   enum random_origins origin,
102                                  size_t length, int level);
103
104/*-- rndunix.c --*/
105int _gcry_rndunix_gather_random (void (*add) (const void *, size_t,
106                                              enum random_origins),
107                                 enum random_origins origin,
108                                 size_t length, int level);
109
110/*-- rndelg.c --*/
111int _gcry_rndegd_gather_random (void (*add) (const void *, size_t,
112                                             enum random_origins),
113                                enum random_origins origin,
114                                size_t length, int level);
115int _gcry_rndegd_connect_socket (int nofail);
116
117/*-- rndw32.c --*/
118int _gcry_rndw32_gather_random (void (*add) (const void *, size_t,
119                                             enum random_origins),
120                                enum random_origins origin,
121                                size_t length, int level);
122void _gcry_rndw32_gather_random_fast (void (*add)(const void*, size_t,
123                                                  enum random_origins),
124                                      enum random_origins origin );
125
126/*-- rndw32ce.c --*/
127int _gcry_rndw32ce_gather_random (void (*add) (const void *, size_t,
128                                               enum random_origins),
129                                  enum random_origins origin,
130                                  size_t length, int level);
131void _gcry_rndw32ce_gather_random_fast (void (*add)(const void*, size_t,
132                                                    enum random_origins),
133                                        enum random_origins origin );
134
135/*-- rndhw.c --*/
136int _gcry_rndhw_failed_p (void);
137void _gcry_rndhw_poll_fast (void (*add)(const void*, size_t,
138                                        enum random_origins),
139                            enum random_origins origin);
140size_t _gcry_rndhw_poll_slow (void (*add)(const void*, size_t,
141                                          enum random_origins),
142                              enum random_origins origin);
143
144
145
146#endif /*G10_RAND_INTERNAL_H*/
147