PolarSSL v1.2.11
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 #include "sha4.h"
35 #if defined(POLARSSL_HAVEGE_C)
36 #include "havege.h"
37 #endif
38 
39 #define POLARSSL_ERR_ENTROPY_SOURCE_FAILED -0x003C
40 #define POLARSSL_ERR_ENTROPY_MAX_SOURCES -0x003E
41 #define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED -0x0040
42 #define POLARSSL_ERR_ENTROPY_FILE_IO_ERROR -0x0058
44 #if !defined(POLARSSL_CONFIG_OPTIONS)
45 #define ENTROPY_MAX_SOURCES 20
46 #define ENTROPY_MAX_GATHER 128
47 #endif /* !POLARSSL_CONFIG_OPTIONS */
48 
49 #define ENTROPY_BLOCK_SIZE 64
51 #define ENTROPY_MAX_SEED_SIZE 1024
52 #define ENTROPY_SOURCE_MANUAL ENTROPY_MAX_SOURCES
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
69 typedef int (*f_source_ptr)(void *, unsigned char *, size_t, size_t *);
70 
74 typedef struct
75 {
77  void * p_source;
78  size_t size;
79  size_t threshold;
80 }
82 
86 typedef struct
87 {
91 #if defined(POLARSSL_HAVEGE_C)
92  havege_state havege_data;
93 #endif
94 }
96 
102 void entropy_init( entropy_context *ctx );
103 
116  f_source_ptr f_source, void *p_source,
117  size_t threshold );
118 
126 int entropy_gather( entropy_context *ctx );
127 
137 int entropy_func( void *data, unsigned char *output, size_t len );
138 
149  const unsigned char *data, size_t len );
150 
151 #if defined(POLARSSL_FS_IO)
152 
162 int entropy_write_seed_file( entropy_context *ctx, const char *path );
163 
176 int entropy_update_seed_file( entropy_context *ctx, const char *path );
177 #endif
178 
179 #ifdef __cplusplus
180 }
181 #endif
182 
183 #endif /* entropy.h */
int entropy_add_source(entropy_context *ctx, f_source_ptr f_source, void *p_source, size_t threshold)
Adds an entropy source to poll.
int entropy_update_manual(entropy_context *ctx, const unsigned char *data, size_t len)
Add data to the accumulator manually.
Configuration options (set of defines)
int entropy_gather(entropy_context *ctx)
Trigger an extra gather poll for the accumulator.
Entropy context structure.
Definition: entropy.h:86
int source_count
Definition: entropy.h:89
void * p_source
The callback data pointer.
Definition: entropy.h:77
Entropy source state.
Definition: entropy.h:74
int entropy_write_seed_file(entropy_context *ctx, const char *path)
Write a seed file.
SHA-384 and SHA-512 cryptographic hash function.
size_t size
Amount received.
Definition: entropy.h:78
f_source_ptr f_source
The entropy source callback.
Definition: entropy.h:76
HAVEGE state structure.
Definition: havege.h:37
HAVEGE: HArdware Volatile Entropy Gathering and Expansion.
sha4_context accumulator
Definition: entropy.h:88
#define ENTROPY_MAX_SOURCES
Maximum number of sources supported.
Definition: entropy.h:45
size_t threshold
Minimum level required before release.
Definition: entropy.h:79
SHA-512 context structure.
Definition: sha4.h:51
int entropy_update_seed_file(entropy_context *ctx, const char *path)
Read and update a seed file.
void entropy_init(entropy_context *ctx)
Initialize the context.
int(* f_source_ptr)(void *, unsigned char *, size_t, size_t *)
Entropy poll callback pointer.
Definition: entropy.h:69
int entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Max ENTROPY_BLOCK_SIZE)