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 )
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];
93  int prediction_resistance;
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 
138 void ctr_drbg_free( ctr_drbg_context *ctx );
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 
210 int ctr_drbg_random_with_add( void *p_rng,
211  unsigned char *output, size_t output_len,
212  const unsigned char *additional, size_t add_len );
213 
227 int ctr_drbg_random( void *p_rng,
228  unsigned char *output, size_t output_len );
229 
230 #if defined(POLARSSL_FS_IO)
231 
241 int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path );
242 
255 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
256 #endif /* POLARSSL_FS_IO */
257 
263 int 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 */