27 #ifndef POLARSSL_CTR_DRBG_H
28 #define POLARSSL_CTR_DRBG_H
34 #define POLARSSL_ERR_CTR_DRBG_ENTROPY_SOURCE_FAILED -0x0034
35 #define POLARSSL_ERR_CTR_DRBG_REQUEST_TOO_BIG -0x0036
36 #define POLARSSL_ERR_CTR_DRBG_INPUT_TOO_BIG -0x0038
37 #define POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR -0x003A
39 #define CTR_DRBG_BLOCKSIZE 16
40 #define CTR_DRBG_KEYSIZE 32
41 #define CTR_DRBG_KEYBITS ( CTR_DRBG_KEYSIZE * 8 )
42 #define CTR_DRBG_SEEDLEN ( CTR_DRBG_KEYSIZE + CTR_DRBG_BLOCKSIZE )
53 #if !defined(CTR_DRBG_ENTROPY_LEN)
54 #if defined(POLARSSL_SHA512_C) && !defined(POLARSSL_ENTROPY_FORCE_SHA256)
55 #define CTR_DRBG_ENTROPY_LEN 48
57 #define CTR_DRBG_ENTROPY_LEN 32
61 #if !defined(CTR_DRBG_RESEED_INTERVAL)
62 #define CTR_DRBG_RESEED_INTERVAL 10000
65 #if !defined(CTR_DRBG_MAX_INPUT)
66 #define CTR_DRBG_MAX_INPUT 256
69 #if !defined(CTR_DRBG_MAX_REQUEST)
70 #define CTR_DRBG_MAX_REQUEST 1024
73 #if !defined(CTR_DRBG_MAX_SEED_INPUT)
74 #define CTR_DRBG_MAX_SEED_INPUT 384
79 #define CTR_DRBG_PR_OFF 0
80 #define CTR_DRBG_PR_ON 1
91 unsigned char counter[16];
104 int (*f_entropy)(
void *,
unsigned char *, size_t);
128 int (*f_entropy)(
void *,
unsigned char *,
size_t),
130 const unsigned char *custom,
176 const unsigned char *additional,
size_t len );
186 const unsigned char *additional,
size_t add_len );
204 unsigned char *output,
size_t output_len,
205 const unsigned char *additional,
size_t add_len );
221 unsigned char *output,
size_t output_len );
223 #if defined(POLARSSL_FS_IO)
260 int (*)(
void *,
unsigned char *,
size_t),
void *,
261 const unsigned char *,
size_t,
size_t );
int ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
CTR_DRBG generate random.
void ctr_drbg_set_prediction_resistance(ctr_drbg_context *ctx, int resistance)
Enable / disable prediction resistance (Default: Off)
int ctr_drbg_init_entropy_len(ctr_drbg_context *, int(*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t, size_t)
int prediction_resistance
int ctr_drbg_random_with_add(void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len)
CTR_DRBG generate random with additional update input.
int ctr_drbg_reseed(ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
CTR_DRBG reseeding (extracts data from entropy source)
CTR_DRBG context structure.
void ctr_drbg_set_reseed_interval(ctr_drbg_context *ctx, int interval)
Set the reseed interval (Default: CTR_DRBG_RESEED_INTERVAL)
int ctr_drbg_update_seed_file(ctr_drbg_context *ctx, const char *path)
Read and update a seed file.
void ctr_drbg_set_entropy_len(ctr_drbg_context *ctx, size_t len)
Set the amount of entropy grabbed on each (re)seed (Default: CTR_DRBG_ENTROPY_LEN) ...
int ctr_drbg_self_test(int verbose)
Checkup routine.
int ctr_drbg_init(ctr_drbg_context *ctx, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
CTR_DRBG initialization.
int ctr_drbg_write_seed_file(ctr_drbg_context *ctx, const char *path)
Write a seed file.
void ctr_drbg_update(ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
CTR_DRBG update state.