PolarSSL v1.1.4
entropy.h
Go to the documentation of this file.
00001 
00027 #ifndef POLARSSL_ENTROPY_H
00028 #define POLARSSL_ENTROPY_H
00029 
00030 #include <string.h>
00031 
00032 #include "config.h"
00033 
00034 #include "sha4.h"
00035 #if defined(POLARSSL_HAVEGE_C)
00036 #include "havege.h"
00037 #endif
00038 
00039 #define POLARSSL_ERR_ENTROPY_SOURCE_FAILED                 -0x003C  
00040 #define POLARSSL_ERR_ENTROPY_MAX_SOURCES                   -0x003E  
00041 #define POLARSSL_ERR_ENTROPY_NO_SOURCES_DEFINED            -0x0040  
00043 #define ENTROPY_MAX_SOURCES     20      
00044 #define ENTROPY_MAX_GATHER      128     
00045 #define ENTROPY_BLOCK_SIZE      64      
00047 #define ENTROPY_SOURCE_MANUAL   ENTROPY_MAX_SOURCES
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00064 typedef int (*f_source_ptr)(void *, unsigned char *, size_t, size_t *);
00065 
00069 typedef struct
00070 {
00071     f_source_ptr    f_source;   
00072     void *          p_source;   
00073     size_t          size;       
00074     size_t          threshold;  
00075 }
00076 source_state;
00077 
00081 typedef struct 
00082 {
00083     sha4_context    accumulator;
00084     int             source_count;
00085     source_state    source[ENTROPY_MAX_SOURCES];
00086 #if defined(POLARSSL_HAVEGE_C)
00087     havege_state    havege_data;
00088 #endif
00089 }
00090 entropy_context;
00091 
00097 void entropy_init( entropy_context *ctx );
00098 
00110 int entropy_add_source( entropy_context *ctx,
00111                         f_source_ptr f_source, void *p_source,
00112                         size_t threshold );
00113 
00121 int entropy_gather( entropy_context *ctx );
00122 
00132 int entropy_func( void *data, unsigned char *output, size_t len );
00133 
00143 int entropy_update_manual( entropy_context *ctx,
00144                            const unsigned char *data, size_t len );
00145 
00146 #ifdef __cplusplus
00147 }
00148 #endif
00149 
00150 #endif /* entropy.h */