00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 #ifndef MBEDTLS_HMAC_DRBG_H
00054 #define MBEDTLS_HMAC_DRBG_H
00055
00056 #if !defined(MBEDTLS_CONFIG_FILE)
00057 #include "config.h"
00058 #else
00059 #include MBEDTLS_CONFIG_FILE
00060 #endif
00061
00062 #include "md.h"
00063
00064 #if defined(MBEDTLS_THREADING_C)
00065 #include "threading.h"
00066 #endif
00067
00068
00069
00070
00071 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
00072 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
00073 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
00074 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
00084 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
00085 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
00086 #endif
00087
00088 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
00089 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
00090 #endif
00091
00092 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
00093 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
00094 #endif
00095
00096 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
00097 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
00098 #endif
00099
00100
00101
00102 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
00103 #define MBEDTLS_HMAC_DRBG_PR_ON 1
00105 #ifdef __cplusplus
00106 extern "C" {
00107 #endif
00108
00112 typedef struct
00113 {
00114
00115
00116 mbedtls_md_context_t md_ctx;
00117 unsigned char V[MBEDTLS_MD_MAX_SIZE];
00118 int reseed_counter;
00120
00121 size_t entropy_len;
00122 int prediction_resistance;
00124 int reseed_interval;
00126
00127 int (*f_entropy)(void *, unsigned char *, size_t);
00128 void *p_entropy;
00130 #if defined(MBEDTLS_THREADING_C)
00131 mbedtls_threading_mutex_t mutex;
00132 #endif
00133 } mbedtls_hmac_drbg_context;
00134
00143 void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
00144
00203 int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
00204 const mbedtls_md_info_t * md_info,
00205 int (*f_entropy)(void *, unsigned char *, size_t),
00206 void *p_entropy,
00207 const unsigned char *custom,
00208 size_t len );
00209
00228 int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
00229 const mbedtls_md_info_t * md_info,
00230 const unsigned char *data, size_t data_len );
00231
00245 void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
00246 int resistance );
00247
00257 void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
00258 size_t len );
00259
00272 void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
00273 int interval );
00274
00287 int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
00288 const unsigned char *additional, size_t add_len );
00289
00303 void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
00304 const unsigned char *additional,
00305 size_t add_len );
00306
00326 int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
00327 const unsigned char *additional, size_t len );
00328
00355 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
00356 unsigned char *output, size_t output_len,
00357 const unsigned char *additional,
00358 size_t add_len );
00359
00378 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
00379
00385 void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
00386
00387 #if defined(MBEDTLS_FS_IO)
00388
00399 int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00400
00415 int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00416 #endif
00417
00418
00419 #if defined(MBEDTLS_SELF_TEST)
00420
00426 int mbedtls_hmac_drbg_self_test( int verbose );
00427 #endif
00428
00429 #ifdef __cplusplus
00430 }
00431 #endif
00432
00433 #endif