entropy.h

Go to the documentation of this file.
00001 
00023 #ifndef MBEDTLS_ENTROPY_H
00024 #define MBEDTLS_ENTROPY_H
00025 
00026 #if !defined(MBEDTLS_CONFIG_FILE)
00027 #include "config.h"
00028 #else
00029 #include MBEDTLS_CONFIG_FILE
00030 #endif
00031 
00032 #include <stddef.h>
00033 
00034 #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256)
00035 #include "sha512.h"
00036 #define MBEDTLS_ENTROPY_SHA512_ACCUMULATOR
00037 #else
00038 #if defined(MBEDTLS_SHA256_C)
00039 #define MBEDTLS_ENTROPY_SHA256_ACCUMULATOR
00040 #include "sha256.h"
00041 #endif
00042 #endif
00043 
00044 #if defined(MBEDTLS_THREADING_C)
00045 #include "threading.h"
00046 #endif
00047 
00048 #if defined(MBEDTLS_HAVEGE_C)
00049 #include "havege.h"
00050 #endif
00051 
00052 #define MBEDTLS_ERR_ENTROPY_SOURCE_FAILED                 -0x003C  
00053 #define MBEDTLS_ERR_ENTROPY_MAX_SOURCES                   -0x003E  
00054 #define MBEDTLS_ERR_ENTROPY_NO_SOURCES_DEFINED            -0x0040  
00055 #define MBEDTLS_ERR_ENTROPY_NO_STRONG_SOURCE              -0x003D  
00056 #define MBEDTLS_ERR_ENTROPY_FILE_IO_ERROR                 -0x003F  
00066 #if !defined(MBEDTLS_ENTROPY_MAX_SOURCES)
00067 #define MBEDTLS_ENTROPY_MAX_SOURCES     20      
00068 #endif
00069 
00070 #if !defined(MBEDTLS_ENTROPY_MAX_GATHER)
00071 #define MBEDTLS_ENTROPY_MAX_GATHER      128     
00072 #endif
00073 
00074 /* \} name SECTION: Module settings */
00075 
00076 #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
00077 #define MBEDTLS_ENTROPY_BLOCK_SIZE      64      
00078 #else
00079 #define MBEDTLS_ENTROPY_BLOCK_SIZE      32      
00080 #endif
00081 
00082 #define MBEDTLS_ENTROPY_MAX_SEED_SIZE   1024    
00083 #define MBEDTLS_ENTROPY_SOURCE_MANUAL   MBEDTLS_ENTROPY_MAX_SOURCES
00084 
00085 #define MBEDTLS_ENTROPY_SOURCE_STRONG   1       
00086 #define MBEDTLS_ENTROPY_SOURCE_WEAK     0       
00088 #ifdef __cplusplus
00089 extern "C" {
00090 #endif
00091 
00103 typedef int (*mbedtls_entropy_f_source_ptr)(void *data, unsigned char *output, size_t len,
00104                             size_t *olen);
00105 
00109 typedef struct
00110 {
00111     mbedtls_entropy_f_source_ptr    f_source;   
00112     void *          p_source;   
00113     size_t          size;       
00114     size_t          threshold;  
00115     int             strong;     
00116 }
00117 mbedtls_entropy_source_state;
00118 
00122 typedef struct
00123 {
00124 #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
00125     mbedtls_sha512_context  accumulator;
00126 #else
00127     mbedtls_sha256_context  accumulator;
00128 #endif
00129     int             source_count;
00130     mbedtls_entropy_source_state    source[MBEDTLS_ENTROPY_MAX_SOURCES];
00131 #if defined(MBEDTLS_HAVEGE_C)
00132     mbedtls_havege_state    havege_data;
00133 #endif
00134 #if defined(MBEDTLS_THREADING_C)
00135     mbedtls_threading_mutex_t mutex;    
00136 #endif
00137 #if defined(MBEDTLS_ENTROPY_NV_SEED)
00138     int initial_entropy_run;
00139 #endif
00140 }
00141 mbedtls_entropy_context;
00142 
00148 void mbedtls_entropy_init( mbedtls_entropy_context *ctx );
00149 
00155 void mbedtls_entropy_free( mbedtls_entropy_context *ctx );
00156 
00174 int mbedtls_entropy_add_source( mbedtls_entropy_context *ctx,
00175                         mbedtls_entropy_f_source_ptr f_source, void *p_source,
00176                         size_t threshold, int strong );
00177 
00186 int mbedtls_entropy_gather( mbedtls_entropy_context *ctx );
00187 
00199 int mbedtls_entropy_func( void *data, unsigned char *output, size_t len );
00200 
00211 int mbedtls_entropy_update_manual( mbedtls_entropy_context *ctx,
00212                            const unsigned char *data, size_t len );
00213 
00214 #if defined(MBEDTLS_ENTROPY_NV_SEED)
00215 
00223 int mbedtls_entropy_update_nv_seed( mbedtls_entropy_context *ctx );
00224 #endif /* MBEDTLS_ENTROPY_NV_SEED */
00225 
00226 #if defined(MBEDTLS_FS_IO)
00227 
00237 int mbedtls_entropy_write_seed_file( mbedtls_entropy_context *ctx, const char *path );
00238 
00251 int mbedtls_entropy_update_seed_file( mbedtls_entropy_context *ctx, const char *path );
00252 #endif /* MBEDTLS_FS_IO */
00253 
00254 #if defined(MBEDTLS_SELF_TEST)
00255 
00263 int mbedtls_entropy_self_test( int verbose );
00264 
00265 #if defined(MBEDTLS_ENTROPY_HARDWARE_ALT)
00266 
00279 int mbedtls_entropy_source_self_test( int verbose );
00280 #endif /* MBEDTLS_ENTROPY_HARDWARE_ALT */
00281 #endif /* MBEDTLS_SELF_TEST */
00282 
00283 #ifdef __cplusplus
00284 }
00285 #endif
00286 
00287 #endif /* entropy.h */

Generated on 11 Mar 2017 for mbed TLS v2.4.2 by  doxygen 1.4.7