PolarSSL v1.2.12
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 )
43 
45 #if !defined(POLARSSL_CONFIG_OPTIONS)
46 #define CTR_DRBG_ENTROPY_LEN 48
47 #define CTR_DRBG_RESEED_INTERVAL 10000
48 #define CTR_DRBG_MAX_INPUT 256
49 #define CTR_DRBG_MAX_REQUEST 1024
50 #define CTR_DRBG_MAX_SEED_INPUT 384
51 #endif /* !POLARSSL_CONFIG_OPTIONS */
52 
53 #define CTR_DRBG_PR_OFF 0
54 #define CTR_DRBG_PR_ON 1
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
63 typedef struct
64 {
65  unsigned char counter[16];
69  size_t entropy_len;
74  /*
75  * Callbacks (Entropy)
76  */
77  int (*f_entropy)(void *, unsigned char *, size_t);
78 
79  void *p_entropy;
80 }
82 
101  int (*f_entropy)(void *, unsigned char *, size_t),
102  void *p_entropy,
103  const unsigned char *custom,
104  size_t len );
105 
116  int resistance );
117 
126  size_t len );
127 
136  int interval );
137 
149  const unsigned char *additional, size_t len );
150 
159  const unsigned char *additional, size_t add_len );
160 
176 int ctr_drbg_random_with_add( void *p_rng,
177  unsigned char *output, size_t output_len,
178  const unsigned char *additional, size_t add_len );
179 
193 int ctr_drbg_random( void *p_rng,
194  unsigned char *output, size_t output_len );
195 
196 #if defined(POLARSSL_FS_IO)
197 
206 int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path );
207 
219 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
220 #endif
221 
227 int ctr_drbg_self_test( int verbose );
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif /* ctr_drbg.h */
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 reseed_counter
Definition: ctr_drbg.h:66
AES context structure.
Definition: aes.h:54
int prediction_resistance
Definition: ctr_drbg.h:67
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.
size_t entropy_len
Definition: ctr_drbg.h:69
AES block cipher.
int ctr_drbg_reseed(ctr_drbg_context *ctx, const unsigned char *additional, size_t len)
CTR_DRBG reseeding (extracts data from entropy source)
int reseed_interval
Definition: ctr_drbg.h:70
CTR_DRBG context structure.
Definition: ctr_drbg.h:63
void * p_entropy
Definition: ctr_drbg.h:79
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.
aes_context aes_ctx
Definition: ctr_drbg.h:72
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.