mbed TLS v1.3.16
hmac_drbg.h
Go to the documentation of this file.
1 
24 #ifndef POLARSSL_HMAC_DRBG_H
25 #define POLARSSL_HMAC_DRBG_H
26 
27 #include "md.h"
28 
29 /*
30  * Error codes
31  */
32 #define POLARSSL_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
33 #define POLARSSL_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
34 #define POLARSSL_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
35 #define POLARSSL_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
45 #if !defined(POLARSSL_HMAC_DRBG_RESEED_INTERVAL)
46 #define POLARSSL_HMAC_DRBG_RESEED_INTERVAL 10000
47 #endif
48 
49 #if !defined(POLARSSL_HMAC_DRBG_MAX_INPUT)
50 #define POLARSSL_HMAC_DRBG_MAX_INPUT 256
51 #endif
52 
53 #if !defined(POLARSSL_HMAC_DRBG_MAX_REQUEST)
54 #define POLARSSL_HMAC_DRBG_MAX_REQUEST 1024
55 #endif
56 
57 #if !defined(POLARSSL_HMAC_DRBG_MAX_SEED_INPUT)
58 #define POLARSSL_HMAC_DRBG_MAX_SEED_INPUT 384
59 #endif
60 
61 /* \} name SECTION: Module settings */
62 
63 #define POLARSSL_HMAC_DRBG_PR_OFF 0
64 #define POLARSSL_HMAC_DRBG_PR_ON 1
66 #ifdef __cplusplus
67 extern "C" {
68 #endif
69 
73 typedef struct
74 {
75  /* Working state: the key K is not stored explicitely,
76  * but is implied by the HMAC context */
78  unsigned char V[POLARSSL_MD_MAX_SIZE];
81  /* Administrative state */
82  size_t entropy_len;
87  /* Callbacks */
88  int (*f_entropy)(void *, unsigned char *, size_t);
89  void *p_entropy;
91 
116  const md_info_t * md_info,
117  int (*f_entropy)(void *, unsigned char *, size_t),
118  void *p_entropy,
119  const unsigned char *custom,
120  size_t len );
121 
136  const md_info_t * md_info,
137  const unsigned char *data, size_t data_len );
138 
149  int resistance );
150 
160  size_t len );
161 
170  int interval );
171 
183  const unsigned char *additional, size_t add_len );
184 
196  const unsigned char *additional, size_t len );
197 
214 int hmac_drbg_random_with_add( void *p_rng,
215  unsigned char *output, size_t output_len,
216  const unsigned char *additional,
217  size_t add_len );
218 
232 int hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
233 
239 void hmac_drbg_free( hmac_drbg_context *ctx );
240 
241 #if defined(POLARSSL_FS_IO)
242 
251 int hmac_drbg_write_seed_file( hmac_drbg_context *ctx, const char *path );
252 
264 int hmac_drbg_update_seed_file( hmac_drbg_context *ctx, const char *path );
265 #endif /* POLARSSL_FS_IO */
266 
267 
268 #if defined(POLARSSL_SELF_TEST)
269 
274 int hmac_drbg_self_test( int verbose );
275 #endif
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #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:73
void hmac_drbg_free(hmac_drbg_context *ctx)
Free an HMAC_DRBG context.
void * p_entropy
Definition: hmac_drbg.h:89
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:61
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:77
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:83
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:82
Message digest information.
Definition: md.h:68
Generic message digest context.
Definition: md.h:126