hmac_drbg.h

Go to the documentation of this file.
00001 
00023 #ifndef MBEDTLS_HMAC_DRBG_H
00024 #define MBEDTLS_HMAC_DRBG_H
00025 
00026 #include "md.h"
00027 
00028 #if defined(MBEDTLS_THREADING_C)
00029 #include "mbedtls/threading.h"
00030 #endif
00031 
00032 /*
00033  * Error codes
00034  */
00035 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG              -0x0003  
00036 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG                -0x0005  
00037 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR                -0x0007  
00038 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED        -0x0009  
00048 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
00049 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL   10000   
00050 #endif
00051 
00052 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
00053 #define MBEDTLS_HMAC_DRBG_MAX_INPUT         256     
00054 #endif
00055 
00056 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
00057 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST       1024    
00058 #endif
00059 
00060 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
00061 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT    384     
00062 #endif
00063 
00064 /* \} name SECTION: Module settings */
00065 
00066 #define MBEDTLS_HMAC_DRBG_PR_OFF   0   
00067 #define MBEDTLS_HMAC_DRBG_PR_ON    1   
00069 #ifdef __cplusplus
00070 extern "C" {
00071 #endif
00072 
00076 typedef struct
00077 {
00078     /* Working state: the key K is not stored explicitely,
00079      * but is implied by the HMAC context */
00080     mbedtls_md_context_t md_ctx;                    
00081     unsigned char V[MBEDTLS_MD_MAX_SIZE];  
00082     int reseed_counter;                     
00084     /* Administrative state */
00085     size_t entropy_len;         
00086     int prediction_resistance;  
00088     int reseed_interval;        
00090     /* Callbacks */
00091     int (*f_entropy)(void *, unsigned char *, size_t); 
00092     void *p_entropy;            
00094 #if defined(MBEDTLS_THREADING_C)
00095     mbedtls_threading_mutex_t mutex;
00096 #endif
00097 } mbedtls_hmac_drbg_context;
00098 
00107 void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
00108 
00133 int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
00134                     const mbedtls_md_info_t * md_info,
00135                     int (*f_entropy)(void *, unsigned char *, size_t),
00136                     void *p_entropy,
00137                     const unsigned char *custom,
00138                     size_t len );
00139 
00153 int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
00154                         const mbedtls_md_info_t * md_info,
00155                         const unsigned char *data, size_t data_len );
00156 
00166 void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
00167                                           int resistance );
00168 
00177 void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
00178                                 size_t len );
00179 
00187 void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
00188                                     int interval );
00189 
00200 void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
00201                        const unsigned char *additional, size_t add_len );
00202 
00213 int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
00214                       const unsigned char *additional, size_t len );
00215 
00232 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
00233                                unsigned char *output, size_t output_len,
00234                                const unsigned char *additional,
00235                                size_t add_len );
00236 
00250 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
00251 
00257 void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
00258 
00259 #if defined(MBEDTLS_FS_IO)
00260 
00269 int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00270 
00282 int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00283 #endif /* MBEDTLS_FS_IO */
00284 
00285 
00286 #if defined(MBEDTLS_SELF_TEST)
00287 
00292 int mbedtls_hmac_drbg_self_test( int verbose );
00293 #endif
00294 
00295 #ifdef __cplusplus
00296 }
00297 #endif
00298 
00299 #endif /* hmac_drbg.h */

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