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
00054
00055 #ifndef MBEDTLS_HMAC_DRBG_H
00056 #define MBEDTLS_HMAC_DRBG_H
00057
00058 #if !defined(MBEDTLS_CONFIG_FILE)
00059 #include "config.h"
00060 #else
00061 #include MBEDTLS_CONFIG_FILE
00062 #endif
00063
00064 #include "md.h"
00065
00066 #if defined(MBEDTLS_THREADING_C)
00067 #include "threading.h"
00068 #endif
00069
00070
00071
00072
00073 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
00074 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
00075 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
00076 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
00086 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
00087 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
00088 #endif
00089
00090 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
00091 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
00092 #endif
00093
00094 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
00095 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
00096 #endif
00097
00098 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
00099 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
00100 #endif
00101
00102
00103
00104 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
00105 #define MBEDTLS_HMAC_DRBG_PR_ON 1
00107 #ifdef __cplusplus
00108 extern "C" {
00109 #endif
00110
00114 typedef struct
00115 {
00116
00117
00118 mbedtls_md_context_t md_ctx;
00119 unsigned char V[MBEDTLS_MD_MAX_SIZE];
00120 int reseed_counter;
00122
00123 size_t entropy_len;
00124 int prediction_resistance;
00126 int reseed_interval;
00128
00129 int (*f_entropy)(void *, unsigned char *, size_t);
00130 void *p_entropy;
00132 #if defined(MBEDTLS_THREADING_C)
00133 mbedtls_threading_mutex_t mutex;
00134 #endif
00135 } mbedtls_hmac_drbg_context;
00136
00145 void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
00146
00205 int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
00206 const mbedtls_md_info_t * md_info,
00207 int (*f_entropy)(void *, unsigned char *, size_t),
00208 void *p_entropy,
00209 const unsigned char *custom,
00210 size_t len );
00211
00230 int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
00231 const mbedtls_md_info_t * md_info,
00232 const unsigned char *data, size_t data_len );
00233
00247 void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
00248 int resistance );
00249
00259 void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
00260 size_t len );
00261
00274 void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
00275 int interval );
00276
00289 int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
00290 const unsigned char *additional, size_t add_len );
00291
00305 void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
00306 const unsigned char *additional,
00307 size_t add_len );
00308
00328 int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
00329 const unsigned char *additional, size_t len );
00330
00357 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
00358 unsigned char *output, size_t output_len,
00359 const unsigned char *additional,
00360 size_t add_len );
00361
00380 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
00381
00387 void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
00388
00389 #if defined(MBEDTLS_FS_IO)
00390
00401 int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00402
00417 int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00418 #endif
00419
00420
00421 #if defined(MBEDTLS_SELF_TEST)
00422
00428 int mbedtls_hmac_drbg_self_test( int verbose );
00429 #endif
00430
00431 #ifdef __cplusplus
00432 }
00433 #endif
00434
00435 #endif