PolarSSL v1.3.1
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 #if defined(POLARSSL_SHA512_C)
47 #define CTR_DRBG_ENTROPY_LEN 48
48 #else
49 #define CTR_DRBG_ENTROPY_LEN 32
50 #endif
51 #define CTR_DRBG_RESEED_INTERVAL 10000
52 #define CTR_DRBG_MAX_INPUT 256
53 #define CTR_DRBG_MAX_REQUEST 1024
54 #define CTR_DRBG_MAX_SEED_INPUT 384
55 #endif /* !POLARSSL_CONFIG_OPTIONS */
56 
57 #define CTR_DRBG_PR_OFF 0
58 #define CTR_DRBG_PR_ON 1
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
67 typedef struct
68 {
69  unsigned char counter[16];
71  int prediction_resistance;
73  size_t entropy_len;
78  /*
79  * Callbacks (Entropy)
80  */
81  int (*f_entropy)(void *, unsigned char *, size_t);
82 
83  void *p_entropy;
84 }
86 
105  int (*f_entropy)(void *, unsigned char *, size_t),
106  void *p_entropy,
107  const unsigned char *custom,
108  size_t len );
109 
120  int resistance );
121 
130  size_t len );
131 
140  int interval );
141 
153  const unsigned char *additional, size_t len );
154 
163  const unsigned char *additional, size_t add_len );
164 
180 int ctr_drbg_random_with_add( void *p_rng,
181  unsigned char *output, size_t output_len,
182  const unsigned char *additional, size_t add_len );
183 
197 int ctr_drbg_random( void *p_rng,
198  unsigned char *output, size_t output_len );
199 
200 #if defined(POLARSSL_FS_IO)
201 
210 int ctr_drbg_write_seed_file( ctr_drbg_context *ctx, const char *path );
211 
223 int ctr_drbg_update_seed_file( ctr_drbg_context *ctx, const char *path );
224 #endif
225 
231 int ctr_drbg_self_test( int verbose );
232 
233 /* Internal functions (do not call directly) */
234 int ctr_drbg_init_entropy_len( ctr_drbg_context *, int (*)(void *, unsigned char *, size_t), void *, const unsigned char *, size_t, size_t );
235 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif /* ctr_drbg.h */