mbed TLS v2.6.0
hmac_drbg.h
Go to the documentation of this file.
1 
25 #ifndef MBEDTLS_HMAC_DRBG_H
26 #define MBEDTLS_HMAC_DRBG_H
27 
28 #include "md.h"
29 
30 #if defined(MBEDTLS_THREADING_C)
31 #include "mbedtls/threading.h"
32 #endif
33 
34 /*
35  * Error codes
36  */
37 #define MBEDTLS_ERR_HMAC_DRBG_REQUEST_TOO_BIG -0x0003
38 #define MBEDTLS_ERR_HMAC_DRBG_INPUT_TOO_BIG -0x0005
39 #define MBEDTLS_ERR_HMAC_DRBG_FILE_IO_ERROR -0x0007
40 #define MBEDTLS_ERR_HMAC_DRBG_ENTROPY_SOURCE_FAILED -0x0009
50 #if !defined(MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
51 #define MBEDTLS_HMAC_DRBG_RESEED_INTERVAL 10000
52 #endif
53 
54 #if !defined(MBEDTLS_HMAC_DRBG_MAX_INPUT)
55 #define MBEDTLS_HMAC_DRBG_MAX_INPUT 256
56 #endif
57 
58 #if !defined(MBEDTLS_HMAC_DRBG_MAX_REQUEST)
59 #define MBEDTLS_HMAC_DRBG_MAX_REQUEST 1024
60 #endif
61 
62 #if !defined(MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT)
63 #define MBEDTLS_HMAC_DRBG_MAX_SEED_INPUT 384
64 #endif
65 
66 /* \} name SECTION: Module settings */
67 
68 #define MBEDTLS_HMAC_DRBG_PR_OFF 0
69 #define MBEDTLS_HMAC_DRBG_PR_ON 1
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
78 typedef struct
79 {
80  /* Working state: the key K is not stored explicitely,
81  * but is implied by the HMAC context */
83  unsigned char V[MBEDTLS_MD_MAX_SIZE];
86  /* Administrative state */
87  size_t entropy_len;
92  /* Callbacks */
93  int (*f_entropy)(void *, unsigned char *, size_t);
94  void *p_entropy;
96 #if defined(MBEDTLS_THREADING_C)
97  mbedtls_threading_mutex_t mutex;
98 #endif
100 
110 
136  const mbedtls_md_info_t * md_info,
137  int (*f_entropy)(void *, unsigned char *, size_t),
138  void *p_entropy,
139  const unsigned char *custom,
140  size_t len );
141 
156  const mbedtls_md_info_t * md_info,
157  const unsigned char *data, size_t data_len );
158 
169  int resistance );
170 
180  size_t len );
181 
190  int interval );
191 
203  const unsigned char *additional, size_t add_len );
204 
216  const unsigned char *additional, size_t len );
217 
234 int mbedtls_hmac_drbg_random_with_add( void *p_rng,
235  unsigned char *output, size_t output_len,
236  const unsigned char *additional,
237  size_t add_len );
238 
252 int mbedtls_hmac_drbg_random( void *p_rng, unsigned char *output, size_t out_len );
253 
260 
261 #if defined(MBEDTLS_FS_IO)
262 
271 int mbedtls_hmac_drbg_write_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
272 
284 int mbedtls_hmac_drbg_update_seed_file( mbedtls_hmac_drbg_context *ctx, const char *path );
285 #endif /* MBEDTLS_FS_IO */
286 
287 
288 #if defined(MBEDTLS_SELF_TEST)
289 
294 int mbedtls_hmac_drbg_self_test( int verbose );
295 #endif
296 
297 #ifdef __cplusplus
298 }
299 #endif
300 
301 #endif /* hmac_drbg.h */
int mbedtls_hmac_drbg_seed(mbedtls_hmac_drbg_context *ctx, const mbedtls_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 initial seeding Seed and setup entropy source for future reseeds.
#define MBEDTLS_MD_MAX_SIZE
Definition: md.h:57
int mbedtls_hmac_drbg_seed_buf(mbedtls_hmac_drbg_context *ctx, const mbedtls_md_info_t *md_info, const unsigned char *data, size_t data_len)
Initilisation of simpified HMAC_DRBG (never reseeds).
void mbedtls_hmac_drbg_set_reseed_interval(mbedtls_hmac_drbg_context *ctx, int interval)
Set the reseed interval (Default: MBEDTLS_HMAC_DRBG_RESEED_INTERVAL)
HMAC_DRBG context.
Definition: hmac_drbg.h:78
void mbedtls_hmac_drbg_free(mbedtls_hmac_drbg_context *ctx)
Free an HMAC_DRBG context.
int mbedtls_hmac_drbg_random(void *p_rng, unsigned char *output, size_t out_len)
HMAC_DRBG generate random.
Generic message digest context.
Definition: md.h:68
Threading abstraction layer.
void mbedtls_hmac_drbg_update(mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t add_len)
HMAC_DRBG update state.
Generic message digest wrapper.
void mbedtls_hmac_drbg_init(mbedtls_hmac_drbg_context *ctx)
HMAC_DRBG context initialization Makes the context ready for mbedtls_hmac_drbg_seed(), mbedtls_hmac_drbg_seed_buf() or mbedtls_hmac_drbg_free().
int mbedtls_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.
int mbedtls_hmac_drbg_reseed(mbedtls_hmac_drbg_context *ctx, const unsigned char *additional, size_t len)
HMAC_DRBG reseeding (extracts data from entropy source)
struct mbedtls_md_info_t mbedtls_md_info_t
Opaque struct defined in md_internal.h.
Definition: md.h:63
mbedtls_md_context_t md_ctx
Definition: hmac_drbg.h:82
void mbedtls_hmac_drbg_set_entropy_len(mbedtls_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 mbedtls_hmac_drbg_init() )
void mbedtls_hmac_drbg_set_prediction_resistance(mbedtls_hmac_drbg_context *ctx, int resistance)
Enable / disable prediction resistance (Default: Off)