PolarSSL v1.3.8
entropy.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_ENTROPY_H
28 #define POLARSSL_ENTROPY_H
29 
30 #include <string.h>
31 
32 #if !defined(POLARSSL_CONFIG_FILE)
33 #include "config.h"
34 #else
35 #include POLARSSL_CONFIG_FILE
36 #endif
37 
38 #if defined(POLARSSL_SHA512_C) && !defined(POLARSSL_ENTROPY_FORCE_SHA256)
39 #include "sha512.h"
40 #define POLARSSL_ENTROPY_SHA512_ACCUMULATOR
41 #else
42 #if defined(POLARSSL_SHA256_C)
43 #define POLARSSL_ENTROPY_SHA256_ACCUMULATOR
44 #include "sha256.h"
45 #endif
46 #endif
47 
48 #if defined(POLARSSL_THREADING_C)
49 #include "threading.h"
50 #endif
51 
52 #if defined(POLARSSL_HAVEGE_C)
53 #include "havege.h"
54 #endif
55 
56 #define POLARSSL_ERR_ENTROPY_SOURCE_FAILED -0x003C
57 #define POLARSSL_ERR_ENTROPY_MAX_SOURCES -0x003E
58 #define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040
59 #define POLARSSL_ERR_ENTROPY_FILE_IO_ERROR -0x0058
69 #if !defined(ENTROPY_MAX_SOURCES)
70 #define ENTROPY_MAX_SOURCES 20
71 #endif
72 
73 #if !defined(ENTROPY_MAX_GATHER)
74 #define ENTROPY_MAX_GATHER 128
75 #endif
76 
77 /* \} name SECTION: Module settings */
78 
79 #if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
80 #define ENTROPY_BLOCK_SIZE 64
81 #else
82 #define ENTROPY_BLOCK_SIZE 32
83 #endif
84 
85 #define ENTROPY_MAX_SEED_SIZE 1024
86 #define ENTROPY_SOURCE_MANUAL ENTROPY_MAX_SOURCES
87 
88 #ifdef __cplusplus
89 extern "C" {
90 #endif
91 
103 typedef int (*f_source_ptr)(void *data, unsigned char *output, size_t len,
104  size_t *olen);
105 
109 typedef struct
110 {
112  void * p_source;
113  size_t size;
114  size_t threshold;
115 }
117 
121 typedef struct
122 {
123 #if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
125 #else
126  sha256_context accumulator;
127 #endif
130 #if defined(POLARSSL_HAVEGE_C)
131  havege_state havege_data;
132 #endif
133 #if defined(POLARSSL_THREADING_C)
134  threading_mutex_t mutex;
135 #endif
136 }
138 
144 void entropy_init( entropy_context *ctx );
145 
151 void entropy_free( entropy_context *ctx );
152 
166  f_source_ptr f_source, void *p_source,
167  size_t threshold );
168 
177 int entropy_gather( entropy_context *ctx );
178 
190 int entropy_func( void *data, unsigned char *output, size_t len );
191 
203  const unsigned char *data, size_t len );
204 
205 #if defined(POLARSSL_FS_IO)
206 
216 int entropy_write_seed_file( entropy_context *ctx, const char *path );
217 
230 int entropy_update_seed_file( entropy_context *ctx, const char *path );
231 #endif /* POLARSSL_FS_IO */
232 
233 #if defined(POLARSSL_SELF_TEST)
234 
239 int entropy_self_test( int verbose );
240 #endif /* POLARSSL_SELF_TEST */
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 
246 #endif /* entropy.h */