36 #ifndef MBEDTLS_CTR_DRBG_H 37 #define MBEDTLS_CTR_DRBG_H 39 #if !defined(MBEDTLS_CONFIG_FILE) 40 #include "mbedtls/config.h" 42 #include MBEDTLS_CONFIG_FILE 47 #if defined(MBEDTLS_THREADING_C) 48 #include "mbedtls/threading.h" 51 #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034 52 #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036 53 #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038 54 #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A 56 #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16 58 #if defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY) 59 #define MBEDTLS_CTR_DRBG_KEYSIZE 16 61 #define MBEDTLS_CTR_DRBG_KEYSIZE 32 64 #define MBEDTLS_CTR_DRBG_KEYBITS ( MBEDTLS_CTR_DRBG_KEYSIZE * 8 ) 65 #define MBEDTLS_CTR_DRBG_SEEDLEN ( MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE ) 76 #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN) 77 #if defined(MBEDTLS_SHA512_C) && !defined(MBEDTLS_ENTROPY_FORCE_SHA256) 78 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48 84 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32 92 #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL) 93 #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000 97 #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT) 98 #define MBEDTLS_CTR_DRBG_MAX_INPUT 256 102 #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST) 103 #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024 107 #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT) 108 #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384 114 #define MBEDTLS_CTR_DRBG_PR_OFF 0 116 #define MBEDTLS_CTR_DRBG_PR_ON 1 148 #if defined(MBEDTLS_THREADING_C) 149 mbedtls_threading_mutex_t mutex;
183 int (*
f_entropy)(
void *,
unsigned char *,
size_t),
185 const unsigned char *custom,
243 const unsigned char *additional,
size_t len );
260 const unsigned char *additional,
281 unsigned char *output,
size_t output_len,
282 const unsigned char *additional,
size_t add_len );
299 unsigned char *output,
size_t output_len );
302 #if ! defined(MBEDTLS_DEPRECATED_REMOVED) 303 #if defined(MBEDTLS_DEPRECATED_WARNING) 304 #define MBEDTLS_DEPRECATED __attribute__((deprecated)) 306 #define MBEDTLS_DEPRECATED 325 const unsigned char *additional,
327 #undef MBEDTLS_DEPRECATED 330 #if defined(MBEDTLS_FS_IO) 359 #if defined(MBEDTLS_SELF_TEST) 367 int mbedtls_ctr_drbg_self_test(
int verbose );
373 int (*)(
void *,
unsigned char *,
size_t),
void *,
374 const unsigned char *,
size_t,
size_t );
The CTR_DRBG context structure.
Definition: ctr_drbg.h:126
int prediction_resistance
Definition: ctr_drbg.h:130
void mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *ctx)
This function clears CTR_CRBG context data.
void mbedtls_ctr_drbg_init(mbedtls_ctr_drbg_context *ctx)
This function initializes the CTR_DRBG context, and prepares it for mbedtls_ctr_drbg_seed() or mbedtl...
size_t entropy_len
Definition: ctr_drbg.h:134
mbedtls_aes_context aes_ctx
Definition: ctr_drbg.h:138
int mbedtls_ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
This function uses CTR_DRBG to generate random data.
void mbedtls_ctr_drbg_set_reseed_interval(mbedtls_ctr_drbg_context *ctx, int interval)
This function sets the reseed interval.
void mbedtls_ctr_drbg_set_prediction_resistance(mbedtls_ctr_drbg_context *ctx, int resistance)
This function turns prediction resistance on or off.
int mbedtls_ctr_drbg_reseed(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
This function reseeds the CTR_DRBG context, that is extracts data from the entropy source...
int(* f_entropy)(void *, unsigned char *, size_t)
Definition: ctr_drbg.h:143
int mbedtls_ctr_drbg_random_with_add(void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len)
This function updates a CTR_DRBG instance with additional data and uses it to generate random data...
int mbedtls_ctr_drbg_update_ret(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
This function updates the state of the CTR_DRBG context.
void mbedtls_ctr_drbg_set_entropy_len(mbedtls_ctr_drbg_context *ctx, size_t len)
This function sets the amount of entropy grabbed on each seed or reseed.
This file contains AES definitions and functions.
int mbedtls_ctr_drbg_seed(mbedtls_ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
This function seeds and sets up the CTR_DRBG entropy source for future reseeds.
unsigned char counter[16]
Definition: ctr_drbg.h:128
int reseed_interval
Definition: ctr_drbg.h:136
MBEDTLS_DEPRECATED void mbedtls_ctr_drbg_update(mbedtls_ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
This function updates the state of the CTR_DRBG context.
void * p_entropy
Definition: ctr_drbg.h:146
The AES context-type definition.
Definition: aes.h:86
int reseed_counter
Definition: ctr_drbg.h:129