PolarSSL v1.3.8
hmac_drbg.h
Go to the documentation of this file.
1 
27 #ifndef POLARSSL_HMAC_DRBG_H
28 #define POLARSSL_HMAC_DRBG_H
29 
30 #include "md.h"
31 
32 /*
33  * Error codes
34  */
35 #define POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
36 #define POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
37 #define POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
38 #define POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
48 #if !defined(POLARSSL_HMAC_DRBG_RESEED_INTERVAL)
49 #define POLARSSL_HMAC_DRBG_RESEED_INTERVAL 10000
50 #endif
51 
52 #if !defined(POLARSSL_HMAC_DRBG_MAX_INPUT)
53 #define POLARSSL_HMAC_DRBG_MAX_INPUT 256
54 #endif
55 
56 #if !defined(POLARSSL_HMAC_DRBG_MAX_REQUEST)
57 #define POLARSSL_HMAC_DRBG_MAX_REQUEST 1024
58 #endif
59 
60 #if !defined(POLARSSL_HMAC_DRBG_MAX_SEED_INPUT)
61 #define POLARSSL_HMAC_DRBG_MAX_SEED_INPUT 384
62 #endif
63 
64 /* \} name SECTION: Module settings */
65 
66 #define POLARSSL_HMAC_DRBG_PR_OFF 0
67 #define POLARSSL_HMAC_DRBG_PR_ON 1
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 
76 typedef struct
77 {
78  /* Working state: the key K is not stored explicitely,
79  * but is implied by the HMAC context */
81  unsigned char V[POLARSSL_MD_MAX_SIZE];
84  /* Administrative state */
85  size_t entropy_len;
86  int prediction_resistance;
90  /* Callbacks */
91  int (*f_entropy)(void *, unsigned char *, size_t);
92  void *p_entropy;
94 
119  const md_info_t * md_info,
120  int (*f_entropy)(void *, unsigned char *, size_t),
121  void *p_entropy,
122  const unsigned char *custom,
123  size_t len );
124 
139  const md_info_t * md_info,
140  const unsigned char *data, size_t data_len );
141 
152  int resistance );
153 
163  size_t len );
164 
173  int interval );
174 
186  const unsigned char *additional, size_t add_len );
187 
199  const unsigned char *additional, size_t len );
200 
217 int hmac_drbg_random_with_add( void *p_rng,
218  unsigned char *output, size_t output_len,
219  const unsigned char *additional,
220  size_t add_len );
221 
235 int hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
236 
242 void hmac_drbg_free( hmac_drbg_context *ctx );
243 
244 #if defined(POLARSSL_FS_IO)
245 
254 int hmac_drbg_write_seed_file( hmac_drbg_context *ctx, const char *path );
255 
267 int hmac_drbg_update_seed_file( hmac_drbg_context *ctx, const char *path );
268 #endif /* POLARSSL_FS_IO */
269 
270 
271 #if defined(POLARSSL_SELF_TEST)
272 
277 int hmac_drbg_self_test( int verbose );
278 #endif
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 #endif /* hmac_drbg.h */