00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef MBEDTLS_HMAC_DRBG_H
00025 #define MBEDTLS_HMAC_DRBG_H
00026
00027 #if !defined(MBEDTLS_CONFIG_FILE)
00028 #include "config.h"
00029 #else
00030 #include MBEDTLS_CONFIG_FILE
00031 #endif
00032
00033 #include "md.h"
00034
00035 #if defined(MBEDTLS_THREADING_C)
00036 #include "threading.h"
00037 #endif
00038
00039
00040
00041
00042 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
00043 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
00044 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
00045 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
00055 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
00056 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
00057 #endif
00058
00059 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
00060 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
00061 #endif
00062
00063 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
00064 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
00065 #endif
00066
00067 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
00068 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
00069 #endif
00070
00071
00072
00073 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
00074 #define MBEDTLS_HMAC_DRBG_PR_ON 1
00076 #ifdef __cplusplus
00077 extern "C" {
00078 #endif
00079
00083 typedef struct
00084 {
00085
00086
00087 mbedtls_md_context_t md_ctx;
00088 unsigned char V[MBEDTLS_MD_MAX_SIZE];
00089 int reseed_counter;
00091
00092 size_t entropy_len;
00093 int prediction_resistance;
00095 int reseed_interval;
00097
00098 int (*f_entropy)(void *, unsigned char *, size_t);
00099 void *p_entropy;
00101 #if defined(MBEDTLS_THREADING_C)
00102 mbedtls_threading_mutex_t mutex;
00103 #endif
00104 } mbedtls_hmac_drbg_context;
00105
00114 void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
00115
00140 int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
00141 const mbedtls_md_info_t * md_info,
00142 int (*f_entropy)(void *, unsigned char *, size_t),
00143 void *p_entropy,
00144 const unsigned char *custom,
00145 size_t len );
00146
00160 int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
00161 const mbedtls_md_info_t * md_info,
00162 const unsigned char *data, size_t data_len );
00163
00173 void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
00174 int resistance );
00175
00184 void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
00185 size_t len );
00186
00194 void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
00195 int interval );
00196
00210 int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
00211 const unsigned char *additional, size_t add_len );
00212
00226 void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
00227 const unsigned char *additional,
00228 size_t add_len );
00229
00240 int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
00241 const unsigned char *additional, size_t len );
00242
00259 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
00260 unsigned char *output, size_t output_len,
00261 const unsigned char *additional,
00262 size_t add_len );
00263
00277 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
00278
00284 void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
00285
00286 #if defined(MBEDTLS_FS_IO)
00287
00296 int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00297
00309 int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00310 #endif
00311
00312
00313 #if defined(MBEDTLS_SELF_TEST)
00314
00319 int mbedtls_hmac_drbg_self_test( int verbose );
00320 #endif
00321
00322 #ifdef __cplusplus
00323 }
00324 #endif
00325
00326 #endif