29 #ifndef MBEDTLS_CTR_DRBG_H
30 #define MBEDTLS_CTR_DRBG_H
37 #if defined(MBEDTLS_AES_C)
45 #if defined(MBEDTLS_THREADING_C)
50 #define MBEDTLS_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
52 #define MBEDTLS_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
54 #define MBEDTLS_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
56 #define MBEDTLS_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
58 #define MBEDTLS_CTR_DRBG_BLOCKSIZE 16
60 #if defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY)
61 #define MBEDTLS_CTR_DRBG_KEYSIZE 16
68 #define MBEDTLS_CTR_DRBG_KEYSIZE 32
76 #define MBEDTLS_CTR_DRBG_KEYBITS (MBEDTLS_CTR_DRBG_KEYSIZE * 8)
77 #define MBEDTLS_CTR_DRBG_SEEDLEN (MBEDTLS_CTR_DRBG_KEYSIZE + MBEDTLS_CTR_DRBG_BLOCKSIZE)
92 #if !defined(MBEDTLS_CTR_DRBG_ENTROPY_LEN)
93 #if defined(MBEDTLS_ENTROPY_SHA512_ACCUMULATOR)
96 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 48
102 #if !defined(MBEDTLS_CTR_DRBG_USE_128_BIT_KEY)
107 #define MBEDTLS_CTR_DRBG_ENTROPY_LEN 32
111 #if !defined(MBEDTLS_CTR_DRBG_RESEED_INTERVAL)
112 #define MBEDTLS_CTR_DRBG_RESEED_INTERVAL 10000
116 #if !defined(MBEDTLS_CTR_DRBG_MAX_INPUT)
117 #define MBEDTLS_CTR_DRBG_MAX_INPUT 256
121 #if !defined(MBEDTLS_CTR_DRBG_MAX_REQUEST)
122 #define MBEDTLS_CTR_DRBG_MAX_REQUEST 1024
126 #if !defined(MBEDTLS_CTR_DRBG_MAX_SEED_INPUT)
127 #define MBEDTLS_CTR_DRBG_MAX_SEED_INPUT 384
133 #define MBEDTLS_CTR_DRBG_PR_OFF 0
135 #define MBEDTLS_CTR_DRBG_PR_ON 1
142 #if MBEDTLS_CTR_DRBG_ENTROPY_LEN >= MBEDTLS_CTR_DRBG_KEYSIZE * 3 / 2
149 #define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN 0
157 #define MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN (MBEDTLS_CTR_DRBG_ENTROPY_LEN + 1) / 2
160 #if !defined(MBEDTLS_AES_C)
161 typedef struct mbedtls_ctr_drbg_psa_context {
164 } mbedtls_ctr_drbg_psa_context;
192 #if defined(MBEDTLS_AES_C)
206 #if defined(MBEDTLS_THREADING_C)
266 #if MBEDTLS_CTR_DRBG_ENTROPY_NONCE_LEN == 0
278 #if defined(MBEDTLS_THREADING_C)
333 int (*f_entropy)(
void *,
unsigned char *,
size_t),
335 const unsigned char *custom,
447 const unsigned char *additional,
size_t len);
470 const unsigned char *additional,
505 unsigned char *output,
size_t output_len,
506 const unsigned char *additional,
size_t add_len);
514 #if defined(MBEDTLS_THREADING_C)
533 unsigned char *output,
size_t output_len);
535 #if defined(MBEDTLS_FS_IO)
566 #if defined(MBEDTLS_SELF_TEST)
The CTR_DRBG context structure.
int 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 mbedtls_ctr_drbg_free(mbedtls_ctr_drbg_context *ctx)
This function resets CTR_DRBG context to the state immediately after initial call of mbedtls_ctr_drbg...
Platform Security Architecture cryptography module.
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...
#define MBEDTLS_PRIVATE(member)
int mbedtls_ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
This function uses CTR_DRBG to generate random data.
int mbedtls_ctr_drbg_write_seed_file(mbedtls_ctr_drbg_context *ctx, const char *path)
This function writes a seed file.
void mbedtls_ctr_drbg_set_reseed_interval(mbedtls_ctr_drbg_context *ctx, int interval)
This function sets the reseed interval.
Entropy accumulator implementation.
void mbedtls_ctr_drbg_set_prediction_resistance(mbedtls_ctr_drbg_context *ctx, int resistance)
This function turns prediction resistance on or off. The default value is 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...
Threading abstraction layer.
int mbedtls_ctr_drbg_update_seed_file(mbedtls_ctr_drbg_context *ctx, const char *path)
This function reads and updates a seed file. The seed is added to this instance.
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...
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.
Macro wrapper for struct's members.
int mbedtls_ctr_drbg_set_nonce_len(mbedtls_ctr_drbg_context *ctx, size_t len)
This function sets the amount of entropy grabbed as a nonce for the initial seeding.
struct mbedtls_ctr_drbg_context mbedtls_ctr_drbg_context
The CTR_DRBG context structure.
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.
Build-time configuration info.
int mbedtls_ctr_drbg_self_test(int verbose)
The CTR_DRBG checkup routine.