00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef MBEDTLS_HMAC_DRBG_H
00029 #define MBEDTLS_HMAC_DRBG_H
00030
00031 #if !defined(MBEDTLS_CONFIG_FILE)
00032 #include "config.h"
00033 #else
00034 #include MBEDTLS_CONFIG_FILE
00035 #endif
00036
00037 #include "md.h"
00038
00039 #if defined(MBEDTLS_THREADING_C)
00040 #include "threading.h"
00041 #endif
00042
00043
00044
00045
00046 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
00047 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
00048 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
00049 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
00059 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
00060 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
00061 #endif
00062
00063 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
00064 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
00065 #endif
00066
00067 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
00068 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
00069 #endif
00070
00071 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
00072 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
00073 #endif
00074
00075
00076
00077 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
00078 #define MBEDTLS_HMAC_DRBG_PR_ON 1
00080 #ifdef __cplusplus
00081 extern "C" {
00082 #endif
00083
00087 typedef struct
00088 {
00089
00090
00091 mbedtls_md_context_t md_ctx;
00092 unsigned char V[MBEDTLS_MD_MAX_SIZE];
00093 int reseed_counter;
00095
00096 size_t entropy_len;
00097 int prediction_resistance;
00099 int reseed_interval;
00101
00102 int (*f_entropy)(void *, unsigned char *, size_t);
00103 void *p_entropy;
00105 #if defined(MBEDTLS_THREADING_C)
00106 mbedtls_threading_mutex_t mutex;
00107 #endif
00108 } mbedtls_hmac_drbg_context;
00109
00118 void mbedtls_hmac_drbg_init( mbedtls_hmac_drbg_context *ctx );
00119
00178 int mbedtls_hmac_drbg_seed( mbedtls_hmac_drbg_context *ctx,
00179 const mbedtls_md_info_t * md_info,
00180 int (*f_entropy)(void *, unsigned char *, size_t),
00181 void *p_entropy,
00182 const unsigned char *custom,
00183 size_t len );
00184
00203 int mbedtls_hmac_drbg_seed_buf( mbedtls_hmac_drbg_context *ctx,
00204 const mbedtls_md_info_t * md_info,
00205 const unsigned char *data, size_t data_len );
00206
00220 void mbedtls_hmac_drbg_set_prediction_resistance( mbedtls_hmac_drbg_context *ctx,
00221 int resistance );
00222
00232 void mbedtls_hmac_drbg_set_entropy_len( mbedtls_hmac_drbg_context *ctx,
00233 size_t len );
00234
00247 void mbedtls_hmac_drbg_set_reseed_interval( mbedtls_hmac_drbg_context *ctx,
00248 int interval );
00249
00262 int mbedtls_hmac_drbg_update_ret( mbedtls_hmac_drbg_context *ctx,
00263 const unsigned char *additional, size_t add_len );
00264
00278 void mbedtls_hmac_drbg_update( mbedtls_hmac_drbg_context *ctx,
00279 const unsigned char *additional,
00280 size_t add_len );
00281
00301 int mbedtls_hmac_drbg_reseed( mbedtls_hmac_drbg_context *ctx,
00302 const unsigned char *additional, size_t len );
00303
00330 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
00331 unsigned char *output, size_t output_len,
00332 const unsigned char *additional,
00333 size_t add_len );
00334
00353 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
00354
00360 void mbedtls_hmac_drbg_free( mbedtls_hmac_drbg_context *ctx );
00361
00362 #if defined(MBEDTLS_FS_IO)
00363
00374 int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00375
00390 int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
00391 #endif
00392
00393
00394 #if defined(MBEDTLS_SELF_TEST)
00395
00401 int mbedtls_hmac_drbg_self_test( int verbose );
00402 #endif
00403
00404 #ifdef __cplusplus
00405 }
00406 #endif
00407
00408 #endif