PolarSSL v1.3.9
ctr_drbg.h
Go to the documentation of this file.
1
27#ifndef POLARSSL_CTR_DRBG_H
28#define POLARSSL_CTR_DRBG_H
29
30#include <string.h>
31
32#include "aes.h"
33
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
56#else
57#define CTR_DRBG_ENTROPY_LEN 32
58#endif
59#endif
60
61#if !defined(CTR_DRBG_RESEED_INTERVAL)
62#define CTR_DRBG_RESEED_INTERVAL 10000
63#endif
64
65#if !defined(CTR_DRBG_MAX_INPUT)
66#define CTR_DRBG_MAX_INPUT 256
67#endif
68
69#if !defined(CTR_DRBG_MAX_REQUEST)
70#define CTR_DRBG_MAX_REQUEST 1024
71#endif
72
73#if !defined(CTR_DRBG_MAX_SEED_INPUT)
74#define CTR_DRBG_MAX_SEED_INPUT 384
75#endif
76
77/* \} name SECTION: Module settings */
78
79#define CTR_DRBG_PR_OFF 0
80#define CTR_DRBG_PR_ON 1
82#ifdef __cplusplus
83extern "C" {
84#endif
85
89typedef struct
90{
91 unsigned char counter[16];
95 size_t entropy_len;
101 /*
102 * Callbacks (Entropy)
103 */
104 int (*f_entropy)(void *, unsigned char *, size_t);
105
106 void *p_entropy;
107}
109
128 int (*f_entropy)(void *, unsigned char *, size_t),
129 void *p_entropy,
130 const unsigned char *custom,
131 size_t len );
132
139
150 int resistance );
151
160 size_t len );
161
170 int interval );
171
183 const unsigned char *additional, size_t len );
184
193 const unsigned char *additional, size_t add_len );
194
211 unsigned char *output, size_t output_len,
212 const unsigned char *additional, size_t add_len );
213
227int ctr_drbg_random( void *p_rng,
228 unsigned char *output, size_t output_len );
229
230#if defined(POLARSSL_FS_IO)
241int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path );
242
255int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
256#endif /* POLARSSL_FS_IO */
257
263int ctr_drbg_self_test( int verbose );
264
265/* Internal functions (do not call directly) */
267 int (*)(void *, unsigned char *, size_t), void *,
268 const unsigned char *, size_t, size_t );
269
270#ifdef __cplusplus
271}
272#endif
273
274#endif /* ctr_drbg.h */
AES block cipher.
void ctr_drbg_set_prediction_resistance(ctr_drbg_context *ctx, int resistance)
Enable / disable prediction resistance (Default: Off)
int ctr_drbg_update_seed_file(ctr_drbg_context *ctx, const char *path)
Read and update a seed file.
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_init_entropy_len(ctr_drbg_context *, int(*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t, size_t)
int ctr_drbg_write_seed_file(ctr_drbg_context *ctx, const char *path)
Write a seed file.
int ctr_drbg_random(void *p_rng, unsigned char *output, size_t output_len)
CTR_DRBG generate random.
void ctr_drbg_set_reseed_interval(ctr_drbg_context *ctx, int interval)
Set the reseed interval (Default: CTR_DRBG_RESEED_INTERVAL)
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)
void ctr_drbg_update(ctr_drbg_context *ctx, const unsigned char *additional, size_t add_len)
CTR_DRBG update state.
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_self_test(int verbose)
Checkup routine.
void ctr_drbg_free(ctr_drbg_context *ctx)
Clear CTR_CRBG context data.
int ctr_drbg_reseed(ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
CTR_DRBG reseeding (extracts data from entropy source)
AES context structure.
Definition: aes.h:69
CTR_DRBG context structure.
Definition: ctr_drbg.h:90
size_t entropy_len
Definition: ctr_drbg.h:95
aes_context aes_ctx
Definition: ctr_drbg.h:99
int prediction_resistance
Definition: ctr_drbg.h:93
void * p_entropy
Definition: ctr_drbg.h:106
int reseed_counter
Definition: ctr_drbg.h:92
int reseed_interval
Definition: ctr_drbg.h:97