PolarSSL v1.3.7
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;
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 */
void hmac_drbg_set_entropy_len(hmac_drbg_context *ctx, size_t len)
Set the amount of entropy grabbed on each reseed (Default: given by the security strength, which depends on the hash used, see hmac_drbg_init() )
int hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len)
HMAC_DRBG generate random.
void hmac_drbg_set_reseed_interval(hmac_drbg_context *ctx, int interval)
Set the reseed interval (Default: POLARSSL_HMAC_DRBG_RESEED_INTERVAL)
int hmac_drbg_reseed(hmac_drbg_context *ctx, const unsigned char *additional, size_t len)
HMAC_DRBG reseeding (extracts data from entropy source)
HMAC_DRBG context.
Definition: hmac_drbg.h:76
void hmac_drbg_free(hmac_drbg_context *ctx)
Free an HMAC_DRBG context.
void * p_entropy
Definition: hmac_drbg.h:92
void hmac_drbg_set_prediction_resistance(hmac_drbg_context *ctx, int resistance)
Enable / disable prediction resistance (Default: Off)
Generic message digest wrapper.
int hmac_drbg_init(hmac_drbg_context *ctx, const md_info_t *md_info, int(*f_entropy)(void *, unsigned char *, size_t), void *p_entropy, const unsigned char *custom, size_t len)
HMAC_DRBG initialisation.
#define POLARSSL_MD_MAX_SIZE
Definition: md.h:67
int hmac_drbg_random_with_add(void *p_rng, unsigned char *output, size_t output_len, const unsigned char *additional, size_t add_len)
HMAC_DRBG generate random with additional update input.
md_context_t md_ctx
Definition: hmac_drbg.h:80
int hmac_drbg_init_buf(hmac_drbg_context *ctx, const md_info_t *md_info, const unsigned char *data, size_t data_len)
Initilisation of simpified HMAC_DRBG (never reseeds).
int prediction_resistance
Definition: hmac_drbg.h:86
void hmac_drbg_update(hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len)
HMAC_DRBG update state.
size_t entropy_len
Definition: hmac_drbg.h:85
Message digest information.
Definition: md.h:74
Generic message digest context.
Definition: md.h:132