PolarSSL v1.1.4
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 
44 #define CTR_DRBG_ENTROPY_LEN 48
45 #define CTR_DRBG_RESEED_INTERVAL 10000
46 #define CTR_DRBG_MAX_INPUT 256
47 #define CTR_DRBG_MAX_REQUEST 1024
48 #define CTR_DRBG_MAX_SEED_INPUT 384
50 #define CTR_DRBG_PR_OFF 0
51 #define CTR_DRBG_PR_ON 1
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
60 typedef struct
61 {
62  unsigned char counter[16];
64  int prediction_resistance;
66  size_t entropy_len;
71  /*
72  * Callbacks (Entropy)
73  */
74  int (*f_entropy)(void *, unsigned char *, size_t);
75 
76  void *p_entropy;
77 }
79 
98  int (*f_entropy)(void *, unsigned char *, size_t),
99  void *p_entropy,
100  const unsigned char *custom,
101  size_t len );
102 
113  int resistance );
114 
123  size_t len );
124 
133  int interval );
134 
146  const unsigned char *additional, size_t len );
147 
156  const unsigned char *additional, size_t add_len );
157 
173 int ctr_drbg_random_with_add( void *p_rng,
174  unsigned char *output, size_t output_len,
175  const unsigned char *additional, size_t add_len );
176 
190 int ctr_drbg_random( void *p_rng,
191  unsigned char *output, size_t output_len );
192 
193 #if defined(POLARSSL_FS_IO)
194 
202 int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path );
203 
214 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
215 #endif
216 
222 int ctr_drbg_self_test( int verbose );
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 #endif /* ctr_drbg.h */