PolarSSL v1.3.7
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 
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
83 extern "C" {
84 #endif
85 
89 typedef 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 
143  int resistance );
144 
153  size_t len );
154 
163  int interval );
164 
176  const unsigned char *additional, size_t len );
177 
186  const unsigned char *additional, size_t add_len );
187 
203 int ctr_drbg_random_with_add( void *p_rng,
204  unsigned char *output, size_t output_len,
205  const unsigned char *additional, size_t add_len );
206 
220 int ctr_drbg_random( void *p_rng,
221  unsigned char *output, size_t output_len );
222 
223 #if defined(POLARSSL_FS_IO)
224 
234 int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path );
235 
248 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
249 #endif /* POLARSSL_FS_IO */
250 
256 int ctr_drbg_self_test( int verbose );
257 
258 /* Internal functions (do not call directly) */
260  int (*)(void *, unsigned char *, size_t), void *,
261  const unsigned char *, size_t, size_t );
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #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:92
AES context structure.
Definition: aes.h:68
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
Definition: ctr_drbg.h:93
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:95
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:97
CTR_DRBG context structure.
Definition: ctr_drbg.h:89
void * p_entropy
Definition: ctr_drbg.h:106
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:99
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.