PolarSSL v1.2.10
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
43 #if !defined(POLARSSL_CONFIG_OPTIONS)
44 #define ENTROPY_MAX_SOURCES 20
45 #define ENTROPY_MAX_GATHER 128
46 #endif /* !POLARSSL_CONFIG_OPTIONS */
47 
48 #define ENTROPY_BLOCK_SIZE 64
50 #define ENTROPY_SOURCE_MANUAL ENTROPY_MAX_SOURCES
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
67 typedef int (*f_source_ptr)(void *, unsigned char *, size_t, size_t *);
68 
72 typedef struct
73 {
75  void * p_source;
76  size_t size;
77  size_t threshold;
78 }
80 
84 typedef struct
85 {
89 #if defined(POLARSSL_HAVEGE_C)
90  havege_state havege_data;
91 #endif
92 }
94 
100 void entropy_init( entropy_context *ctx );
101 
114  f_source_ptr f_source, void *p_source,
115  size_t threshold );
116 
124 int entropy_gather( entropy_context *ctx );
125 
135 int entropy_func( void *data, unsigned char *output, size_t len );
136 
147  const unsigned char *data, size_t len );
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #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:84
int source_count
Definition: entropy.h:87
void * p_source
The callback data pointer.
Definition: entropy.h:75
Entropy source state.
Definition: entropy.h:72
SHA-384 and SHA-512 cryptographic hash function.
size_t size
Amount received.
Definition: entropy.h:76
f_source_ptr f_source
The entropy source callback.
Definition: entropy.h:74
HAVEGE state structure.
Definition: havege.h:37
HAVEGE: HArdware Volatile Entropy Gathering and Expansion.
sha4_context accumulator
Definition: entropy.h:86
#define ENTROPY_MAX_SOURCES
Maximum number of sources supported.
Definition: entropy.h:44
size_t threshold
Minimum level required before release.
Definition: entropy.h:77
SHA-512 context structure.
Definition: sha4.h:51
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:67
int entropy_func(void *data, unsigned char *output, size_t len)
Retrieve entropy from the accumulator (Max ENTROPY_BLOCK_SIZE)