PolarSSL v1.3.1
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 #include "config.h"
33 
34 #if defined(POLARSSL_SHA512_C)
35 #include "sha512.h"
36 #define POLARSSL_ENTROPY_SHA512_ACCUMULATOR
37 #else
38 #if defined(POLARSSL_SHA256_C)
39 #define POLARSSL_ENTROPY_SHA256_ACCUMULATOR
40 #include "sha256.h"
41 #endif
42 #endif
43 
44 #if defined(POLARSSL_THREADING_C)
45 #include "threading.h"
46 #endif
47 
48 #if defined(POLARSSL_HAVEGE_C)
49 #include "havege.h"
50 #endif
51 
52 #define POLARSSL_ERR_ENTROPY_SOURCE_FAILED -0x003C
53 #define POLARSSL_ERR_ENTROPY_MAX_SOURCES -0x003E
54 #define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040
56 #if !defined(POLARSSL_CONFIG_OPTIONS)
57 #define ENTROPY_MAX_SOURCES 20
58 #define ENTROPY_MAX_GATHER 128
59 #endif /* !POLARSSL_CONFIG_OPTIONS */
60 
61 #if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
62 #define ENTROPY_BLOCK_SIZE 64
63 #else
64 #define ENTROPY_BLOCK_SIZE 32
65 #endif
66 
67 #define ENTROPY_SOURCE_MANUAL ENTROPY_MAX_SOURCES
68 
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
84 typedef int (*f_source_ptr)(void *, unsigned char *, size_t, size_t *);
85 
89 typedef struct
90 {
92  void * p_source;
93  size_t size;
94  size_t threshold;
95 }
97 
101 typedef struct
102 {
103 #if defined(POLARSSL_ENTROPY_SHA512_ACCUMULATOR)
105 #else
106  sha256_context accumulator;
107 #endif
110 #if defined(POLARSSL_HAVEGE_C)
111  havege_state havege_data;
112 #endif
113 #if defined(POLARSSL_THREADING_C)
114  threading_mutex_t mutex;
115 #endif
116 }
118 
124 void entropy_init( entropy_context *ctx );
125 
131 void entropy_free( entropy_context *ctx );
132 
145  f_source_ptr f_source, void *p_source,
146  size_t threshold );
147 
155 int entropy_gather( entropy_context *ctx );
156 
167 int entropy_func( void *data, unsigned char *output, size_t len );
168 
179  const unsigned char *data, size_t len );
180 
181 #ifdef __cplusplus
182 }
183 #endif
184 
185 #endif /* entropy.h */